From 4d3bee9264c4e60fb811019fc1699e17a338d13d Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 16 Sep 2010 19:44:40 +0000 Subject: [PATCH] Support limiting renderables in Pipeline to specific passes Allow removing renderables from Pipeline --- source/pipeline.cpp | 40 ++++++++++++++++++++++++++++++++++++++-- source/pipeline.h | 13 ++++++++++++- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/source/pipeline.cpp b/source/pipeline.cpp index 517037a0..f05d15b8 100644 --- a/source/pipeline.cpp +++ b/source/pipeline.cpp @@ -72,7 +72,37 @@ const PipelinePass &Pipeline::get_pass(const Tag &tag) const void Pipeline::add_renderable(const Renderable &r) { + for(vector::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::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::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::const_iterator i=pass.effects.begin(); i!=pass.effects.end(); ++i) (*i)->prepare(); - for(vector::const_iterator i=renderables.begin(); i!=renderables.end(); ++i) - (*i)->render(tag); + for(vector::const_iterator i=renderables.begin(); i!=renderables.end(); ++i) + if(i->passes.empty() || i->passes.count(tag)) + i->renderable->render(tag); for(vector::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 diff --git a/source/pipeline.h b/source/pipeline.h index 5da9a7b3..3f0ea2fa 100644 --- a/source/pipeline.h +++ b/source/pipeline.h @@ -9,6 +9,7 @@ Distributed under the LGPL #define MSP_GL_PIPELINE_H_ #include +#include #include "pipelinepass.h" #include "renderable.h" @@ -25,12 +26,20 @@ class Texture2D; class Pipeline: public Renderable { private: + struct Slot + { + const Renderable *renderable; + std::set passes; + + Slot(const Renderable *); + }; + typedef std::map PassMap; PassMap passes; std::vector pass_order; const Camera *camera; - std::vector renderables; + std::vector renderables; std::vector effects; std::vector 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 &); -- 2.45.2