]> git.tdb.fi Git - libs/gl.git/blobdiff - source/pipeline.cpp
Remove dynamic allocation from VertexFormat
[libs/gl.git] / source / pipeline.cpp
index a27058effc08020ed7395645c268249a233b4f9f..dc1eba1d117cdcca5d6b190c53b3545ed31fd86c 100644 (file)
@@ -176,7 +176,10 @@ void Pipeline::render(Renderer &renderer, const Tag &tag) const
                setup_frame();
 
        const Framebuffer *out_fbo = Framebuffer::current();
-       // XXX Make sure the correct FBO is restored if an exception is thrown
+       // 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])
        {
@@ -185,10 +188,19 @@ 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)
        {
-               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());
 
@@ -200,10 +212,11 @@ void Pipeline::render(Renderer &renderer, const Tag &tag) const
                                renderer.render(*j->renderable, i->get_tag());
        }
 
-       renderer.end();
-
        if(target[0])
        {
+               BindRestore unbind_depth_test(static_cast<DepthTest *>(0));
+               BindRestore unbind_blend(static_cast<Blend *>(0));
+
                if(samples)
                        target[0]->fbo.blit_from(target_ms->fbo, COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT, false);
 
@@ -214,10 +227,8 @@ void Pipeline::render(Renderer &renderer, const Tag &tag) const
                                target[1-j]->fbo.bind();
                        else
                                out_fbo->bind();
-                       postproc[i]->render(target[j]->color, target[j]->depth);
+                       postproc[i]->render(renderer, target[j]->color, target[j]->depth);
                }
-
-               out_fbo->bind();
        }
 
        if(!was_in_frame)