]> git.tdb.fi Git - libs/gl.git/blob - source/render/occludedscene.h
d51b29b36c87def2ef0ed1e7c30544a0aabea148
[libs/gl.git] / source / render / occludedscene.h
1 #ifndef MSP_GL_OCCLUDEDSCENE_H_
2 #define MSP_GL_OCCLUDEDSCENE_H_
3
4 #include <set>
5 #include <vector>
6 #include "blend.h"
7 #include "depthtest.h"
8 #include "query.h"
9 #include "scene.h"
10
11 namespace Msp {
12 namespace GL {
13
14 class Mesh;
15 class Program;
16
17 /**
18 A scene that performs occlusion queries on renderables to skip those that are
19 entirely occluded by others.
20 */
21 class OccludedScene: public Scene
22 {
23 public:
24         using Scene::Loader;
25
26 private:
27         struct OccludedRenderable
28         {
29                 Renderable *renderable;
30                 const Geometry::BoundingSphere<float, 3> *bounding_sphere;
31                 bool in_frustum;
32                 bool occluder;
33
34                 OccludedRenderable();
35         };
36
37         const Mesh &bounding_mesh;
38         const Program &bounding_shader;
39         Blend no_color_write;
40         DepthTest no_depth_write;
41         std::set<Renderable *> renderables;
42         float occluder_min_size;
43         mutable QueryPool queries;
44         mutable std::vector<OccludedRenderable> occluded_cache;
45         mutable bool cache_dirty;
46
47 public:
48         OccludedScene();
49
50         virtual void add(Renderable &);
51         virtual void remove(Renderable &);
52
53 private:
54         void populate_cache() const;
55
56 public:
57         virtual void setup_frame(Renderer &);
58         virtual void finish_frame();
59
60         virtual void render(Renderer &, Tag = Tag()) const;
61 };
62
63 } // namespace GL
64 } // namespace Msp
65
66 #endif