]> git.tdb.fi Git - libs/gl.git/commitdiff
Handle all shader data in Renderer through the generic mechanism
authorMikko Rasa <tdb@tdb.fi>
Mon, 9 Aug 2021 12:10:11 +0000 (15:10 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 9 Aug 2021 12:10:11 +0000 (15:10 +0300)
source/render/renderer.cpp
source/render/renderer.h

index a8f5ce3ab07f9ea3c6ef867678043315f84394de..1d43a939432f9a593381992824aedec7fca87f84 100644 (file)
@@ -44,6 +44,7 @@ void Renderer::init()
        state_stack.push_back(State());
        shdata_stack.reserve(32);
        state = &state_stack.back();
+       add_shader_data(standard_shdata);
 }
 
 Renderer::~Renderer()
@@ -54,7 +55,7 @@ Renderer::~Renderer()
 void Renderer::set_camera(const Camera &c)
 {
        state->camera = &c;
-       changed |= CAMERA_SHDATA;
+       add_shader_data(c.get_shader_data());
        set_matrix(Matrix());
 }
 
@@ -161,7 +162,8 @@ void Renderer::set_lighting(const Lighting *l)
 void Renderer::set_clipping(const Clipping *c)
 {
        state->clipping = c;
-       changed |= CLIPPING_SHDATA;
+       if(c)
+               add_shader_data(c->get_shader_data());
 }
 
 void Renderer::set_shader_program(const Program *p, const ProgramData *d)
@@ -226,16 +228,9 @@ void Renderer::pop_state()
        if(state_stack.size()==1)
                throw stack_underflow("Renderer::pop_state");
 
-       const Camera *old_camera = state->camera;
-       const Clipping *old_clipping = state->clipping;
        state_stack.pop_back();
        state = &state_stack.back();
        changed |= MATRIX;
-       bool camera_changed = (state->camera!=old_camera);
-       if(camera_changed)
-               changed |= CAMERA_SHDATA;
-       if(state->clipping!=old_clipping)
-               changed |= CLIPPING_SHDATA;
 }
 
 void Renderer::end()
@@ -330,25 +325,7 @@ void Renderer::apply_state()
                LinAl::SquareMatrix<float, 3> nm = state->model_matrix.block<3, 3>(0, 0);
                nm = transpose(invert(nm));
                standard_shdata.uniform("world_obj_normal_matrix", nm);
-               changed = (changed&~MATRIX)|STANDARD_SHDATA;
-       }
-
-       if(state->camera && ((changed&CAMERA_SHDATA) || shprog_changed))
-       {
-               state->camera->get_shader_data().apply();
-               changed &= ~CAMERA_SHDATA;
-       }
-
-       if(state->clipping && ((changed&CLIPPING_SHDATA) || shprog_changed))
-       {
-               state->clipping->get_shader_data().apply();
-               changed &= ~CLIPPING_SHDATA;
-       }
-
-       if((changed&STANDARD_SHDATA) || shprog_changed)
-       {
-               standard_shdata.apply();
-               changed &= ~STANDARD_SHDATA;
+               changed &= ~MATRIX;
        }
 
        bool shdata_changed = changed&SHADER_DATA;
index 489cebb8f407b1f1cd8f4f76db9d5cbe39905580..50254cdf1de09824cb50f9bd37a9f85436a41606 100644 (file)
@@ -103,10 +103,7 @@ private:
        enum ChangeMask
        {
                MATRIX = 2,
-               SHADER_DATA = 16,
-               STANDARD_SHDATA = 64,
-               CAMERA_SHDATA = 128,
-               CLIPPING_SHDATA = 512
+               SHADER_DATA = 16
        };
 
        const Camera *default_camera;