]> git.tdb.fi Git - libs/gl.git/commitdiff
Move blend state from Sequence::Step to RenderMethod
authorMikko Rasa <tdb@tdb.fi>
Sat, 16 Oct 2021 08:49:11 +0000 (11:49 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 16 Oct 2021 16:03:00 +0000 (19:03 +0300)
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
source/builders/sequencetemplate.cpp
source/builders/sequencetemplate.h
source/materials/rendermethod.cpp
source/materials/rendermethod.h
source/render/sequence.cpp
source/render/sequence.h
tools/viewer.cpp

index 45d4f873b1e03a486bca93e4264028fb09cf66ec..5fca61400a03645941c06a053c1353ff16513ba2 100644 (file)
@@ -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);
index e8e451fc9a54d78a5b6d1d1bfc415a64ffef90be..e48750e5f5df9299b25590658e1a6b2d3eae3603 100644 (file)
@@ -144,8 +144,6 @@ void SequenceTemplate::ClearLoader::stencil(int s)
 SequenceTemplate::Step::Loader::Loader(Step &p, Collection &c):
        DataFile::CollectionObjectLoader<Step>(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);
index 972a6b0b18939e6deda71e243d3dd89a31594eb9..044cbd5e083f7ee90610cec18753c7bb404212e7 100644 (file)
@@ -5,7 +5,6 @@
 #include <vector>
 #include <msp/core/typeregistry.h>
 #include <msp/datafile/objectloader.h>
-#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;
        };
index c5ad35d5b3e95976f6c35e047a0ed37fc9e630fc..3208929cc2a98e1de31d8f18cb4edf12456859d0 100644 (file)
@@ -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());
index 723aa5a25733c980c85d6db62e06eb1bc4d04669..94f716a41c871d4705f76bc585ad493087379fa6 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <msp/core/refptr.h>
 #include <msp/datafile/objectloader.h>
+#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<TextureSlot> 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);
index 44a7381b160044f60c8e15c6d88617513715f786..4ccf540809d4a3138f4e30e3d23a0ca3e0e35370 100644 (file)
@@ -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
index efead27f98e9fcc45490ba5dffff351666c598f9..13431ac469e824c4b9e5d1a4283678d710011090 100644 (file)
@@ -2,7 +2,7 @@
 #define MSP_GL_SEQUENCE_H_
 
 #include <vector>
-#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; }
        };
 
index c54d7278c4cba0a23a4a935850a2eb25ead4d816..666372c3e6bbcdf3de0c5c3ed37a83e9e91cc009 100644 (file)
@@ -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);