]> git.tdb.fi Git - libs/gl.git/blobdiff - source/pipeline.cpp
Add a rendering supervisor class
[libs/gl.git] / source / pipeline.cpp
index 62aeaab938b60830d30dad685443a1e6490b95bb..570014d3692e4ab1405e22761b90511a02379020 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgl
-Copyright © 2009-2010  Mikko Rasa, Mikkosoft Productions
+Copyright © 2009-2011  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -14,6 +14,7 @@ Distributed under the LGPL
 #include "pipeline.h"
 #include "postprocessor.h"
 #include "renderbuffer.h"
+#include "renderer.h"
 #include "tests.h"
 #include "texture2d.h"
 
@@ -116,18 +117,24 @@ void Pipeline::add_postprocessor(PostProcessor &pp)
        if(!fbo)
        {
                fbo = new Framebuffer;
+
                color_buf = new Texture2D;
                color_buf->set_min_filter(NEAREST);
                color_buf->set_mag_filter(NEAREST);
+               color_buf->set_wrap(CLAMP_TO_EDGE);
                color_buf->storage((hdr ? RGB16F : RGB), width, height);
                fbo->attach(COLOR_ATTACHMENT0, *color_buf, 0);
-               depth_buf = new Renderbuffer;
+
+               depth_buf = new Texture2D;
+               depth_buf->set_min_filter(NEAREST);
+               depth_buf->set_mag_filter(NEAREST);
+               depth_buf->set_wrap(CLAMP_TO_EDGE);
                depth_buf->storage(DEPTH_COMPONENT, width, height);
-               fbo->attach(DEPTH_ATTACHMENT, *depth_buf);
+               fbo->attach(DEPTH_ATTACHMENT, *depth_buf, 0);
        }
 }
 
-void Pipeline::render(const Tag &tag) const
+void Pipeline::render(Renderer &renderer, const Tag &tag) const
 {
        const PipelinePass &pass = get_pass(tag);
 
@@ -140,7 +147,7 @@ void Pipeline::render(const Tag &tag) const
 
        for(vector<Slot>::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
                if(i->passes.empty() || i->passes.count(tag))
-                       i->renderable->render(tag);
+                       i->renderable->render(renderer, tag);
 
        for(vector<Effect *>::const_iterator i=pass.effects.end(); i!=pass.effects.begin();)
                (*--i)->cleanup();
@@ -160,8 +167,9 @@ void Pipeline::render_all() const
        for(vector<Effect *>::const_iterator i=effects.begin(); i!=effects.end(); ++i)
                (*i)->prepare();
 
+       Renderer renderer(camera);
        for(vector<Tag>::const_iterator i=pass_order.begin(); i!=pass_order.end(); ++i)
-               render(*i);
+               render(renderer, *i);
 
        for(vector<Effect *>::const_iterator i=effects.end(); i!=effects.begin();)
                (*--i)->cleanup();
@@ -171,7 +179,7 @@ void Pipeline::render_all() const
 
        // XXX Need two color buffer textures to handle multiple post-processors correctly
        for(vector<PostProcessor *>::const_iterator i=postproc.begin(); i!=postproc.end(); ++i)
-               (*i)->render(*color_buf);
+               (*i)->render(*color_buf, *depth_buf);
 }