]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/texture.cpp
Load textures in a type-generic way
[libs/gl.git] / source / core / texture.cpp
index 4968e2e678bd6103c239103828cc1c78b0ff4b2b..54577aacd55e06f389361f0eda96305b42a63057 100644 (file)
@@ -2,23 +2,25 @@
 #include "error.h"
 #include "resourcemanager.h"
 #include "texture.h"
+#include "texture1d.h"
+#include "texture2d.h"
+#include "texture2darray.h"
+#include "texture3d.h"
+#include "texturecube.h"
 
 using namespace std;
 
 namespace Msp {
 namespace GL {
 
-Texture::Texture(unsigned t, ResourceManager *m):
-       TextureBackend(t, !m),
+Texture::Texture(unsigned t):
+       TextureBackend(t),
        format(NO_PIXELFORMAT),
        storage_fmt(format),
        swizzle(NO_SWIZZLE),
        use_srgb_format(false),
        auto_gen_mipmap(false)
-{
-       if(m)
-               set_manager(m);
-}
+{ }
 
 void Texture::set_format(PixelFormat fmt)
 {
@@ -64,23 +66,27 @@ void Texture::load_image(const string &fn, unsigned lv)
        image(img, lv);
 }
 
-
-Texture::Loader::Loader(Texture &t):
-       DataFile::CollectionObjectLoader<Texture>(t, 0)
+Texture::GenericLoader::TypeRegistry &Texture::get_texture_registry()
 {
-       init();
+       static GenericLoader::TypeRegistry registry;
+       static bool initialized = false;
+       if(!initialized)
+       {
+               initialized = true;
+               registry.register_type<Texture1D>("1d");
+               registry.register_type<Texture2D>("2d");
+               registry.register_type<Texture3D>("3d");
+               registry.register_type<Texture2DArray>("2d_array");
+               registry.register_type<TextureCube>("cube");
+       }
+       return registry;
 }
 
-Texture::Loader::Loader(Texture &t, Collection &c):
-       DataFile::CollectionObjectLoader<Texture>(t, &c)
-{
-       init();
-}
 
-void Texture::Loader::init()
+Texture::Loader::Loader(Texture &t, Collection *c):
+       CollectionObjectLoader<Texture>(t, c),
+       levels(0)
 {
-       levels = 0;
-
        add("external_image", &Loader::external_image);
        add("external_image_srgb", &Loader::external_image_srgb);
        add("generate_mipmap", &Loader::generate_mipmap);
@@ -134,11 +140,7 @@ void Texture::Loader::generate_mipmap(bool gm)
 void Texture::Loader::image_data(const string &data)
 {
        if(obj.manager)
-       {
                obj.set_manager(0);
-               if(!obj.id)
-                       obj.generate_id();
-       }
 
        Graphics::Image img;
        IO::Memory mem(data.data(), data.size());