]> git.tdb.fi Git - libs/gl.git/commitdiff
Make clearing the render target a responsibility of Sequence
authorMikko Rasa <tdb@tdb.fi>
Sat, 25 Sep 2021 11:03:58 +0000 (14:03 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 25 Sep 2021 11:09:41 +0000 (14:09 +0300)
blender/io_mspgl/export_scene.py
demos/desertpillars/source/desertpillars.cpp
source/builders/sequencebuilder.cpp
source/builders/sequencetemplate.cpp
source/builders/sequencetemplate.h
source/effects/environmentmap.cpp
source/effects/shadowmap.cpp
source/render/sequence.cpp
source/render/sequence.h
source/render/view.cpp

index ee9c8c2ff340135e62567061df30dfecb9e3a6eb..0f1d1935601504fd7bbd59b372754579b064482e 100644 (file)
@@ -118,6 +118,8 @@ class SceneExporter:
                if scene.background_set:
                        content = resources[scene.name+".wrapper.scene"]
 
+               seq_res.statements.append(Statement("clear"))
+
                ss = Statement("step", "", "content")
                ss.sub.append(Statement("depth_test", Token("LEQUAL")))
                ss.sub.append(seq_res.create_reference_statement("lighting", resources[scene.name+".lightn"]))
index b5db8afd1f05d02867376819a160f2d2fea0fbc0..016cc95d12bb878ee38dfbe11866a9f143cff5c6 100644 (file)
@@ -39,6 +39,7 @@ DesertPillars::DesertPillars(int, char **):
        sky->set_debug_name("Sky");
 
        shadow_seq = make_unique<GL::Sequence>();
+       shadow_seq->set_clear_enabled(true);
        shadow_seq->set_debug_name("Shadow sequence");
        GL::Sequence::Step *step = &shadow_seq->add_step("shadow", content);
        step->set_depth_test(GL::LEQUAL);
@@ -53,6 +54,7 @@ DesertPillars::DesertPillars(int, char **):
        sequence.reset(seq_bld.build(view));
 
        env_seq = make_unique<GL::Sequence>();
+       env_seq->set_clear_enabled(true);
        env_seq->set_debug_name("Environment sequence");
        step = &env_seq->add_step("", *shadow_map);
        step->set_lighting(&resources.get<GL::Lighting>("Desert.lightn"));
index 2c170511fcb5eb049c9aaccabf03d61ae1d77313..6e87081d4ab5805d8173240eba3ca0b800331045 100644 (file)
@@ -49,6 +49,8 @@ void SequenceBuilder::build(Sequence &sequence) const
                sequence.set_debug_name(debug_name);
 #endif
 
+       sequence.set_clear_enabled(tmpl.is_clear_enabled());
+
        for(const SequenceTemplate::Step &s: tmpl.get_steps())
        {
                Renderable *renderable = get_item(renderables, s.slot_name);
index be8f3d7186b3450018e04c5da50605bdb4d97467..83c4b7671f75234b42125b30509dff9e1bde2371 100644 (file)
@@ -19,7 +19,8 @@ SequenceTemplate::SequenceTemplate():
        hdr(false),
        alpha(false),
        required_multisample(0),
-       max_multisample(0)
+       max_multisample(0),
+       clear_enabled(false)
 { }
 
 SequenceTemplate::~SequenceTemplate()
@@ -64,6 +65,7 @@ SequenceTemplate::Loader::Loader(SequenceTemplate &t, Collection &c):
 {
        add("hdr", &SequenceTemplate::hdr);
        add("alpha", &SequenceTemplate::alpha);
+       add("clear", &Loader::clear);
        add("multisample", &Loader::multisample);
        add("multisample", &Loader::multisample_range);
        add("postprocessor", &Loader::postprocessor);
@@ -79,6 +81,11 @@ void SequenceTemplate::Loader::postprocessor_loaded()
        obj.postprocessors.push_back(get_postprocessor_template());
 }
 
+void SequenceTemplate::Loader::clear()
+{
+       obj.clear_enabled = true;
+}
+
 void SequenceTemplate::Loader::multisample(unsigned samples)
 {
        obj.required_multisample = samples;
index 9de2082d9ab68bdba42b112da51e1e460fa6fd20..660a043297bb2f8046c283bf6954ae538d620f09 100644 (file)
@@ -54,6 +54,7 @@ public:
                Loader(SequenceTemplate &, Collection &);
 
                virtual void postprocessor_loaded();
+               void clear();
                void multisample(unsigned);
                void multisample_range(unsigned, unsigned);
                void postprocessor(const std::string &);
@@ -117,6 +118,7 @@ private:
        unsigned max_multisample;
        std::vector<Step> steps;
        std::vector<PostProcessor> postprocessors;
+       bool clear_enabled;
 
 public:
        SequenceTemplate();
@@ -128,6 +130,7 @@ public:
        unsigned get_maximum_multisample() const { return max_multisample; }
        const std::vector<Step> &get_steps() const { return steps; }
        const std::vector<PostProcessor> &get_postprocessors() const { return postprocessors; }
+       bool is_clear_enabled() const { return clear_enabled; }
 
        template<typename T>
        static void register_postprocessor(const std::string &);
index a675f7e249291d759bda1de98417a463874cca91..0cd1d4b99e3821f0c28b0b06c72328c93a28cbac 100644 (file)
@@ -139,7 +139,6 @@ void EnvironmentMap::setup_frame(Renderer &renderer)
        {
                faces[i].camera.set_position(center);
                renderer.set_framebuffer(&faces[i].fbo);
-               renderer.clear();
                renderer.set_camera(faces[i].camera);
                renderer.render(environment);
        }
index 2935838531f0dd9ca848eb95ed4984c4f2b28746..bf07577878476506ad815a95f2144e4aaef98d07 100644 (file)
@@ -80,7 +80,6 @@ void ShadowMap::setup_frame(Renderer &renderer)
 
        Renderer::Push push(renderer);
        renderer.set_framebuffer(&fbo);
-       renderer.clear(DEPTH_BUFFER_BIT);
        renderer.set_camera(shadow_camera);
        renderer.set_depth_test(&depth_test);
 
index 535e81859aa0dea0a8d403088abc8ae2ce819d6a..254a6c462abcbdc01aa232a104c05cf5380db269 100644 (file)
@@ -17,14 +17,16 @@ Sequence::Sequence():
        width(0),
        height(0),
        target{0, 0},
-       target_ms(0)
+       target_ms(0),
+       clear_enabled(false)
 { }
 
 Sequence::Sequence(unsigned w, unsigned h, const FrameFormat &f):
        width(w),
        height(h),
        target_format(f),
-       target_ms(0)
+       target_ms(0),
+       clear_enabled(false)
 {
        if(target_format.empty())
                throw invalid_argument("Sequence::Sequence");
@@ -48,6 +50,11 @@ Sequence::~Sequence()
        delete target_ms;
 }
 
+void Sequence::set_clear_enabled(bool c)
+{
+       clear_enabled = c;
+}
+
 Sequence::Step &Sequence::add_step(Tag tag, Renderable &r)
 {
        steps.push_back(Step(tag, &r));
@@ -99,10 +106,10 @@ void Sequence::render(Renderer &renderer, Tag tag) const
        const Framebuffer *out_fbo = renderer.get_framebuffer();
 
        if(target[0])
-       {
                renderer.set_framebuffer(&(target_ms ? target_ms : target[0])->get_framebuffer());
+
+       if(clear_enabled)
                renderer.clear();
-       }
 
        for(const Step &s: steps)
        {
index e1ad77bde8baf8f6b23aff926da02f2c8e1dffd4..061b04de3406a60b78c883f11a7b9ad2e2740666 100644 (file)
@@ -82,6 +82,7 @@ private:
        FrameFormat target_format;
        RenderTarget *target[2];
        RenderTarget *target_ms;
+       bool clear_enabled;
 
 public:
        Sequence();
@@ -92,6 +93,8 @@ public:
        unsigned get_height() const { return height; }
        const FrameFormat &get_target_format() { return target_format; }
 
+       void set_clear_enabled(bool);
+
        /** Adds a step to the sequence.  It's permissible to add the same
        Renderable multiple times. */
        Step &add_step(Tag, Renderable &);
index ba4b9469e723db14c6adcb6b972e4e976c3bf1c4..ac244335943bc5b2398dd8fc23b5705553bf82ef 100644 (file)
@@ -42,7 +42,6 @@ void View::render(Renderer &renderer)
 {
        Renderer::Push _push(renderer);
        renderer.set_framebuffer(&target);
-       renderer.clear();
        if(content)
        {
                if(camera)