From fb1e7ede05b07625232c2092d99e9d6b2d54a153 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 28 Mar 2021 17:01:10 +0300 Subject: [PATCH] Fix loading .tex2d files with ResourceManager 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 | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/source/resources/resources.cpp b/source/resources/resources.cpp index ef8b9325..68d9739e 100644 --- a/source/resources/resources.cpp +++ b/source/resources/resources.cpp @@ -132,20 +132,23 @@ Texture2D *Resources::create_texture2d(const string &name) if(RefPtr io = open_raw(name)) { - Graphics::Image image; - if(!resource_manager) - image.load_io(*io); - - RefPtr tex = new Texture2D(resource_manager); + RefPtr 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(); } -- 2.43.0