From: Mikko Rasa Date: Tue, 28 Aug 2012 10:18:41 +0000 (+0300) Subject: Route rendering calls through Renderer and add an exclusion system X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=2e6a73a93eac0a18063ec675a24a8e6eeeb80a0c;p=libs%2Fgl.git Route rendering calls through Renderer and add an exclusion system This is necessary for generating environment maps for an object, since the object itself should not be included in the map. The alternative is to create a separate Scene, but that's rather clumsy. --- diff --git a/source/instancescene.cpp b/source/instancescene.cpp index ffbfa558..6ddfa0d2 100644 --- a/source/instancescene.cpp +++ b/source/instancescene.cpp @@ -26,7 +26,7 @@ void InstanceScene::render(Renderer &renderer, const Tag &tag) const { for(InstanceMap::const_iterator i=renderables.begin(); i!=renderables.end(); ++i) for(RenderableSet::const_iterator j=i->second.begin(); j!=i->second.end(); ++j) - (*j)->render(renderer, tag); + renderer.render(**j, tag); } } // namespace GL diff --git a/source/orderedscene.cpp b/source/orderedscene.cpp index 547af77a..40149b34 100644 --- a/source/orderedscene.cpp +++ b/source/orderedscene.cpp @@ -1,5 +1,6 @@ #include #include "orderedscene.h" +#include "renderer.h" namespace Msp { namespace GL { @@ -37,7 +38,7 @@ void OrderedScene::insert_after(const Renderable &after, const Renderable &r) void OrderedScene::render(Renderer &renderer, const Tag &tag) const { for(RenderableList::const_iterator i=renderables.begin(); i!=renderables.end(); ++i) - (*i)->render(renderer, tag); + renderer.render(**i, tag); } } // namespace GL diff --git a/source/pipeline.cpp b/source/pipeline.cpp index bfd7bc67..2dd178f2 100644 --- a/source/pipeline.cpp +++ b/source/pipeline.cpp @@ -128,7 +128,7 @@ void Pipeline::render(Renderer &renderer, const Tag &tag) const for(vector::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()); + renderer.render(*j->renderable, i->get_tag()); } if(target[0]) diff --git a/source/renderer.cpp b/source/renderer.cpp index fd4dc576..6734edc4 100644 --- a/source/renderer.cpp +++ b/source/renderer.cpp @@ -5,6 +5,7 @@ #include "material.h" #include "program.h" #include "programdata.h" +#include "renderable.h" #include "renderer.h" #include "texture.h" #include "texturing.h" @@ -132,6 +133,22 @@ void Renderer::escape() Buffer::unbind_from(ELEMENT_ARRAY_BUFFER); } +void Renderer::exclude(const Renderable &renderable) +{ + excluded.insert(&renderable); +} + +void Renderer::include(const Renderable &renderable) +{ + excluded.erase(&renderable); +} + +void Renderer::render(const Renderable &renderable, const Tag &tag) +{ + if(!excluded.count(&renderable)) + renderable.render(*this, tag); +} + void Renderer::draw(const Batch &batch) { if(!vertex_array) diff --git a/source/renderer.h b/source/renderer.h index 6115a7fe..91d20674 100644 --- a/source/renderer.h +++ b/source/renderer.h @@ -1,8 +1,10 @@ #ifndef MSP_GL_RENDERER_H_ #define MSP_GL_RENDERER_H_ +#include #include #include "matrix.h" +#include "tag.h" namespace Msp { namespace GL { @@ -13,6 +15,7 @@ class Camera; class Material; class Program; class ProgramData; +class Renderable; class Texture; class Texturing; class VertexArray; @@ -45,6 +48,17 @@ public: ~Push() { renderer.pop_state(); } }; + class Exclude + { + private: + Renderer &renderer; + const Renderable &renderable; + + public: + Exclude(Renderer &r, const Renderable &e): renderer(r), renderable(e) { renderer.exclude(renderable); } + ~Exclude() { renderer.include(renderable); } + }; + private: struct State { @@ -79,6 +93,7 @@ private: const VertexArray *vertex_array; bool vertex_array_changed; const Buffer *element_buffer; + std::set excluded; public: Renderer(const Camera *); @@ -117,6 +132,10 @@ public: Renderer. */ void escape(); + void exclude(const Renderable &); + void include(const Renderable &); + + void render(const Renderable &, const Tag & = Tag()); void draw(const Batch &); private: diff --git a/source/shadowmap.cpp b/source/shadowmap.cpp index 95ef8583..ea4982fe 100644 --- a/source/shadowmap.cpp +++ b/source/shadowmap.cpp @@ -48,7 +48,7 @@ void ShadowMap::set_texture_unit(unsigned u) void ShadowMap::render(Renderer &renderer, const Tag &tag) const { if(!enabled_passes.count(tag)) - return renderable.render(renderer, tag); + return renderer.render(renderable, tag); Vector4 lpos = light.get_position(); if(lpos.w) @@ -126,7 +126,7 @@ void ShadowMap::render(Renderer &renderer, const Tag &tag) const Renderer::Push _push_rend(renderer); renderer.add_shader_data(shdata); - renderable.render(renderer, tag); + renderer.render(renderable, tag); Texture::unbind_from(unit); TexGen::unbind_from(SCOORD); diff --git a/source/simplescene.cpp b/source/simplescene.cpp index e7ffc638..9e0623d8 100644 --- a/source/simplescene.cpp +++ b/source/simplescene.cpp @@ -1,3 +1,4 @@ +#include "renderer.h" #include "simplescene.h" namespace Msp { @@ -16,7 +17,7 @@ void SimpleScene::remove(const Renderable &r) void SimpleScene::render(Renderer &renderer, const Tag &tag) const { for(RenderableSet::const_iterator i=renderables.begin(); i!=renderables.end(); ++i) - (*i)->render(renderer, tag); + renderer.render(**i, tag); } } // namespace GL