]> git.tdb.fi Git - libs/gl.git/commitdiff
Refactor batch setup in Renderer to a helper function
authorMikko Rasa <tdb@tdb.fi>
Sat, 3 Sep 2022 13:36:44 +0000 (16:36 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 3 Sep 2022 13:38:44 +0000 (16:38 +0300)
source/render/renderer.cpp
source/render/renderer.h

index 50d3887369a30cbcdf6b8b1f99e83ea33ca08a94..aab37b6796bece1dc7d2b58e1018fc51f1666a78 100644 (file)
@@ -279,21 +279,23 @@ void Renderer::clear(const ClearValue *values)
 void Renderer::draw(const Batch &batch)
 {
        apply_state();
-       batch.refresh(frame_index);
-       PipelineState &ps = get_pipeline_state();
-       ps.set_primitive_type(batch.get_type());
-       commands.use_pipeline(&ps);
+       apply_batch(batch);
        commands.draw(batch);
 }
 
 void Renderer::draw_instanced(const Batch &batch, unsigned count)
 {
        apply_state();
+       apply_batch(batch);
+       commands.draw_instanced(batch, count);
+}
+
+void Renderer::apply_batch(const Batch &batch)
+{
        batch.refresh(frame_index);
        PipelineState &ps = get_pipeline_state();
        ps.set_primitive_type(batch.get_type());
        commands.use_pipeline(&ps);
-       commands.draw_instanced(batch, count);
 }
 
 void Renderer::dispatch(unsigned count_x, unsigned count_y, unsigned count_z)
index 39ac462fbb96d4901c8f9ec884ba141dce04ecb6..da2cf8bac866d8284a2fe4c6395a935f8eba5258 100644 (file)
@@ -231,6 +231,10 @@ public:
        /** Draws multiple instances of a batch of primitives.  A shader must be active. */
        void draw_instanced(const Batch &, unsigned);
 
+private:
+       void apply_batch(const Batch &);
+
+public:
        /** Dispatches a compute operation. */
        void dispatch(unsigned, unsigned = 1, unsigned = 1);