diff --git a/src/Magnum/GL/AbstractTexture.cpp b/src/Magnum/GL/AbstractTexture.cpp index 9398de5c3..c5ffe5847 100644 --- a/src/Magnum/GL/AbstractTexture.cpp +++ b/src/Magnum/GL/AbstractTexture.cpp @@ -2099,7 +2099,10 @@ Vector2i AbstractTexture::DataHelper<2>::compressedBlockSize(const GLenum target 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}; + const Vector2i value = DataHelper<2>::compressedBlockSize(target, format); + /* If the 2D size is zero (e.g. when the format is uncompressed), return a + zero in 3D as well */ + return value == Vector2i{} ? Vector3i{} : Vector3i{value, 1}; } #endif diff --git a/src/Magnum/GL/Test/CubeMapTextureArrayGLTest.cpp b/src/Magnum/GL/Test/CubeMapTextureArrayGLTest.cpp index 8d4d0d1a1..d350fc324 100644 --- a/src/Magnum/GL/Test/CubeMapTextureArrayGLTest.cpp +++ b/src/Magnum/GL/Test/CubeMapTextureArrayGLTest.cpp @@ -46,6 +46,10 @@ namespace Magnum { namespace GL { namespace Test { namespace { struct CubeMapTextureArrayGLTest: OpenGLTester { explicit CubeMapTextureArrayGLTest(); + #ifndef MAGNUM_TARGET_GLES + void compressedBlockSize(); + #endif + void construct(); void constructMove(); void wrap(); @@ -273,29 +277,34 @@ const struct { }; CubeMapTextureArrayGLTest::CubeMapTextureArrayGLTest() { - addTests({&CubeMapTextureArrayGLTest::construct, - &CubeMapTextureArrayGLTest::constructMove, - &CubeMapTextureArrayGLTest::wrap, + addTests({ + #ifndef MAGNUM_TARGET_GLES + &CubeMapTextureArrayGLTest::compressedBlockSize, + #endif - &CubeMapTextureArrayGLTest::label, + &CubeMapTextureArrayGLTest::construct, + &CubeMapTextureArrayGLTest::constructMove, + &CubeMapTextureArrayGLTest::wrap, - &CubeMapTextureArrayGLTest::bind, - &CubeMapTextureArrayGLTest::bindImage, + &CubeMapTextureArrayGLTest::label, - &CubeMapTextureArrayGLTest::sampling, - &CubeMapTextureArrayGLTest::sampling, - &CubeMapTextureArrayGLTest::samplingSrgbDecode, - &CubeMapTextureArrayGLTest::samplingBorderInteger, - &CubeMapTextureArrayGLTest::samplingSwizzle, - &CubeMapTextureArrayGLTest::samplingDepthStencilMode, - #ifdef MAGNUM_TARGET_GLES - &CubeMapTextureArrayGLTest::samplingBorder, - #endif + &CubeMapTextureArrayGLTest::bind, + &CubeMapTextureArrayGLTest::bindImage, - &CubeMapTextureArrayGLTest::storage, + &CubeMapTextureArrayGLTest::sampling, + &CubeMapTextureArrayGLTest::sampling, + &CubeMapTextureArrayGLTest::samplingSrgbDecode, + &CubeMapTextureArrayGLTest::samplingBorderInteger, + &CubeMapTextureArrayGLTest::samplingSwizzle, + &CubeMapTextureArrayGLTest::samplingDepthStencilMode, + #ifdef MAGNUM_TARGET_GLES + &CubeMapTextureArrayGLTest::samplingBorder, + #endif - &CubeMapTextureArrayGLTest::view, - &CubeMapTextureArrayGLTest::viewOnNonArray}); + &CubeMapTextureArrayGLTest::storage, + + &CubeMapTextureArrayGLTest::view, + &CubeMapTextureArrayGLTest::viewOnNonArray}); addInstancedTests({ &CubeMapTextureArrayGLTest::image, @@ -341,6 +350,30 @@ CubeMapTextureArrayGLTest::CubeMapTextureArrayGLTest() { using namespace Containers::Literals; +#ifndef MAGNUM_TARGET_GLES +void CubeMapTextureArrayGLTest::compressedBlockSize() { + /* For uncompressed formats returns zero */ + CORRADE_COMPARE(CubeMapTextureArray::compressedBlockSize(TextureFormat::RGBA8), Vector2i{}); + CORRADE_COMPARE(CubeMapTextureArray::compressedBlockDataSize(TextureFormat::RGBA8), 0); + + MAGNUM_VERIFY_NO_GL_ERROR(); + + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::EXT::texture_compression_s3tc::string() << "is not supported."); + + { + /* Same happens with e.g. ASTC 10x10, where it reports 1 (?!) */ + CORRADE_EXPECT_FAIL_IF(Context::current().detectedDriver() & Context::DetectedDriver::Mesa, + "Mesa misreports compressed block size for certain formats."); + CORRADE_COMPARE(CubeMapTextureArray::compressedBlockSize(TextureFormat::CompressedRGBAS3tcDxt1), Vector2i{4}); + } + CORRADE_COMPARE(CubeMapTextureArray::compressedBlockSize(TextureFormat::CompressedRGBAS3tcDxt3), Vector2i{4}); + CORRADE_COMPARE(CubeMapTextureArray::compressedBlockDataSize(TextureFormat::CompressedRGBAS3tcDxt1), 8); + + MAGNUM_VERIFY_NO_GL_ERROR(); +} +#endif + void CubeMapTextureArrayGLTest::construct() { #ifndef MAGNUM_TARGET_GLES if(!Context::current().isExtensionSupported()) diff --git a/src/Magnum/GL/Test/CubeMapTextureGLTest.cpp b/src/Magnum/GL/Test/CubeMapTextureGLTest.cpp index 361ed38c9..89ba66d6c 100644 --- a/src/Magnum/GL/Test/CubeMapTextureGLTest.cpp +++ b/src/Magnum/GL/Test/CubeMapTextureGLTest.cpp @@ -56,6 +56,10 @@ namespace Magnum { namespace GL { namespace Test { namespace { struct CubeMapTextureGLTest: OpenGLTester { explicit CubeMapTextureGLTest(); + #ifndef MAGNUM_TARGET_GLES + void compressedBlockSize(); + #endif + void construct(); void constructMove(); void wrap(); @@ -326,47 +330,52 @@ const struct { #endif CubeMapTextureGLTest::CubeMapTextureGLTest() { - addTests({&CubeMapTextureGLTest::construct, - &CubeMapTextureGLTest::constructMove, - &CubeMapTextureGLTest::wrap, - - #ifndef MAGNUM_TARGET_WEBGL - &CubeMapTextureGLTest::label, - #endif - - &CubeMapTextureGLTest::bind, - #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) - &CubeMapTextureGLTest::bindImage, - #endif - - &CubeMapTextureGLTest::sampling, - &CubeMapTextureGLTest::sampling, - #ifndef MAGNUM_TARGET_WEBGL - &CubeMapTextureGLTest::samplingSrgbDecode, - #endif - #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) - &CubeMapTextureGLTest::samplingSwizzle, - #elif !defined(MAGNUM_TARGET_WEBGL) - &CubeMapTextureGLTest::samplingMaxLevel, - &CubeMapTextureGLTest::samplingCompare, - #endif - #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) - &CubeMapTextureGLTest::samplingBorderInteger, - #endif - #ifndef MAGNUM_TARGET_GLES2 - &CubeMapTextureGLTest::samplingDepthStencilMode, - #endif - #if defined(MAGNUM_TARGET_GLES) && !defined(MAGNUM_TARGET_WEBGL) - &CubeMapTextureGLTest::samplingBorder, - #endif - - &CubeMapTextureGLTest::storageImageSize, - - #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) - &CubeMapTextureGLTest::view, - &CubeMapTextureGLTest::viewOnArray - #endif - }); + addTests({ + #ifndef MAGNUM_TARGET_GLES + &CubeMapTextureGLTest::compressedBlockSize, + #endif + + &CubeMapTextureGLTest::construct, + &CubeMapTextureGLTest::constructMove, + &CubeMapTextureGLTest::wrap, + + #ifndef MAGNUM_TARGET_WEBGL + &CubeMapTextureGLTest::label, + #endif + + &CubeMapTextureGLTest::bind, + #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) + &CubeMapTextureGLTest::bindImage, + #endif + + &CubeMapTextureGLTest::sampling, + &CubeMapTextureGLTest::sampling, + #ifndef MAGNUM_TARGET_WEBGL + &CubeMapTextureGLTest::samplingSrgbDecode, + #endif + #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) + &CubeMapTextureGLTest::samplingSwizzle, + #elif !defined(MAGNUM_TARGET_WEBGL) + &CubeMapTextureGLTest::samplingMaxLevel, + &CubeMapTextureGLTest::samplingCompare, + #endif + #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) + &CubeMapTextureGLTest::samplingBorderInteger, + #endif + #ifndef MAGNUM_TARGET_GLES2 + &CubeMapTextureGLTest::samplingDepthStencilMode, + #endif + #if defined(MAGNUM_TARGET_GLES) && !defined(MAGNUM_TARGET_WEBGL) + &CubeMapTextureGLTest::samplingBorder, + #endif + + &CubeMapTextureGLTest::storageImageSize, + + #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) + &CubeMapTextureGLTest::view, + &CubeMapTextureGLTest::viewOnArray + #endif + }); addInstancedTests({ &CubeMapTextureGLTest::storage, @@ -476,6 +485,30 @@ template Containers::ArrayView unsafeSuffix( return {data - offset, size + offset}; } +#ifndef MAGNUM_TARGET_GLES +void CubeMapTextureGLTest::compressedBlockSize() { + /* For uncompressed formats returns zero */ + CORRADE_COMPARE(CubeMapTexture::compressedBlockSize(TextureFormat::RGBA8), Vector2i{}); + CORRADE_COMPARE(CubeMapTexture::compressedBlockDataSize(TextureFormat::RGBA8), 0); + + MAGNUM_VERIFY_NO_GL_ERROR(); + + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::EXT::texture_compression_s3tc::string() << "is not supported."); + + { + /* Same happens with e.g. ASTC 10x10, where it reports 1 (?!) */ + CORRADE_EXPECT_FAIL_IF(Context::current().detectedDriver() & Context::DetectedDriver::Mesa, + "Mesa misreports compressed block size for certain formats."); + CORRADE_COMPARE(CubeMapTexture::compressedBlockSize(TextureFormat::CompressedRGBAS3tcDxt1), Vector2i{4}); + } + CORRADE_COMPARE(CubeMapTexture::compressedBlockSize(TextureFormat::CompressedRGBAS3tcDxt3), Vector2i{4}); + CORRADE_COMPARE(CubeMapTexture::compressedBlockDataSize(TextureFormat::CompressedRGBAS3tcDxt1), 8); + + MAGNUM_VERIFY_NO_GL_ERROR(); +} +#endif + void CubeMapTextureGLTest::construct() { { CubeMapTexture texture; diff --git a/src/Magnum/GL/Test/RectangleTextureGLTest.cpp b/src/Magnum/GL/Test/RectangleTextureGLTest.cpp index 4460ebca2..6dae88c35 100644 --- a/src/Magnum/GL/Test/RectangleTextureGLTest.cpp +++ b/src/Magnum/GL/Test/RectangleTextureGLTest.cpp @@ -46,6 +46,8 @@ namespace Magnum { namespace GL { namespace Test { namespace { struct RectangleTextureGLTest: OpenGLTester { explicit RectangleTextureGLTest(); + void compressedBlockSize(); + void construct(); void constructMove(); void wrap(); @@ -121,7 +123,9 @@ const struct { }; RectangleTextureGLTest::RectangleTextureGLTest() { - addTests({&RectangleTextureGLTest::construct, + addTests({&RectangleTextureGLTest::compressedBlockSize, + + &RectangleTextureGLTest::construct, &RectangleTextureGLTest::constructMove, &RectangleTextureGLTest::wrap, @@ -167,6 +171,16 @@ RectangleTextureGLTest::RectangleTextureGLTest() { using namespace Containers::Literals; +void RectangleTextureGLTest::compressedBlockSize() { + /* For uncompressed formats returns zero */ + CORRADE_COMPARE(RectangleTexture::compressedBlockSize(TextureFormat::RGBA8), Vector2i{}); + CORRADE_COMPARE(RectangleTexture::compressedBlockDataSize(TextureFormat::RGBA8), 0); + + MAGNUM_VERIFY_NO_GL_ERROR(); + + CORRADE_SKIP("No rectangle texture compression format exists."); +} + void RectangleTextureGLTest::construct() { if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::ARB::texture_rectangle::string() << "is not supported."); diff --git a/src/Magnum/GL/Test/TextureArrayGLTest.cpp b/src/Magnum/GL/Test/TextureArrayGLTest.cpp index 26f1a34e3..2bbdb273e 100644 --- a/src/Magnum/GL/Test/TextureArrayGLTest.cpp +++ b/src/Magnum/GL/Test/TextureArrayGLTest.cpp @@ -54,6 +54,11 @@ namespace Magnum { namespace GL { namespace Test { namespace { struct TextureArrayGLTest: OpenGLTester { explicit TextureArrayGLTest(); + #ifndef MAGNUM_TARGET_GLES + void compressedBlockSize1D(); + void compressedBlockSize2D(); + #endif + #ifndef MAGNUM_TARGET_GLES void construct1D(); #endif @@ -294,6 +299,11 @@ const struct { TextureArrayGLTest::TextureArrayGLTest() { addTests({ + #ifndef MAGNUM_TARGET_GLES + &TextureArrayGLTest::compressedBlockSize1D, + &TextureArrayGLTest::compressedBlockSize2D, + #endif + #ifndef MAGNUM_TARGET_GLES &TextureArrayGLTest::construct1D, #endif @@ -451,6 +461,40 @@ TextureArrayGLTest::TextureArrayGLTest() { using namespace Containers::Literals; #endif +#ifndef MAGNUM_TARGET_GLES +void TextureArrayGLTest::compressedBlockSize1D() { + /* For uncompressed formats returns zero */ + CORRADE_COMPARE(Texture1DArray::compressedBlockSize(TextureFormat::RGBA8), 0); + CORRADE_COMPARE(Texture1DArray::compressedBlockDataSize(TextureFormat::RGBA8), 0); + + MAGNUM_VERIFY_NO_GL_ERROR(); + + CORRADE_SKIP("No 1D texture compression format exists."); +} + +void TextureArrayGLTest::compressedBlockSize2D() { + /* For uncompressed formats returns zero */ + CORRADE_COMPARE(Texture2DArray::compressedBlockSize(TextureFormat::RGBA8), Vector2i{}); + CORRADE_COMPARE(Texture2DArray::compressedBlockDataSize(TextureFormat::RGBA8), 0); + + MAGNUM_VERIFY_NO_GL_ERROR(); + + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::EXT::texture_compression_s3tc::string() << "is not supported."); + + { + /* Same happens with e.g. ASTC 10x10, where it reports 1 (?!) */ + CORRADE_EXPECT_FAIL_IF(Context::current().detectedDriver() & Context::DetectedDriver::Mesa, + "Mesa misreports compressed block size for certain formats."); + CORRADE_COMPARE(Texture2DArray::compressedBlockSize(TextureFormat::CompressedRGBAS3tcDxt1), Vector2i{4}); + } + CORRADE_COMPARE(Texture2DArray::compressedBlockSize(TextureFormat::CompressedRGBAS3tcDxt3), Vector2i{4}); + CORRADE_COMPARE(Texture2DArray::compressedBlockDataSize(TextureFormat::CompressedRGBAS3tcDxt1), 8); + + MAGNUM_VERIFY_NO_GL_ERROR(); +} +#endif + #ifndef MAGNUM_TARGET_GLES void TextureArrayGLTest::construct1D() { if(!Context::current().isExtensionSupported()) diff --git a/src/Magnum/GL/Test/TextureGLTest.cpp b/src/Magnum/GL/Test/TextureGLTest.cpp index 0179ae5e0..78c8f19b5 100644 --- a/src/Magnum/GL/Test/TextureGLTest.cpp +++ b/src/Magnum/GL/Test/TextureGLTest.cpp @@ -58,6 +58,12 @@ namespace Magnum { namespace GL { namespace Test { namespace { struct TextureGLTest: OpenGLTester { explicit TextureGLTest(); + #ifndef MAGNUM_TARGET_GLES + void compressedBlockSize1D(); + void compressedBlockSize2D(); + void compressedBlockSize3D(); + #endif + #ifndef MAGNUM_TARGET_GLES void construct1D(); #endif @@ -457,6 +463,12 @@ const struct { TextureGLTest::TextureGLTest() { addTests({ + #ifndef MAGNUM_TARGET_GLES + &TextureGLTest::compressedBlockSize1D, + &TextureGLTest::compressedBlockSize2D, + &TextureGLTest::compressedBlockSize3D, + #endif + #ifndef MAGNUM_TARGET_GLES &TextureGLTest::construct1D, #endif @@ -705,6 +717,56 @@ TextureGLTest::TextureGLTest() { using namespace Containers::Literals; #endif +#ifndef MAGNUM_TARGET_GLES +void TextureGLTest::compressedBlockSize1D() { + /* For uncompressed formats returns zero */ + CORRADE_COMPARE(Texture1D::compressedBlockSize(TextureFormat::RGBA8), 0); + CORRADE_COMPARE(Texture1D::compressedBlockDataSize(TextureFormat::RGBA8), 0); + + MAGNUM_VERIFY_NO_GL_ERROR(); + + CORRADE_SKIP("No 1D texture compression format exists."); +} + +void TextureGLTest::compressedBlockSize2D() { + /* For uncompressed formats returns zero */ + CORRADE_COMPARE(Texture2D::compressedBlockSize(TextureFormat::RGBA8), Vector2i{}); + CORRADE_COMPARE(Texture2D::compressedBlockDataSize(TextureFormat::RGBA8), 0); + + MAGNUM_VERIFY_NO_GL_ERROR(); + + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::EXT::texture_compression_s3tc::string() << "is not supported."); + + { + /* Same happens with e.g. ASTC 10x10, where it reports 1 (?!) */ + CORRADE_EXPECT_FAIL_IF(Context::current().detectedDriver() & Context::DetectedDriver::Mesa, + "Mesa misreports compressed block size for certain formats."); + CORRADE_COMPARE(Texture2D::compressedBlockSize(TextureFormat::CompressedRGBAS3tcDxt1), Vector2i{4}); + } + CORRADE_COMPARE(Texture2D::compressedBlockSize(TextureFormat::CompressedRGBAS3tcDxt3), Vector2i{4}); + CORRADE_COMPARE(Texture2D::compressedBlockDataSize(TextureFormat::CompressedRGBAS3tcDxt1), 8); + + MAGNUM_VERIFY_NO_GL_ERROR(); +} + +void TextureGLTest::compressedBlockSize3D() { + /* For uncompressed formats returns zero */ + CORRADE_COMPARE(Texture3D::compressedBlockSize(TextureFormat::RGBA8), Vector3i{}); + CORRADE_COMPARE(Texture3D::compressedBlockDataSize(TextureFormat::RGBA8), 0); + + MAGNUM_VERIFY_NO_GL_ERROR(); + + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::ARB::texture_compression_bptc::string() << "is not supported."); + + CORRADE_COMPARE(Texture3D::compressedBlockSize(TextureFormat::CompressedRGBABptcUnorm), (Vector3i{4, 4, 1})); + CORRADE_COMPARE(Texture3D::compressedBlockDataSize(TextureFormat::CompressedRGBABptcUnorm), 16); + + MAGNUM_VERIFY_NO_GL_ERROR(); +} +#endif + #ifndef MAGNUM_TARGET_GLES void TextureGLTest::construct1D() { {