From: Mikko Rasa Date: Mon, 8 Jul 2019 16:24:02 +0000 (+0300) Subject: Make explicit mipmap generation public X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=85c6c43eb0f937f31f4a91ef3731d8bb2e98c8b4;p=libs%2Fgl.git Make explicit mipmap generation public Also changed set_generate_mipmap to set_auto_generate_mipmap to clarify that it concerns automatic mipmap generation. --- diff --git a/source/resources.cpp b/source/resources.cpp index 03e10e2d..22814cb8 100644 --- a/source/resources.cpp +++ b/source/resources.cpp @@ -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 diff --git a/source/texture.cpp b/source/texture.cpp index 9d76e062..f1689145 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -7,6 +7,7 @@ #include #include #include +#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) diff --git a/source/texture.h b/source/texture.h index 94614c45..19da0069 100644 --- a/source/texture.h +++ b/source/texture.h @@ -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 diff --git a/source/texture1d.cpp b/source/texture1d.cpp index e746409b..39782efd 100644 --- a/source/texture1d.cpp +++ b/source/texture1d.cpp @@ -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<