--- /dev/null
+#ifndef MSP_GL_OCCLUDEDSCENE_H_
+#define MSP_GL_OCCLUDEDSCENE_H_
+
+#include <set>
+#include <vector>
+#include "mesh.h"
+#include "program.h"
+#include "scene.h"
+
+namespace Msp {
+namespace GL {
+
+/**
+A scene that performs occlusion queries on renderables to skip those that are
+entirely occluded by others.
+*/
+class OccludedScene: public Scene
+{
+private:
+ struct OccludedRenderable
+ {
+ Renderable *renderable;
+ const Geometry::BoundingSphere<float, 3> *bounding_sphere;
+ bool in_frustum;
+ bool occluder;
+ unsigned query;
+
+ OccludedRenderable();
+ };
+
+ typedef std::set<Renderable *> RenderableSet;
+ typedef std::vector<OccludedRenderable> OccludedArray;
+
+ Mesh bounding_mesh;
+ Program bounding_shader;
+ RenderableSet renderables;
+ float occluder_min_size;
+ mutable OccludedArray occluded_cache;
+ mutable bool cache_dirty;
+
+public:
+ OccludedScene();
+ ~OccludedScene();
+
+ virtual void add(Renderable &);
+ virtual void remove(Renderable &);
+
+private:
+ void populate_cache() const;
+
+public:
+ virtual void setup_frame(Renderer &);
+ virtual void finish_frame();
+
+ virtual void render(Renderer &, const Tag & = Tag()) const;
+};
+
+} // namespace GL
+} // namespace Msp
+
+#endif