]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/texture.h
Load textures in a type-generic way
[libs/gl.git] / source / core / texture.h
index 6073cdcb2fcb5e071145731e4c1c88abbf1d02b0..154a8c030018f0087e062001ad851c8c8ae77758 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef MSP_GL_TEXTURE_H_
 #define MSP_GL_TEXTURE_H_
 
+#include <msp/datafile/dynamicobjectloader.h>
 #include <msp/datafile/objectloader.h>
 #include <msp/graphics/image.h>
 #include "pixelformat.h"
@@ -30,10 +31,10 @@ protected:
                unsigned levels;
 
        public:
-               Loader(Texture &);
-               Loader(Texture &, Collection &);
+               Loader(Texture &t): Loader(t, 0) { }
+               Loader(Texture &t, Collection &c): Loader(t, &c) { }
        private:
-               void init();
+               Loader(Texture &, Collection *);
 
                virtual void finish();
 
@@ -49,6 +50,19 @@ protected:
                void mipmap_levels(unsigned);
        };
 
+public:
+       class GenericLoader: public DataFile::DynamicObjectLoader<Texture>
+       {
+               friend class Texture;
+
+       public:
+               GenericLoader(Collection &c): DynamicObjectLoader<Texture>(&c) { }
+
+       protected:
+               virtual const TypeRegistry &get_type_registry() const { return get_texture_registry(); }
+       };
+
+protected:
        enum FormatSwizzle
        {
                NO_SWIZZLE,
@@ -63,7 +77,7 @@ protected:
        bool use_srgb_format;
        bool auto_gen_mipmap;
 
-       Texture(unsigned, ResourceManager * = 0);
+       Texture(unsigned);
 
        void set_format(PixelFormat);
 
@@ -83,6 +97,9 @@ public:
        virtual std::uint64_t get_data_size() const { return 0; }
 
        using TextureBackend::set_debug_name;
+
+private:
+       static GenericLoader::TypeRegistry &get_texture_registry();
 };
 
 } // namespace GL