]> git.tdb.fi Git - libs/gl.git/blobdiff - source/pipeline.cpp
Add a Camera class
[libs/gl.git] / source / pipeline.cpp
index b0a38a2d3240a11cc63dd8ee9c801e22a534514e..0256850844fef66ebd3d32fb117d73d6be7d6dd0 100644 (file)
@@ -5,6 +5,7 @@ Copyright © 2009  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
+#include "camera.h"
 #include "effect.h"
 #include "except.h"
 #include "framebuffer.h"
@@ -20,6 +21,7 @@ namespace Msp {
 namespace GL {
 
 Pipeline::Pipeline(unsigned w, unsigned h, bool d):
+       camera(0),
        width(w),
        height(h),
        hdr(d),
@@ -35,19 +37,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 +62,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);
@@ -101,10 +103,7 @@ void Pipeline::render(const Tag &tag) const
        if(pass.lighting)
                pass.lighting->bind();
        for(vector<Effect *>::const_iterator i=pass.effects.begin(); i!=pass.effects.end(); ++i)
-       {
                (*i)->prepare();
-               glViewport(0, 0, width, height);
-       }
        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();)
@@ -115,22 +114,25 @@ void Pipeline::render(const Tag &tag) const
 
 void Pipeline::render_all() const
 {
+       if(camera)
+               camera->apply();
+
        if(fbo)
        {
                fbo->bind();
-               glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
+               clear(COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT);
        }
+
        for(vector<Effect *>::const_iterator i=effects.begin(); i!=effects.end(); ++i)
-       {
                (*i)->prepare();
-               glViewport(0, 0, width, height);
-       }
        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();
+
        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);