X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fpipeline.cpp;h=67ddf6566cf3592422490f3f61343f094beb8286;hb=5eb4e7ebd0dc36bc0d9817dedcc152f3bd581f70;hp=de98b2d383283d4822d1ed7e9b684ac60ed98e4b;hpb=f14435e58bfa0fa697a06ba9a454bb30cd37d9d8;p=libs%2Fgl.git diff --git a/source/pipeline.cpp b/source/pipeline.cpp index de98b2d3..67ddf656 100644 --- a/source/pipeline.cpp +++ b/source/pipeline.cpp @@ -1,7 +1,6 @@ +#include #include "blend.h" #include "camera.h" -#include "effect.h" -#include "except.h" #include "framebuffer.h" #include "lighting.h" #include "pipeline.h" @@ -35,6 +34,9 @@ Pipeline::~Pipeline() delete fbo; delete color_buf; delete depth_buf; + delete fbo_ms; + delete color_buf_ms; + delete depth_buf_ms; } void Pipeline::set_hdr(bool h) @@ -56,30 +58,10 @@ void Pipeline::set_camera(const Camera *c) camera = c; } -PipelinePass &Pipeline::add_pass(const Tag &tag) -{ - if(passes.count(tag)) - throw KeyError("Pass already exists"); - - PipelinePass &pass = passes[tag]; - pass_order.push_back(tag); - return pass; -} - -PipelinePass &Pipeline::get_pass(const Tag &tag) -{ - PassMap::iterator i = passes.find(tag); - if(i==passes.end()) - throw KeyError("Unknown pass"); - return i->second; -} - -const PipelinePass &Pipeline::get_pass(const Tag &tag) const +Pipeline::Pass &Pipeline::add_pass(const Tag &tag) { - PassMap::const_iterator i = passes.find(tag); - if(i==passes.end()) - throw KeyError("Unknown pass"); - return i->second; + passes.push_back(Pass(tag)); + return passes.back(); } void Pipeline::add_renderable(const Renderable &r) @@ -117,11 +99,6 @@ void Pipeline::remove_renderable(const Renderable &r) } } -void Pipeline::add_effect(Effect &e) -{ - effects.push_back(&e); -} - void Pipeline::add_postprocessor(PostProcessor &pp) { postproc.push_back(&pp); @@ -131,46 +108,38 @@ void Pipeline::add_postprocessor(PostProcessor &pp) } } -void Pipeline::render(Renderer &renderer, const Tag &tag) const +void Pipeline::render(const Tag &tag) const { - const PipelinePass &pass = get_pass(tag); + if(tag.id) + return; - Bind bind_depth_test(pass.depth_test); - Bind bind_blend(pass.blend); - Bind bind_lighting(pass.lighting); - - for(vector::const_iterator i=pass.effects.begin(); i!=pass.effects.end(); ++i) - (*i)->prepare(); - - for(vector::const_iterator i=renderables.begin(); i!=renderables.end(); ++i) - if(i->passes.empty() || i->passes.count(tag)) - i->renderable->render(renderer, tag); - - for(vector::const_iterator i=pass.effects.end(); i!=pass.effects.begin();) - (*--i)->cleanup(); + Renderer renderer(camera); + render(renderer, tag); } -void Pipeline::render_all() const +void Pipeline::render(Renderer &renderer, const Tag &tag) const { - if(camera) - camera->apply(); + if(tag.id) + return; if(fbo) { Framebuffer *f = (fbo_ms ? fbo_ms : fbo); + // XXX exception safety f->bind(); f->clear(COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT); } - for(vector::const_iterator i=effects.begin(); i!=effects.end(); ++i) - (*i)->prepare(); - - Renderer renderer(camera); - for(vector::const_iterator i=pass_order.begin(); i!=pass_order.end(); ++i) - render(renderer, *i); + for(PassList::const_iterator i=passes.begin(); i!=passes.end(); ++i) + { + Bind bind_depth_test(i->get_depth_test()); + Bind bind_blend(i->get_blend()); + Bind bind_lighting(i->get_lighting()); - for(vector::const_iterator i=effects.end(); i!=effects.begin();) - (*--i)->cleanup(); + for(vector::const_iterator j=renderables.begin(); j!=renderables.end(); ++j) + if(j->passes.empty() || j->passes.count(i->get_tag())) + j->renderable->render(renderer, i->get_tag()); + } if(fbo) { @@ -228,6 +197,29 @@ void Pipeline::create_fbos() } +Pipeline::Pass::Pass(const Tag &t): + tag(t), + lighting(0), + depth_test(0), + blend(0) +{ } + +void Pipeline::Pass::set_lighting(const Lighting *l) +{ + lighting = l; +} + +void Pipeline::Pass::set_depth_test(const DepthTest *d) +{ + depth_test = d; +} + +void Pipeline::Pass::set_blend(const Blend *b) +{ + blend = b; +} + + Pipeline::Slot::Slot(const Renderable *r): renderable(r) { }