]> git.tdb.fi Git - libs/gl.git/commitdiff
Refactor texture external image loading into a helper function
authorMikko Rasa <tdb@tdb.fi>
Wed, 3 Feb 2021 22:58:19 +0000 (00:58 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 3 Feb 2021 23:08:29 +0000 (01:08 +0200)
source/texture.cpp
source/texture.h
source/texture2darray.cpp

index b747a2a6b0d7001b3d06e7a2811f91e93f075e78..703ea96c5fabfddb2cb8b33c65cb8056df205f16 100644 (file)
@@ -306,14 +306,18 @@ unsigned Texture::Loader::get_levels() const
 
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-void Texture::Loader::external_image(const string &fn)
+void Texture::Loader::load_external_image(Graphics::Image &img, const std::string &fn)
 {
-       Graphics::Image img;
        RefPtr<IO::Seekable> io = get_collection().open_raw(fn);
        if(!io)
                throw IO::file_not_found(fn);
        img.load_io(*io);
+}
 
+void Texture::Loader::external_image(const string &fn)
+{
+       Graphics::Image img;
+       load_external_image(img, fn);
        obj.image(img, get_levels(), srgb);
 }
 
index 30c6496a5658525e00a6ac59374996c25f08d7e3..6ee0b8a107754e83c7bf2d49b4fe6f68f2e11db4 100644 (file)
@@ -39,7 +39,10 @@ protected:
                void init();
 
                unsigned get_levels() const;
+       protected:
+               void load_external_image(Graphics::Image &, const std::string &);
 
+       private:
                void external_image(const std::string &);
                void filter(TextureFilter);
                void generate_mipmap(bool);
index c080481b106590f5a6a159be78ad1618142cf85f..4d37263c76b75c59ddb06f5e03d6e0096cd43439 100644 (file)
@@ -72,11 +72,7 @@ void Texture2DArray::Loader::init()
 void Texture2DArray::Loader::external_image(unsigned z, const string &fn)
 {
        Graphics::Image img;
-       RefPtr<IO::Seekable> io = get_collection().open_raw(fn);
-       if(!io)
-               throw IO::file_not_found(fn);
-       img.load_io(*io);
-
+       load_external_image(img, fn);
        obj.layer_image(0, z, img);
 }