X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fpipeline.cpp;h=a7f4130bbab1fffd2605521426f562dbf42a92bf;hb=bec07999d95b76f4b47cffcc564d0cd0afc0435e;hp=29c42324add861d9e7813ba252f4fde9217f20b5;hpb=d386eadfd08b556ecb05627a7ceca14652e8b1e5;p=libs%2Fgl.git diff --git a/source/pipeline.cpp b/source/pipeline.cpp index 29c42324..a7f4130b 100644 --- a/source/pipeline.cpp +++ b/source/pipeline.cpp @@ -9,20 +9,38 @@ #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()); +} + +Pipeline::Pipeline(const Framebuffer &fbo) +{ + init(fbo.get_width(), fbo.get_height()); +} + +void Pipeline::init(unsigned w, unsigned h) +{ + camera = 0; + width = w; + height = h; + hdr = false; + alpha = false; + samples = 0; + target_ms = 0; target[0] = 0; target[1] = 0; } @@ -39,7 +57,7 @@ void Pipeline::set_hdr(bool h) if(h==hdr) return; - bool old_hdr= hdr; + bool old_hdr = hdr; hdr = h; try { @@ -52,6 +70,24 @@ void Pipeline::set_hdr(bool h) } } +void Pipeline::set_alpha(bool a) +{ + if(a==alpha) + return; + + bool old_alpha = alpha; + alpha = a; + try + { + create_targets(2); + } + catch(...) + { + alpha = old_alpha; + throw; + } +} + void Pipeline::set_multisample(unsigned s) { if(s==samples) @@ -70,61 +106,27 @@ void Pipeline::set_multisample(unsigned s) } } -void Pipeline::set_camera(const Camera *c) -{ - camera = c; -} - -Pipeline::Pass &Pipeline::add_pass(const Tag &tag) +Pipeline::Pass &Pipeline::add_pass(const Tag &tag, Renderable &r) { - passes.push_back(Pass(tag, 0)); + passes.push_back(Pass(tag, &r)); return passes.back(); } -void Pipeline::add_renderable(Renderable &r) -{ - for(vector::iterator i=renderables.begin(); i!=renderables.end(); ++i) - if(i->renderable==&r) - { - i->passes.clear(); - return; - } - - renderables.push_back(&r); -} - -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) - { - i->passes.insert(tag); - return; - } - - renderables.push_back(&r); - renderables.back().passes.insert(tag); -} - -void Pipeline::remove_renderable(Renderable &r) +void Pipeline::add_postprocessor(PostProcessor &pp) { - for(vector::iterator i=renderables.begin(); i!=renderables.end(); ++i) - if(i->renderable==&r) - { - renderables.erase(i); - return; - } + add_postprocessor(&pp, true); } -Pipeline::Pass &Pipeline::add_pass(const Tag &tag, Renderable &r) +void Pipeline::add_postprocessor_owned(PostProcessor *pp) { - passes.push_back(Pass(tag, &r)); - return passes.back(); + add_postprocessor(pp, false); } -void Pipeline::add_postprocessor(PostProcessor &pp) +void Pipeline::add_postprocessor(PostProcessor *pp, bool keep) { - postproc.push_back(&pp); + postproc.push_back(pp); + if(keep) + postproc.back().keep(); try { create_targets(0); @@ -154,21 +156,13 @@ void Pipeline::finish_frame() i->renderable->finish_frame(); } -void Pipeline::render() -{ - Renderer renderer(camera); - setup_frame(renderer); - render(renderer); - finish_frame(); -} - void Pipeline::render(Renderer &renderer, const Tag &tag) const { if(tag.id) 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()); @@ -177,10 +171,9 @@ void Pipeline::render(Renderer &renderer, const Tag &tag) const { Framebuffer &fbo = (samples ? target_ms : target[0])->get_framebuffer(); fbo.bind(); - fbo.clear(COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT); + fbo.clear(); } - for(PassList::const_iterator i=passes.begin(); i!=passes.end(); ++i) { if(const DepthTest *dt = i->get_depth_test()) @@ -241,7 +234,7 @@ void Pipeline::create_targets(unsigned recreate) target_ms = 0; } - PixelFormat color_pf = (hdr ? RGB16F : RGB); + PixelFormat color_pf = (hdr ? (alpha ? RGBA16F : RGB16F) : (alpha ? RGBA8 : RGB8)); RenderTargetFormat fmt = (RENDER_COLOR,color_pf, RENDER_DEPTH); if(!postproc.empty() || samples) {