]> git.tdb.fi Git - libs/gl.git/commitdiff
Load .tex2d format textures with resource manager
authorMikko Rasa <tdb@tdb.fi>
Fri, 5 Feb 2021 21:30:45 +0000 (23:30 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 5 Feb 2021 22:14:04 +0000 (00:14 +0200)
This allows universal use of .tex2d to specify texture settings, even
when the actual image data is loaded from an external file.

source/resources.cpp
source/texture.cpp

index dd9a3c68c3543b549f425a863a842ad2d35bcc04..8de2529fe94c861c771e25fc4121de7778890121 100644 (file)
@@ -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::Seekable> io = open_raw(name))
@@ -132,16 +132,25 @@ Texture2D *Resources::create_texture2d(const string &name)
 
                RefPtr<Texture2D> 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);
index 703ea96c5fabfddb2cb8b33c65cb8056df205f16..24994f7c69d0022be6e78230350c8ade6ffcc393 100644 (file)
@@ -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)