From 99e833421259dd90b164a9c49d63c936c343c65f Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 4 Feb 2021 00:58:19 +0200 Subject: [PATCH] Refactor texture external image loading into a helper function --- source/texture.cpp | 8 ++++++-- source/texture.h | 3 +++ source/texture2darray.cpp | 6 +----- 3 files changed, 10 insertions(+), 7 deletions(-) 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); } -- 2.43.0