From 56cdc71a52826d1ff2c52bec79be505696b04659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 1 Aug 2015 22:58:42 +0200 Subject: [PATCH] Compressed image support, part 14: queries for compressed block sizes. --- doc/opengl-support.dox | 2 +- src/Magnum/AbstractTexture.cpp | 28 +++++++++++++++++++++++++++ src/Magnum/AbstractTexture.h | 11 +++++++++++ src/Magnum/CubeMapTexture.h | 28 +++++++++++++++++++++++++++ src/Magnum/CubeMapTextureArray.h | 28 +++++++++++++++++++++++++++ src/Magnum/RectangleTexture.h | 22 +++++++++++++++++++++ src/Magnum/Texture.h | 33 ++++++++++++++++++++++++++++++++ src/Magnum/TextureArray.h | 28 +++++++++++++++++++++++++++ 8 files changed, 179 insertions(+), 1 deletion(-) diff --git a/doc/opengl-support.dox b/doc/opengl-support.dox index 94480a052..2a39b4ed4 100644 --- a/doc/opengl-support.dox +++ b/doc/opengl-support.dox @@ -179,7 +179,7 @@ GLSL 4.30 | done @extension{ARB,explicit_uniform_location} | done @extension{ARB,fragment_layer_viewport} | done (shading language only) @extension{ARB,framebuffer_no_attachments} | | -@extension{ARB,internalformat_query2} | | +@extension{ARB,internalformat_query2} | only compressed texture block queries @extension{ARB,invalidate_subdata} | done @extension{ARB,multi_draw_indirect} | | @extension{ARB,program_interface_query} | | diff --git a/src/Magnum/AbstractTexture.cpp b/src/Magnum/AbstractTexture.cpp index 8f0bad58a..d4fc418a5 100644 --- a/src/Magnum/AbstractTexture.cpp +++ b/src/Magnum/AbstractTexture.cpp @@ -197,6 +197,14 @@ void AbstractTexture::bindImplementationMulti(const GLint firstTextureUnit, Cont } #endif +#ifndef MAGNUM_TARGET_GLES +Int AbstractTexture::compressedBlockDataSize(const GLenum target, const TextureFormat format) { + GLint value; + glGetInternalformativ(target, GLenum(format), GL_TEXTURE_COMPRESSED_BLOCK_SIZE, 1, &value); + return value; +} +#endif + AbstractTexture::AbstractTexture(GLenum target): _target{target}, _flags{ObjectFlag::DeleteOnDestruction} { (this->*Context::current()->state().texture->createImplementation)(); CORRADE_INTERNAL_ASSERT(_id != Implementation::State::DisengagedBinding); @@ -1625,6 +1633,26 @@ template void MAGNUM_EXPORT AbstractTexture::subImage<3>(GLint, const Range3Di&, #endif #ifndef DOXYGEN_GENERATING_OUTPUT +#ifndef MAGNUM_TARGET_GLES +Math::Vector<1, GLint> AbstractTexture::DataHelper<1>::compressedBlockSize(const GLenum target, const TextureFormat format) { + GLint value; + glGetInternalformativ(target, GLenum(format), GL_TEXTURE_COMPRESSED_BLOCK_WIDTH, 1, &value); + return value; +} + +Vector2i AbstractTexture::DataHelper<2>::compressedBlockSize(const GLenum target, const TextureFormat format) { + Vector2i value{Math::NoInit}; + glGetInternalformativ(target, GLenum(format), GL_TEXTURE_COMPRESSED_BLOCK_WIDTH, 1, &value.x()); + glGetInternalformativ(target, GLenum(format), GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT, 1, &value.y()); + return value; +} + +Vector3i AbstractTexture::DataHelper<3>::compressedBlockSize(const GLenum target, const TextureFormat format) { + /** @todo use real value when OpenGL has proper queries for 3D compression formats */ + return Vector3i{DataHelper<2>::compressedBlockSize(target, format), 1}; +} +#endif + #ifndef MAGNUM_TARGET_GLES Math::Vector<1, GLint> AbstractTexture::DataHelper<1>::imageSize(AbstractTexture& texture, const GLint level) { Math::Vector<1, GLint> value; diff --git a/src/Magnum/AbstractTexture.h b/src/Magnum/AbstractTexture.h index defd3bc1a..2921da856 100644 --- a/src/Magnum/AbstractTexture.h +++ b/src/Magnum/AbstractTexture.h @@ -338,6 +338,10 @@ class MAGNUM_EXPORT AbstractTexture: public AbstractObject { #endif template struct DataHelper {}; + #ifndef MAGNUM_TARGET_GLES + static Int compressedBlockDataSize(GLenum target, TextureFormat format); + #endif + explicit AbstractTexture(GLenum target); explicit AbstractTexture(NoCreateT, GLenum target) noexcept: _target{target}, _id{0}, _flags{ObjectFlag::DeleteOnDestruction} {} explicit AbstractTexture(GLuint id, GLenum target, ObjectFlags flags) noexcept: _target{target}, _id{id}, _flags{flags} {} @@ -584,6 +588,7 @@ class MAGNUM_EXPORT AbstractTexture: public AbstractObject { #ifndef DOXYGEN_GENERATING_OUTPUT #ifndef MAGNUM_TARGET_GLES template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<1> { + static Math::Vector<1, GLint> compressedBlockSize(GLenum target, TextureFormat format); static Math::Vector<1, GLint> imageSize(AbstractTexture& texture, GLint level); static void setWrapping(AbstractTexture& texture, const Array1D& wrapping); @@ -604,6 +609,9 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<1> { }; #endif template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<2> { + #ifndef MAGNUM_TARGET_GLES + static Vector2i compressedBlockSize(GLenum target, TextureFormat format); + #endif #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) static Vector2i imageSize(AbstractTexture& texture, GLint level); #endif @@ -646,6 +654,9 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<2> { }; template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> { #if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) + #ifndef MAGNUM_TARGET_GLES + static Vector3i compressedBlockSize(GLenum target, TextureFormat format); + #endif #ifndef MAGNUM_TARGET_GLES2 static Vector3i imageSize(AbstractTexture& texture, GLint level); #endif diff --git a/src/Magnum/CubeMapTexture.h b/src/Magnum/CubeMapTexture.h index 98650ab4f..dda1c8861 100644 --- a/src/Magnum/CubeMapTexture.h +++ b/src/Magnum/CubeMapTexture.h @@ -102,6 +102,34 @@ class MAGNUM_EXPORT CubeMapTexture: public AbstractTexture { */ static Vector2i maxSize(); + #ifndef MAGNUM_TARGET_GLES + /** + * @copybrief Texture::compressedBlockSize() + * + * See @ref Texture::compressedBlockSize() for more information. + * @requires_gl43 Extension @extension{ARB,internalformat_query2} + * @requires_gl Compressed texture queries are not available in OpenGL + * ES. + */ + static Vector2i compressedBlockSize(TextureFormat format) { + return DataHelper<2>::compressedBlockSize(GL_TEXTURE_CUBE_MAP, format); + } + + /** + * @copybrief Texture::compressedBlockDataSize() + * + * See @ref Texture::compressedBlockDataSize() for more information. + * @requires_gl43 Extension @extension{ARB,internalformat_query2} + * @requires_gl Compressed texture queries are not available in OpenGL + * ES. + * @see @ref compressedBlockSize(), @fn_gl{Getinternalformat} with + * @def_gl{TEXTURE_COMPRESSED_BLOCK_SIZE} + */ + static Int compressedBlockDataSize(TextureFormat format) { + return AbstractTexture::compressedBlockDataSize(GL_TEXTURE_CUBE_MAP, format); + } + #endif + /** * @brief Wrap existing OpenGL cube map texture object * @param id OpenGL cube map texture ID diff --git a/src/Magnum/CubeMapTextureArray.h b/src/Magnum/CubeMapTextureArray.h index 059c05add..fc9f8f9ce 100644 --- a/src/Magnum/CubeMapTextureArray.h +++ b/src/Magnum/CubeMapTextureArray.h @@ -98,6 +98,34 @@ class MAGNUM_EXPORT CubeMapTextureArray: public AbstractTexture { */ static Vector3i maxSize(); + #ifndef MAGNUM_TARGET_GLES + /** + * @copybrief Texture::compressedBlockSize() + * + * See @ref Texture::compressedBlockSize() for more information. + * @requires_gl43 Extension @extension{ARB,internalformat_query2} + * @requires_gl Compressed texture queries are not available in OpenGL + * ES. + */ + static Vector2i compressedBlockSize(TextureFormat format) { + return DataHelper<2>::compressedBlockSize(GL_TEXTURE_CUBE_MAP_ARRAY, format); + } + + /** + * @copybrief Texture::compressedBlockDataSize() + * + * See @ref Texture::compressedBlockDataSize() for more information. + * @requires_gl43 Extension @extension{ARB,internalformat_query2} + * @requires_gl Compressed texture queries are not available in OpenGL + * ES. + * @see @ref compressedBlockSize(), @fn_gl{Getinternalformat} with + * @def_gl{TEXTURE_COMPRESSED_BLOCK_SIZE} + */ + static Int compressedBlockDataSize(TextureFormat format) { + return AbstractTexture::compressedBlockDataSize(GL_TEXTURE_CUBE_MAP_ARRAY, format); + } + #endif + /** * @brief Wrap existing OpenGL cube map array texture object * @param id OpenGL cube map array texture ID diff --git a/src/Magnum/RectangleTexture.h b/src/Magnum/RectangleTexture.h index 0962c9e7a..186af3f70 100644 --- a/src/Magnum/RectangleTexture.h +++ b/src/Magnum/RectangleTexture.h @@ -80,6 +80,28 @@ class MAGNUM_EXPORT RectangleTexture: public AbstractTexture { */ static Vector2i maxSize(); + /** + * @copybrief Texture::compressedBlockSize() + * + * See @ref Texture::compressedBlockSize() for more information. + * @requires_gl43 Extension @extension{ARB,internalformat_query2} + */ + static Vector2i compressedBlockSize(TextureFormat format) { + return DataHelper<2>::compressedBlockSize(GL_TEXTURE_RECTANGLE, format); + } + + /** + * @copybrief Texture::compressedBlockDataSize() + * + * See @ref Texture::compressedBlockDataSize() for more information. + * @requires_gl43 Extension @extension{ARB,internalformat_query2} + * @see @ref compressedBlockSize(), @fn_gl{Getinternalformat} with + * @def_gl{TEXTURE_COMPRESSED_BLOCK_SIZE} + */ + static Int compressedBlockDataSize(TextureFormat format) { + return AbstractTexture::compressedBlockDataSize(GL_TEXTURE_RECTANGLE, format); + } + /** * @brief Wrap existing OpenGL rectangle texture object * @param id OpenGL rectangle texture ID diff --git a/src/Magnum/Texture.h b/src/Magnum/Texture.h index 8bfa7e9bc..288b0189a 100644 --- a/src/Magnum/Texture.h +++ b/src/Magnum/Texture.h @@ -123,6 +123,39 @@ template class Texture: public AbstractTexture { return Implementation::maxTextureSize(); } + #ifndef MAGNUM_TARGET_GLES + /** + * @brief Compressed block size + * + * If @p format is compressed, returns compressed block size (in + * pixels). For uncompressed formats returns zero vector. + * @see @ref compressedBlockDataSize(), @fn_gl{Getinternalformat} with + * @def_gl{TEXTURE_COMPRESSED_BLOCK_WIDTH}, + * @def_gl{TEXTURE_COMPRESSED_BLOCK_HEIGHT} + * @requires_gl43 Extension @extension{ARB,internalformat_query2} + * @requires_gl Compressed texture queries are not available in OpenGL + * ES. + */ + static VectorTypeFor compressedBlockSize(TextureFormat format) { + return DataHelper::compressedBlockSize(Implementation::textureTarget(), format); + } + + /** + * @brief Compressed block data size + * + * If @p format is compressed, returns compressed block data size (in + * bytes). For uncompressed formats returns zero. + * @see @ref compressedBlockSize(), @fn_gl{Getinternalformat} with + * @def_gl{TEXTURE_COMPRESSED_BLOCK_SIZE} + * @requires_gl43 Extension @extension{ARB,internalformat_query2} + * @requires_gl Compressed texture queries are not available in OpenGL + * ES. + */ + static Int compressedBlockDataSize(TextureFormat format) { + return AbstractTexture::compressedBlockDataSize(Implementation::textureTarget(), format); + } + #endif + /** * @brief Wrap existing OpenGL texture object * @param id OpenGL texture ID diff --git a/src/Magnum/TextureArray.h b/src/Magnum/TextureArray.h index e87cba8ec..a61370ed4 100644 --- a/src/Magnum/TextureArray.h +++ b/src/Magnum/TextureArray.h @@ -111,6 +111,34 @@ template class TextureArray: public AbstractTexture { */ static VectorTypeFor maxSize(); + #ifndef MAGNUM_TARGET_GLES + /** + * @copybrief Texture::compressedBlockSize() + * + * See @ref Texture::compressedBlockSize() for more information. + * @requires_gl43 Extension @extension{ARB,internalformat_query2} + * @requires_gl Compressed texture queries are not available in OpenGL + * ES. + */ + static VectorTypeFor compressedBlockSize(TextureFormat format) { + return DataHelper::compressedBlockSize(Implementation::textureArrayTarget(), format); + } + + /** + * @copybrief Texture::compressedBlockDataSize() + * + * See @ref Texture::compressedBlockDataSize() for more information. + * @requires_gl43 Extension @extension{ARB,internalformat_query2} + * @requires_gl Compressed texture queries are not available in OpenGL + * ES. + * @see @ref compressedBlockSize(), @fn_gl{Getinternalformat} with + * @def_gl{TEXTURE_COMPRESSED_BLOCK_SIZE} + */ + static Int compressedBlockDataSize(TextureFormat format) { + return AbstractTexture::compressedBlockDataSize(Implementation::textureArrayTarget(), format); + } + #endif + /** * @brief Wrap existing OpenGL texture array object * @param id OpenGL texture array ID