From: Mikko Rasa Date: Wed, 3 Feb 2021 22:58:19 +0000 (+0200) Subject: Refactor texture external image loading into a helper function X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=99e833421259dd90b164a9c49d63c936c343c65f;p=libs%2Fgl.git Refactor texture external image loading into a helper function --- diff --git a/source/texture.cpp b/source/texture.cpp index b747a2a6..703ea96c 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -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 = 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); } diff --git a/source/texture.h b/source/texture.h index 30c6496a..6ee0b8a1 100644 --- a/source/texture.h +++ b/source/texture.h @@ -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); diff --git a/source/texture2darray.cpp b/source/texture2darray.cpp index c080481b..4d37263c 100644 --- a/source/texture2darray.cpp +++ b/source/texture2darray.cpp @@ -72,11 +72,7 @@ void Texture2DArray::Loader::init() void Texture2DArray::Loader::external_image(unsigned z, const string &fn) { Graphics::Image img; - RefPtr 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); }