]> git.tdb.fi Git - libs/gl.git/commitdiff
Avoid re-applying shader data unnecessarily
authorMikko Rasa <tdb@tdb.fi>
Tue, 21 Aug 2012 23:02:26 +0000 (02:02 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 21 Aug 2012 23:02:26 +0000 (02:02 +0300)
source/renderer.cpp
source/renderer.h

index 03042e67c12f80ac95904ca4c66e8f4e80e6baee..ee845e08b12d18d66c864cf936b3b48a8eae935f 100644 (file)
@@ -75,6 +75,7 @@ void Renderer::set_shader(const Program *p, const ProgramData *d)
                state->shdata.assign(1, d);
        else
                state->shdata.clear();
+       shdata_changed = true;
 }
 
 void Renderer::add_shader_data(const ProgramData *d)
@@ -83,6 +84,7 @@ void Renderer::add_shader_data(const ProgramData *d)
                throw invalid_operation("Renderer::add_shader_data");
 
        state->shdata.push_back(d);
+       shdata_changed = true;
 }
 
 void Renderer::set_vertex_array(const VertexArray *a)
@@ -117,6 +119,7 @@ void Renderer::pop_state()
        state = &state_stack.back();
        mtx_stack.pop();
        mtx_changed = true;
+       shdata_changed = true;
 }
 
 void Renderer::escape()
@@ -170,8 +173,12 @@ void Renderer::apply_state()
        if(state->shprog)
        {
                state->shprog->bind();
-               for(vector<const ProgramData *>::const_iterator i=state->shdata.begin(); i!=state->shdata.end(); ++i)
-                       (*i)->apply();
+               if(shdata_changed)
+               {
+                       for(vector<const ProgramData *>::const_iterator i=state->shdata.begin(); i!=state->shdata.end(); ++i)
+                               (*i)->apply();
+                       shdata_changed = false;
+               }
        }
        else
                Program::unbind();
index 866881c7b66aeebb8b913c43af4ee14b357c1885..501d1db3159667c42f92f3ecdfe2e85cb28fc1c4 100644 (file)
@@ -70,6 +70,7 @@ private:
        const VertexArray *vertex_array;
        bool vertex_array_changed;
        const Buffer *element_buffer;
+       bool shdata_changed;
 
 public:
        Renderer(const Camera *);