]> git.tdb.fi Git - libs/gl.git/commitdiff
Route rendering calls through Renderer and add an exclusion system
authorMikko Rasa <tdb@tdb.fi>
Tue, 28 Aug 2012 10:18:41 +0000 (13:18 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 28 Aug 2012 10:18:41 +0000 (13:18 +0300)
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.

source/instancescene.cpp
source/orderedscene.cpp
source/pipeline.cpp
source/renderer.cpp
source/renderer.h
source/shadowmap.cpp
source/simplescene.cpp

index ffbfa558f42e4bf2ad35f799579c2b438544e91d..6ddfa0d2c5a2dd44cf2e33e6980b98466a15caa5 100644 (file)
@@ -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
index 547af77aa1d852bb63a3757d6492ad657e026193..40149b3477f9dc3e4a1de60cf7d759dc66f2cfd7 100644 (file)
@@ -1,5 +1,6 @@
 #include <algorithm>
 #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
index bfd7bc679c6d69c4432d8f3d52a83003c4b16157..2dd178f247a53b97d26f74bbfe526292e21ae4d2 100644 (file)
@@ -128,7 +128,7 @@ void Pipeline::render(Renderer &renderer, const Tag &tag) const
 
                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());
+                               renderer.render(*j->renderable, i->get_tag());
        }
 
        if(target[0])
index fd4dc576d09ba12c526a38d0638f9f6437693a25..6734edc4bd20458be56563bdddfd57a2589ab203 100644 (file)
@@ -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)
index 6115a7feeae33deadf6bb327f2d83703cd6f2d87..91d20674a2c5a476a390c9d63c9ab9404adb93ec 100644 (file)
@@ -1,8 +1,10 @@
 #ifndef MSP_GL_RENDERER_H_
 #define MSP_GL_RENDERER_H_
 
+#include <set>
 #include <vector>
 #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<const Renderable *> 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:
index 95ef8583ccc9ab8e6b85fce1476f36d95d789cb2..ea4982fe9f60bb67e31c66b2761f6e70331056c9 100644 (file)
@@ -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);
index e7ffc63841d02cb8110cdd9b9e93e7be53e4d821..9e0623d860f0dbd0a87dad795ceac2bd25112e76 100644 (file)
@@ -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