]> git.tdb.fi Git - libs/gl.git/commitdiff
Allow creating sequences without size
authorMikko Rasa <tdb@tdb.fi>
Fri, 24 Sep 2021 22:38:59 +0000 (01:38 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 25 Sep 2021 11:08:37 +0000 (14:08 +0300)
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
source/builders/sequencebuilder.cpp
source/builders/sequencebuilder.h
source/render/sequence.cpp
source/render/sequence.h
tools/viewer.cpp

index dee2c490148c2ea2ad95325785e1be05137edb88..b5db8afd1f05d02867376819a160f2d2fea0fbc0 100644 (file)
@@ -38,13 +38,12 @@ DesertPillars::DesertPillars(int, char **):
        sky = make_unique<GL::Sky>(content, sun);
        sky->set_debug_name("Sky");
 
-       unsigned shadow_size = 8192;
-       shadow_seq = make_unique<GL::Sequence>(shadow_size, shadow_size);
+       shadow_seq = make_unique<GL::Sequence>();
        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<GL::ShadowMap>(shadow_size, *sky, sun, *shadow_seq);
+       shadow_map = make_unique<GL::ShadowMap>(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<GL::Sequence>(env_size, env_size);
+       env_seq = make_unique<GL::Sequence>();
        env_seq->set_debug_name("Environment sequence");
        step = &env_seq->add_step("", *shadow_map);
        step->set_lighting(&resources.get<GL::Lighting>("Desert.lightn"));
index 300ba23846ae5eba8571194a915119b4327dc370..2c170511fcb5eb049c9aaccabf03d61ae1d77313 100644 (file)
@@ -87,6 +87,13 @@ void SequenceBuilder::build(Sequence &sequence) const
        }
 }
 
+Sequence *SequenceBuilder::build() const
+{
+       RefPtr<Sequence> sequence = new Sequence();
+       build(*sequence);
+       return sequence.release();
+}
+
 Sequence *SequenceBuilder::build(unsigned w, unsigned h) const
 {
        RefPtr<Sequence> sequence = new Sequence(w, h, create_frame_format());
index 93a522cc2907723ead83469fb2b11f6a06c4e156..4cc93037dba95a322b1e04b9b77003f61bdb1d3f 100644 (file)
@@ -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;
index d5b3ae94f9634a827865d9cdec0c11d2224fbb22..535e81859aa0dea0a8d403088abc8ae2ce819d6a 100644 (file)
@@ -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()
index 0bc65cb78e5f1c5d410b4d5cbc52ca6e4a18adf1..e1ad77bde8baf8f6b23aff926da02f2c8e1dffd4 100644 (file)
@@ -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. */
index 20c11c311a61e92efd59ced67d8b3a8c91be9ca2..4c7b01e8ac71172d4f23e272dc6de276f5dba58c 100644 (file)
@@ -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);