From c4d81a13ca8ac1479eca78ee190f3762ef3cbec4 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 18 Aug 2021 16:59:26 +0300 Subject: [PATCH] Add a helper function to set variables and flags in PipelineState --- source/core/pipelinestate.cpp | 38 +++++++++++++---------------------- source/core/pipelinestate.h | 4 ++++ 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/source/core/pipelinestate.cpp b/source/core/pipelinestate.cpp index cfeed9ab..66188d91 100644 --- a/source/core/pipelinestate.cpp +++ b/source/core/pipelinestate.cpp @@ -39,49 +39,39 @@ PipelineState::~PipelineState() last_applied = 0; } -void PipelineState::set_shader_program(const Program *p) +template +void PipelineState::set(T &target, T value, unsigned flag) { - if(p!=shprog) + if(value!=target) { - shprog = p; - changes |= SHPROG; + target = value; + changes |= flag; } } +void PipelineState::set_shader_program(const Program *p) +{ + set(shprog, p, SHPROG); +} + void PipelineState::set_vertex_setup(const VertexSetup *s) { - if(s!=vertex_setup) - { - vertex_setup = s; - changes |= VERTEX_SETUP; - } + set(vertex_setup, s, VERTEX_SETUP); } void PipelineState::set_front_face(FaceWinding w) { - if(w!=front_face) - { - front_face = w; - changes |= FACE_CULL; - } + set(front_face, w, FACE_CULL); } void PipelineState::set_face_cull(CullMode c) { - if(c!=face_cull) - { - face_cull = c; - changes |= FACE_CULL; - } + set(face_cull, c, FACE_CULL); } void PipelineState::set_enabled_clip_planes(unsigned p) { - if(p!=enabled_clip_planes) - { - enabled_clip_planes = p; - changes |= CLIP_PLANES; - } + set(enabled_clip_planes, p, CLIP_PLANES); } void PipelineState::set_texture(unsigned binding, const Texture *tex, const Sampler *samp) diff --git a/source/core/pipelinestate.h b/source/core/pipelinestate.h index 55d96485..1d313c3b 100644 --- a/source/core/pipelinestate.h +++ b/source/core/pipelinestate.h @@ -65,6 +65,10 @@ public: PipelineState(); ~PipelineState(); +private: + template + void set(T &, T, unsigned); +public: void set_shader_program(const Program *); void set_vertex_setup(const VertexSetup *); void set_front_face(FaceWinding); -- 2.43.0