]> git.tdb.fi Git - libs/gl.git/commitdiff
Track whether implicit shader data needs to be re-applied
authorMikko Rasa <tdb@tdb.fi>
Wed, 26 Oct 2016 17:29:54 +0000 (20:29 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 26 Oct 2016 17:29:54 +0000 (20:29 +0300)
source/renderer.cpp
source/renderer.h

index 8daa13ce414bbc508a6924064ac282392a7bfb5c..3ddb3a6553acd3e1c9ae1593d40dc639e7a07ece 100644 (file)
@@ -92,6 +92,7 @@ unsigned Renderer::allocate_effect_texunit()
 void Renderer::set_material(const Material *m)
 {
        state->material = m;
+       changed |= MATERIAL_SHDATA;
 }
 
 void Renderer::set_lighting(const Lighting *l)
@@ -99,7 +100,10 @@ void Renderer::set_lighting(const Lighting *l)
        state->lighting = l;
        state->lighting_matrix = mtx_stack.top();
        if(l)
+       {
                l->update_shader_data(standard_shdata, mtx_stack.top());
+               changed |= STANDARD_SHDATA;
+       }
        changed |= LIGHTING;
 }
 
@@ -305,12 +309,20 @@ void Renderer::apply_state()
                                LinAl::SquareMatrix<float, 3> nm = m.block<3, 3>(0, 0);
                                nm = transpose(invert(nm));
                                standard_shdata.uniform_matrix3("eye_obj_normal_matrix", &nm(0, 0));
-                               changed &= ~MODERN_MATRIX;
+                               changed = (changed&~MODERN_MATRIX)|STANDARD_SHDATA;
                        }
 
-                       if(state->material)
+                       if(state->material && (changed&MATERIAL_SHDATA))
+                       {
                                state->material->get_shader_data().apply();
-                       standard_shdata.apply();
+                               changed &= ~MATERIAL_SHDATA;
+                       }
+
+                       if(changed&STANDARD_SHDATA)
+                       {
+                               standard_shdata.apply();
+                               changed &= ~STANDARD_SHDATA;
+                       }
                }
 
                if((changed&SHADER_DATA) || shprog_changed)
index 3d561b4fd8f0daea3cc69afa0fc0d1c7b8be86f1..a4c5ef03ca93ad316bb7af61723ac103456c657c 100644 (file)
@@ -99,7 +99,9 @@ private:
                MATRIX = LEGACY_MATRIX|MODERN_MATRIX,
                LIGHTING = 4,
                CLIPPING = 8,
-               SHADER_DATA = 16
+               SHADER_DATA = 16,
+               MATERIAL_SHDATA = 32,
+               STANDARD_SHDATA = 64
        };
 
        MtxStack mtx_stack;