]> git.tdb.fi Git - libs/gl.git/blob - source/render/scene.h
Adjust naming of instances in Scene loader
[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         };
41
42 public:
43         class GenericLoader: public DataFile::DynamicObjectLoader<Scene>
44         {
45                 friend class Scene;
46
47         public:
48                 GenericLoader(DataFile::Collection &c): DynamicObjectLoader<Scene>(&c) { }
49
50         protected:
51                 virtual const TypeRegistry &get_type_registry() const { return get_scene_registry(); }
52         };
53
54 protected:
55         mutable Matrix culling_matrix;
56         mutable Vector4 frustum_edges[6];
57
58         Scene() = default;
59 private:
60         Scene(const Scene &);
61         Scene &operator=(const Scene &);
62 public:
63         virtual ~Scene() = default;
64
65         virtual void add(Renderable &) = 0;
66         virtual void remove(Renderable &) = 0;
67
68 protected:
69         bool setup_frustum(const Renderer &) const;
70         bool frustum_cull(const Renderable &) const;
71
72 public:
73         template<typename T>
74         static void register_type(const std::string &);
75 private:
76         static GenericLoader::TypeRegistry &get_scene_registry();
77 };
78
79 template<typename T>
80 void Scene::register_type(const std::string &kw)
81 {
82         get_scene_registry().register_type<T>(kw);
83 }
84
85 } // namespace GL
86 } // namespace Msp
87
88 #endif