From f7f197c40941ffaf03fcddeb20536dec8074ca00 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 21 Dec 2014 11:42:44 -0300 Subject: [PATCH] -ability to set default textures in shader (needed for visual shader editing) -work in progress new graph system (will replace current one) -crash fix in s3m loader (out of bounds acess) -fixed vbox overriding of separation (fixes empty line between section tabs) --- drivers/chibi/cp_loader_s3m.cpp | 2 +- drivers/gles1/rasterizer_gles1.cpp | 10 + drivers/gles1/rasterizer_gles1.h | 3 + drivers/gles2/rasterizer_gles2.cpp | 49 ++++- drivers/gles2/rasterizer_gles2.h | 3 + platform/x11/os_x11.cpp | 8 +- scene/gui/box_container.cpp | 4 +- scene/gui/graph_node.cpp | 183 +++++++++++++++--- scene/gui/graph_node.h | 23 ++- scene/register_scene_types.cpp | 2 + .../resources/default_theme/default_theme.cpp | 12 +- scene/resources/default_theme/graph_node.png | Bin 734 -> 770 bytes scene/resources/default_theme/graph_port.png | Bin 0 -> 509 bytes scene/resources/default_theme/theme_data.h | 10 + scene/resources/shader.cpp | 43 ++++ scene/resources/shader.h | 7 +- servers/visual/rasterizer.h | 4 + servers/visual/rasterizer_dummy.cpp | 10 + servers/visual/rasterizer_dummy.h | 4 + servers/visual/visual_server_raster.cpp | 10 + servers/visual/visual_server_raster.h | 4 + servers/visual/visual_server_wrap_mt.h | 4 + servers/visual_server.h | 4 + 23 files changed, 353 insertions(+), 46 deletions(-) create mode 100644 scene/resources/default_theme/graph_port.png diff --git a/drivers/chibi/cp_loader_s3m.cpp b/drivers/chibi/cp_loader_s3m.cpp index c5f0830ae6f..8b9871463fb 100644 --- a/drivers/chibi/cp_loader_s3m.cpp +++ b/drivers/chibi/cp_loader_s3m.cpp @@ -162,7 +162,7 @@ CPLoader::Error CPLoader_S3M::load_sample(CPSample *p_sample) { p_sample->set_default_volume(def_volume); p_sample->set_name(name); - char scrs[4]; + char scrs[5]; file->get_byte_array((uint8_t*)scrs,4); scrs[4]=0; diff --git a/drivers/gles1/rasterizer_gles1.cpp b/drivers/gles1/rasterizer_gles1.cpp index 00fc85c41c3..902c105d64c 100644 --- a/drivers/gles1/rasterizer_gles1.cpp +++ b/drivers/gles1/rasterizer_gles1.cpp @@ -1021,6 +1021,16 @@ void RasterizerGLES1::shader_get_param_list(RID p_shader, List *p_ } + +void RasterizerGLES1::shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture) { + +} + +RID RasterizerGLES1::shader_get_default_texture_param(RID p_shader, const StringName& p_name) const { + + return RID(); +} + /* COMMON MATERIAL API */ diff --git a/drivers/gles1/rasterizer_gles1.h b/drivers/gles1/rasterizer_gles1.h index 0995089dd7f..d3e38f3dedc 100644 --- a/drivers/gles1/rasterizer_gles1.h +++ b/drivers/gles1/rasterizer_gles1.h @@ -875,6 +875,9 @@ public: virtual void shader_get_param_list(RID p_shader, List *p_param_list) const; + virtual void shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture); + virtual RID shader_get_default_texture_param(RID p_shader, const StringName& p_name) const; + /* COMMON MATERIAL API */ virtual RID material_create(); diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index 9f2fd032fa3..9d47084c1c7 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -1539,6 +1539,29 @@ void RasterizerGLES2::shader_get_param_list(RID p_shader, List *p_ } +void RasterizerGLES2::shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture) { + + Shader *shader=shader_owner.get(p_shader); + ERR_FAIL_COND(!shader); + ERR_FAIL_COND(!texture_owner.owns(p_texture)); + + if (p_texture.is_valid()) + shader->default_textures[p_name]=p_texture; + else + shader->default_textures.erase(p_name); + +} + +RID RasterizerGLES2::shader_get_default_texture_param(RID p_shader, const StringName& p_name) const{ + const Shader *shader=shader_owner.get(p_shader); + + const Map::Element *E=shader->default_textures.find(p_name); + if (!E) + return RID(); + return E->get(); +} + + /* COMMON MATERIAL API */ @@ -4991,9 +5014,26 @@ bool RasterizerGLES2::_setup_material(const Geometry *p_geometry,const Material Texture *t=NULL; if (rid.is_valid()) { + t=texture_owner.get(rid); - if (!t) + if (!t) { E->get().value=RID(); //nullify, invalid texture + rid=RID(); + } + } else { + + + } + + if (!rid.is_valid()) { + //use from default textures + Map::Element *F=p_material->shader_cache->default_textures.find(E->key()); + if (F) { + t=texture_owner.get(F->get()); + if (!t) { + p_material->shader_cache->default_textures.erase(E->key()); + } + } } @@ -5020,6 +5060,13 @@ bool RasterizerGLES2::_setup_material(const Geometry *p_geometry,const Material } + for (Map::Element *E=p_material->shader_cache->default_textures.front();E;E=E->next()) { + if (p_material->shader_params.has(E->key())) + continue; + + + } + if (p_material->shader_cache->has_texscreen && framebuffer.active) { material_shader.set_uniform(MaterialShaderGLES2::TEXSCREEN_SCREEN_MULT,Vector2(float(viewport.width)/framebuffer.width,float(viewport.height)/framebuffer.height)); material_shader.set_uniform(MaterialShaderGLES2::TEXSCREEN_TEX,texcoord); diff --git a/drivers/gles2/rasterizer_gles2.h b/drivers/gles2/rasterizer_gles2.h index 27f7848b136..dc596f9f6ca 100644 --- a/drivers/gles2/rasterizer_gles2.h +++ b/drivers/gles2/rasterizer_gles2.h @@ -195,6 +195,7 @@ class RasterizerGLES2 : public Rasterizer { Map uniforms; StringName first_texture; + Map default_textures; SelfList dirty_list; @@ -1255,6 +1256,8 @@ public: virtual void shader_get_param_list(RID p_shader, List *p_param_list) const; + virtual void shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture); + virtual RID shader_get_default_texture_param(RID p_shader, const StringName& p_name) const; /* COMMON MATERIAL API */ diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 804809a87dc..aa9e4c63c9b 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -1458,14 +1458,14 @@ OS_X11::OS_X11() { AudioDriverManagerSW::add_driver(&driver_rtaudio); #endif -#ifdef ALSA_ENABLED - AudioDriverManagerSW::add_driver(&driver_alsa); -#endif - #ifdef PULSEAUDIO_ENABLED AudioDriverManagerSW::add_driver(&driver_pulseaudio); #endif +#ifdef ALSA_ENABLED + AudioDriverManagerSW::add_driver(&driver_alsa); +#endif + minimized = false; xim_style=NULL; mouse_mode=MOUSE_MODE_VISIBLE; diff --git a/scene/gui/box_container.cpp b/scene/gui/box_container.cpp index 216c6d71226..5ed60e88f8b 100644 --- a/scene/gui/box_container.cpp +++ b/scene/gui/box_container.cpp @@ -44,7 +44,7 @@ void BoxContainer::_resort() { Size2i new_size=get_size();; - int sep=get_constant("separation",vertical?"VBoxContainer":"HBoxContainer"); + int sep=get_constant("separation");//,vertical?"VBoxContainer":"HBoxContainer"); bool first=true; int children_count=0; @@ -202,7 +202,7 @@ Size2 BoxContainer::get_minimum_size() const { /* Calculate MINIMUM SIZE */ Size2i minimum; - int sep=get_constant("separation",vertical?"VBoxContainer":"HBoxContainer"); + int sep=get_constant("separation");//,vertical?"VBoxContainer":"HBoxContainer"); bool first=true; diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp index 96f8828efcc..6e3afeefd01 100644 --- a/scene/gui/graph_node.cpp +++ b/scene/gui/graph_node.cpp @@ -1,6 +1,98 @@ #include "graph_node.h" +bool GraphNode::_set(const StringName& p_name, const Variant& p_value) { + + if (!p_name.operator String().begins_with("slot/")) + return false; + + int idx=p_name.operator String().get_slice("/",1).to_int(); + String what = p_name.operator String().get_slice("/",2); + + + Slot si; + if (slot_info.has(idx)) + si=slot_info[idx]; + + + if (what=="left_enabled") + si.enable_left=p_value; + else if (what=="left_type") + si.type_left=p_value; + else if (what=="left_color") + si.color_left=p_value; + else if (what=="right_enabled") + si.enable_right=p_value; + else if (what=="right_type") + si.type_right=p_value; + else if (what=="right_color") + si.color_right=p_value; + else + return false; + + set_slot(idx,si.enable_left,si.type_left,si.color_left,si.enable_right,si.type_right,si.color_right); + update(); + return true; +} + +bool GraphNode::_get(const StringName& p_name,Variant &r_ret) const{ + + + print_line("get "+p_name.operator String()); + if (!p_name.operator String().begins_with("slot/")) { + print_line("no begins"); + return false; + } + + int idx=p_name.operator String().get_slice("/",1).to_int(); + String what = p_name.operator String().get_slice("/",2); + + + + Slot si; + if (slot_info.has(idx)) + si=slot_info[idx]; + + if (what=="left_enabled") + r_ret=si.enable_left; + else if (what=="left_type") + r_ret=si.type_left; + else if (what=="left_color") + r_ret=si.color_left; + else if (what=="right_enabled") + r_ret=si.enable_right; + else if (what=="right_type") + r_ret=si.type_right; + else if (what=="right_color") + r_ret=si.color_right; + else + return false; + + print_line("ask for: "+p_name.operator String()+" get: "+String(r_ret)); + return true; +} +void GraphNode::_get_property_list( List *p_list) const{ + + int idx=0; + for(int i=0;icast_to(); + if (!c || c->is_set_as_toplevel() || !c->get_owner()) + continue; + + String base="slot/"+itos(idx)+"/"; + + p_list->push_back(PropertyInfo(Variant::BOOL,base+"left_enabled")); + p_list->push_back(PropertyInfo(Variant::INT,base+"left_type")); + p_list->push_back(PropertyInfo(Variant::COLOR,base+"left_color")); + p_list->push_back(PropertyInfo(Variant::BOOL,base+"right_enabled")); + p_list->push_back(PropertyInfo(Variant::INT,base+"right_type")); + p_list->push_back(PropertyInfo(Variant::COLOR,base+"right_color")); + + idx++; + } +} + + void GraphNode::_resort() { @@ -13,7 +105,7 @@ void GraphNode::_resort() { for(int i=0;icast_to(); - if (!c || !c->is_visible()) + if (!c) continue; if (c->is_set_as_toplevel()) continue; @@ -34,11 +126,12 @@ void GraphNode::_resort() { int w = get_size().x - sb->get_minimum_size().x; + cache_y.clear(); for(int i=0;icast_to(); - if (!c || !c->is_visible()) + if (!c) continue; - if (c->is_set_as_toplevel()) + if (c->is_set_as_toplevel() || !c->get_owner()) continue; Size2i size=c->get_combined_minimum_size(); @@ -46,14 +139,18 @@ void GraphNode::_resort() { Rect2 r(sb->get_margin(MARGIN_LEFT),sb->get_margin(MARGIN_TOP)+vofs,w,size.y); fit_child_in_rect(c,r); - + cache_y.push_back(vofs+size.y*0.5); if (vofs>0) vofs+=sep; vofs+=size.y; + } + _change_notify(); + update(); + } @@ -62,7 +159,26 @@ void GraphNode::_notification(int p_what) { if (p_what==NOTIFICATION_DRAW) { Ref sb=get_stylebox("frame"); + Ref port =get_icon("port"); + Point2i icofs = -port->get_size()*0.5; + int edgeofs=3; + icofs.y+=sb->get_margin(MARGIN_TOP); draw_style_box(sb,Rect2(Point2(),get_size())); + + for (Map::Element *E=slot_info.front();E;E=E->next()) { + + if (E->key()>cache_y.size()) + continue; + if (!slot_info.has(E->key())) + continue; + const Slot &s=slot_info[E->key()]; + //left + if (s.enable_left) + port->draw(get_canvas_item(),icofs+Point2(edgeofs,cache_y[E->key()]),s.color_left); + if (s.enable_right) + port->draw(get_canvas_item(),icofs+Point2(get_size().x-edgeofs,cache_y[E->key()]),s.color_right); + + } } if (p_what==NOTIFICATION_SORT_CHILDREN) { @@ -82,16 +198,22 @@ String GraphNode::get_title() const { return title; } -void GraphNode::set_slot(int p_idx,int p_type_left,int p_index_left,const Color& p_color_left, int p_type_right,int p_index_right,const Color& p_color_right) { +void GraphNode::set_slot(int p_idx,bool p_enable_left,int p_type_left,const Color& p_color_left, bool p_enable_right,int p_type_right,const Color& p_color_right) { ERR_FAIL_COND(p_idx<0); + + if (!p_enable_left && p_type_left==0 && p_color_left==Color(1,1,1,1) && !p_enable_right && p_type_right==0 && p_color_right==Color(1,1,1,1)) { + slot_info.erase(p_idx); + return; + } + Slot s; + s.enable_left=p_enable_left; s.type_left=p_type_left; s.color_left=p_color_left; - s.index_left=p_index_left; + s.enable_right=p_enable_right; s.type_right=p_type_right; s.color_right=p_color_right; - s.index_right=p_index_right; slot_info[p_idx]=s; update(); } @@ -106,46 +228,52 @@ void GraphNode::clear_all_slots(){ slot_info.clear(); update(); } +bool GraphNode::is_slot_enabled_left(int p_idx) const{ + + if (!slot_info.has(p_idx)) + return false; + return slot_info[p_idx].enable_left; + +} + int GraphNode::get_slot_type_left(int p_idx) const{ if (!slot_info.has(p_idx)) - return TYPE_DISABLED; + return 0; return slot_info[p_idx].type_left; } -int GraphNode::get_slot_index_left(int p_idx) const{ - if (!slot_info.has(p_idx)) - return TYPE_DISABLED; - return slot_info[p_idx].index_left; - -} Color GraphNode::get_slot_color_left(int p_idx) const{ if (!slot_info.has(p_idx)) - return Color(); + return Color(1,1,1,1); return slot_info[p_idx].color_left; } +bool GraphNode::is_slot_enabled_right(int p_idx) const{ + + if (!slot_info.has(p_idx)) + return false; + return slot_info[p_idx].enable_right; + +} + + + int GraphNode::get_slot_type_right(int p_idx) const{ if (!slot_info.has(p_idx)) - return TYPE_DISABLED; + return 0; return slot_info[p_idx].type_right; } -int GraphNode::get_slot_index_right(int p_idx) const{ - if (!slot_info.has(p_idx)) - return TYPE_DISABLED; - return slot_info[p_idx].index_right; - -} Color GraphNode::get_slot_color_right(int p_idx) const{ if (!slot_info.has(p_idx)) - return Color(); + return Color(1,1,1,1); return slot_info[p_idx].color_right; } @@ -161,9 +289,9 @@ Size2 GraphNode::get_minimum_size() const { for(int i=0;icast_to(); - if (!c || !c->is_visible()) + if (!c) continue; - if (c->is_set_as_toplevel()) + if (c->is_set_as_toplevel() || !c->get_owner()) continue; Size2i size=c->get_combined_minimum_size(); @@ -186,6 +314,7 @@ void GraphNode::_bind_methods() { } -GraphNode::GraphNode() -{ +GraphNode::GraphNode() { + + } diff --git a/scene/gui/graph_node.h b/scene/gui/graph_node.h index 1b2e8cec216..3b89da9f0f2 100644 --- a/scene/gui/graph_node.h +++ b/scene/gui/graph_node.h @@ -10,14 +10,19 @@ class GraphNode : public Container { String title; struct Slot { + bool enable_left; int type_left; - int index_left; Color color_left; + bool enable_right; int type_right; - int index_right; Color color_right; + + + Slot() { enable_left=false; type_left=0; color_left=Color(1,1,1,1); enable_right=false; type_right=0; color_right=Color(1,1,1,1); }; }; + Vector cache_y; + Map slot_info; void _resort(); @@ -25,24 +30,26 @@ protected: void _notification(int p_what); static void _bind_methods(); + + bool _set(const StringName& p_name, const Variant& p_value); + bool _get(const StringName& p_name,Variant &r_ret) const; + void _get_property_list( List *p_list) const; + public: - enum { - TYPE_DISABLED=-1 - }; void set_title(const String& p_title); String get_title() const; - void set_slot(int p_idx,int p_type_left,int p_index_left,const Color& p_color_left, int p_type_right,int p_index_right,const Color& p_color_right); + void set_slot(int p_idx,bool p_enable_left,int p_type_left,const Color& p_color_left, bool p_enable_right,int p_type_right,const Color& p_color_right); void clear_slot(int p_idx); void clear_all_slots(); + bool is_slot_enabled_left(int p_idx) const; int get_slot_type_left(int p_idx) const; - int get_slot_index_left(int p_idx) const; Color get_slot_color_left(int p_idx) const; + bool is_slot_enabled_right(int p_idx) const; int get_slot_type_right(int p_idx) const; - int get_slot_index_right(int p_idx) const; Color get_slot_color_right(int p_idx) const; virtual Size2 get_minimum_size() const; diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index 741deccdbee..962e8c26e0d 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -75,6 +75,7 @@ #include "scene/gui/split_container.h" #include "scene/gui/video_player.h" #include "scene/gui/reference_frame.h" +#include "scene/gui/graph_node.h" #include "scene/resources/video_stream.h" #include "scene/2d/particles_2d.h" #include "scene/2d/path_2d.h" @@ -303,6 +304,7 @@ void register_scene_types() { ObjectTypeDB::register_virtual_type(); ObjectTypeDB::register_type(); ObjectTypeDB::register_type(); + ObjectTypeDB::register_type(); OS::get_singleton()->yield(); //may take time to init diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index f27cfb95113..050e4629026 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -65,7 +65,7 @@ static Ref make_icon(T p_src) { Ref texture( memnew( ImageTexture ) ); - texture->create_from_image( Image(p_src) ); + texture->create_from_image( Image(p_src),ImageTexture::FLAG_FILTER ); return texture; } @@ -416,7 +416,15 @@ void make_default_theme() { t->set_color("font_color_hover","PopupMenu", control_font_color ); t->set_constant("hseparation","PopupMenu",2); t->set_constant("vseparation","PopupMenu",1); - + + Ref graphsb = make_stylebox(graph_node_png,6,21,6,5,16,21,16,5); + //graphsb->set_expand_margin_size(MARGIN_LEFT,10); + //graphsb->set_expand_margin_size(MARGIN_RIGHT,10); + t->set_stylebox("frame","GraphNode", graphsb ); + t->set_constant("separation","GraphNode", 1 ); + t->set_icon("port","GraphNode", make_icon( graph_port_png ) ); + + t->set_stylebox("bg","Tree", make_stylebox( tree_bg_png,4,4,4,5,3,3,3,3) ); t->set_stylebox("bg_focus","Tree", focus ); Ref tree_selected = make_stylebox( selection_png,4,4,4,4); diff --git a/scene/resources/default_theme/graph_node.png b/scene/resources/default_theme/graph_node.png index b9fe334948609d0d5504c82c9acc5184f52fb882..3adccf2c3b7b1daee5a2d79051ec377c708821e3 100644 GIT binary patch delta 663 zcmV;I0%-l-1%d{UQwS6g11=S|2TGA!D1T~6L_t(o!|j*5ZWB=uhQIMHv4e$U1rXvQ zr2rZvkRqOe0?||P0w4++3ZO*L&>(@}1*qr|1TV1Eth z0e=9SMr{LU<_>kQx0Jh=Oa z*-op5zhe+}M+z!=g@2V%yu~PnFbLbeY)JtDfKluGoxo0O57GR&vmga% z`iokNs(>hhpeUk}bJMZjhJ{93MNv>i#Fb%FCvjnP8o;W}Zm480?p-O0GC2cZwl7RY zb6VIjNC9B1E%60Wbwy}ezfR9!`+_T4b56G64^jfyg5nfVRKzcfXssWaRDXFv-2nKu zf{0G*f@X=TJIGQIbM4$&z(s2N8{r zn45?4^i9=3)ybC+qgr&FHi`G2++nYl0g^4l;`xiaa$0)-wmO52L4VH~H26oW0X3io z)PNdL18Ts336P3U;5}zx_kZDQQ-B2`V@zz5U3ev6jER8=unoV;u1E23d9Am~G>A=L zt+z@P50`;;z@(e&9B`r2?mlfbXU_#eP${l4#zyh*!(g+26L<$~NN$De04IPWKy$+K x9RojsZ+?$9QW7*w_rVEOs4qF$r|{$U7fhEOBwGlJl>h($07*qoL+etKoAkZ-o%S1XHN5r-0jZ2XE8IIy~~mq z6$IIVfo1o-&wRh{4Z{xn>mj9?%+1VS5s@1ra;YlV%wC(>(@uB!C7^%_kN}OjnSc4) zvnS^6Ke+RlL&sW`t8K3jxcl%HD_=YJI^E?*z({};m_Bu~{qfn8=WXW{m$^zn+Du8) zgzGo2Eq(s7bQTzu~IFx3=u*Li!oB&wa>)No3QBL##=k7U?;$vwo;Oo z{Z<2Xtm2HJs91jjpsHcZ#L5fiH$Z4Bi0olO%?hFBUlbA|NM&CIJ6qRwxqp$kCCBWY z0nW|Oo_=wVb6|Pp(^cSop}^%ME}XykOUds(ysfsdw*KS5CsOjKM_LW20X5*i0i?hR zF!+t!H^6FL#2QcoYCsM6I{=FS3wOeA>h{l4=VK!zD$qR77JL0JdqLDeuiqulv&HaJ zO$v+vx4PC_FgU!iwQ)H~l3(dcfa)-J`K$g~Zvk-e;@JX@0LQ~T8m@Gc^-&-LHh}M8 zZbk)z@PQCC74DN#D%c3ffvpfbhzgQmr5V&rhvZ}epaC)r$r<2&0e zSad^gZEa<4bO1wgWnpw>WFU8GbZ8()Nlj2!fese{00Cu5L_t&-(@oG%Yua!e2jI^) ze||}3(qv%;VRlFHq%GTZ1rda>UhCQG^lj`d_$Ib@;6=KlY@j=>Ikq+k8%r|M#%!8T zPlY}&;Sm5JDbwlH+HSWa-}k!!kmvc2X0!QuHk(xlZoBwbmI5t=O3Bi_%CeAU8CciQilSJjX;y2ZQ7Hw>Qm~W-ODTv5(=@G%`(mvR27|b& zso6Sa6tJQ|&M >::Element *E=default_textures.front();E;E=E->next()) { + arr.push_back(E->key()); + arr.push_back(E->get()); + } + if (arr.size()) + c["default_tex"]=arr; return c; } @@ -132,8 +139,41 @@ void Shader::_set_code(const Dictionary& p_string) { light=p_string["light"]; set_code(p_string["vertex"],p_string["fragment"],light); + if (p_string.has("default_tex")) { + Array arr=p_string["default_tex"]; + if ((arr.size()&1)==0) { + for(int i=0;i& p_texture) { + + if (p_texture.is_valid()) + default_textures[p_param]=p_texture; + else + default_textures.erase(p_param); +} + +Ref Shader::get_default_texture_param(const StringName& p_param) const{ + + if (default_textures.has(p_param)) + return default_textures[p_param]; + else + return Ref(); +} + +void Shader::get_default_texture_param_list(List* r_textures) const{ + + for(const Map >::Element *E=default_textures.front();E;E=E->next()) { + + r_textures->push_back(E->key()); + } + +} + + void Shader::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_mode","mode"),&Shader::set_mode); @@ -144,6 +184,9 @@ void Shader::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_fragment_code"),&Shader::get_fragment_code); ObjectTypeDB::bind_method(_MD("get_light_code"),&Shader::get_light_code); + ObjectTypeDB::bind_method(_MD("set_default_texture_param","param","texture:Texture"),&Shader::set_default_texture_param); + ObjectTypeDB::bind_method(_MD("get_default_texture_param:Texture","param"),&Shader::get_default_texture_param); + ObjectTypeDB::bind_method(_MD("has_param","name"),&Shader::has_param); ObjectTypeDB::bind_method(_MD("_set_code","code"),&Shader::_set_code); diff --git a/scene/resources/shader.h b/scene/resources/shader.h index fff6f1d28a5..e1b8288c51b 100644 --- a/scene/resources/shader.h +++ b/scene/resources/shader.h @@ -31,7 +31,7 @@ #include "resource.h" #include "io/resource_loader.h" - +#include "scene/resources/texture.h" class Shader : public Resource { OBJ_TYPE(Shader,Resource); @@ -48,6 +48,7 @@ class Shader : public Resource { // convertion fast and save memory. mutable bool params_cache_dirty; mutable Map params_cache; //map a shader param to a material param.. + Map > default_textures; protected: @@ -72,6 +73,10 @@ public: void get_param_list(List *p_params) const; bool has_param(const StringName& p_param) const; + void set_default_texture_param(const StringName& p_param, const Ref &p_texture); + Ref get_default_texture_param(const StringName& p_param) const; + void get_default_texture_param_list(List* r_textures) const; + virtual RID get_rid() const; Shader(); diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h index 55625a2218e..8731095425d 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer.h @@ -187,6 +187,7 @@ public: virtual bool texture_has_alpha(RID p_texture) const=0; virtual void texture_set_size_override(RID p_texture,int p_width, int p_height)=0; + virtual void texture_set_reload_hook(RID p_texture,ObjectID p_owner,const StringName& p_function) const=0; /* SHADER API */ @@ -203,6 +204,9 @@ public: virtual void shader_get_param_list(RID p_shader, List *p_param_list) const=0; + virtual void shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture)=0; + virtual RID shader_get_default_texture_param(RID p_shader, const StringName& p_name) const=0; + /* COMMON MATERIAL API */ virtual RID material_create()=0; diff --git a/servers/visual/rasterizer_dummy.cpp b/servers/visual/rasterizer_dummy.cpp index a671821e25e..a3999600141 100644 --- a/servers/visual/rasterizer_dummy.cpp +++ b/servers/visual/rasterizer_dummy.cpp @@ -221,6 +221,16 @@ void RasterizerDummy::shader_get_param_list(RID p_shader, List *p_ } + +void RasterizerDummy::shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture) { + +} + +RID RasterizerDummy::shader_get_default_texture_param(RID p_shader, const StringName& p_name) const { + + return RID(); +} + /* COMMON MATERIAL API */ diff --git a/servers/visual/rasterizer_dummy.h b/servers/visual/rasterizer_dummy.h index 44bca423a43..d879fcafebf 100644 --- a/servers/visual/rasterizer_dummy.h +++ b/servers/visual/rasterizer_dummy.h @@ -429,6 +429,10 @@ public: virtual void shader_get_param_list(RID p_shader, List *p_param_list) const; + + virtual void shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture); + virtual RID shader_get_default_texture_param(RID p_shader, const StringName& p_name) const; + /* COMMON MATERIAL API */ virtual RID material_create(); diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp index af50b9b592b..7cfa6dbb321 100644 --- a/servers/visual/visual_server_raster.cpp +++ b/servers/visual/visual_server_raster.cpp @@ -157,6 +157,16 @@ void VisualServerRaster::shader_get_param_list(RID p_shader, List } +void VisualServerRaster::shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture) { + + rasterizer->shader_set_default_texture_param(p_shader,p_name,p_texture); +} + +RID VisualServerRaster::shader_get_default_texture_param(RID p_shader, const StringName& p_name) const{ + + return rasterizer->shader_get_default_texture_param(p_shader,p_name); +} + /* Material */ diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index 3064f9ceb08..ce520775505 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -756,6 +756,10 @@ public: virtual void shader_get_param_list(RID p_shader, List *p_param_list) const; + virtual void shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture); + virtual RID shader_get_default_texture_param(RID p_shader, const StringName& p_name) const; + + /* COMMON MATERIAL API */ virtual RID material_create(); diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h index a4653b10131..7d2b8a3767c 100644 --- a/servers/visual/visual_server_wrap_mt.h +++ b/servers/visual/visual_server_wrap_mt.h @@ -653,6 +653,10 @@ public: FUNC1RC(String,shader_get_light_code,RID); FUNC2SC(shader_get_param_list,RID,List*); + FUNC3(shader_set_default_texture_param,RID,const StringName&,RID); + FUNC2RC(RID,shader_get_default_texture_param,RID,const StringName&); + + /*virtual void shader_get_param_list(RID p_shader, List *p_param_list) { if (Thread::get_caller_ID()!=server_thread) { command_queue.push_and_sync( visual_server, &VisualServer::shader_get_param_list,p_shader,p_param_list); diff --git a/servers/visual_server.h b/servers/visual_server.h index ed04b0d09ca..4336a914075 100644 --- a/servers/visual_server.h +++ b/servers/visual_server.h @@ -140,6 +140,7 @@ public: SHADER_POST_PROCESS, }; + virtual RID shader_create(ShaderMode p_mode=SHADER_MATERIAL)=0; virtual void shader_set_mode(RID p_shader,ShaderMode p_mode)=0; @@ -151,6 +152,9 @@ public: virtual String shader_get_light_code(RID p_shader) const=0; virtual void shader_get_param_list(RID p_shader, List *p_param_list) const=0; + virtual void shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture)=0; + virtual RID shader_get_default_texture_param(RID p_shader, const StringName& p_name) const=0; + /* COMMON MATERIAL API */