X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Frender%2Fscene.h;h=692dcd0dfc6c7ebf88e0e8c7f0b26d7c0aae4b33;hb=9e63512930bc7dace6dc169c65161961e5dcfcf6;hp=639a467fa849cb526c19ac31744b957f820af7ea;hpb=7aaec9a70b8d7733429bec043f8e33e02956f266;p=libs%2Fgl.git diff --git a/source/render/scene.h b/source/render/scene.h index 639a467f..692dcd0d 100644 --- a/source/render/scene.h +++ b/source/render/scene.h @@ -1,23 +1,29 @@ #ifndef MSP_GL_SCENE_H_ #define MSP_GL_SCENE_H_ -#include +#include +#include #include #include "matrix.h" #include "renderable.h" -#include "vector.h" namespace Msp { namespace GL { /** -Scenes are containers for other Renderables. This is a base class that can't -be instantiated. Examples of available Scene types are SimpleScene, -InstancedScene and OrderedScene. +Container for other renderables. Subclasses provide different ways of +rendering the contents. + +All types of Scenes perform frustum culling on the contents, skipping +renderables whose bounding sphere is fully outside the view volume. If a +bounding sphere cannot be determined, culling is not performed on that +renderable. + +SimpleScene is a good default choice if there are no specific requirements. */ class Scene: public Renderable { -public: +protected: class Loader: public DataFile::CollectionObjectLoader { public: @@ -26,28 +32,42 @@ public: private: ContentMap *content; + static unsigned inline_counter; + public: - Loader(Scene &, Collection &); - Loader(Scene &, Collection &, ContentMap &); + Loader(Scene &s, Collection &c): Loader(s, c, 0) { } + Loader(Scene &s, Collection &c, ContentMap &m) : Loader(s, c, &m) { } private: - void init(); + Loader(Scene &, Collection &, ContentMap *); void object(const std::string &); void object_tagged(const std::string &, const std::string &); + void scene(const std::string &); + void scene_inline(); + }; + +public: + class GenericLoader: public DataFile::DynamicObjectLoader + { + friend class Scene; + + public: + GenericLoader(DataFile::Collection &c): DynamicObjectLoader(&c) { } + + protected: + virtual const TypeRegistry &get_type_registry() const { return get_scene_registry(); } }; protected: - // XXX If a loaded renderable is removed from the scene it needs to be removed from here as well - std::vector owned_data; mutable Matrix culling_matrix; mutable Vector4 frustum_edges[6]; - Scene() { } + Scene() = default; private: Scene(const Scene &); Scene &operator=(const Scene &); public: - virtual ~Scene(); + virtual ~Scene() = default; virtual void add(Renderable &) = 0; virtual void remove(Renderable &) = 0; @@ -55,8 +75,20 @@ public: protected: bool setup_frustum(const Renderer &) const; bool frustum_cull(const Renderable &) const; + +public: + template + static void register_type(const std::string &); +private: + static GenericLoader::TypeRegistry &get_scene_registry(); }; +template +void Scene::register_type(const std::string &kw) +{ + get_scene_registry().register_type(kw); +} + } // namespace GL } // namespace Msp