]> git.tdb.fi Git - libs/gl.git/commitdiff
Simplify Pipeline pass management
authorMikko Rasa <tdb@tdb.fi>
Mon, 20 Aug 2012 13:13:46 +0000 (16:13 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 20 Aug 2012 13:13:46 +0000 (16:13 +0300)
Originally I planned to use Pipelines to bundle objects with effects like
environmentally mapped reflection.  However, that task was delegated to
effects themselves recently, so there's no longer need for passthrough
rendering in Pipeline.  The render_all function was also a nuisance, as
it required Pipelines to be treated differently from other Renderables.

Passes are now stored in a list instead of a map.  This allows multiple
passes with the same tag (think multipass lighting), and avoids the need
to store the pass order separately.

source/pipeline.cpp
source/pipeline.h

index ce15597080618114fc719e1e332732f20809cb76..67ddf6566cf3592422490f3f61343f094beb8286 100644 (file)
@@ -60,19 +60,8 @@ void Pipeline::set_camera(const Camera *c)
 
 Pipeline::Pass &Pipeline::add_pass(const Tag &tag)
 {
 
 Pipeline::Pass &Pipeline::add_pass(const Tag &tag)
 {
-       Pass &pass = insert_unique(passes, tag, Pass())->second;
-       pass_order.push_back(tag);
-       return pass;
-}
-
-Pipeline::Pass &Pipeline::get_pass(const Tag &tag)
-{
-       return get_item(passes, tag);
-}
-
-const Pipeline::Pass &Pipeline::get_pass(const Tag &tag) const
-{
-       return get_item(passes, tag);
+       passes.push_back(Pass(tag));
+       return passes.back();
 }
 
 void Pipeline::add_renderable(const Renderable &r)
 }
 
 void Pipeline::add_renderable(const Renderable &r)
@@ -119,34 +108,38 @@ void Pipeline::add_postprocessor(PostProcessor &pp)
        }
 }
 
        }
 }
 
-void Pipeline::render(Renderer &renderer, const Tag &tag) const
+void Pipeline::render(const Tag &tag) const
 {
 {
-       const Pass &pass = get_pass(tag);
+       if(tag.id)
+               return;
 
 
-       Bind bind_depth_test(pass.get_depth_test());
-       Bind bind_blend(pass.get_blend());
-       Bind bind_lighting(pass.get_lighting());
-
-       for(vector<Slot>::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
-               if(i->passes.empty() || i->passes.count(tag))
-                       i->renderable->render(renderer, tag);
+       Renderer renderer(camera);
+       render(renderer, tag);
 }
 
 }
 
-void Pipeline::render_all() const
+void Pipeline::render(Renderer &renderer, const Tag &tag) const
 {
 {
-       if(camera)
-               camera->apply();
+       if(tag.id)
+               return;
 
        if(fbo)
        {
                Framebuffer *f = (fbo_ms ? fbo_ms : fbo);
 
        if(fbo)
        {
                Framebuffer *f = (fbo_ms ? fbo_ms : fbo);
+               // XXX exception safety
                f->bind();
                f->clear(COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT);
        }
 
                f->bind();
                f->clear(COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT);
        }
 
-       Renderer renderer(camera);
-       for(vector<Tag>::const_iterator i=pass_order.begin(); i!=pass_order.end(); ++i)
-               render(renderer, *i);
+       for(PassList::const_iterator i=passes.begin(); i!=passes.end(); ++i)
+       {
+               Bind bind_depth_test(i->get_depth_test());
+               Bind bind_blend(i->get_blend());
+               Bind bind_lighting(i->get_lighting());
+
+               for(vector<Slot>::const_iterator j=renderables.begin(); j!=renderables.end(); ++j)
+                       if(j->passes.empty() || j->passes.count(i->get_tag()))
+                               j->renderable->render(renderer, i->get_tag());
+       }
 
        if(fbo)
        {
 
        if(fbo)
        {
@@ -204,7 +197,8 @@ void Pipeline::create_fbos()
 }
 
 
 }
 
 
-Pipeline::Pass::Pass():
+Pipeline::Pass::Pass(const Tag &t):
+       tag(t),
        lighting(0),
        depth_test(0),
        blend(0)
        lighting(0),
        depth_test(0),
        blend(0)
index 011a96bba5e37d6ca1bd056bfe1cede1c047cb03..c14245fa9d83b81c637c4fc530223db9477ea3a0 100644 (file)
@@ -23,12 +23,15 @@ public:
        class Pass
        {
        private:
        class Pass
        {
        private:
+               Tag tag;
                const Lighting *lighting;
                const DepthTest *depth_test;
                const Blend *blend;
 
        public:
                const Lighting *lighting;
                const DepthTest *depth_test;
                const Blend *blend;
 
        public:
-               Pass();
+               Pass(const Tag &);
+
+               const Tag &get_tag() const { return tag; }
 
                void set_lighting(const Lighting *);
                void set_depth_test(const DepthTest *);
 
                void set_lighting(const Lighting *);
                void set_depth_test(const DepthTest *);
@@ -47,10 +50,9 @@ private:
                Slot(const Renderable *);
        };
 
                Slot(const Renderable *);
        };
 
-       typedef std::map<Tag, Pass> PassMap;
+       typedef std::list<Pass> PassList;
 
 
-       PassMap passes;
-       std::vector<Tag> pass_order;
+       PassList passes;
        const Camera *camera;
        std::vector<Slot> renderables;
        std::vector<PostProcessor *> postproc;
        const Camera *camera;
        std::vector<Slot> renderables;
        std::vector<PostProcessor *> postproc;
@@ -74,16 +76,14 @@ public:
        void set_camera(const Camera *);
 
        Pass &add_pass(const Tag &tag);
        void set_camera(const Camera *);
 
        Pass &add_pass(const Tag &tag);
-       Pass &get_pass(const Tag &tag);
-       const Pass &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_postprocessor(PostProcessor &);
 
 
        void add_renderable(const Renderable &);
        void add_renderable_for_pass(const Renderable &, const Tag &);
        void remove_renderable(const Renderable &);
        void add_postprocessor(PostProcessor &);
 
+       virtual void render(const Tag &tag = Tag()) const;
        virtual void render(Renderer &, const Tag &tag = Tag()) const;
        virtual void render(Renderer &, const Tag &tag = Tag()) const;
-       void render_all() const;
 
 private:
        void create_fbos();
 
 private:
        void create_fbos();