From 92f87b75f96392c0f6b306a55738cdab413a7b92 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 22 Aug 2012 02:02:26 +0300 Subject: [PATCH] Avoid re-applying shader data unnecessarily --- source/renderer.cpp | 11 +++++++++-- source/renderer.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/source/renderer.cpp b/source/renderer.cpp index 03042e67..ee845e08 100644 --- a/source/renderer.cpp +++ b/source/renderer.cpp @@ -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_iterator i=state->shdata.begin(); i!=state->shdata.end(); ++i) - (*i)->apply(); + if(shdata_changed) + { + for(vector::const_iterator i=state->shdata.begin(); i!=state->shdata.end(); ++i) + (*i)->apply(); + shdata_changed = false; + } } else Program::unbind(); diff --git a/source/renderer.h b/source/renderer.h index 866881c7..501d1db3 100644 --- a/source/renderer.h +++ b/source/renderer.h @@ -70,6 +70,7 @@ private: const VertexArray *vertex_array; bool vertex_array_changed; const Buffer *element_buffer; + bool shdata_changed; public: Renderer(const Camera *); -- 2.45.2