]> git.tdb.fi Git - libs/gl.git/blobdiff - source/resources/resources.h
Load textures in a type-generic way
[libs/gl.git] / source / resources / resources.h
index 3036c2f463ef44425d0a4f48939a84fb363aae37..f1aec26b283b2d6cb871f551e84456ffcc8e6b1e 100644 (file)
@@ -12,6 +12,7 @@ class Mesh;
 class Module;
 class Program;
 class ResourceManager;
+class Scene;
 class Texture2D;
 
 /**
@@ -20,20 +21,43 @@ application-specific collection.
 */
 class Resources: virtual public DataFile::Collection
 {
+public:
+       class Loader: public DataFile::DerivedObjectLoader<Resources, Collection::Loader>
+       {
+       public:
+               Loader(Resources &);
+
+       private:
+               template<typename T, typename L = typename T::GenericLoader>
+               void generic(const std::string &);
+       };
+
 private:
-       TextureFilter default_tex_filter;
-       float default_tex_anisotropy;
+       template<typename T>
+       class GenericResourceLoader: public T::GenericLoader
+       {
+       private:
+               Resources &resources;
+
+       public:
+               GenericResourceLoader(Resources &r): T::GenericLoader(r), resources(r) { }
+
+       protected:
+               virtual void type(const DataFile::Symbol &);
+       };
+
        bool srgb_conversion;
        ResourceManager *resource_manager;
 
+       static Resources *global_resources;
+
 public:
-       Resources();
+       Resources(bool = true);
+       virtual ~Resources();
 
+       static Resources &get_global();
        static const DataFile::CollectionSource &get_builtins();
 
-       void set_default_texture_filter(TextureFilter);
-       void set_default_texture_anisotropy(float);
-
        /** Enables or disables sRGB conversion.  If enabled, textures and material
        colors are converted from sRGB to linear color space when loaded. */
        DEPRECATED void set_srgb_conversion(bool);
@@ -43,11 +67,16 @@ public:
        void set_resource_manager(ResourceManager *);
 
 protected:
-       Material *create_material(const std::string &);
+       template<typename T, typename L = typename T::GenericLoader>
+       T *create_generic(const std::string &);
+
        Mesh *create_mesh(const std::string &);
-       Texture2D *create_texture2d(const std::string &);
+       Texture *create_texture(const std::string &);
        Module *create_module(const std::string &);
        Program *create_program(const std::string &);
+
+       template<typename T>
+       static void set_debug_name(const std::string &, T &);
 };
 
 } // namespace GL