]> git.tdb.fi Git - libs/gl.git/blobdiff - source/pipeline.cpp
Improve the ambient occlusion algorithm
[libs/gl.git] / source / pipeline.cpp
index 54ef25a10bca8e59a123eb96322123e393595640..5294ffbd859d84f4c29ce7878dcd5a01a6fd376b 100644 (file)
@@ -72,7 +72,37 @@ const PipelinePass &Pipeline::get_pass(const Tag &tag) const
 
 void Pipeline::add_renderable(const Renderable &r)
 {
+       for(vector<Slot>::iterator i=renderables.begin(); i!=renderables.end(); ++i)
+               if(i->renderable==&r)
+               {
+                       i->passes.clear();
+                       return;
+               }
+
+       renderables.push_back(&r);
+}
+
+void Pipeline::add_renderable_for_pass(const Renderable &r, const Tag &tag)
+{
+       for(vector<Slot>::iterator i=renderables.begin(); i!=renderables.end(); ++i)
+               if(i->renderable==&r)
+               {
+                       i->passes.insert(tag);
+                       return;
+               }
+
        renderables.push_back(&r);
+       renderables.back().passes.insert(tag);
+}
+
+void Pipeline::remove_renderable(const Renderable &r)
+{
+       for(vector<Slot>::iterator i=renderables.begin(); i!=renderables.end(); ++i)
+               if(i->renderable==&r)
+               {
+                       renderables.erase(i);
+                       return;
+               }
 }
 
 void Pipeline::add_effect(Effect &e)
@@ -86,16 +116,20 @@ 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->storage((hdr ? RGB16F : RGB), width, height, 0);
-               color_buf->image(0, RGB, UNSIGNED_BYTE, 0);
+               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);
-               Framebuffer::unbind();
+               fbo->attach(DEPTH_ATTACHMENT, *depth_buf, 0);
        }
 }
 
@@ -110,8 +144,9 @@ void Pipeline::render(const Tag &tag) const
        for(vector<Effect *>::const_iterator i=pass.effects.begin(); i!=pass.effects.end(); ++i)
                (*i)->prepare();
 
-       for(vector<const Renderable *>::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
-               (*i)->render(tag);
+       for(vector<Slot>::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
+               if(i->passes.empty() || i->passes.count(tag))
+                       i->renderable->render(tag);
 
        for(vector<Effect *>::const_iterator i=pass.effects.end(); i!=pass.effects.begin();)
                (*--i)->cleanup();
@@ -125,7 +160,7 @@ void Pipeline::render_all() const
        if(fbo)
        {
                fbo->bind();
-               clear(COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT);
+               fbo->clear(COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT);
        }
 
        for(vector<Effect *>::const_iterator i=effects.begin(); i!=effects.end(); ++i)
@@ -142,8 +177,13 @@ 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);
 }
 
+
+Pipeline::Slot::Slot(const Renderable *r):
+       renderable(r)
+{ }
+
 } // namespace GL
 } // namespace Msp