diff options
author | Juan Linietsky <reduzio@gmail.com> | 2015-01-12 20:44:02 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2015-01-12 20:44:02 -0300 |
commit | 30d36581100f0bf71c6d2502be9a03443bdf8708 (patch) | |
tree | 2ac0ce5967e150269a71bece0ea0bd16c3eb1054 /drivers/gles2 | |
parent | 544ce2a1dbaa5548490c975c2f6f6ed7c21377b9 (diff) |
-fixed issue with shader not being reset on layers, closes #1199
-ability for shader to use parent shader and params, closes #1198
Diffstat (limited to 'drivers/gles2')
-rw-r--r-- | drivers/gles2/rasterizer_gles2.cpp | 39 | ||||
-rw-r--r-- | drivers/gles2/rasterizer_gles2.h | 6 |
2 files changed, 21 insertions, 24 deletions
diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index 80dd1a7898..44fb210526 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -4961,7 +4961,7 @@ _FORCE_INLINE_ void RasterizerGLES2::_update_material_shader_params(Material *p_ keep=false; else if (old_mparams[E->key()].value.get_type()!=E->value().default_value.get_type()) { //type changed between old and new - /*if (old_mparams[E->key()].value.get_type()==Variant::OBJECT) { + /* if (old_mparams[E->key()].value.get_type()==Variant::OBJECT) { if (E->value().default_value.get_type()!=Variant::_RID) //hackfor textures keep=false; } else if (!old_mparams[E->key()].value.is_num() || !E->value().default_value.get_type()) @@ -7799,7 +7799,7 @@ void RasterizerGLES2::canvas_begin() { canvas_shader.bind(); canvas_shader.set_uniform(CanvasShaderGLES2::TEXTURE, 0); _set_color_attrib(Color(1,1,1)); - Transform canvas_transform; + canvas_transform=Transform(); canvas_transform.translate(-(viewport.width / 2.0f), -(viewport.height / 2.0f), 0.0f); float csy = 1.0; if (current_rt && current_rt_vflip) @@ -7813,6 +7813,9 @@ void RasterizerGLES2::canvas_begin() { canvas_opacity=1.0; canvas_blend_mode=VS::MATERIAL_BLEND_MODE_MIX; + canvas_texscreen_used=false; + uses_texpixel_size=false; + canvas_last_shader=RID(); } @@ -8294,26 +8297,13 @@ void RasterizerGLES2::canvas_set_transform(const Matrix32& p_transform) { //canvas_transform = Variant(p_transform); } + void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list) { CanvasItem *current_clip=NULL; - RID last_shader; - - Transform canvas_transform; - canvas_transform.translate(-(viewport.width / 2.0f), -(viewport.height / 2.0f), 0.0f); - float csy = 1.0; - if (current_rt && current_rt_vflip) - csy = -1.0; - canvas_transform.scale( Vector3( 2.0f / viewport.width, csy * -2.0f / viewport.height, 1.0f ) ); canvas_opacity=1.0; - uses_texpixel_size=false; - - - canvas_shader.set_uniform(CanvasShaderGLES2::PROJECTION_MATRIX,canvas_transform); - canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX,Matrix32()); - while(p_item_list) { CanvasItem *ci=p_item_list; @@ -8324,7 +8314,7 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list) { } memdelete(ci->vp_render); ci->vp_render=NULL; - last_shader=RID(); + canvas_last_shader=RID(); } if (current_clip!=ci->final_clip_owner) { @@ -8345,12 +8335,13 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list) { //begin rect + CanvasItem *shader_owner = ci->shader_owner?ci->shader_owner:ci; - if (ci->shader!=last_shader) { + if (shader_owner->shader!=canvas_last_shader) { Shader *shader = NULL; - if (ci->shader.is_valid()) { - shader = shader_owner.get(ci->shader); + if (shader_owner->shader.is_valid()) { + shader = this->shader_owner.get(shader_owner->shader); if (shader && !shader->valid) { shader=NULL; } @@ -8361,9 +8352,9 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list) { if (canvas_shader.bind()) rebind_texpixel_size=true; - if (ci->shader_version!=shader->version) { + if (shader_owner->shader_version!=shader->version) { //todo optimize uniforms - ci->shader_version=shader->version; + shader_owner->shader_version=shader->version; } //this can be optimized.. int tex_id=1; @@ -8371,7 +8362,7 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list) { for(Map<StringName,ShaderLanguage::Uniform>::Element *E=shader->uniforms.front();E;E=E->next()) { - Map<StringName,Variant>::Element *F=ci->shader_param.find(E->key()); + Map<StringName,Variant>::Element *F=shader_owner->shader_param.find(E->key()); Variant &v=F?F->get():E->get().default_value; if (v.get_type()==Variant::_RID || v.get_type()==Variant::OBJECT) { int loc = canvas_shader.get_custom_uniform_location(idx); //should be automatic.. @@ -8422,7 +8413,7 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list) { } canvas_shader.set_uniform(CanvasShaderGLES2::PROJECTION_MATRIX,canvas_transform); - last_shader=ci->shader; + canvas_last_shader=shader_owner->shader; } canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX,ci->final_transform); diff --git a/drivers/gles2/rasterizer_gles2.h b/drivers/gles2/rasterizer_gles2.h index 65947fb034..0f77d18dee 100644 --- a/drivers/gles2/rasterizer_gles2.h +++ b/drivers/gles2/rasterizer_gles2.h @@ -1174,6 +1174,11 @@ class RasterizerGLES2 : public Rasterizer { float canvas_opacity; bool uses_texpixel_size; bool rebind_texpixel_size; + Transform canvas_transform; + RID canvas_last_shader; + bool canvas_texscreen_used; + + _FORCE_INLINE_ Texture* _bind_canvas_texture(const RID& p_texture); VS::MaterialBlendMode canvas_blend_mode; @@ -1542,6 +1547,7 @@ public: virtual void canvas_draw_primitive(const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, RID p_texture,float p_width); virtual void canvas_draw_polygon(int p_vertex_count, const int* p_indices, const Vector2* p_vertices, const Vector2* p_uvs, const Color* p_colors,const RID& p_texture,bool p_singlecolor); virtual void canvas_set_transform(const Matrix32& p_transform); + virtual void canvas_render_items(CanvasItem *p_item_list); /* ENVIRONMENT */ |