X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Frender%2Fsequence.cpp;h=2a5b351c888d2b7e3c609706061f8ae352301bda;hb=9e63512930bc7dace6dc169c65161961e5dcfcf6;hp=e953b4d6925944b10d872301ef35667a7904f857;hpb=e9a898f315b5d1396f196d785913a283c30940f2;p=libs%2Fgl.git diff --git a/source/render/sequence.cpp b/source/render/sequence.cpp index e953b4d6..2a5b351c 100644 --- a/source/render/sequence.cpp +++ b/source/render/sequence.cpp @@ -1,68 +1,66 @@ -#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" -#include "view.h" using namespace std; namespace Msp { namespace GL { -Sequence::Sequence(unsigned w, unsigned h, const FrameFormat &f) +Tag Sequence::noclear_tag = "noclear"; + +Sequence::Sequence(unsigned w, unsigned h, const FrameFormat &f): + width(w), + height(h), + target_format(f) { - init(w, h, f); + 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(const View &view, const FrameFormat &f) +Sequence::~Sequence() { - init(view.get_width(), view.get_height(), f); + for(OwnedObject &o: owned_data) + o.delete_func(o.pointer); + delete target[0]; + delete target[1]; + delete target_ms; } -Sequence::Sequence(const Framebuffer &fbo, const FrameFormat &f) +void Sequence::set_clear_enabled(bool c) { - init(fbo.get_width(), fbo.get_height(), f); + clear_enabled = c; } -void Sequence::init(unsigned w, unsigned h, const FrameFormat &f) +void Sequence::set_clear_colors(const vector &c) { - width = w; - height = h; - target_format = f; + clear_enabled = true; + clear_colors = c; +} - 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; - } +void Sequence::set_clear_depth(float d) +{ + clear_enabled = true; + clear_depth = d; } -Sequence::~Sequence() +void Sequence::set_clear_stencil(int s) { - for(PostProcStep &p: postproc) - if(p.owned) - delete p.postproc; - delete target[0]; - delete target[1]; - delete target_ms; + clear_enabled = true; + clear_stencil = s; } Sequence::Step &Sequence::add_step(Tag tag, Renderable &r) @@ -72,24 +70,10 @@ Sequence::Step &Sequence::add_step(Tag tag, Renderable &r) } void Sequence::add_postprocessor(PostProcessor &pp) -{ - add_postprocessor(&pp, false); -} - -void Sequence::add_postprocessor_owned(PostProcessor *pp) -{ - add_postprocessor(pp, true); -} - -void Sequence::add_postprocessor(PostProcessor *pp, bool owned) { if(target_format.empty()) - { - if(owned) - delete pp; throw invalid_operation("Sequence::add_postprocessor"); - } - postproc.push_back(PostProcStep(pp, owned)); + postproc.push_back(&pp); } void Sequence::setup_frame(Renderer &renderer) @@ -108,7 +92,7 @@ void Sequence::finish_frame() void Sequence::render(Renderer &renderer, Tag tag) const { - if(tag.id) + if(tag.id && tag!=noclear_tag) return; Renderer::Push _push(renderer); @@ -116,9 +100,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 && tag!=noclear_tag) + { + 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_shader_data()); - renderer.set_clipping(s.get_clipping()); if(const Renderable *renderable = s.get_renderable()) - renderer.render(*renderable, s.get_tag()); + renderable->render(renderer, s.get_tag()); } if(target[0]) { if(target_ms) - renderer.resolve_multisample(target[0]->get_framebuffer(), COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT); + renderer.resolve_multisample(target[0]->get_framebuffer()); renderer.set_depth_test(0); renderer.set_stencil_test(0); @@ -152,7 +156,7 @@ void Sequence::render(Renderer &renderer, Tag tag) const renderer.set_framebuffer(i+1get_framebuffer() : out_fbo); const Texture2D &color = target[j]->get_target_texture(COLOR_ATTACHMENT); const Texture2D &depth = target[j]->get_target_texture(DEPTH_ATTACHMENT); - postproc[i].postproc->render(renderer, color, depth); + postproc[i]->render(renderer, color, depth); } } } @@ -174,7 +178,6 @@ void Sequence::set_debug_name(const string &name) Sequence::Step::Step(Tag t, Renderable *r): tag(t), lighting(0), - clipping(0), renderable(r) { } @@ -193,15 +196,5 @@ void Sequence::Step::set_stencil_test(const StencilTest &st) stencil_test = st; } -void Sequence::Step::set_blend(const Blend &b) -{ - blend = b; -} - -void Sequence::Step::set_clipping(const Clipping *c) -{ - clipping = c; -} - } // namespace GL } // namespace Msp