]> git.tdb.fi Git - libs/gl.git/blobdiff - source/resources/resources.cpp
Use persistent uniform blocks for Camera, Lighting and Clipping
[libs/gl.git] / source / resources / resources.cpp
index 66f6f082b927d2d6cdd5499a859f23bde6eadff2..682acde23d6603604f411193e7407d9cb09d530b 100644 (file)
@@ -3,6 +3,7 @@
 #include "animation.h"
 #include "armature.h"
 #include "camera.h"
+#include "error.h"
 #include "font.h"
 #include "keyframe.h"
 #include "light.h"
@@ -33,7 +34,9 @@ namespace GL {
 void init_shaderlib(DataFile::BuiltinSource &);
 void init_builtin_data(DataFile::BuiltinSource &);
 
-Resources::Resources():
+Resources *Resources::global_resources = 0;
+
+Resources::Resources(bool set_as_global):
        default_tex_filter(Texture::can_generate_mipmap() ? LINEAR_MIPMAP_LINEAR : LINEAR),
        default_tex_anisotropy(1.0f),
        srgb_conversion(false),
@@ -41,11 +44,13 @@ Resources::Resources():
 {
        add_type<Animation>().suffix(".anim").keyword("animation");
        add_type<Armature>().suffix(".arma").keyword("armature");
-       add_type<Camera>().keyword("camera");
+       add_type<Camera>().keyword("camera")
+               .notify(&Resources::set_debug_name<Camera>);
        add_type<Font>().keyword("font");
        add_type<KeyFrame>().suffix(".kframe").keyword("keyframe");
        add_type<Light>().keyword("light");
-       add_type<Lighting>().suffix(".lightn").keyword("lighting");
+       add_type<Lighting>().suffix(".lightn").keyword("lighting")
+               .notify(&Resources::set_debug_name<Lighting>);
        add_type<Material>().suffix(".mat")
                .creator(&Resources::create_material).notify(&Resources::set_debug_name<Material>);
        add_type<Mesh>().keyword("mesh")
@@ -75,6 +80,22 @@ Resources::Resources():
                .notify(&Resources::set_debug_name<Texture2DArray>);
 
        add_source(get_builtins());
+
+       if(set_as_global && !global_resources)
+               global_resources = this;
+}
+
+Resources::~Resources()
+{
+       if(this==global_resources)
+               global_resources = 0;
+}
+
+Resources &Resources::get_global()
+{
+       if(!global_resources)
+               throw invalid_operation("no global resources");
+       return *global_resources;
 }
 
 const DataFile::CollectionSource &Resources::get_builtins()