]> git.tdb.fi Git - libs/gl.git/commitdiff
Fix loading .tex2d files with ResourceManager
authorMikko Rasa <tdb@tdb.fi>
Sun, 28 Mar 2021 14:01:10 +0000 (17:01 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 28 Mar 2021 14:46:22 +0000 (17:46 +0300)
The texture's loader already informs the resource manager of the location
of the image, so it shouldn't be done here.  There's also no need to load
the image first anymore.

source/resources/resources.cpp

index ef8b93255fca8927104d35e4434e4a68cf5ee1bf..68d9739e7a49d64039a0f47d53d46159021bf88c 100644 (file)
@@ -132,20 +132,23 @@ Texture2D *Resources::create_texture2d(const string &name)
 
        if(RefPtr<IO::Seekable> io = open_raw(name))
        {
-               Graphics::Image image;
-               if(!resource_manager)
-                       image.load_io(*io);
-
-               RefPtr<Texture2D> tex = new Texture2D(resource_manager);
+               RefPtr<Texture2D> tex;
 
                if(ext==".tex2d")
                {
+                       tex = new Texture2D(resource_manager);
                        DataFile::Parser parser(*io, name);
                        Texture2D::Loader ldr(*tex, *this);
                        ldr.load(parser);
                }
                else
                {
+                       // Verify that the image is loadable
+                       Graphics::Image image;
+                       if(!resource_manager)
+                               image.load_io(*io);
+
+                       tex = new Texture2D(resource_manager);
                        Sampler &samp = tex->get_default_sampler();
                        if(is_mipmapped(default_tex_filter))
                        {
@@ -156,12 +159,13 @@ Texture2D *Resources::create_texture2d(const string &name)
                                samp.set_mag_filter(default_tex_filter);
                        samp.set_min_filter(default_tex_filter);
                        samp.set_max_anisotropy(default_tex_anisotropy);
+
+                       if(resource_manager)
+                               resource_manager->set_resource_location(*tex, *this, name);
+                       else
+                               tex->image(image);
                }
 
-               if(resource_manager)
-                       resource_manager->set_resource_location(*tex, *this, name);
-               else
-                       tex->image(image);
                return tex.release();
        }