]> git.tdb.fi Git - libs/gl.git/commitdiff
Remove automatic mipmap generation from the public interface of Texture
authorMikko Rasa <tdb@tdb.fi>
Thu, 16 Sep 2021 22:00:07 +0000 (01:00 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 16 Sep 2021 22:06:54 +0000 (01:06 +0300)
The flag is now only used in conjunction of textures loaded from
datafiles.  Mipmap generation can still be manually triggered.

This causes some lossage with the allocation flags if the texture storage
extension is not supported.  I'll likely refactor the allocation system
soon.

source/core/texture.cpp
source/core/texture.h
source/core/texture1d.cpp
source/core/texture2d.cpp
source/core/texture3d.cpp
source/core/texturecube.cpp

index b40046705b32bdfbecd459b56ce5e9b7c81ae4d9..5c82dbe535d91a3036c4eed0f0f3e4d93a2e2fdb 100644 (file)
@@ -133,11 +133,6 @@ void Texture::set_parameter_i(GLenum param, int value) const
                glTexParameteri(target, param, value);
 }
 
-bool Texture::can_generate_mipmap()
-{
-       return EXT_framebuffer_object;
-}
-
 void Texture::generate_mipmap()
 {
        // glGenerateMipmap is defined here
@@ -152,14 +147,6 @@ void Texture::generate_mipmap()
        }
 }
 
-void Texture::set_auto_generate_mipmap(bool gm)
-{
-       if(gm)
-               static Require _req(EXT_framebuffer_object);
-
-       auto_gen_mipmap = gm;
-}
-
 void Texture::load_image(const string &fn, bool)
 {
        load_image(fn, 0U);
@@ -235,6 +222,12 @@ void Texture::Loader::init()
        add("mipmap_levels", &Loader::mipmap_levels);
 }
 
+void Texture::Loader::finish()
+{
+       if(obj.auto_gen_mipmap)
+               obj.generate_mipmap();
+}
+
 void Texture::Loader::load_external_image(Graphics::Image &img, const string &fn)
 {
        RefPtr<IO::Seekable> io = get_collection().open_raw(fn);
@@ -269,7 +262,7 @@ void Texture::Loader::external_image_common(const string &fn)
 
 void Texture::Loader::generate_mipmap(bool gm)
 {
-       obj.set_auto_generate_mipmap(gm);
+       obj.auto_gen_mipmap = gm;
 }
 
 void Texture::Loader::image_data(const string &data)
index 1631f69f248109a1a06764f9fd038b05841e685e..04a810856a5dedab8b16ecbbd453f6817fddd1d7 100644 (file)
@@ -37,6 +37,8 @@ protected:
        private:
                void init();
 
+               virtual void finish();
+
        protected:
                void load_external_image(Graphics::Image &, const std::string &);
 
@@ -84,17 +86,8 @@ protected:
 public:
        PixelFormat get_format() const { return format; }
 
-       static bool can_generate_mipmap();
-
        void generate_mipmap();
 
-       /** Sets automatic mipmap generation.  If enabled, mipmaps are generated
-       when a texture image is uploaded. */
-       void set_auto_generate_mipmap(bool);
-
-       /// Deprecated.  Use set_auto_generate_mipmap instead.
-       DEPRECATED void set_generate_mipmap(bool g) { set_auto_generate_mipmap(g); }
-
        /// Loads a Graphics::Image from a file and uploads it to the texture.
        virtual void load_image(const std::string &, unsigned = 0);
 
index 1dbe36eb293e6b02d6a01608b23fb546938eb71a..03e02159a5b8dd49e6847366cd37c8e4d56d8e19 100644 (file)
@@ -86,11 +86,6 @@ void Texture1D::image(unsigned level, const void *data)
        glTexImage1D(target, level, fmt, get_level_size(level), 0, comp, type, data);
 
        allocated |= 1<<level;
-       if(auto_gen_mipmap && level==0)
-       {
-               generate_mipmap();
-               allocated |= (1<<levels)-1;
-       }
 }
 
 void Texture1D::image(unsigned level, PixelComponents comp, DataType type, const void *data)
