X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Frender%2Fsequence.cpp;h=74b8bc3b0b4fe9a6835d9f5fab5326dddcc62fe3;hp=5a3afa452e2e9235ade6e0cfc6558073672fa23e;hb=HEAD;hpb=1fba50491957cdd28cff4082a32764691d8ec473 diff --git a/source/render/sequence.cpp b/source/render/sequence.cpp index 5a3afa45..4f10026a 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" @@ -13,24 +12,12 @@ using namespace std; namespace Msp { namespace GL { -Sequence::Sequence(): - width(0), - height(0), - target{0, 0}, - target_ms(0), - clear_enabled(false), - clear_depth(1.0f), - clear_stencil(0) -{ } +const Tag Sequence::noclear_tag = "noclear"; 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) + target_format(f) { if(target_format.empty()) throw invalid_argument("Sequence::Sequence"); @@ -46,9 +33,8 @@ Sequence::Sequence(unsigned w, unsigned h, const FrameFormat &f): Sequence::~Sequence() { - for(PostProcStep &p: postproc) - if(p.owned) - delete p.postproc; + for(OwnedObject &o: owned_data) + o.delete_func(o.pointer); delete target[0]; delete target[1]; delete target_ms; @@ -79,29 +65,15 @@ void Sequence::set_clear_stencil(int s) Sequence::Step &Sequence::add_step(Tag tag, Renderable &r) { - steps.push_back(Step(tag, &r)); + steps.emplace_back(tag, &r); return steps.back(); } 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) @@ -120,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); @@ -130,14 +102,14 @@ void Sequence::render(Renderer &renderer, Tag tag) const if(target[0]) renderer.set_framebuffer(&(target_ms ? target_ms : target[0])->get_framebuffer()); - if(clear_enabled) + 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]; + ClearValue clear_values[FrameFormat::MAX_ATTACHMENTS]; 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; @@ -161,20 +133,22 @@ void Sequence::render(Renderer &renderer, Tag tag) const renderer.set_depth_test(&s.get_depth_test()); renderer.set_stencil_test(&s.get_stencil_test()); - renderer.set_blend(&s.get_blend()); - if (const Lighting *lighting = s.get_lighting()) + if(const Lighting *lighting = s.get_lighting()) renderer.add_shader_data(lighting->get_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]) { + RenderTarget *source = target[0]; if(target_ms) - renderer.resolve_multisample(target[0]->get_framebuffer()); + { + renderer.resolve_multisample(); + source = target_ms; + } renderer.set_depth_test(0); renderer.set_stencil_test(0); @@ -182,11 +156,12 @@ void Sequence::render(Renderer &renderer, Tag tag) const for(unsigned i=0; iget_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); + unsigned j = 1-i%2; + renderer.set_framebuffer(i+1get_framebuffer() : out_fbo); + const Texture2D &color = source->get_target_texture(COLOR_ATTACHMENT); + const Texture2D &depth = source->get_target_texture(DEPTH_ATTACHMENT); + postproc[i]->render(renderer, color, depth); + source = target[j]; } } } @@ -208,7 +183,6 @@ void Sequence::set_debug_name(const string &name) Sequence::Step::Step(Tag t, Renderable *r): tag(t), lighting(0), - clipping(0), renderable(r) { } @@ -227,15 +201,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