From: Mikko Rasa Date: Sat, 3 Sep 2022 13:36:44 +0000 (+0300) Subject: Refactor batch setup in Renderer to a helper function X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=29fe33d3dde1df0e11c741b0c02af2f33b685571;p=libs%2Fgl.git Refactor batch setup in Renderer to a helper function --- diff --git a/source/render/renderer.cpp b/source/render/renderer.cpp index 50d38873..aab37b67 100644 --- a/source/render/renderer.cpp +++ b/source/render/renderer.cpp @@ -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) diff --git a/source/render/renderer.h b/source/render/renderer.h index 39ac462f..da2cf8ba 100644 --- a/source/render/renderer.h +++ b/source/render/renderer.h @@ -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);