@@ -118,9 +113,6 @@ void Texture1D::sub_image(unsigned level, int x, unsigned wd, const void *data)
                bind_scratch();
                glTexSubImage1D(target, level, x, wd, comp, type, data);
        }
-
-       if(auto_gen_mipmap && level==0)
-               generate_mipmap();
 }
 
 void Texture1D::sub_image(unsigned level, int x, unsigned wd, PixelComponents comp, DataType type, const void *data)
index ed0b206c1e05069ada3d8e677c84995b706e920b..0fc300e0a09e7b4659aefe3bb842228797f6f3b1 100644 (file)
@@ -116,11 +116,6 @@ void Texture2D::image(unsigned level, const void *data)
        glTexImage2D(target, level, fmt, size.x, size.y, 0, comp, type, data);
 
        allocated |= 1<<level;
-       if(auto_gen_mipmap && level==0)
-       {
-               generate_mipmap();
-               allocated |= (1<<levels)-1;
-       }
 }
 
 void Texture2D::image(unsigned level, PixelComponents comp, DataType type, const void *data)
@@ -148,9 +143,6 @@ void Texture2D::sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht
                bind_scratch();
                glTexSubImage2D(target, level, x, y, wd, ht, comp, type, data);
        }
-
-       if(auto_gen_mipmap && level==0)
-               generate_mipmap();
 }
 
 void Texture2D::sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht, PixelComponents comp, DataType type, const void *data)
@@ -303,6 +295,8 @@ bool Texture2D::AsyncLoader::process()
                glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pixel_buffer.get_id());
                texture.image(image, 0, true);
                glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
+               if(texture.auto_gen_mipmap)
+                       texture.generate_mipmap();
        }
 
        ++phase;
index 705a40ba5574cc950078d119e9061a90e6bd9272..a7dae70350dab74416eb399b22dbcac63481e21d 100644 (file)
@@ -103,11 +103,6 @@ void Texture3D::image(unsigned level, const void *data)
        glTexImage3D(target, level, fmt, size.x, size.y, size.z, 0, comp, type, data);
 
        allocated |= 1<<level;
-       if(auto_gen_mipmap && level==0)
-       {
-               generate_mipmap();
-               allocated |= (1<<levels)-1;
-       }
 }
 
 void Texture3D::image(unsigned level, PixelComponents comp, DataType type, const void *data)
@@ -135,9 +130,6 @@ void Texture3D::sub_image(unsigned level, int x, int y, int z, unsigned wd, unsi
                bind_scratch();
                glTexSubImage3D(target, level, x, y, z, wd, ht, dp, comp, type, data);
        }
-
-       if(auto_gen_mipmap && level==0)
-               generate_mipmap();
 }
 
 void Texture3D::sub_image(unsigned level, int x, int y, int z, unsigned wd, unsigned ht, unsigned dp, PixelComponents comp, DataType type, const void *data)
index a2c6c8eb62725c21ce21553cf30926b01fe127e8..6eaa3a4470445d3221afeba689a86f508fb76bc0 100644 (file)
@@ -127,14 +127,7 @@ void TextureCube::image(TextureCubeFace face, unsigned level, const void *data)
        {
                allocated |= 1<<get_face_index(face);
                if((allocated&63)==63)
-               {
                        allocated |= 64;
-                       if(auto_gen_mipmap && level==0 && (allocated&63)==63)
-                       {
-                               generate_mipmap();
-                               allocated |= (64<<levels)-1;
-                       }
-               }
        }
        else if(!(allocated&(64<<level)))
        {
@@ -171,9 +164,6 @@ void TextureCube::sub_image(TextureCubeFace face, unsigned level, int x, int y,
                bind_scratch();
                glTexSubImage2D(face, level, x, y, wd, ht, comp, type, data);
        }
-
-       if(auto_gen_mipmap && level==0)
-               generate_mipmap();
 }
 
 void TextureCube::sub_image(TextureCubeFace face, unsigned level, int x, int y, unsigned wd, unsigned ht, PixelComponents comp, DataType type, const void *data)