From: Mikko Rasa Date: Fri, 5 Feb 2021 21:30:45 +0000 (+0200) Subject: Load .tex2d format textures with resource manager X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=d0a888978ab0c2226ed5961c736c7cac551e79b1;p=libs%2Fgl.git Load .tex2d format textures with resource manager This allows universal use of .tex2d to specify texture settings, even when the actual image data is loaded from an external file. --- diff --git a/source/resources.cpp b/source/resources.cpp index dd9a3c68..8de2529f 100644 --- a/source/resources.cpp +++ b/source/resources.cpp @@ -121,7 +121,7 @@ Mesh *Resources::create_mesh(const string &name) Texture2D *Resources::create_texture2d(const string &name) { string ext = FS::extpart(name); - if(ext==".tex2d") + if(ext==".tex2d" && !resource_manager) return 0; if(RefPtr io = open_raw(name)) @@ -132,16 +132,25 @@ Texture2D *Resources::create_texture2d(const string &name) RefPtr tex = new Texture2D(resource_manager); - Sampler &samp = tex->get_default_sampler(); - if(is_mipmapped(default_tex_filter)) + if(ext==".tex2d") { - tex->set_auto_generate_mipmap(true); - samp.set_mag_filter(LINEAR); + DataFile::Parser parser(*io, name); + Texture2D::Loader ldr(*tex, *this); + ldr.load(parser); } else - samp.set_mag_filter(default_tex_filter); - samp.set_min_filter(default_tex_filter); - samp.set_max_anisotropy(default_tex_anisotropy); + { + Sampler &samp = tex->get_default_sampler(); + if(is_mipmapped(default_tex_filter)) + { + tex->set_auto_generate_mipmap(true); + samp.set_mag_filter(LINEAR); + } + else + 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); diff --git a/source/texture.cpp b/source/texture.cpp index 703ea96c..24994f7c 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -316,9 +316,14 @@ void Texture::Loader::load_external_image(Graphics::Image &img, const std::strin void Texture::Loader::external_image(const string &fn) { - Graphics::Image img; - load_external_image(img, fn); - obj.image(img, get_levels(), srgb); + if(obj.manager) + obj.manager->set_resource_location(obj, get_collection(), fn); + else + { + Graphics::Image img; + load_external_image(img, fn); + obj.image(img, get_levels(), srgb); + } } void Texture::Loader::filter(TextureFilter f)