]> git.tdb.fi Git - libs/gl.git/blob - source/render/scene.h
Add functions to retrieve steps and postprocessors from Sequence
[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 Scenes are containers for other Renderables.  This is a base class that can't
15 be instantiated.  Examples of available Scene types are SimpleScene,
16 InstancedScene and OrderedScene.
17 */
18 class Scene: public Renderable
19 {
20 protected:
21         class Loader: public DataFile::CollectionObjectLoader<Scene>
22         {
23         public:
24                 typedef std::map<std::string, Renderable *> ContentMap;
25
26         private:
27                 ContentMap *content;
28
29                 static unsigned inline_counter;
30
31         public:
32                 Loader(Scene &s, Collection &c): Loader(s, c, 0) { }
33                 Loader(Scene &s, Collection &c, ContentMap &m) : Loader(s, c, &m) { }
34         private:
35                 Loader(Scene &, Collection &, ContentMap *);
36
37                 void object(const std::string &);
38                 void object_tagged(const std::string &, const std::string &);
39                 void scene(const std::string &);
40                 void scene_inline();
41         };
42
43 public:
44         class GenericLoader: public DataFile::DynamicObjectLoader<Scene>
45         {
46                 friend class Scene;
47
48         public:
49                 GenericLoader(DataFile::Collection &c): DynamicObjectLoader<Scene>(&c) { }
50
51         protected:
52                 virtual const TypeRegistry &get_type_registry() const { return get_scene_registry(); }
53         };
54
55 protected:
56         mutable Matrix culling_matrix;
57         mutable Vector4 frustum_edges[6];
58
59         Scene() = default;
60 private:
61         Scene(const Scene &);
62         Scene &operator=(const Scene &);
63 public:
64         virtual ~Scene() = default;
65
66         virtual void add(Renderable &) = 0;
67         virtual void remove(Renderable &) = 0;
68
69 protected:
70         bool setup_frustum(const Renderer &) const;
71         bool frustum_cull(const Renderable &) const;
72
73 public:
74         template<typename T>
75         static void register_type(const std::string &);
76 private:
77         static GenericLoader::TypeRegistry &get_scene_registry();
78 };
79
80 template<typename T>
81 void Scene::register_type(const std::string &kw)
82 {
83         get_scene_registry().register_type<T>(kw);
84 }
85
86 } // namespace GL
87 } // namespace Msp
88
89 #endif