From 18fda5b5a13215c500cb402f7d2b081e439a1f0e Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 16 Oct 2021 11:49:11 +0300 Subject: [PATCH] Move blend state from Sequence::Step to RenderMethod Even though all blended objects are typically rendered in a single step, it may be desirable to use different blend modes for different objects. --- source/builders/sequencebuilder.cpp | 1 - source/builders/sequencetemplate.cpp | 12 ------------ source/builders/sequencetemplate.h | 4 ---- source/materials/rendermethod.cpp | 18 ++++++++++++++++++ source/materials/rendermethod.h | 6 ++++++ source/render/sequence.cpp | 6 ------ source/render/sequence.h | 5 +---- tools/viewer.cpp | 1 - 8 files changed, 25 insertions(+), 28 deletions(-) diff --git a/source/builders/sequencebuilder.cpp b/source/builders/sequencebuilder.cpp index 45d4f873..5fca6140 100644 --- a/source/builders/sequencebuilder.cpp +++ b/source/builders/sequencebuilder.cpp @@ -64,7 +64,6 @@ void SequenceBuilder::build(Sequence &sequence) const continue; Sequence::Step &step = sequence.add_step(s.tag, *renderable); - step.set_blend(s.blend); step.set_depth_test(s.depth_test); step.set_stencil_test(s.stencil_test); step.set_lighting(s.lighting); diff --git a/source/builders/sequencetemplate.cpp b/source/builders/sequencetemplate.cpp index e8e451fc..e48750e5 100644 --- a/source/builders/sequencetemplate.cpp +++ b/source/builders/sequencetemplate.cpp @@ -144,8 +144,6 @@ void SequenceTemplate::ClearLoader::stencil(int s) SequenceTemplate::Step::Loader::Loader(Step &p, Collection &c): DataFile::CollectionObjectLoader(p, &c) { - add("blend", &Loader::blend); - add("blend", &Loader::blend_factors); add("depth_test", &Loader::depth_test); add("depth_test", &Loader::depth_compare); add("lighting", &Loader::lighting); @@ -160,16 +158,6 @@ void SequenceTemplate::Step::Loader::set_inline_base_name(const string &n) inline_base_name = n; } -void SequenceTemplate::Step::Loader::blend() -{ - load_sub(obj.blend); -} - -void SequenceTemplate::Step::Loader::blend_factors(BlendFactor src, BlendFactor dest) -{ - obj.blend = Blend(src, dest); -} - void SequenceTemplate::Step::Loader::depth_test() { load_sub(obj.depth_test); diff --git a/source/builders/sequencetemplate.h b/source/builders/sequencetemplate.h index 972a6b0b..044cbd5e 100644 --- a/source/builders/sequencetemplate.h +++ b/source/builders/sequencetemplate.h @@ -5,7 +5,6 @@ #include #include #include -#include "blend.h" #include "depthtest.h" #include "postprocessor.h" #include "resources.h" @@ -75,8 +74,6 @@ public: void set_inline_base_name(const std::string &); private: - void blend(); - void blend_factors(BlendFactor, BlendFactor); void depth_test(); void depth_compare(Predicate); void lighting(const std::string &); @@ -90,7 +87,6 @@ public: const Lighting *lighting = 0; DepthTest depth_test; StencilTest stencil_test; - Blend blend; std::string slot_name; Renderable *default_renderable = 0; }; diff --git a/source/materials/rendermethod.cpp b/source/materials/rendermethod.cpp index c5ad35d5..3208929c 100644 --- a/source/materials/rendermethod.cpp +++ b/source/materials/rendermethod.cpp @@ -86,6 +86,11 @@ void RenderMethod::set_face_cull(CullMode fc) face_cull = fc; } +void RenderMethod::set_blend(const Blend &b) +{ + blend = b; +} + void RenderMethod::set_receive_shadows(bool rs) { receive_shadows = rs; @@ -99,6 +104,7 @@ void RenderMethod::apply(Renderer &renderer) const if(material) renderer.add_shader_data(material->get_shader_data()); renderer.set_face_cull(face_cull); + renderer.set_blend(&blend); } void RenderMethod::set_debug_name(const string &name) @@ -122,6 +128,8 @@ RenderMethod::Loader::Loader(RenderMethod &p, Collection &c): void RenderMethod::Loader::init_actions() { + add("blend", &Loader::blend); + add("blend", &Loader::blend_factors); add("face_cull", &RenderMethod::face_cull); add("shader", &Loader::shader); add("image_based_lighting", &RenderMethod::image_based_lighting); @@ -146,6 +154,16 @@ void RenderMethod::Loader::finish() obj.maybe_create_material_shader(); } +void RenderMethod::Loader::blend() +{ + load_sub(obj.blend); +} + +void RenderMethod::Loader::blend_factors(BlendFactor src, BlendFactor dest) +{ + obj.blend = Blend(src, dest); +} + void RenderMethod::Loader::material_inline() { Material::GenericLoader ldr(get_collection()); diff --git a/source/materials/rendermethod.h b/source/materials/rendermethod.h index 723aa5a2..94f716a4 100644 --- a/source/materials/rendermethod.h +++ b/source/materials/rendermethod.h @@ -3,6 +3,7 @@ #include #include +#include "blend.h" #include "cullface.h" #include "material.h" @@ -40,6 +41,8 @@ public: private: virtual void finish(); + void blend(); + void blend_factors(BlendFactor, BlendFactor); void material_inline(); void material(const std::string &); void shader(const std::string &); @@ -80,6 +83,7 @@ private: std::string material_slot; std::vector textures; CullMode face_cull = CULL_BACK; + Blend blend; bool receive_shadows = false; bool image_based_lighting = false; @@ -98,6 +102,8 @@ public: Tag get_texture_tag(const std::string &) const; void set_face_cull(CullMode); CullMode get_face_cull() const { return face_cull; } + void set_blend(const Blend &); + const Blend &get_blend() const { return blend; } void set_receive_shadows(bool); bool get_receive_shadows() const { return receive_shadows; } void set_image_based_lighting(bool); diff --git a/source/render/sequence.cpp b/source/render/sequence.cpp index 44a7381b..4ccf5408 100644 --- a/source/render/sequence.cpp +++ b/source/render/sequence.cpp @@ -148,7 +148,6 @@ void Sequence::render(Renderer &renderer, Tag tag) const renderer.set_depth_test(&s.get_depth_test()); renderer.set_stencil_test(&s.get_stencil_test()); - renderer.set_blend(&s.get_blend()); if(const Lighting *lighting = s.get_lighting()) renderer.add_shader_data(lighting->get_shader_data()); @@ -212,10 +211,5 @@ void Sequence::Step::set_stencil_test(const StencilTest &st) stencil_test = st; } -void Sequence::Step::set_blend(const Blend &b) -{ - blend = b; -} - } // namespace GL } // namespace Msp diff --git a/source/render/sequence.h b/source/render/sequence.h index efead27f..13431ac4 100644 --- a/source/render/sequence.h +++ b/source/render/sequence.h @@ -2,7 +2,7 @@ #define MSP_GL_SEQUENCE_H_ #include -#include "blend.h" +#include "color.h" #include "depthtest.h" #include "frameformat.h" #include "renderable.h" @@ -39,7 +39,6 @@ public: const Lighting *lighting; DepthTest depth_test; StencilTest stencil_test; - Blend blend; Renderable *renderable; public: @@ -50,11 +49,9 @@ public: void set_lighting(const Lighting *); void set_depth_test(const DepthTest &); void set_stencil_test(const StencilTest &); - void set_blend(const Blend &); const Lighting *get_lighting() const { return lighting; } const DepthTest &get_depth_test() const { return depth_test; } const StencilTest &get_stencil_test() const { return stencil_test; } - const Blend &get_blend() const { return blend; } Renderable *get_renderable() const { return renderable; } }; diff --git a/tools/viewer.cpp b/tools/viewer.cpp index c54d7278..666372c3 100644 --- a/tools/viewer.cpp +++ b/tools/viewer.cpp @@ -238,7 +238,6 @@ Viewer::Viewer(int argc, char **argv): GL::Sequence::Step &step = sequence->add_step(0, *renderable); step.set_lighting(&lighting); step.set_depth_test(GL::LEQUAL); - step.set_blend(GL::Blend(GL::SRC_ALPHA, GL::ONE_MINUS_SRC_ALPHA)); } view.set_content(sequence); -- 2.43.0