]> git.tdb.fi Git - libs/gl.git/blobdiff - source/pipeline.cpp
Add object-oriented interfaces for the various tests and blending
[libs/gl.git] / source / pipeline.cpp
index ea8b56a30763d74b2f98c93aec18e8a4f8173b5f..97c452658153acb8c7561652ee22dcc0fc928961 100644 (file)
@@ -1,10 +1,12 @@
 /* $Id$
 
 This file is part of libmspgl
-Copyright © 2009  Mikko Rasa, Mikkosoft Productions
+Copyright © 2009-2010  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
+#include "blend.h"
+#include "camera.h"
 #include "effect.h"
 #include "except.h"
 #include "framebuffer.h"
@@ -12,6 +14,7 @@ Distributed under the LGPL
 #include "pipeline.h"
 #include "postprocessor.h"
 #include "renderbuffer.h"
+#include "tests.h"
 #include "texture2d.h"
 
 using namespace std;
@@ -20,6 +23,7 @@ namespace Msp {
 namespace GL {
 
 Pipeline::Pipeline(unsigned w, unsigned h, bool d):
+       camera(0),
        width(w),
        height(h),
        hdr(d),
@@ -35,19 +39,24 @@ Pipeline::~Pipeline()
        delete depth_buf;
 }
 
+void Pipeline::set_camera(const Camera *c)
+{
+       camera = c;
+}
+
 PipelinePass &Pipeline::add_pass(const Tag &tag)
 {
-       if(passes.count(tag.id))
+       if(passes.count(tag))
                throw KeyError("Pass already exists");
 
-       PipelinePass &pass=passes[tag.id];
+       PipelinePass &pass=passes[tag];
        pass_order.push_back(tag);
        return pass;
 }
 
 PipelinePass &Pipeline::get_pass(const Tag &tag)
 {
-       map<unsigned, PipelinePass>::iterator i=passes.find(tag.id);
+       PassMap::iterator i=passes.find(tag);
        if(i==passes.end())
                throw KeyError("Unknown pass");
        return i->second;
@@ -55,17 +64,12 @@ PipelinePass &Pipeline::get_pass(const Tag &tag)
 
 const PipelinePass &Pipeline::get_pass(const Tag &tag) const
 {
-       map<unsigned, PipelinePass>::const_iterator i=passes.find(tag.id);
+       PassMap::const_iterator i=passes.find(tag);
        if(i==passes.end())
                throw KeyError("Unknown pass");
        return i->second;
 }
 
-bool Pipeline::has_pass(const Tag &tag) const
-{
-       return passes.count(tag.id);
-}
-
 void Pipeline::add_renderable(const Renderable &r)
 {
        renderables.push_back(&r);
@@ -98,33 +102,44 @@ void Pipeline::add_postprocessor(PostProcessor &pp)
 void Pipeline::render(const Tag &tag) const
 {
        const PipelinePass &pass=get_pass(tag);
-       if(pass.lighting)
-               pass.lighting->bind();
+
+       Bind bind_depth_test(pass.depth_test);
+       Bind bind_blend(pass.blend);
+       Bind bind_lighting(pass.lighting);
+
        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<Effect *>::const_iterator i=pass.effects.end(); i--!=pass.effects.begin();)
-               (*i)->cleanup();
-       if(pass.lighting)
-               Lighting::unbind();
+
+       for(vector<Effect *>::const_iterator i=pass.effects.end(); i!=pass.effects.begin();)
+               (*--i)->cleanup();
 }
 
 void Pipeline::render_all() const
 {
+       if(camera)
+               camera->apply();
+
        if(fbo)
        {
                fbo->bind();
                clear(COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT);
        }
+
        for(vector<Effect *>::const_iterator i=effects.begin(); i!=effects.end(); ++i)
                (*i)->prepare();
+
        for(vector<Tag>::const_iterator i=pass_order.begin(); i!=pass_order.end(); ++i)
                render(*i);
-       for(vector<Effect *>::const_iterator i=effects.end(); i--!=effects.begin();)
-               (*i)->cleanup();
+
+       for(vector<Effect *>::const_iterator i=effects.end(); i!=effects.begin();)
+               (*--i)->cleanup();
+
        if(fbo)
                Framebuffer::unbind();
+
        // 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);