From f5b167254004c1babd929fe4b290bfb191236808 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 12 Apr 2017 00:22:14 +0200 Subject: [PATCH] GL_TEXTURE_COMPRESSED_IMAGE_SIZE is *always* size of one cubemap face. For some reason I thought it's size of one face pre-ARB_DSA and size of all six faces on ARB_DSA. NVidia drivers (which return different size based on whether the texture is immutable, which is totally crazy) didn't help with that at all. Now I realized this while fixing test failures on Mesa. IIRC I couldn't find a clear explanation in the spec anyway, so I'll just bite the bullet and assume *this* is the correct way now. Mesa tests now pass instead of saying that my provided buffer size is too small. --- src/Magnum/CubeMapTexture.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/Magnum/CubeMapTexture.cpp b/src/Magnum/CubeMapTexture.cpp index 8091fc505..bf5b3ee9a 100644 --- a/src/Magnum/CubeMapTexture.cpp +++ b/src/Magnum/CubeMapTexture.cpp @@ -109,7 +109,7 @@ void CubeMapTexture::compressedImage(const Int level, CompressedImage3D& image) createIfNotAlready(); const Vector3i size{imageSize(level), 6}; - const GLint textureDataSize = (this->*Context::current().state().texture->getCubeLevelCompressedImageSizeImplementation)(level); + const GLint textureDataSize = (this->*Context::current().state().texture->getCubeLevelCompressedImageSizeImplementation)(level)*6; std::size_t dataOffset, dataSize; std::tie(dataOffset, dataSize) = Implementation::compressedImageDataOffsetSizeFor(image, size, textureDataSize); GLint format; @@ -135,7 +135,7 @@ void CubeMapTexture::compressedImage(const Int level, CompressedBufferImage3D& i createIfNotAlready(); const Vector3i size{imageSize(level), 6}; - const GLint textureDataSize = (this->*Context::current().state().texture->getCubeLevelCompressedImageSizeImplementation)(level); + const GLint textureDataSize = (this->*Context::current().state().texture->getCubeLevelCompressedImageSizeImplementation)(level)*6; std::size_t dataOffset, dataSize; std::tie(dataOffset, dataSize) = Implementation::compressedImageDataOffsetSizeFor(image, size, textureDataSize); GLint format; @@ -199,9 +199,7 @@ BufferImage2D CubeMapTexture::image(const CubeMapCoordinate coordinate, const In void CubeMapTexture::compressedImage(const CubeMapCoordinate coordinate, const Int level, CompressedImage2D& image) { const Vector2i size = imageSize(level); - /* The function returns size of all six faces, divide the result to get size - of one face */ - const GLint textureDataSize = (this->*Context::current().state().texture->getCubeLevelCompressedImageSizeImplementation)(level)/6; + const GLint textureDataSize = (this->*Context::current().state().texture->getCubeLevelCompressedImageSizeImplementation)(level); const std::size_t dataSize = Implementation::compressedImageDataSizeFor(image, size, textureDataSize); GLint format; (this->*Context::current().state().texture->getCubeLevelParameterivImplementation)(level, GL_TEXTURE_INTERNAL_FORMAT, &format); @@ -224,9 +222,7 @@ CompressedImage2D CubeMapTexture::compressedImage(const CubeMapCoordinate coordi void CubeMapTexture::compressedImage(const CubeMapCoordinate coordinate, const Int level, CompressedBufferImage2D& image, const BufferUsage usage) { const Vector2i size = imageSize(level); - /* The function returns size of all six faces, divide the result to get size - of one face */ - const GLint textureDataSize = (this->*Context::current().state().texture->getCubeLevelCompressedImageSizeImplementation)(level)/6; + const GLint textureDataSize = (this->*Context::current().state().texture->getCubeLevelCompressedImageSizeImplementation)(level); const std::size_t dataSize = Implementation::compressedImageDataSizeFor(image, size, textureDataSize); GLint format; (this->*Context::current().state().texture->getCubeLevelParameterivImplementation)(level, GL_TEXTURE_INTERNAL_FORMAT, &format); @@ -382,8 +378,7 @@ GLint CubeMapTexture::getLevelCompressedImageSizeImplementationDefault(const GLi GLint value; glGetTexLevelParameteriv(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &value); - /* Size of all six faces */ - return value*6; + return value; } GLint CubeMapTexture::getLevelCompressedImageSizeImplementationDefaultImmutableWorkaround(const GLint level) { @@ -405,7 +400,7 @@ GLint CubeMapTexture::getLevelCompressedImageSizeImplementationDSANonImmutableWo GLint immutable; glGetTextureParameteriv(_id, GL_TEXTURE_IMMUTABLE_LEVELS, &immutable); - return immutable ? value : value*6; + return immutable ? value/6 : value; } GLint CubeMapTexture::getLevelCompressedImageSizeImplementationDSAEXT(const GLint level) { @@ -415,8 +410,7 @@ GLint CubeMapTexture::getLevelCompressedImageSizeImplementationDSAEXT(const GLin GLint value; glGetTextureLevelParameterivEXT(_id, GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &value); - /* Size of all six faces */ - return value*6; + return value; } GLint CubeMapTexture::getLevelCompressedImageSizeImplementationDSAEXTImmutableWorkaround(const GLint level) {