From: Mikko Rasa Date: Thu, 30 Oct 2014 08:19:13 +0000 (+0200) Subject: Roll the various changed flags into a single mask X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=6d2e5c8e7ef79706adfce1b69695e3c8071c6ddb;p=libs%2Fgl.git Roll the various changed flags into a single mask --- diff --git a/source/renderer.cpp b/source/renderer.cpp index bac7b6b8..54d12051 100644 --- a/source/renderer.cpp +++ b/source/renderer.cpp @@ -22,11 +22,10 @@ namespace GL { Renderer::Renderer(const Camera *c): mtx_stack(*this), - mtx_changed(true), + changed(MATRIX), matrices_loaded(false), camera(c), state_stack(1), - lighting_changed(false), element_buffer(0) { state_stack.reserve(16); @@ -78,7 +77,7 @@ void Renderer::set_lighting(const Lighting *l) state->lighting_matrix = mtx_stack.top(); if(l) l->update_shader_data(standard_shdata, mtx_stack.top()); - lighting_changed = true; + changed |= LIGHTING; } void Renderer::set_shader_program(const Program *p, const ProgramData *d) @@ -96,7 +95,7 @@ void Renderer::add_shader_data(const ProgramData &d) { shdata_stack.push_back(&d); state->shdata_count = shdata_stack.size(); - shdata_changed = true; + changed |= SHADER_DATA; } void Renderer::set_mesh(const Mesh *m) @@ -136,8 +135,7 @@ void Renderer::pop_state() if(shdata_stack.size()>state->shdata_count) shdata_stack.erase(shdata_stack.begin()+state->shdata_count, shdata_stack.end()); mtx_stack.pop(); - mtx_changed = true; - shdata_changed = true; + changed |= MATRIX|SHADER_DATA; } void Renderer::escape() @@ -229,14 +227,13 @@ void Renderer::apply_state() else Material::unbind(); - if(lighting_changed) + if(changed&LIGHTING) { if(state->lighting) { MatrixStack::modelview() = state->lighting_matrix; state->lighting->bind(); - mtx_changed = true; - lighting_changed = false; + changed = (changed&~LIGHTING)|MATRIX; } else Lighting::unbind(); @@ -262,11 +259,11 @@ void Renderer::apply_state() standard_shdata.apply(); } - if(shdata_changed) + if(changed&SHADER_DATA) { for(vector::const_iterator i=shdata_stack.begin(); i!=shdata_stack.end(); ++i) (*i)->apply(); - shdata_changed = false; + changed &= ~SHADER_DATA; } } else @@ -308,10 +305,10 @@ void Renderer::apply_state() matrices_loaded = true; } - if(mtx_changed) + if(changed&MATRIX) { MatrixStack::modelview() = mtx_stack.top(); - mtx_changed = false; + changed &= ~MATRIX; } } } @@ -337,7 +334,7 @@ Renderer::MtxStack::MtxStack(Renderer &r): void Renderer::MtxStack::update() { - renderer.mtx_changed = true; + renderer.changed |= MATRIX; } } // namespace GL diff --git a/source/renderer.h b/source/renderer.h index 5d8f686e..a3ddaa3b 100644 --- a/source/renderer.h +++ b/source/renderer.h @@ -89,16 +89,21 @@ private: virtual void update(); }; + enum ChangeMask + { + MATRIX = 1, + LIGHTING = 4, + SHADER_DATA = 8 + }; + MtxStack mtx_stack; - bool mtx_changed; + unsigned char changed; bool matrices_loaded; const Camera *camera; std::vector state_stack; State *state; - bool lighting_changed; ProgramData standard_shdata; std::vector shdata_stack; - bool shdata_changed; const Buffer *element_buffer; std::set excluded;