X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fpipeline.cpp;h=0df03ca7df7231931874355f855de9c3284cd148;hb=9cf5d10abe5bdff0708c41544f6e8b15aca5151f;hp=466aa23c69b6b3107457817f8efea8f33aa829ac;hpb=db498c7e634fa999cf4b4a8b67c49813009b1790;p=libs%2Fgl.git diff --git a/source/pipeline.cpp b/source/pipeline.cpp index 466aa23c..0df03ca7 100644 --- a/source/pipeline.cpp +++ b/source/pipeline.cpp @@ -37,14 +37,20 @@ Pipeline::~Pipeline() void Pipeline::set_hdr(bool h) { + if(h==hdr) + return; + hdr = h; - create_targets(true); + create_targets(2); } void Pipeline::set_multisample(unsigned s) { + if(s==samples) + return; + samples = s; - create_targets(false); + create_targets(1); } void Pipeline::set_camera(const Camera *c) @@ -96,7 +102,7 @@ void Pipeline::remove_renderable(const Renderable &r) void Pipeline::add_postprocessor(PostProcessor &pp) { postproc.push_back(&pp); - create_targets(false); + create_targets(0); } void Pipeline::setup_frame() const @@ -131,10 +137,14 @@ void Pipeline::render(Renderer &renderer, const Tag &tag) const if(!in_frame) setup_frame(); + const Framebuffer *out_fbo = Framebuffer::current(); + /* Binding the current object is a no-op, but this will restore the original + FBO in case an exception is thrown. */ + Bind restore_fbo(out_fbo, true); + if(target[0]) { Framebuffer &fbo = (samples ? target_ms->fbo : target[0]->fbo); - // XXX exception safety fbo.bind(); fbo.clear(COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT); } @@ -143,7 +153,7 @@ void Pipeline::render(Renderer &renderer, const Tag &tag) const { Bind bind_depth_test(i->get_depth_test()); Bind bind_blend(i->get_blend()); - Bind bind_lighting(i->get_lighting()); + renderer.set_lighting(i->get_lighting()); for(vector::const_iterator j=renderables.begin(); j!=renderables.end(); ++j) if(j->passes.empty() || j->passes.count(i->get_tag())) @@ -161,34 +171,40 @@ void Pipeline::render(Renderer &renderer, const Tag &tag) const if(i+1fbo.bind(); else - Framebuffer::unbind(); + out_fbo->bind(); postproc[i]->render(target[j]->color, target[j]->depth); } - Framebuffer::unbind(); + out_fbo->bind(); } if(!was_in_frame) finish_frame(); } -void Pipeline::create_targets(bool recreate) +void Pipeline::create_targets(unsigned recreate) { - if(recreate) + if(recreate>=2) { delete target[0]; delete target[1]; - delete target_ms; target[0] = 0; target[1] = 0; + } + if(recreate>=1) + { + delete target_ms; target_ms = 0; } PixelFormat fmt = (hdr ? RGB16F : RGB); - if(!target[0]) - target[0] = new RenderTarget(width, height, fmt); - if(!target[1] && postproc.size()>1) - target[1] = new RenderTarget(width, height, fmt); + if(!postproc.empty() || samples) + { + if(!target[0]) + target[0] = new RenderTarget(width, height, fmt); + if(!target[1] && postproc.size()>1) + target[1] = new RenderTarget(width, height, fmt); + } if(!target_ms && samples) target_ms = new MultisampleTarget(width, height, samples, fmt); @@ -236,6 +252,8 @@ Pipeline::RenderTarget::RenderTarget(unsigned w, unsigned h, PixelFormat f) depth.set_wrap(CLAMP_TO_EDGE); depth.storage(DEPTH_COMPONENT, w, h); fbo.attach(DEPTH_ATTACHMENT, depth, 0); + + fbo.require_complete(); } @@ -246,6 +264,8 @@ Pipeline::MultisampleTarget::MultisampleTarget(unsigned w, unsigned h, unsigned depth.storage_multisample(s, DEPTH_COMPONENT, w, h); fbo.attach(DEPTH_ATTACHMENT, depth); + + fbo.require_complete(); } } // namespace GL