From 47f817343df1d06d91a4f7c4d5b47df40b24366c Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 31 Jan 2021 02:09:16 +0200 Subject: [PATCH] Move filter heuristic for mipmap levels to Texture::Loader --- source/texture.cpp | 9 +++++++-- source/texture.h | 2 ++ source/texture1d.cpp | 5 +---- source/texture2d.cpp | 5 +---- source/texture3d.cpp | 5 +---- source/texturecube.cpp | 5 +---- 6 files changed, 13 insertions(+), 18 deletions(-) diff --git a/source/texture.cpp b/source/texture.cpp index 401cb968..b8c14792 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -407,6 +407,11 @@ void Texture::Loader::init() add("wrap_t", &Loader::wrap_t); } +unsigned Texture::Loader::get_levels() const +{ + return (is_mipmapped(obj.default_sampler.get_min_filter()) ? levels : 1); +} + void Texture::Loader::external_image(const string &fn) { Graphics::Image img; @@ -415,7 +420,7 @@ void Texture::Loader::external_image(const string &fn) throw IO::file_not_found(fn); img.load_io(*io); - obj.image(img, levels, srgb); + obj.image(img, get_levels(), srgb); } void Texture::Loader::filter(TextureFilter f) @@ -434,7 +439,7 @@ void Texture::Loader::image_data(const string &data) IO::Memory mem(data.data(), data.size()); img.load_io(mem); - obj.image(img, levels, srgb); + obj.image(img, get_levels(), srgb); } void Texture::Loader::mag_filter(TextureFilter f) diff --git a/source/texture.h b/source/texture.h index 8aac0592..774b7e83 100644 --- a/source/texture.h +++ b/source/texture.h @@ -83,6 +83,8 @@ protected: private: void init(); + unsigned get_levels() const; + void external_image(const std::string &); void filter(TextureFilter); void generate_mipmap(bool); diff --git a/source/texture1d.cpp b/source/texture1d.cpp index d09a9570..38dc8a8b 100644 --- a/source/texture1d.cpp +++ b/source/texture1d.cpp @@ -110,10 +110,7 @@ void Texture1D::image(const Graphics::Image &img, unsigned lv, bool srgb) unsigned w = img.get_width(); PixelFormat fmt = pixelformat_from_graphics(img.get_format()); if(width==0) - { - unsigned l = (is_mipmapped(min_filter) ? lv : 1); - storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w, l); - } + storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w, lv); else if(w!=width) throw incompatible_data("Texture1D::image"); diff --git a/source/texture2d.cpp b/source/texture2d.cpp index 75868625..abdfe0d1 100644 --- a/source/texture2d.cpp +++ b/source/texture2d.cpp @@ -143,10 +143,7 @@ void Texture2D::image(const Graphics::Image &img, unsigned lv, bool srgb, bool f unsigned h = img.get_height(); PixelFormat fmt = pixelformat_from_graphics(img.get_format()); if(width==0) - { - unsigned l = (is_mipmapped(min_filter) ? lv : 1); - storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w, h, l); - } + storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w, h, lv); else if(w!=width || h!=height || (lv && lv!=levels)) throw incompatible_data("Texture2D::image"); diff --git a/source/texture3d.cpp b/source/texture3d.cpp index c107fd74..48b358c2 100644 --- a/source/texture3d.cpp +++ b/source/texture3d.cpp @@ -190,10 +190,7 @@ void Texture3D::image(const Graphics::Image &img, unsigned lv, bool srgb) PixelFormat fmt = pixelformat_from_graphics(img.get_format()); if(width==0) - { - unsigned l = (is_mipmapped(min_filter) ? lv : 1); - storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w, h, d, l); - } + storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w, h, d, lv); else if(w!=width || h!=height || d!=depth) throw incompatible_data("Texture3D::load_image"); diff --git a/source/texturecube.cpp b/source/texturecube.cpp index 14ddf43d..bac60ffd 100644 --- a/source/texturecube.cpp +++ b/source/texturecube.cpp @@ -176,10 +176,7 @@ void TextureCube::image(const Graphics::Image &img, unsigned lv, bool srgb) PixelFormat fmt = pixelformat_from_graphics(img.get_format()); if(size==0) - { - unsigned l = (is_mipmapped(min_filter) ? lv : 1); - storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w, l); - } + storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w, lv); else if(w!=size || h!=size) throw incompatible_data("TextureCube::image"); -- 2.43.0