]> git.tdb.fi Git - libs/gl.git/commitdiff
Roll the various changed flags into a single mask
authorMikko Rasa <tdb@tdb.fi>
Thu, 30 Oct 2014 08:19:13 +0000 (10:19 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 30 Oct 2014 08:19:13 +0000 (10:19 +0200)
source/renderer.cpp
source/renderer.h

index bac7b6b854bcc2ea1c51d684b2ff700589e2d9a8..54d12051c9945066badc10231685e43398aad0f1 100644 (file)
@@ -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 ProgramData *>::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
index 5d8f686e35806a419e4a46167fd75161666ed725..a3ddaa3bd28f3832ce2a21884384727c897ede5f 100644 (file)
@@ -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> state_stack;
        State *state;
-       bool lighting_changed;
        ProgramData standard_shdata;
        std::vector<const ProgramData *> shdata_stack;
-       bool shdata_changed;
        const Buffer *element_buffer;
        std::set<const Renderable *> excluded;