]> git.tdb.fi Git - libs/gl.git/blob - source/occludedscene.h
Store Renderables as non-const pointers or references
[libs/gl.git] / source / occludedscene.h
1 #ifndef MSP_GL_OCCLUDEDSCENE_H_
2 #define MSP_GL_OCCLUDEDSCENE_H_
3
4 #include <set>
5 #include <vector>
6 #include "mesh.h"
7 #include "program.h"
8 #include "scene.h"
9
10 namespace Msp {
11 namespace GL {
12
13 /**
14 A scene that performs occlusion queries on renderables to skip those that are
15 entirely occluded by others.
16 */
17 class OccludedScene: public Scene
18 {
19 private:
20         struct OccludedRenderable
21         {
22                 Renderable *renderable;
23                 const Geometry::BoundingSphere<float, 3> *bounding_sphere;
24                 bool in_frustum;
25                 bool occluder;
26                 unsigned query;
27
28                 OccludedRenderable();
29         };
30
31         typedef std::set<Renderable *> RenderableSet;
32         typedef std::vector<OccludedRenderable> OccludedArray;
33
34         Mesh bounding_mesh;
35         Program bounding_shader;
36         RenderableSet renderables;
37         float occluder_min_size;
38         mutable OccludedArray occluded_cache;
39         mutable bool cache_dirty;
40
41 public:
42         OccludedScene();
43         ~OccludedScene();
44
45         virtual void add(Renderable &);
46         virtual void remove(Renderable &);
47
48         virtual void render(Renderer &, const Tag &) const;
49 };
50
51 } // namespace GL
52 } // namespace Msp
53
54 #endif