]> git.tdb.fi Git - libs/gl.git/commitdiff
Support limiting renderables in Pipeline to specific passes
authorMikko Rasa <tdb@tdb.fi>
Thu, 16 Sep 2010 19:44:40 +0000 (19:44 +0000)
committerMikko Rasa <tdb@tdb.fi>
Thu, 16 Sep 2010 19:44:40 +0000 (19:44 +0000)
Allow removing renderables from Pipeline

source/pipeline.cpp
source/pipeline.h

index 517037a0029785198fd724c44e5c92943f11ee82..f05d15b8271fe0ce9f216b62258f50d10758f231 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)
@@ -109,8 +139,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();
@@ -144,5 +175,10 @@ void Pipeline::render_all() const
                (*i)->render(*color_buf);
 }
 
+
+Pipeline::Slot::Slot(const Renderable *r):
+       renderable(r)
+{ }
+
 } // namespace GL
 } // namespace Msp
index 5da9a7b32141035b891191c027ff146b108fd824..3f0ea2fa235390a81232c5b95bd26a014a93128d 100644 (file)
@@ -9,6 +9,7 @@ Distributed under the LGPL
 #define MSP_GL_PIPELINE_H_
 
 #include <map>
+#include <set>
 #include "pipelinepass.h"
 #include "renderable.h"
 
@@ -25,12 +26,20 @@ class Texture2D;
 class Pipeline: public Renderable
 {
 private:
+       struct Slot
+       {
+               const Renderable *renderable;
+               std::set<Tag> passes;
+
+               Slot(const Renderable *);
+       };
+
        typedef std::map<Tag, PipelinePass> PassMap;
 
        PassMap passes;
        std::vector<Tag> pass_order;
        const Camera *camera;
-       std::vector<const Renderable *> renderables;
+       std::vector<Slot> renderables;
        std::vector<Effect *> effects;
        std::vector<PostProcessor *> postproc;
        unsigned width;
@@ -51,6 +60,8 @@ public:
        const PipelinePass &get_pass(const Tag &tag) const;
 
        void add_renderable(const Renderable &);
+       void add_renderable_for_pass(const Renderable &, const Tag &);
+       void remove_renderable(const Renderable &);
        void add_effect(Effect &);
        void add_postprocessor(PostProcessor &);