]> git.tdb.fi Git - libs/gl.git/blob - source/render/occludedscene.h
Check the flat qualifier from the correct member
[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 which performs occlusion queries on renderables to skip those which are
19 entirely occluded by others.
20
21 Renderables must have valid model matrices and bounding spheres to participate
22 in occlusion culling.  Those lacking one or both are always rendered.
23 */
24 class OccludedScene: public Scene
25 {
26 public:
27         using Scene::Loader;
28
29 private:
30         struct OccludedRenderable
31         {
32                 Renderable *renderable = 0;
33                 const Geometry::BoundingSphere<float, 3> *bounding_sphere = 0;
34                 bool in_frustum = false;
35                 bool occluder = false;
36         };
37
38         const Mesh &bounding_mesh;
39         const Program &bounding_shader;
40         Blend no_color_write;
41         DepthTest no_depth_write = { LEQUAL, false };
42         std::vector<Renderable *> content;
43         float occluder_min_size = 0.25f;
44         mutable QueryPool queries;
45         mutable std::vector<OccludedRenderable> occluded_cache;
46         mutable bool cache_dirty = false;
47
48 public:
49         OccludedScene();
50
51         virtual void add(Renderable &);
52         virtual void remove(Renderable &);
53
54 private:
55         void populate_cache() const;
56
57 public:
58         virtual void setup_frame(Renderer &);
59         virtual void finish_frame();
60
61         virtual void render(Renderer &, Tag = Tag()) const;
62 };
63
64 } // namespace GL
65 } // namespace Msp
66
67 #endif