]> git.tdb.fi Git - libs/gl.git/blobdiff - source/render/renderer.cpp
Store simpler states by value in PipelineState
[libs/gl.git] / source / render / renderer.cpp
index 4beb2da7eca300d13450806b65d2eb503cd71f8e..0c5bf77454ed25c32151f2a44ed189723234a192 100644 (file)
@@ -241,11 +241,7 @@ void Renderer::set_object_lod_bias(unsigned b)
 
 void Renderer::clear(const ClearValue *values)
 {
-       const State &state = get_state();
-
-       pipeline_state.set_framebuffer(state.framebuffer);
-       pipeline_state.set_viewport(state.viewport);
-       pipeline_state.set_scissor(state.scissor);
+       apply_framebuffer();
        commands.use_pipeline(&pipeline_state);
        commands.clear(values);
 }
@@ -295,6 +291,16 @@ void Renderer::end_query(const QueryPool &pool, unsigned index)
        commands.end_query(pool, index);
 }
 
+void Renderer::apply_framebuffer()
+{
+       const State &state = get_state();
+
+       pipeline_state.set_framebuffer(state.framebuffer);
+       static const Rect default_rect = Rect::max();
+       pipeline_state.set_viewport(state.viewport ? *state.viewport : default_rect);
+       pipeline_state.set_scissor(state.scissor ? *state.scissor : default_rect);
+}
+
 void Renderer::apply_state()
 {
        const State &state = get_state();
@@ -302,9 +308,7 @@ void Renderer::apply_state()
        if(!state.shprog)
                throw invalid_operation("Renderer::apply_state");
 
-       pipeline_state.set_framebuffer(state.framebuffer);
-       pipeline_state.set_viewport(state.viewport);
-       pipeline_state.set_scissor(state.scissor);
+       apply_framebuffer();
 
        bool shprog_changed = (state.shprog!=pipeline_state.get_shader_program());
        pipeline_state.set_shader_program(state.shprog);
@@ -359,9 +363,12 @@ void Renderer::apply_state()
                                pipeline_state.set_texture(t.binding, t.texture, t.level, t.sampler);
                }
 
-       pipeline_state.set_depth_test(state.depth_test);
-       pipeline_state.set_stencil_test(state.stencil_test);
-       pipeline_state.set_blend(state.blend);
+       static const DepthTest default_depth_test;
+       pipeline_state.set_depth_test(state.depth_test ? *state.depth_test : default_depth_test);
+       static const StencilTest default_stencil_test;
+       pipeline_state.set_stencil_test(state.stencil_test ? *state.stencil_test : default_stencil_test);
+       static const Blend default_blend;
+       pipeline_state.set_blend(state.blend ? *state.blend : default_blend);
 }