]> git.tdb.fi Git - libs/gl.git/commitdiff
Treat standard and camera shader data specially in Renderer
authorMikko Rasa <tdb@tdb.fi>
Sun, 13 Mar 2022 07:34:18 +0000 (09:34 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 13 Mar 2022 07:34:18 +0000 (09:34 +0200)
Don't add them to the generic shdata stack.  Some effects apply their own
camera, which led to two overlapping ProgramData objects on the stack.
Although the results were correct, this caused PipelineState to flag the
uniform blocks as dirty every frame and do unnecessary work.

source/render/renderer.cpp
source/render/renderer.h

index 336b631aaf91c467dbca5577abd81f2b79ebaebe..fceee6e8c631f71cacfb3a3ce908ad65cce8afc1 100644 (file)
@@ -40,7 +40,6 @@ void Renderer::begin()
 
        RendererBackend::begin();
 
-       add_shader_data(standard_shdata);
        commands.begin_frame(frame_index);
 }
 
@@ -103,7 +102,6 @@ void Renderer::set_pipeline_key(uintptr_t key)
 void Renderer::set_camera(const Camera &c)
 {
        get_state().camera = &c;
-       add_shader_data(c.get_shader_data());
        set_matrix(Matrix());
 }
 
@@ -347,6 +345,17 @@ void Renderer::apply_state()
        bool shprog_changed = (state.shprog!=ps.get_shader_program());
        ps.set_shader_program(state.shprog);
 
+       bool shdata_changed = changed&SHADER_DATA;
+       for(auto i=shdata_stack.begin(); (!shdata_changed && i!=shdata_stack.end()); ++i)
+               shdata_changed = (i->shdata->get_generation()!=i->generation);
+       bool extra_shdata = (shdata_stack.size()>state.shdata_count);
+
+       if(changed&CAMERA)
+       {
+               shdata_changed = true;
+               changed &= ~CAMERA;
+       }
+
        if(changed&MATRIX)
        {
                standard_shdata.uniform("world_obj_matrix", state.model_matrix);
@@ -354,17 +363,16 @@ void Renderer::apply_state()
                nm = transpose(invert(nm));
                standard_shdata.uniform("world_obj_normal_matrix", nm);
                changed &= ~MATRIX;
+               shdata_changed = true;
        }
 
-       bool shdata_changed = changed&SHADER_DATA;
-       for(auto i=shdata_stack.begin(); (!shdata_changed && i!=shdata_stack.end()); ++i)
-               shdata_changed = (i->shdata->get_generation()!=i->generation);
-       bool extra_shdata = (shdata_stack.size()>state.shdata_count);
-
        if(shdata_changed || shprog_changed || pipeline_changed || extra_shdata)
        {
                if(extra_shdata)
                        shdata_stack.erase(shdata_stack.begin()+state.shdata_count, shdata_stack.end());
+               standard_shdata.apply(*state.shprog, ps, frame_index);
+               if(state.camera)
+                       state.camera->get_shader_data().apply(*state.shprog, ps, frame_index);
                for(const BoundProgramData &d: shdata_stack)
                {
                        d.shdata->apply(*state.shprog, ps, frame_index);
index 75c8cc8b58aaada99b371eb1bfc553d47d3d4ad7..31ad65ea1a373bf8c6c5478d4bf878d571ffce4f 100644 (file)
@@ -105,6 +105,7 @@ private:
        {
                PIPELINE_KEY = 1,
                MATRIX = 2,
+               CAMERA = 4,
                SHADER_DATA = 16
        };