]> git.tdb.fi Git - libs/gl.git/commitdiff
Move filter heuristic for mipmap levels to Texture::Loader
authorMikko Rasa <tdb@tdb.fi>
Sun, 31 Jan 2021 00:09:16 +0000 (02:09 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 31 Jan 2021 00:36:51 +0000 (02:36 +0200)
source/texture.cpp
source/texture.h
source/texture1d.cpp
source/texture2d.cpp
source/texture3d.cpp
source/texturecube.cpp

index 401cb968578d9d9eb7ac7e433869929d3f221e2f..b8c14792dad403e9fd98e2885dc99188fd17be80 100644 (file)
@@ -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)
index 8aac05927288cfcbcdb8253230f8df97829f6c82..774b7e83610b17ea8ea1a861c23b41917ea256c1 100644 (file)
@@ -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);
index d09a9570306e077b771d31dce598757e2fc715fb..38dc8a8bde5644ef5841bd52d7ae5636a7e40bbf 100644 (file)
@@ -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");
 
index 7586862591675534a50bf13b076021701ec004b0..abdfe0d1569ca50d7f06e15531e5e01997cb47bc 100644 (file)
@@ -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");
 
index c107fd7451a16a6f2f9c5368e065d20442249277..48b358c2edd2ad0e2a899138713b8bb5d82135c9 100644 (file)
@@ -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");
 
index 14ddf43d41c2cdc076e4489a62e2ed2e7341dd36..bac60ffdd9612317ecfd3af6251ff78ef1aa3c93 100644 (file)
@@ -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");