]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/texture.cpp
Remove support for array size specialization from the engine as well
[libs/gl.git] / source / core / texture.cpp
index 85f5fb5836ebdcdb56af17191343a9c2f21be9ea..5f21229fa8abc2d80c3e0029364bb519bd961bee 100644 (file)
@@ -1,24 +1,27 @@
+#include <msp/datafile/rawdata.h>
 #include <msp/io/memory.h>
 #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,16 +67,34 @@ void Texture::load_image(const string &fn, unsigned lv)
        image(img, lv);
 }
 
+Texture::GenericLoader::TypeRegistry &Texture::get_texture_registry()
+{
+       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):
        CollectionObjectLoader<Texture>(t, c),
        levels(0)
 {
-       add("external_image", &Loader::external_image);
-       add("external_image_srgb", &Loader::external_image_srgb);
+       add("external_data", &Loader::external_data);
+       add("external_image", &Loader::external_image, false);
+       add("external_image_srgb", &Loader::external_image, true);
        add("generate_mipmap", &Loader::generate_mipmap);
        add("image_data", &Loader::image_data);
        add("mipmap_levels", &Loader::mipmap_levels);
+       add("raw_data", &Loader::raw_data);
 }
 
 void Texture::Loader::finish()
@@ -90,20 +111,22 @@ void Texture::Loader::load_external_image(Graphics::Image &img, const string &fn
        img.load_io(*io);
 }
 
-void Texture::Loader::external_image(const string &fn)
-{
-       obj.use_srgb_format = false;
-       external_image_common(fn);
-}
-
-void Texture::Loader::external_image_srgb(const string &fn)
+void Texture::Loader::external_data(const string &fn)
 {
-       obj.use_srgb_format = true;
-       external_image_common(fn);
+       if(obj.manager)
+               obj.manager->set_resource_location(obj, get_collection(), fn);
+       else
+       {
+               DataFile::RawData rd;
+               rd.open_file(get_collection(), fn);
+               rd.load();
+               obj.image(0, rd.get_data());
+       }
 }
 
-void Texture::Loader::external_image_common(const string &fn)
+void Texture::Loader::external_image(bool srgb, const string &fn)
 {
+       obj.use_srgb_format = srgb;
        if(obj.manager)
                obj.manager->set_resource_location(obj, get_collection(), fn);
        else
@@ -122,11 +145,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());
@@ -140,5 +159,13 @@ void Texture::Loader::mipmap_levels(unsigned l)
        levels = l;
 }
 
+void Texture::Loader::raw_data(const string &data)
+{
+       if(obj.manager)
+               obj.set_manager(0);
+
+       obj.image(0, data.data());
+}
+
 } // namespace GL
 } // namespace Msp