]> git.tdb.fi Git - libs/gl.git/blobdiff - source/render/sequence.cpp
Make it possible to specify explicit clear values
[libs/gl.git] / source / render / sequence.cpp
index 254a6c462abcbdc01aa232a104c05cf5380db269..7a964c870d39e2bbe40a9cbf4a2571d1e1f40843 100644 (file)
@@ -18,7 +18,9 @@ Sequence::Sequence():
        height(0),
        target{0, 0},
        target_ms(0),
-       clear_enabled(false)
+       clear_enabled(false),
+       clear_depth(1.0f),
+       clear_stencil(0)
 { }
 
 Sequence::Sequence(unsigned w, unsigned h, const FrameFormat &f):
@@ -26,7 +28,9 @@ Sequence::Sequence(unsigned w, unsigned h, const FrameFormat &f):
        height(h),
        target_format(f),
        target_ms(0),
-       clear_enabled(false)
+       clear_enabled(false),
+       clear_depth(1.0f),
+       clear_stencil(0)
 {
        if(target_format.empty())
                throw invalid_argument("Sequence::Sequence");
@@ -55,6 +59,24 @@ void Sequence::set_clear_enabled(bool c)
        clear_enabled = c;
 }
 
+void Sequence::set_clear_colors(const vector<Color> &c)
+{
+       clear_enabled = true;
+       clear_colors = c;
+}
+
+void Sequence::set_clear_depth(float d)
+{
+       clear_enabled = true;
+       clear_depth = d;
+}
+
+void Sequence::set_clear_stencil(int s)
+{
+       clear_enabled = true;
+       clear_stencil = s;
+}
+
 Sequence::Step &Sequence::add_step(Tag tag, Renderable &r)
 {
        steps.push_back(Step(tag, &r));
@@ -109,7 +131,29 @@ void Sequence::render(Renderer &renderer, Tag tag) const
                renderer.set_framebuffer(&(target_ms ? target_ms : target[0])->get_framebuffer());
 
        if(clear_enabled)
-               renderer.clear();
+       {
+               const Framebuffer *target_fbo = renderer.get_framebuffer();
+               if(!target_fbo)
+                       throw invalid_operation("Sequence::render");
+
+               const FrameFormat &format = target_fbo->get_format();
+               ClearValue clear_values[7];
+               unsigned i = 0;
+               Color default_color = (clear_colors.empty() ? Color(0.0f, 0.0f, 0.0f, 0.0f) : clear_colors.front());
+               ClearValue *cv = clear_values;
+               for(FrameAttachment a: format)
+               {
+                       if(get_attach_point(a)==get_attach_point(DEPTH_ATTACHMENT))
+                               cv->depth_stencil.depth = clear_depth;
+                       else if(get_attach_point(a)==get_attach_point(STENCIL_ATTACHMENT))
+                               cv->depth_stencil.stencil = clear_stencil;
+                       else
+                               cv->color = (i<clear_colors.size() ? clear_colors[i++] : default_color);
+                       ++cv;
+               }
+
+               renderer.clear(clear_values);
+       }
 
        for(const Step &s: steps)
        {