Culler implementations to come soon.
--- /dev/null
+#ifndef MSP_GL_CULLER_H_
+#define MSP_GL_CULLER_H_
+
+namespace Msp {
+namespace GL {
+
+class Renderable;
+class Renderer;
+
+class Culler
+{
+protected:
+ Culler() { }
+public:
+ virtual ~Culler() { }
+
+ virtual void setup_frame(const Renderer &) { };
+
+ virtual bool cull(const Renderer &, const Renderable &) const = 0;
+};
+
+} // namespace GL
+} // namespace Msp
+
+#endif
void InstanceScene::render(Renderer &renderer, const Tag &tag) const
{
+ setup_cullers(renderer);
for(InstanceMap::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
for(RenderableSet::const_iterator j=i->second.begin(); j!=i->second.end(); ++j)
- renderer.render(**j, tag);
+ if(!cull(renderer, **j))
+ renderer.render(**j, tag);
}
} // namespace GL
void OrderedScene::render(Renderer &renderer, const Tag &tag) const
{
+ setup_cullers(renderer);
for(RenderableList::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
- renderer.render(**i, tag);
+ if(!cull(renderer, **i))
+ renderer.render(**i, tag);
}
} // namespace GL
+#include "culler.h"
#include "renderer.h"
#include "scene.h"
+using namespace std;
+
namespace Msp {
namespace GL {
+void Scene::add_culler(Culler &c)
+{
+ cullers.push_back(&c);
+}
+
+void Scene::remove_culler(Culler &c)
+{
+ list<Culler *>::iterator i = find(cullers.begin(), cullers.end(), &c);
+ if(i!=cullers.end())
+ cullers.erase(i);
+}
+
void Scene::render(const Tag &tag) const
{
Renderer renderer(0);
render(renderer, tag);
}
+void Scene::setup_cullers(const Renderer &renderer) const
+{
+ for(list<Culler *>::const_iterator i=cullers.begin(); i!=cullers.end(); ++i)
+ (*i)->setup_frame(renderer);
+}
+
+bool Scene::cull(const Renderer &renderer, const Renderable &renderable) const
+{
+ for(list<Culler *>::const_iterator i=cullers.begin(); i!=cullers.end(); ++i)
+ if((*i)->cull(renderer, renderable))
+ return true;
+ return false;
+}
+
} // namespace GL
} // namespace Msp
namespace Msp {
namespace GL {
+class Culler;
+
/**
Scenes are containers for other Renderables. This is a base class that can't
be instantiated. At the moment the available Scene types are SimpleScene,
class Scene: public Renderable
{
protected:
+ std::list<Culler *> cullers;
+
Scene() { }
public:
virtual ~Scene() { }
virtual void add(const Renderable &) = 0;
virtual void remove(const Renderable &) = 0;
+ void add_culler(Culler &);
+ void remove_culler(Culler &);
+
using Renderable::render;
virtual void render(const Tag & = Tag()) const;
+
+protected:
+ virtual void setup_cullers(const Renderer &) const;
+ virtual bool cull(const Renderer &, const Renderable &) const;
};
} // namespace GL
void SimpleScene::render(Renderer &renderer, const Tag &tag) const
{
+ setup_cullers(renderer);
for(RenderableSet::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
- renderer.render(**i, tag);
+ if(!cull(renderer, **i))
+ renderer.render(**i, tag);
}
} // namespace GL