X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fpipeline.cpp;h=27cc3e3c63cc9d274e3573c7da915b21b846899d;hp=4c4007233d2b9fd82cc82f9bf7cccdf0cc56f3e4;hb=bb162b9edd4b8c0e9faeed75da4148f5b9735450;hpb=7791ca3eac17e355d1de508b1730dc854ed7712d diff --git a/source/pipeline.cpp b/source/pipeline.cpp index 4c400723..27cc3e3c 100644 --- a/source/pipeline.cpp +++ b/source/pipeline.cpp @@ -9,20 +9,32 @@ #include "renderer.h" #include "tests.h" #include "texture2d.h" +#include "view.h" using namespace std; namespace Msp { namespace GL { -Pipeline::Pipeline(unsigned w, unsigned h, bool d): - camera(0), - width(w), - height(h), - hdr(d), - samples(0), - target_ms(0) +Pipeline::Pipeline(unsigned w, unsigned h, bool d) { + init(w, h); + hdr = d; +} + +Pipeline::Pipeline(const View &view) +{ + init(view.get_width(), view.get_height()); +} + +void Pipeline::init(unsigned w, unsigned h) +{ + camera = 0; + width = w; + height = h; + hdr = false; + samples = 0; + target_ms = 0; target[0] = 0; target[1] = 0; } @@ -81,7 +93,7 @@ Pipeline::Pass &Pipeline::add_pass(const Tag &tag) return passes.back(); } -void Pipeline::add_renderable(const Renderable &r) +void Pipeline::add_renderable(Renderable &r) { for(vector::iterator i=renderables.begin(); i!=renderables.end(); ++i) if(i->renderable==&r) @@ -93,7 +105,7 @@ void Pipeline::add_renderable(const Renderable &r) renderables.push_back(&r); } -void Pipeline::add_renderable_for_pass(const Renderable &r, const Tag &tag) +void Pipeline::add_renderable_for_pass(Renderable &r, const Tag &tag) { for(vector::iterator i=renderables.begin(); i!=renderables.end(); ++i) if(i->renderable==&r) @@ -106,7 +118,7 @@ void Pipeline::add_renderable_for_pass(const Renderable &r, const Tag &tag) renderables.back().passes.insert(tag); } -void Pipeline::remove_renderable(const Renderable &r) +void Pipeline::remove_renderable(Renderable &r) { for(vector::iterator i=renderables.begin(); i!=renderables.end(); ++i) if(i->renderable==&r) @@ -116,7 +128,7 @@ void Pipeline::remove_renderable(const Renderable &r) } } -Pipeline::Pass &Pipeline::add_pass(const Tag &tag, const Renderable &r) +Pipeline::Pass &Pipeline::add_pass(const Tag &tag, Renderable &r) { passes.push_back(Pass(tag, &r)); return passes.back(); @@ -124,7 +136,19 @@ Pipeline::Pass &Pipeline::add_pass(const Tag &tag, const Renderable &r) void Pipeline::add_postprocessor(PostProcessor &pp) { - postproc.push_back(&pp); + add_postprocessor(&pp, true); +} + +void Pipeline::add_postprocessor_owned(PostProcessor *pp) +{ + add_postprocessor(pp, false); +} + +void Pipeline::add_postprocessor(PostProcessor *pp, bool keep) +{ + postproc.push_back(pp); + if(keep) + postproc.back().keep(); try { create_targets(0); @@ -136,32 +160,29 @@ void Pipeline::add_postprocessor(PostProcessor &pp) } } -void Pipeline::setup_frame() const +void Pipeline::setup_frame(Renderer &renderer) { for(PassList::const_iterator i=passes.begin(); i!=passes.end(); ++i) - if(const Renderable *renderable = i->get_renderable()) - renderable->setup_frame(); + if(Renderable *renderable = i->get_renderable()) + renderable->setup_frame(renderer); for(vector::const_iterator i=renderables.begin(); i!=renderables.end(); ++i) - i->renderable->setup_frame(); + i->renderable->setup_frame(renderer); } -void Pipeline::finish_frame() const +void Pipeline::finish_frame() { for(PassList::const_iterator i=passes.begin(); i!=passes.end(); ++i) - if(const Renderable *renderable = i->get_renderable()) + if(Renderable *renderable = i->get_renderable()) renderable->finish_frame(); for(vector::const_iterator i=renderables.begin(); i!=renderables.end(); ++i) i->renderable->finish_frame(); } -void Pipeline::render(const Tag &tag) const +void Pipeline::render() { - if(tag.id) - return; - Renderer renderer(camera); - setup_frame(); - render(renderer, tag); + setup_frame(renderer); + render(renderer); finish_frame(); } @@ -171,7 +192,7 @@ void Pipeline::render(Renderer &renderer, const Tag &tag) const return; const Framebuffer *out_fbo = Framebuffer::current(); - // These is a no-ops but will ensure the related state gets restored + // These are no-ops but will ensure the related state gets restored BindRestore restore_fbo(out_fbo); BindRestore restore_depth_test(DepthTest::current()); BindRestore restore_blend(Blend::current()); @@ -183,7 +204,6 @@ void Pipeline::render(Renderer &renderer, const Tag &tag) const fbo.clear(COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT); } - for(PassList::const_iterator i=passes.begin(); i!=passes.end(); ++i) { if(const DepthTest *dt = i->get_depth_test()) @@ -259,7 +279,7 @@ void Pipeline::create_targets(unsigned recreate) } -Pipeline::Pass::Pass(const Tag &t, const Renderable *r): +Pipeline::Pass::Pass(const Tag &t, Renderable *r): tag(t), lighting(0), depth_test(0), @@ -289,7 +309,7 @@ void Pipeline::Pass::set_clipping(const Clipping *c) } -Pipeline::Slot::Slot(const Renderable *r): +Pipeline::Slot::Slot(Renderable *r): renderable(r) { }