X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Frender%2Fsequence.cpp;h=e0c333dec2b26b679ed0b293063678b9c5b6680d;hb=9813f8711628a0fbe786406e974dc33546dc9cee;hp=535e81859aa0dea0a8d403088abc8ae2ce819d6a;hpb=d4e380914f02800b7d915a8748ac9ccd7029bc3b;p=libs%2Fgl.git diff --git a/source/render/sequence.cpp b/source/render/sequence.cpp index 535e8185..e0c333de 100644 --- a/source/render/sequence.cpp +++ b/source/render/sequence.cpp @@ -1,10 +1,9 @@ -#include -#include "blend.h" +#include #include "error.h" -#include "framebuffer.h" #include "lighting.h" #include "postprocessor.h" #include "renderer.h" +#include "rendertarget.h" #include "sequence.h" #include "texture2d.h" @@ -17,14 +16,20 @@ Sequence::Sequence(): width(0), height(0), target{0, 0}, - target_ms(0) + target_ms(0), + clear_enabled(false), + clear_depth(1.0f), + clear_stencil(0) { } Sequence::Sequence(unsigned w, unsigned h, const FrameFormat &f): width(w), height(h), target_format(f), - target_ms(0) + target_ms(0), + clear_enabled(false), + clear_depth(1.0f), + clear_stencil(0) { if(target_format.empty()) throw invalid_argument("Sequence::Sequence"); @@ -48,6 +53,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)); @@ -99,9 +127,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 = (iget_framebuffer(), COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT); + renderer.resolve_multisample(target[0]->get_framebuffer()); renderer.set_depth_test(0); renderer.set_stencil_test(0);