Browse Source

GL: add missing tests for texture format compressed block size queries.

And of course, besides the already-existing workaround for NV where it
reports size in bits instead of bytes, Mesa reports completely broken
pixel sizes in some cases. For DX1 I get 2x2 (?!), for ASTC 10x10 I get
1x1, which is basically unfixable.

I wonder how at all these utilities were used internally with success for
so long. Or were they never used because in every case I ended up
supplying the properties manually?
pull/651/merge
Vladimír Vondruš 1 year ago
parent
commit
134b8bd8b2
  1. 5
      src/Magnum/GL/AbstractTexture.cpp
  2. 69
      src/Magnum/GL/Test/CubeMapTextureArrayGLTest.cpp
  3. 115
      src/Magnum/GL/Test/CubeMapTextureGLTest.cpp
  4. 16
      src/Magnum/GL/Test/RectangleTextureGLTest.cpp
  5. 44
      src/Magnum/GL/Test/TextureArrayGLTest.cpp
  6. 62
      src/Magnum/GL/Test/TextureGLTest.cpp

5
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

69
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<GenericSampler>,
&CubeMapTextureArrayGLTest::sampling<GLSampler>,
&CubeMapTextureArrayGLTest::samplingSrgbDecode,
&CubeMapTextureArrayGLTest::samplingBorderInteger,
&CubeMapTextureArrayGLTest::samplingSwizzle,
&CubeMapTextureArrayGLTest::samplingDepthStencilMode,
#ifdef MAGNUM_TARGET_GLES
&CubeMapTextureArrayGLTest::samplingBorder,
#endif
&CubeMapTextureArrayGLTest::bind,
&CubeMapTextureArrayGLTest::bindImage,
&CubeMapTextureArrayGLTest::storage,
&CubeMapTextureArrayGLTest::sampling<GenericSampler>,
&CubeMapTextureArrayGLTest::sampling<GLSampler>,
&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<Extensions::EXT::texture_compression_s3tc>())
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<Extensions::ARB::texture_cube_map_array>())

115
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<GenericSampler>,
&CubeMapTextureGLTest::sampling<GLSampler>,
#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<GenericSampler>,
&CubeMapTextureGLTest::sampling<GLSampler>,
#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<std::size_t size, class T> Containers::ArrayView<const T> 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<Extensions::EXT::texture_compression_s3tc>())
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;

16
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<Extensions::ARB::texture_rectangle>())
CORRADE_SKIP(Extensions::ARB::texture_rectangle::string() << "is not supported.");

44
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<Extensions::EXT::texture_compression_s3tc>())
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<Extensions::EXT::texture_array>())

62
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<Extensions::EXT::texture_compression_s3tc>())
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<Extensions::ARB::texture_compression_bptc>())
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() {
{

Loading…
Cancel
Save