X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Frender%2Fsequence.cpp;h=7a964c870d39e2bbe40a9cbf4a2571d1e1f40843;hp=e953b4d6925944b10d872301ef35667a7904f857;hb=006bdb4f8660098fc524dcca80b24c943c65b249;hpb=e9a898f315b5d1396f196d785913a283c30940f2 diff --git a/source/render/sequence.cpp b/source/render/sequence.cpp index e953b4d6..7a964c87 100644 --- a/source/render/sequence.cpp +++ b/source/render/sequence.cpp @@ -7,52 +7,41 @@ #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), + clear_depth(1.0f), + clear_stencil(0) +{ } -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), + clear_depth(1.0f), + clear_stencil(0) { - 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 +54,29 @@ Sequence::~Sequence() delete target_ms; } +void Sequence::set_clear_enabled(bool c) +{ + clear_enabled = c; +} + +void Sequence::set_clear_colors(const vector &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)); @@ -116,9 +128,31 @@ 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()); - renderer.clear(); + + if(clear_enabled) + { + 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