From d4e380914f02800b7d915a8748ac9ccd7029bc3b Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 25 Sep 2021 01:38:59 +0300 Subject: [PATCH] Allow creating sequences without size Also require a frame format when a size is specified. Sequences used as content renderables of effects commonly have no postprocessors, in which case internal render targets are not needed either and the size is not meaningful. --- demos/desertpillars/source/desertpillars.cpp | 8 ++--- source/builders/sequencebuilder.cpp | 7 ++++ source/builders/sequencebuilder.h | 1 + source/render/sequence.cpp | 38 ++++++++++---------- source/render/sequence.h | 6 ++-- tools/viewer.cpp | 2 +- 6 files changed, 34 insertions(+), 28 deletions(-) diff --git a/demos/desertpillars/source/desertpillars.cpp b/demos/desertpillars/source/desertpillars.cpp index dee2c490..b5db8afd 100644 --- a/demos/desertpillars/source/desertpillars.cpp +++ b/demos/desertpillars/source/desertpillars.cpp @@ -38,13 +38,12 @@ DesertPillars::DesertPillars(int, char **): sky = make_unique(content, sun); sky->set_debug_name("Sky"); - unsigned shadow_size = 8192; - shadow_seq = make_unique(shadow_size, shadow_size); + shadow_seq = make_unique(); shadow_seq->set_debug_name("Shadow sequence"); GL::Sequence::Step *step = &shadow_seq->add_step("shadow", content); step->set_depth_test(GL::LEQUAL); - shadow_map = make_unique(shadow_size, *sky, sun, *shadow_seq); + shadow_map = make_unique(8192, *sky, sun, *shadow_seq); shadow_map->set_debug_name("Shadow map"); shadow_map->set_target(GL::Vector3(0.0f, 0.0f, 0.0f), 20.0f); @@ -53,8 +52,7 @@ DesertPillars::DesertPillars(int, char **): seq_bld.set_debug_name("Main sequence"); sequence.reset(seq_bld.build(view)); - unsigned env_size = 256; - env_seq = make_unique(env_size, env_size); + env_seq = make_unique(); 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 300ba238..2c170511 100644 --- a/source/builders/sequencebuilder.cpp +++ b/source/builders/sequencebuilder.cpp @@ -87,6 +87,13 @@ void SequenceBuilder::build(Sequence &sequence) const } } +Sequence *SequenceBuilder::build() const +{ + RefPtr sequence = new Sequence(); + build(*sequence); + return sequence.release(); +} + Sequence *SequenceBuilder::build(unsigned w, unsigned h) const { RefPtr sequence = new Sequence(w, h, create_frame_format()); diff --git a/source/builders/sequencebuilder.h b/source/builders/sequencebuilder.h index 93a522cc..4cc93037 100644 --- a/source/builders/sequencebuilder.h +++ b/source/builders/sequencebuilder.h @@ -32,6 +32,7 @@ public: void set_debug_name(const std::string &); void build(Sequence &) const; + Sequence *build() const; Sequence *build(unsigned, unsigned) const; Sequence *build(const View &) const; Sequence *build(const Framebuffer &) const; diff --git a/source/render/sequence.cpp b/source/render/sequence.cpp index d5b3ae94..535e8185 100644 --- a/source/render/sequence.cpp +++ b/source/render/sequence.cpp @@ -13,29 +13,29 @@ using namespace std; namespace Msp { namespace GL { +Sequence::Sequence(): + width(0), + height(0), + target{0, 0}, + target_ms(0) +{ } + Sequence::Sequence(unsigned w, unsigned h, const FrameFormat &f): width(w), height(h), - target_format(f) + target_format(f), + target_ms(0) { - if(!target_format.empty()) - { - FrameFormat postproc_fmt = target_format; - postproc_fmt.set_samples(1); - target[0] = new RenderTarget(width, height, postproc_fmt); - target[1] = new RenderTarget(width, height, postproc_fmt); - - if(target_format.get_samples()>1) - target_ms = new RenderTarget(width, height, target_format); - else - target_ms = 0; - } - else - { - target_ms = 0; - target[0] = 0; - target[1] = 0; - } + if(target_format.empty()) + throw invalid_argument("Sequence::Sequence"); + + FrameFormat postproc_fmt = target_format; + postproc_fmt.set_samples(1); + target[0] = new RenderTarget(width, height, postproc_fmt); + target[1] = new RenderTarget(width, height, postproc_fmt); + + if(target_format.get_samples()>1) + target_ms = new RenderTarget(width, height, target_format); } Sequence::~Sequence() diff --git a/source/render/sequence.h b/source/render/sequence.h index 0bc65cb7..e1ad77bd 100644 --- a/source/render/sequence.h +++ b/source/render/sequence.h @@ -84,13 +84,13 @@ private: RenderTarget *target_ms; public: - Sequence(unsigned, unsigned, const FrameFormat & = FrameFormat()); + Sequence(); + Sequence(unsigned, unsigned, const FrameFormat &); ~Sequence(); - const FrameFormat &get_target_format() { return target_format; } - unsigned get_width() const { return width; } unsigned get_height() const { return height; } + const FrameFormat &get_target_format() { return target_format; } /** Adds a step to the sequence. It's permissible to add the same Renderable multiple times. */ diff --git a/tools/viewer.cpp b/tools/viewer.cpp index 20c11c31..4c7b01e8 100644 --- a/tools/viewer.cpp +++ b/tools/viewer.cpp @@ -234,7 +234,7 @@ Viewer::Viewer(int argc, char **argv): if(!sequence) { - sequence = new GL::Sequence(view.get_width(), view.get_height()); + sequence = new GL::Sequence(); GL::Sequence::Step &step = sequence->add_step(0, *renderable); step.set_lighting(&lighting); step.set_depth_test(GL::LEQUAL); -- 2.43.0