diff --git a/include/blt/gfx/texture.h b/include/blt/gfx/texture.h index 376b1b8..bad6817 100644 --- a/include/blt/gfx/texture.h +++ b/include/blt/gfx/texture.h @@ -137,6 +137,13 @@ namespace blt::gfx glGenTextures(1, &textureID); } + protected: + void setDefaults() const; + + inline void generateMipmaps() const + { + glGenerateMipmap(textureBindType); + } public: inline void bind() const { @@ -148,16 +155,6 @@ namespace blt::gfx glBindTexture(textureBindType, 0); } - void setDefaults() const; - - inline void generateMipmaps() const - { - // it's a little inefficient binding and unbinding for these small calls, they really should be done in the constructor or data upload - bind(); - glGenerateMipmap(textureBindType); - unbind(); - } - [[nodiscard]] inline unsigned int getTextureID() const { return textureID; @@ -176,6 +173,7 @@ namespace blt::gfx texture_gl(width, height, GL_TEXTURE_2D, colorMode) { bind(); + setDefaults(); // TODO: const int MIPMAP_LEVELS = 4; glTexStorage2D( @@ -196,6 +194,7 @@ namespace blt::gfx textureBindType, level, x_offset, y_offset, sub_width, sub_height, dataColorMode, GL_UNSIGNED_BYTE, data ); + generateMipmaps(); unbind(); } @@ -226,6 +225,7 @@ namespace blt::gfx texture_gl(width, height, GL_TEXTURE_2D_ARRAY, colorMode), m_layers(layers) { bind(); + setDefaults(); // 6+ mipmaps is about where I stop noticing any difference (size is 4x4 pixels, so that makes sense) glTexStorage3D(textureBindType, 6, colorMode, width, height, layers); BLT_DEBUG("Creating 2D Texture Array with ID: %d", textureID); @@ -243,6 +243,7 @@ namespace blt::gfx textureBindType, level, x_offset, y_offset, index, sub_width, sub_height, 1, dataColorMode, GL_UNSIGNED_BYTE, data ); + generateMipmaps(); unbind(); } }; diff --git a/src/blt/gfx/texture.cpp b/src/blt/gfx/texture.cpp index 6d40526..1432fc2 100644 --- a/src/blt/gfx/texture.cpp +++ b/src/blt/gfx/texture.cpp @@ -70,7 +70,6 @@ blt::gfx::texture_file& blt::gfx::texture_file::resize(int target_width, int tar void blt::gfx::texture_gl::setDefaults() const { - bind(); glTexParameteri(textureBindType, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(textureBindType, GL_TEXTURE_WRAP_T, GL_REPEAT); // nearest preserves the pixely look @@ -82,5 +81,4 @@ void blt::gfx::texture_gl::setDefaults() const glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &a); glTexParameterf(textureBindType, GL_TEXTURE_MAX_ANISOTROPY_EXT, a); #endif - unbind(); }