From 29fe33d3dde1df0e11c741b0c02af2f33b685571 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 3 Sep 2022 16:36:44 +0300 Subject: [PATCH] Refactor batch setup in Renderer to a helper function --- source/render/renderer.cpp | 12 +++++++----- source/render/renderer.h | 4 ++++ 2 files changed, 11 insertions(+), 5 deletions(-) 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); -- 2.45.2