X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fpipeline.cpp;h=0469cb773643da9d7e11825c9de81cfaf6163963;hp=e3da053070b0cb0dcadc84e62f6b91cf4befab5a;hb=dafd3a42a2f06bfd8e88f9240fc2f4bd3d401541;hpb=e1f9db7e8550d5c9629ac5ad0e2f8dc2dd4efa8d diff --git a/source/pipeline.cpp b/source/pipeline.cpp index e3da0530..0469cb77 100644 --- a/source/pipeline.cpp +++ b/source/pipeline.cpp @@ -21,8 +21,7 @@ Pipeline::Pipeline(unsigned w, unsigned h, bool d): height(h), hdr(d), samples(0), - target_ms(0), - in_frame(false) + target_ms(0) { target[0] = 0; target[1] = 0; @@ -139,7 +138,6 @@ void Pipeline::add_postprocessor(PostProcessor &pp) void Pipeline::setup_frame() const { - in_frame = true; for(PassList::const_iterator i=passes.begin(); i!=passes.end(); ++i) if(const Renderable *renderable = i->get_renderable()) renderable->setup_frame(); @@ -149,7 +147,6 @@ void Pipeline::setup_frame() const void Pipeline::finish_frame() const { - in_frame = false; for(PassList::const_iterator i=passes.begin(); i!=passes.end(); ++i) if(const Renderable *renderable = i->get_renderable()) renderable->finish_frame(); @@ -157,13 +154,12 @@ void Pipeline::finish_frame() const i->renderable->finish_frame(); } -void Pipeline::render(const Tag &tag) const +void Pipeline::render() const { - if(tag.id) - return; - Renderer renderer(camera); - render(renderer, tag); + setup_frame(); + render(renderer); + finish_frame(); } void Pipeline::render(Renderer &renderer, const Tag &tag) const @@ -171,25 +167,32 @@ void Pipeline::render(Renderer &renderer, const Tag &tag) const if(tag.id) return; - bool was_in_frame = in_frame; - if(!in_frame) - setup_frame(); - const Framebuffer *out_fbo = Framebuffer::current(); - // This is a no-op but will ensure the FBO binding gets restored + // These is a 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()); if(target[0]) { - Framebuffer &fbo = (samples ? target_ms->fbo : target[0]->fbo); + Framebuffer &fbo = (samples ? target_ms : target[0])->get_framebuffer(); fbo.bind(); fbo.clear(COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT); } + 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()); + if(const DepthTest *dt = i->get_depth_test()) + dt->bind(); + else + DepthTest::unbind(); + + if(const Blend *b = i->get_blend()) + b->bind(); + else + Blend::unbind(); + renderer.set_lighting(i->get_lighting()); renderer.set_clipping(i->get_clipping()); @@ -201,26 +204,26 @@ void Pipeline::render(Renderer &renderer, const Tag &tag) const renderer.render(*j->renderable, i->get_tag()); } - renderer.end(); - if(target[0]) { + DepthTest::unbind(); + Blend::unbind(); + if(samples) - target[0]->fbo.blit_from(target_ms->fbo, COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT, false); + target[0]->blit_from(*target_ms); for(unsigned i=0; ifbo.bind(); + target[1-j]->get_framebuffer().bind(); else out_fbo->bind(); - postproc[i]->render(target[j]->color, target[j]->depth); + const Texture2D &color = target[j]->get_target_texture(RENDER_COLOR); + const Texture2D &depth = target[j]->get_target_texture(RENDER_DEPTH); + postproc[i]->render(renderer, color, depth); } } - - if(!was_in_frame) - finish_frame(); } void Pipeline::create_targets(unsigned recreate) @@ -238,7 +241,8 @@ void Pipeline::create_targets(unsigned recreate) target_ms = 0; } - PixelFormat fmt = (hdr ? RGB16F : RGB); + PixelFormat color_pf = (hdr ? RGB16F : RGB); + RenderTargetFormat fmt = (RENDER_COLOR,color_pf, RENDER_DEPTH); if(!postproc.empty() || samples) { if(!target[0]) @@ -248,7 +252,7 @@ void Pipeline::create_targets(unsigned recreate) } if(!target_ms && samples) - target_ms = new MultisampleTarget(width, height, samples, fmt); + target_ms = new RenderTarget(width, height, samples, fmt); } @@ -286,35 +290,5 @@ Pipeline::Slot::Slot(const Renderable *r): renderable(r) { } - -Pipeline::RenderTarget::RenderTarget(unsigned w, unsigned h, PixelFormat f) -{ - color.set_min_filter(NEAREST); - color.set_mag_filter(NEAREST); - color.set_wrap(CLAMP_TO_EDGE); - color.storage(f, w, h); - fbo.attach(COLOR_ATTACHMENT0, color, 0); - - depth.set_min_filter(NEAREST); - depth.set_mag_filter(NEAREST); - depth.set_wrap(CLAMP_TO_EDGE); - depth.storage(DEPTH_COMPONENT, w, h); - fbo.attach(DEPTH_ATTACHMENT, depth, 0); - - fbo.require_complete(); -} - - -Pipeline::MultisampleTarget::MultisampleTarget(unsigned w, unsigned h, unsigned s, PixelFormat f) -{ - color.storage_multisample(s, f, w, h); - fbo.attach(COLOR_ATTACHMENT0, color); - - depth.storage_multisample(s, DEPTH_COMPONENT, w, h); - fbo.attach(DEPTH_ATTACHMENT, depth); - - fbo.require_complete(); -} - } // namespace GL } // namespace Msp