]> git.tdb.fi Git - libs/gl.git/blobdiff - source/render/sequence.cpp
Make clearing the render target a responsibility of Sequence
[libs/gl.git] / source / render / sequence.cpp
index e953b4d6925944b10d872301ef35667a7904f857..254a6c462abcbdc01aa232a104c05cf5380db269 100644 (file)
@@ -7,52 +7,37 @@
 #include "renderer.h"
 #include "sequence.h"
 #include "texture2d.h"
-#include "view.h"
 
 using namespace std;
 
 namespace Msp {
 namespace GL {
 
-Sequence::Sequence(unsigned w, unsigned h, const FrameFormat &f)
-{
-       init(w, h, f);
-}
-
-Sequence::Sequence(const View &view, const FrameFormat &f)
-{
-       init(view.get_width(), view.get_height(), f);
-}
+Sequence::Sequence():
+       width(0),
+       height(0),
+       target{0, 0},
+       target_ms(0),
+       clear_enabled(false)
+{ }
 
-Sequence::Sequence(const Framebuffer &fbo, const FrameFormat &f)
+Sequence::Sequence(unsigned w, unsigned h, const FrameFormat &f):
+       width(w),
+       height(h),
+       target_format(f),
+       target_ms(0),
+       clear_enabled(false)
 {
-       init(fbo.get_width(), fbo.get_height(), f);
-}
+       if(target_format.empty())
+               throw invalid_argument("Sequence::Sequence");
 
-void Sequence::init(unsigned w, unsigned h, const FrameFormat &f)
-{
-       width = w;
-       height = h;
-       target_format = f;
+       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.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.get_samples()>1)
+               target_ms = new RenderTarget(width, height, target_format);
 }
 
 Sequence::~Sequence()
@@ -65,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));
@@ -116,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)
        {