]> git.tdb.fi Git - libs/gl.git/commitdiff
Make explicit mipmap generation public
authorMikko Rasa <tdb@tdb.fi>
Mon, 8 Jul 2019 16:24:02 +0000 (19:24 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 8 Jul 2019 16:24:02 +0000 (19:24 +0300)
Also changed set_generate_mipmap to set_auto_generate_mipmap to clarify
that it concerns automatic mipmap generation.

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

index 03e10e2dccac03e46b1fa0b904cef0b821c8db17..22814cb820525809836226b2a455afd844d668cd 100644 (file)
@@ -121,7 +121,7 @@ Texture2D *Resources::create_texture2d(const string &name)
 
                if(is_mipmapped(default_tex_filter))
                {
-                       tex->set_generate_mipmap(true);
+                       tex->set_auto_generate_mipmap(true);
                        tex->set_mag_filter(LINEAR);
                }
                else
index 9d76e0626bff7818015bfbdc0b6e7d0b2244c2f0..f1689145c8af9c5754569213a7561b0505e63b2c 100644 (file)
@@ -7,6 +7,7 @@
 #include <msp/gl/extensions/sgis_generate_mipmap.h>
 #include <msp/io/memory.h>
 #include <msp/strings/format.h>
+#include "bindable.h"
 #include "error.h"
 #include "resourcemanager.h"
 #include "resources.h"
@@ -68,7 +69,7 @@ Texture::Texture(GLenum t, ResourceManager *m):
        wrap_s(REPEAT),
        wrap_t(REPEAT),
        wrap_r(REPEAT),
-       gen_mipmap(false),
+       auto_gen_mipmap(0),
        compare(false),
        cmp_func(LEQUAL),
        dirty_params(0)
@@ -157,7 +158,7 @@ void Texture::update_parameter(int mask) const
        if(mask&WRAP_R)
                set_parameter_i(GL_TEXTURE_WRAP_R, wrap_r);
        if(mask&GENERATE_MIPMAP)
-               set_parameter_i(GL_GENERATE_MIPMAP, gen_mipmap);
+               set_parameter_i(GL_GENERATE_MIPMAP, auto_gen_mipmap!=0);
        if(mask&COMPARE)
                set_parameter_i(GL_TEXTURE_COMPARE_MODE, (compare ? GL_COMPARE_R_TO_TEXTURE : GL_NONE));
        if(mask&COMPARE_FUNC)
@@ -266,24 +267,31 @@ bool Texture::can_generate_mipmap()
        return (EXT_framebuffer_object || SGIS_generate_mipmap);
 }
 
-void Texture::set_generate_mipmap(bool gm)
+void Texture::generate_mipmap()
 {
-       if(gm && !EXT_framebuffer_object)
-               static Require _req(SGIS_generate_mipmap);
-       gen_mipmap = gm;
-       if(!EXT_framebuffer_object)
-               update_parameter(GENERATE_MIPMAP);
+       // glGenerateMipmap is defined here
+       static Require _req(EXT_framebuffer_object);
+
+       if(ARB_direct_state_access)
+               glGenerateTextureMipmap(id);
+       else
+       {
+               BindRestore _bind(this);
+               glGenerateMipmap(target);
+       }
 }
 
-void Texture::auto_generate_mipmap()
+void Texture::set_auto_generate_mipmap(bool gm)
 {
-       // glGenerateMipmap is defined here
        if(EXT_framebuffer_object)
+               auto_gen_mipmap = gm;
+       else
        {
-               if(ARB_direct_state_access)
-                       glGenerateTextureMipmap(id);
-               else
-                       glGenerateMipmap(target);
+               if(gm)
+                       static Require _req(SGIS_generate_mipmap);
+
+               auto_gen_mipmap = gm*2;
+               update_parameter(GENERATE_MIPMAP);
        }
 }
 
@@ -437,7 +445,7 @@ void Texture::Loader::filter(TextureFilter f)
 
 void Texture::Loader::generate_mipmap(bool gm)
 {
-       obj.set_generate_mipmap(gm);
+       obj.set_auto_generate_mipmap(gm);
 }
 
 void Texture::Loader::image_data(const string &data)
index 94614c45c7319748c102456dcd6c1b3bb6119649..19da006937cf536aef73bc9ae43e0ba3bc3472b1 100644 (file)
@@ -128,7 +128,7 @@ protected:
        TextureWrap wrap_s;
        TextureWrap wrap_t;
        TextureWrap wrap_r;
-       bool gen_mipmap;
+       Msp::UInt8 auto_gen_mipmap;
        bool compare;
        Predicate cmp_func;
        mutable int dirty_params;
@@ -170,14 +170,15 @@ public:
 
        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_generate_mipmap(bool);
+       void set_auto_generate_mipmap(bool);
 
