From: Mikko Rasa Date: Sat, 25 Sep 2021 11:03:58 +0000 (+0300) Subject: Make clearing the render target a responsibility of Sequence X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=ff8a8bfa114a690b7b25d9503bb5ed811d6aeca9;p=libs%2Fgl.git Make clearing the render target a responsibility of Sequence --- diff --git a/blender/io_mspgl/export_scene.py b/blender/io_mspgl/export_scene.py index ee9c8c2f..0f1d1935 100644 --- a/blender/io_mspgl/export_scene.py +++ b/blender/io_mspgl/export_scene.py @@ -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"])) diff --git a/demos/desertpillars/source/desertpillars.cpp b/demos/desertpillars/source/desertpillars.cpp index b5db8afd..016cc95d 100644 --- a/demos/desertpillars/source/desertpillars.cpp +++ b/demos/desertpillars/source/desertpillars.cpp @@ -39,6 +39,7 @@ DesertPillars::DesertPillars(int, char **): sky->set_debug_name("Sky"); shadow_seq = make_unique(); + 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(); + 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("Desert.lightn")); diff --git a/source/builders/sequencebuilder.cpp b/source/builders/sequencebuilder.cpp index 2c170511..6e87081d 100644 --- a/source/builders/sequencebuilder.cpp +++ b/source/builders/sequencebuilder.cpp @@ -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); diff --git a/source/builders/sequencetemplate.cpp b/source/builders/sequencetemplate.cpp index be8f3d71..83c4b767 100644 --- a/source/builders/sequencetemplate.cpp +++ b/source/builders/sequencetemplate.cpp @@ -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; diff --git a/source/builders/sequencetemplate.h b/source/builders/sequencetemplate.h index 9de2082d..660a0432 100644 --- a/source/builders/sequencetemplate.h +++ b/source/builders/sequencetemplate.h @@ -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 steps; std::vector postprocessors; + bool clear_enabled; public: SequenceTemplate(); @@ -128,6 +130,7 @@ public: unsigned get_maximum_multisample() const { return max_multisample; } const std::vector &get_steps() const { return steps; } const std::vector &get_postprocessors() const { return postprocessors; } + bool is_clear_enabled() const { return clear_enabled; } template static void register_postprocessor(const std::string &); diff --git a/source/effects/environmentmap.cpp b/source/effects/environmentmap.cpp index a675f7e2..0cd1d4b9 100644 --- a/source/effects/environmentmap.cpp +++ b/source/effects/environmentmap.cpp @@ -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); } diff --git a/source/effects/shadowmap.cpp b/source/effects/shadowmap.cpp index 29358385..bf075778 100644 --- a/source/effects/shadowmap.cpp +++ b/source/effects/shadowmap.cpp @@ -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); diff --git a/source/render/sequence.cpp b/source/render/sequence.cpp index 535e8185..254a6c46 100644 --- a/source/render/sequence.cpp +++ b/source/render/sequence.cpp @@ -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) { diff --git a/source/render/sequence.h b/source/render/sequence.h index e1ad77bd..061b04de 100644 --- a/source/render/sequence.h +++ b/source/render/sequence.h @@ -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 &); diff --git a/source/render/view.cpp b/source/render/view.cpp index ba4b9469..ac244335 100644 --- a/source/render/view.cpp +++ b/source/render/view.cpp @@ -42,7 +42,6 @@ void View::render(Renderer &renderer) { Renderer::Push _push(renderer); renderer.set_framebuffer(&target); - renderer.clear(); if(content) { if(camera)