]> git.tdb.fi Git - libs/gl.git/blob - source/render/scene.h
Check the flat qualifier from the correct member
[libs/gl.git] / source / render / scene.h
1 #ifndef MSP_GL_SCENE_H_
2 #define MSP_GL_SCENE_H_
3
4 #include <map>
5 #include <msp/datafile/dynamicobjectloader.h>
6 #include <msp/datafile/objectloader.h>
7 #include "matrix.h"
8 #include "renderable.h"
9
10 namespace Msp {
11 namespace GL {
12
13 /**
14 Container for other renderables.  Subclasses provide different ways of
15 rendering the contents.
16
17 All types of Scenes perform frustum culling on the contents, skipping
18 renderables whose bounding sphere is fully outside the view volume.  If a
19 bounding sphere cannot be determined, culling is not performed on that
20 renderable.
21
22 SimpleScene is a good default choice if there are no specific requirements.
23 */
24 class Scene: public Renderable
25 {
26 protected:
27         class Loader: public DataFile::CollectionObjectLoader<Scene>
28         {
29         public:
30                 typedef std::map<std::string, Renderable *> ContentMap;
31
32         private:
33                 ContentMap *content;
34
35                 static unsigned inline_counter;
36
37         public:
38                 Loader(Scene &s, Collection &c): Loader(s, c, 0) { }
39                 Loader(Scene &s, Collection &c, ContentMap &m) : Loader(s, c, &m) { }
40         private:
41                 Loader(Scene &, Collection &, ContentMap *);
42
43                 void object(const std::string &);
44                 void object_tagged(const std::string &, const std::string &);
45                 void scene(const std::string &);
46                 void scene_inline();
47         };
48
49 public:
50         class GenericLoader: public DataFile::DynamicObjectLoader<Scene>
51         {
52                 friend class Scene;
53
54         public:
55                 GenericLoader(DataFile::Collection &c): DynamicObjectLoader<Scene>(&c) { }
56
57         protected:
58                 virtual const TypeRegistry &get_type_registry() const { return get_scene_registry(); }
59         };
60
61 protected:
62         mutable Matrix culling_matrix;
63         mutable Vector4 frustum_edges[6];
64
65         Scene() = default;
66 public:
67         virtual ~Scene() = default;
68
69         virtual void add(Renderable &) = 0;
70         virtual void remove(Renderable &) = 0;
71
72 protected:
73         bool setup_frustum(const Renderer &) const;
74         bool frustum_cull(const Renderable &) const;
75
76 public:
77         template<typename T>
78         static void register_type(const std::string &);
79 private:
80         static GenericLoader::TypeRegistry &get_scene_registry();
81 };
82
83 template<typename T>
84 void Scene::register_type(const std::string &kw)
85 {
86         get_scene_registry().register_type<T>(kw);
87 }
88
89 } // namespace GL
90 } // namespace Msp
91
92 #endif