-protected:
-       void auto_generate_mipmap();
+       /// Deprecated.  Use set_auto_generate_mipmap instead.
+       void set_generate_mipmap(bool g) { set_auto_generate_mipmap(g); }
 
-public:
        /** Sets depth texture comparison.  Has no effect on other formats.  When
        comparison is enabled, the third component of the texture coordinate is
        compared against the texel value, and the result is returned as the texture
index e746409b8101dfca984017761e5a46998927edf8..39782efd8124d357e5bacdb88278309ea578d2b3 100644 (file)
@@ -74,9 +74,9 @@ void Texture1D::image(unsigned level, PixelFormat fmt, DataType type, const void
        glTexImage1D(target, level, ifmt, w, 0, get_upload_format(fmt), type, data);
 
        allocated |= 1<<level;
-       if(gen_mipmap && level==0)
+       if(auto_gen_mipmap==1 && level==0)
        {
-               auto_generate_mipmap();
+               generate_mipmap();
                allocated |= (1<<get_n_levels())-1;
        }
 }
@@ -95,8 +95,8 @@ void Texture1D::sub_image(unsigned level, int x, unsigned wd, PixelFormat fmt, D
        else
                glTexSubImage1D(target, level, x, wd, fmt, type, data);
 
-       if(gen_mipmap && level==0)
-               auto_generate_mipmap();
+       if(auto_gen_mipmap==1 && level==0)
+               generate_mipmap();
 }
 
 void Texture1D::image(const Graphics::Image &img, bool srgb)
index 806e4a179bded9f8a71264ecce78bccafc529870..94224147c70434b53bcb8ef9ea78328e9f81284b 100644 (file)
@@ -104,9 +104,9 @@ void Texture2D::image(unsigned level, PixelFormat fmt, DataType type, const void
        glTexImage2D(target, level, ifmt, w, h, 0, get_upload_format(fmt), type, data);
 
        allocated |= 1<<level;
-       if(gen_mipmap && level==0)
+       if(auto_gen_mipmap==1 && level==0)
        {
-               auto_generate_mipmap();
+               generate_mipmap();
                allocated |= (1<<get_n_levels())-1;
        }
 }
@@ -125,8 +125,8 @@ void Texture2D::sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht
        else
                glTexSubImage2D(target, level, x, y, wd, ht, fmt, type, data);
 
-       if(gen_mipmap && level==0)
-               auto_generate_mipmap();
+       if(auto_gen_mipmap==1 && level==0)
+               generate_mipmap();
 }
 
 void Texture2D::image(const Graphics::Image &img, bool srgb)
index 7c4b04469d23a0b17961543cf34ff9e21688977a..5b33c3c6e1ef9153b68a654586dc37c42b1da7d6 100644 (file)
@@ -93,9 +93,9 @@ void Texture3D::image(unsigned level, PixelFormat fmt, DataType type, const void
        glTexImage3D(target, level, ifmt, width, height, depth, 0, get_upload_format(fmt), type, data);
 
        allocated |= 1<<level;
-       if(gen_mipmap && level==0)
+       if(auto_gen_mipmap==1 && level==0)
        {
-               auto_generate_mipmap();
+               generate_mipmap();
                allocated |= (1<<get_n_levels())-1;
        }
 }
@@ -114,8 +114,8 @@ void Texture3D::sub_image(unsigned level, int x, int y, int z, unsigned wd, unsi
        else
                glTexSubImage3D(target, level, x, y, z, wd, ht, dp, fmt, type, data);
 
-       if(gen_mipmap && level==0)
-               auto_generate_mipmap();
+       if(auto_gen_mipmap==1 && level==0)
+               generate_mipmap();
 }
 
 void Texture3D::load_image(const string &fn, int dp)
index 8306324153747078300a9b593d392d78f91cd5a6..cd18c10d6909a2c459c4b2409789069900a67b88 100644 (file)
@@ -106,10 +106,10 @@ void TextureCube::image(TextureCubeFace face, unsigned level, PixelFormat fmt, D
 
        // XXX Allocation should be tracked per-face, but we'll run out of bits
        allocated |= 1<<level;
-       if(gen_mipmap && level==0)
+       if(auto_gen_mipmap==1 && level==0)
        {
                // TODO Only do this once all faces are created
-               auto_generate_mipmap();
+               generate_mipmap();
                allocated |= (1<<get_n_levels())-1;
        }
 }
@@ -124,8 +124,8 @@ void TextureCube::sub_image(TextureCubeFace face, unsigned level, int x, int y,
 
        glTexSubImage2D(face, level, x, y, wd, ht, get_upload_format(fmt), type, data);
 
-       if(gen_mipmap && level==0)
-               auto_generate_mipmap();
+       if(auto_gen_mipmap==1 && level==0)
+               generate_mipmap();
 }
 
 void TextureCube::image(TextureCubeFace face, const Graphics::Image &img, bool srgb)