diff --git a/src/Magnum/Test/CubeMapTextureArrayGLTest.cpp b/src/Magnum/Test/CubeMapTextureArrayGLTest.cpp index 1b17bc93f..b4958758a 100644 --- a/src/Magnum/Test/CubeMapTextureArrayGLTest.cpp +++ b/src/Magnum/Test/CubeMapTextureArrayGLTest.cpp @@ -60,17 +60,20 @@ struct CubeMapTextureArrayGLTest: OpenGLTester { void storage(); void image(); - void compressedImage(); void imageBuffer(); - void compressedImageBuffer(); void subImage(); - void compressedSubImage(); void subImageBuffer(); - void compressedSubImageBuffer(); #ifndef MAGNUM_TARGET_GLES void subImageQuery(); - void compressedSubImageQuery(); void subImageQueryBuffer(); + #endif + + void compressedImage(); + void compressedImageBuffer(); + void compressedSubImage(); + void compressedSubImageBuffer(); + #ifndef MAGNUM_TARGET_GLES + void compressedSubImageQuery(); void compressedSubImageQueryBuffer(); #endif @@ -78,14 +81,188 @@ struct CubeMapTextureArrayGLTest: OpenGLTester { void invalidateImage(); void invalidateSubImage(); - -private: - #ifndef MAGNUM_TARGET_GLES - CompressedPixelStorage _compressedDataStorage, _compressedSubDataStorage; - #endif - std::size_t _compressedDataOffset, _compressedSubDataOffset; }; +namespace { + constexpr UnsignedByte Data[]{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, + + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x16, 0x47, + 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x1e, 0x4f, + + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, + 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f + }; + + enum: std::size_t { PixelStorageDataCount = 2 }; + + const struct { + const char* name; + Containers::ArrayView data; + PixelStorage storage; + Containers::ArrayView dataSparse; + std::size_t offset; + } PixelStorageData[PixelStorageDataCount]{ + {"default pixel storage", + Containers::arrayView(Data).suffix(16), {}, + Containers::arrayView(Data).suffix(16), 0}, + {"skip Z", + Containers::arrayView(Data).suffix(16), PixelStorage{}.setSkip({0, 0, 1}), + Data, 16} + }; + + /* Just 4x4 0x00 - 0x3f compressed using RGBA DXT3 by the driver, repeated + six times */ + constexpr UnsignedByte CompressedData[]{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + + 0, 17, 17, 34, 34, 51, 51, 67, + 232, 57, 0, 0, 213, 255, 170, 2, + 0, 17, 17, 34, 34, 51, 51, 67, + 232, 57, 0, 0, 213, 255, 170, 2, + 0, 17, 17, 34, 34, 51, 51, 67, + 232, 57, 0, 0, 213, 255, 170, 2, + + 0, 17, 17, 34, 34, 51, 51, 67, + 232, 57, 0, 0, 213, 255, 170, 2, + 0, 17, 17, 34, 34, 51, 51, 67, + 232, 57, 0, 0, 213, 255, 170, 2, + 0, 17, 17, 34, 34, 51, 51, 67, + 232, 57, 0, 0, 213, 255, 170, 2 + }; + + enum: std::size_t { CompressedPixelStorageDataCount = + #ifndef MAGNUM_TARGET_GLES + 2 + #else + 1 + #endif + }; + + const struct { + const char* name; + Containers::ArrayView data; + #ifndef MAGNUM_TARGET_GLES + CompressedPixelStorage storage; + #endif + Containers::ArrayView dataSparse; + std::size_t offset; + } CompressedPixelStorageData[CompressedPixelStorageDataCount]{ + {"default pixel storage", + Containers::arrayView(CompressedData).suffix(16*4), + #ifndef MAGNUM_TARGET_GLES + {}, + #endif + Containers::arrayView(CompressedData).suffix(16*4), 0}, + #ifndef MAGNUM_TARGET_GLES + {"skip Z", + Containers::arrayView(CompressedData).suffix(16*4), + CompressedPixelStorage{} + .setCompressedBlockSize({4, 4, 1}) + .setCompressedBlockDataSize(16) + .setSkip({0, 0, 4}), + CompressedData, 16*4} + #endif + }; + + constexpr UnsignedByte SubData[]{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f + }; + + enum: std::size_t { SubPixelStorageDataCount = 2 }; + + const struct { + const char* name; + Containers::ArrayView data; + PixelStorage storage; + Containers::ArrayView dataSparse; + std::size_t offset; + } SubPixelStorageData[SubPixelStorageDataCount]{ + {"default pixel storage", + Containers::arrayView(SubData).suffix(16), {}, + Containers::arrayView(SubData).suffix(16), 0}, + {"skip Z", + Containers::arrayView(SubData).suffix(16), PixelStorage{}.setSkip({0, 0, 1}), + SubData, 16} + }; + + /* Just 4x4x4 0x00 - 0xff compressed using RGBA DXT3 by the driver */ + constexpr UnsignedByte CompressedSubData[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + + 0, 17, 17, 34, 34, 51, 51, 67, + 232, 57, 0, 0, 213, 255, 170, 2, + 68, 84, 85, 101, 102, 118, 119, 119, + 239, 123, 8, 66, 213, 255, 170, 2, + 136, 136, 153, 153, 170, 170, 187, 187, + 247, 189, 16, 132, 213, 255, 170, 2, + 203, 204, 220, 221, 237, 238, 254, 255, + 255, 255, 24, 190, 213, 255, 170, 2 + }; + + enum: std::size_t { CompressedSubPixelStorageDataCount = + #ifndef MAGNUM_TARGET_GLES + 2 + #else + 1 + #endif + }; + + const struct { + const char* name; + Containers::ArrayView data; + #ifndef MAGNUM_TARGET_GLES + CompressedPixelStorage storage; + #endif + Containers::ArrayView dataSparse; + std::size_t offset; + } CompressedSubPixelStorageData[CompressedSubPixelStorageDataCount]{ + {"default pixel storage", + Containers::arrayView(CompressedSubData).suffix(16*4), + #ifndef MAGNUM_TARGET_GLES + {}, + #endif + Containers::arrayView(CompressedSubData).suffix(16*4), 0}, + #ifndef MAGNUM_TARGET_GLES + {"skip Z", + Containers::arrayView(CompressedSubData).suffix(16*4), + CompressedPixelStorage{} + .setCompressedBlockSize({4, 4, 1}) + .setCompressedBlockDataSize(16) + .setSkip({0, 0, 4}), + CompressedSubData, 16*4} + #endif + }; +} + CubeMapTextureArrayGLTest::CubeMapTextureArrayGLTest() { addTests({&CubeMapTextureArrayGLTest::construct, &CubeMapTextureArrayGLTest::wrap, @@ -102,51 +279,34 @@ CubeMapTextureArrayGLTest::CubeMapTextureArrayGLTest() { &CubeMapTextureArrayGLTest::samplingBorder, #endif - &CubeMapTextureArrayGLTest::storage, - - &CubeMapTextureArrayGLTest::image, - &CubeMapTextureArrayGLTest::compressedImage, - &CubeMapTextureArrayGLTest::imageBuffer, - &CubeMapTextureArrayGLTest::compressedImageBuffer, - &CubeMapTextureArrayGLTest::subImage, - &CubeMapTextureArrayGLTest::compressedSubImage, - &CubeMapTextureArrayGLTest::subImageBuffer, - &CubeMapTextureArrayGLTest::compressedSubImageBuffer, - #ifndef MAGNUM_TARGET_GLES - &CubeMapTextureArrayGLTest::subImageQuery, - &CubeMapTextureArrayGLTest::compressedSubImageQuery, - &CubeMapTextureArrayGLTest::subImageQueryBuffer, - &CubeMapTextureArrayGLTest::compressedSubImageQueryBuffer, - #endif - - &CubeMapTextureArrayGLTest::generateMipmap, + &CubeMapTextureArrayGLTest::storage}); - &CubeMapTextureArrayGLTest::invalidateImage, - &CubeMapTextureArrayGLTest::invalidateSubImage}); + addInstancedTests({ + &CubeMapTextureArrayGLTest::image, + &CubeMapTextureArrayGLTest::imageBuffer, + &CubeMapTextureArrayGLTest::subImage, + &CubeMapTextureArrayGLTest::subImageBuffer, + #ifndef MAGNUM_TARGET_GLES + &CubeMapTextureArrayGLTest::subImageQuery, + &CubeMapTextureArrayGLTest::subImageQueryBuffer + #endif + }, PixelStorageDataCount); - #ifndef MAGNUM_TARGET_GLES - if(Context::current().isExtensionSupported()) - { - _compressedDataStorage = _compressedSubDataStorage = CompressedPixelStorage{} - .setCompressedBlockSize({4, 4, 1}) - .setCompressedBlockDataSize(16) - .setSkip({0, 0, 4}); - _compressedDataOffset = _compressedSubDataOffset = 16*4; - } else - #endif - { + addInstancedTests({ + &CubeMapTextureArrayGLTest::compressedImage, + &CubeMapTextureArrayGLTest::compressedImageBuffer, + &CubeMapTextureArrayGLTest::compressedSubImage, + &CubeMapTextureArrayGLTest::compressedSubImageBuffer, #ifndef MAGNUM_TARGET_GLES - _compressedDataStorage = _compressedSubDataStorage = {}; + &CubeMapTextureArrayGLTest::compressedSubImageQuery, + &CubeMapTextureArrayGLTest::compressedSubImageQueryBuffer, #endif - _compressedDataOffset = _compressedSubDataOffset = 0; - } -} + }, CompressedPixelStorageDataCount); -namespace { - template Containers::ArrayView unsafeSuffix(const T(&data)[size], std::size_t offset) { - static_assert(sizeof(T) == 1, ""); - return {data - offset, size + offset}; - } + addTests({&CubeMapTextureArrayGLTest::generateMipmap, + + &CubeMapTextureArrayGLTest::invalidateImage, + &CubeMapTextureArrayGLTest::invalidateSubImage}); } void CubeMapTextureArrayGLTest::construct() { @@ -400,50 +560,9 @@ void CubeMapTextureArrayGLTest::storage() { MAGNUM_VERIFY_NO_ERROR(); } -namespace { - constexpr UnsignedByte Data[] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, - - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x16, 0x47, - 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x1e, 0x4f, - - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, - 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f - }; - - const auto DataStorage = PixelStorage{}.setSkip({0, 0, 1}); - const auto DataOffset = 16; - - /* Just 4x4 0x00 - 0x3f compressed using RGBA DXT3 by the driver, repeated - six times */ - constexpr UnsignedByte CompressedData[] = { - 0, 17, 17, 34, 34, 51, 51, 67, - 232, 57, 0, 0, 213, 255, 170, 2, - 0, 17, 17, 34, 34, 51, 51, 67, - 232, 57, 0, 0, 213, 255, 170, 2, - 0, 17, 17, 34, 34, 51, 51, 67, - 232, 57, 0, 0, 213, 255, 170, 2, - - 0, 17, 17, 34, 34, 51, 51, 67, - 232, 57, 0, 0, 213, 255, 170, 2, - 0, 17, 17, 34, 34, 51, 51, 67, - 232, 57, 0, 0, 213, 255, 170, 2, - 0, 17, 17, 34, 34, 51, 51, 67, - 232, 57, 0, 0, 213, 255, 170, 2 - }; -} - void CubeMapTextureArrayGLTest::image() { + setTestCaseDescription(PixelStorageData[testCaseInstanceId()].name); + #ifndef MAGNUM_TARGET_GLES if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::texture_cube_map_array::string() + std::string(" is not supported.")); @@ -453,24 +572,29 @@ void CubeMapTextureArrayGLTest::image() { #endif CubeMapTextureArray texture; - texture.setImage(0, TextureFormat::RGBA8, - ImageView3D{DataStorage, PixelFormat::RGBA, PixelType::UnsignedByte, {2, 2, 6}, unsafeSuffix(Data, DataOffset)}); + texture.setImage(0, TextureFormat::RGBA8, ImageView3D{ + PixelStorageData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, {2, 2, 6}, + PixelStorageData[testCaseInstanceId()].dataSparse}); MAGNUM_VERIFY_NO_ERROR(); /** @todo How to test this on ES? */ #ifndef MAGNUM_TARGET_GLES - Image3D image = texture.image(0, {DataStorage, PixelFormat::RGBA, PixelType::UnsignedByte}); + Image3D image = texture.image(0, {PixelStorageData[testCaseInstanceId()].storage, PixelFormat::RGBA, PixelType::UnsignedByte}); MAGNUM_VERIFY_NO_ERROR(); CORRADE_COMPARE(image.size(), Vector3i(2, 2, 6)); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(DataOffset), - Containers::arrayView(Data), TestSuite::Compare::Container); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(PixelStorageData[testCaseInstanceId()].offset), + PixelStorageData[testCaseInstanceId()].data, + TestSuite::Compare::Container); #endif } -void CubeMapTextureArrayGLTest::compressedImage() { +void CubeMapTextureArrayGLTest::imageBuffer() { + setTestCaseDescription(PixelStorageData[testCaseInstanceId()].name); + #ifndef MAGNUM_TARGET_GLES if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::texture_cube_map_array::string() + std::string(" is not supported.")); @@ -478,30 +602,34 @@ void CubeMapTextureArrayGLTest::compressedImage() { if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::EXT::texture_cube_map_array::string() + std::string(" is not supported.")); #endif - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); CubeMapTextureArray texture; - texture.setCompressedImage(0, CompressedImageView3D{ - #ifndef MAGNUM_TARGET_GLES - _compressedDataStorage, - #endif - CompressedPixelFormat::RGBAS3tcDxt3, {4, 4, 6}, unsafeSuffix(CompressedData, _compressedDataOffset)}); + texture.setImage(0, TextureFormat::RGBA8, BufferImage3D{ + PixelStorageData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, {2, 2, 6}, + PixelStorageData[testCaseInstanceId()].dataSparse, + BufferUsage::StaticDraw}); MAGNUM_VERIFY_NO_ERROR(); + /** @todo How to test this on ES? */ #ifndef MAGNUM_TARGET_GLES - CompressedImage3D image = texture.compressedImage(0, {_compressedDataStorage}); + BufferImage3D image = texture.image(0, {PixelStorageData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); + const auto imageData = image.buffer().data(); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), (Vector3i{4, 4, 6})); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(_compressedDataOffset), - Containers::arrayView(CompressedData), TestSuite::Compare::Container); + CORRADE_COMPARE(image.size(), Vector3i(2, 2, 6)); + CORRADE_COMPARE_AS(imageData.suffix(PixelStorageData[testCaseInstanceId()].offset), + PixelStorageData[testCaseInstanceId()].data, + TestSuite::Compare::Container); #endif } -void CubeMapTextureArrayGLTest::imageBuffer() { +void CubeMapTextureArrayGLTest::compressedImage() { + setTestCaseDescription(CompressedPixelStorageData[testCaseInstanceId()].name); + #ifndef MAGNUM_TARGET_GLES if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::texture_cube_map_array::string() + std::string(" is not supported.")); @@ -509,27 +637,39 @@ void CubeMapTextureArrayGLTest::imageBuffer() { if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::EXT::texture_cube_map_array::string() + std::string(" is not supported.")); #endif + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); + + #ifndef MAGNUM_TARGET_GLES + if(CompressedPixelStorageData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); + #endif CubeMapTextureArray texture; - texture.setImage(0, TextureFormat::RGBA8, BufferImage3D{DataStorage, - PixelFormat::RGBA, PixelType::UnsignedByte, {2, 2, 6}, unsafeSuffix(Data, DataOffset), BufferUsage::StaticDraw}); + texture.setCompressedImage(0, CompressedImageView3D{ + #ifndef MAGNUM_TARGET_GLES + CompressedPixelStorageData[testCaseInstanceId()].storage, + #endif + CompressedPixelFormat::RGBAS3tcDxt3, {4, 4, 6}, + CompressedPixelStorageData[testCaseInstanceId()].dataSparse}); MAGNUM_VERIFY_NO_ERROR(); - /** @todo How to test this on ES? */ #ifndef MAGNUM_TARGET_GLES - BufferImage3D image = texture.image(0, {DataStorage, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); - const auto imageData = image.buffer().data(); + CompressedImage3D image = texture.compressedImage(0, {CompressedPixelStorageData[testCaseInstanceId()].storage}); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), Vector3i(2, 2, 6)); - CORRADE_COMPARE_AS(imageData.suffix(DataOffset), Containers::arrayView(Data), + CORRADE_COMPARE(image.size(), (Vector3i{4, 4, 6})); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(CompressedPixelStorageData[testCaseInstanceId()].offset), + CompressedPixelStorageData[testCaseInstanceId()].data, TestSuite::Compare::Container); #endif } void CubeMapTextureArrayGLTest::compressedImageBuffer() { + setTestCaseDescription(CompressedPixelStorageData[testCaseInstanceId()].name); + #ifndef MAGNUM_TARGET_GLES if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::texture_cube_map_array::string() + std::string(" is not supported.")); @@ -540,64 +680,39 @@ void CubeMapTextureArrayGLTest::compressedImageBuffer() { if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); + #ifndef MAGNUM_TARGET_GLES + if(CompressedPixelStorageData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); + #endif + CubeMapTextureArray texture; texture.setCompressedImage(0, CompressedBufferImage3D{ #ifndef MAGNUM_TARGET_GLES - _compressedDataStorage, + CompressedPixelStorageData[testCaseInstanceId()].storage, #endif - CompressedPixelFormat::RGBAS3tcDxt3, {4, 4, 6}, unsafeSuffix(CompressedData, _compressedDataOffset), BufferUsage::StaticDraw}); + CompressedPixelFormat::RGBAS3tcDxt3, {4, 4, 6}, + CompressedPixelStorageData[testCaseInstanceId()].dataSparse, + BufferUsage::StaticDraw}); MAGNUM_VERIFY_NO_ERROR(); /** @todo How to test this on ES? */ #ifndef MAGNUM_TARGET_GLES - CompressedBufferImage3D image = texture.compressedImage(0, {_compressedDataStorage}, BufferUsage::StaticRead); + CompressedBufferImage3D image = texture.compressedImage(0, {CompressedPixelStorageData[testCaseInstanceId()].storage}, BufferUsage::StaticRead); const auto imageData = image.buffer().data(); MAGNUM_VERIFY_NO_ERROR(); CORRADE_COMPARE(image.size(), (Vector3i{4, 4, 6})); - CORRADE_COMPARE_AS(imageData.suffix(_compressedDataOffset), - Containers::arrayView(CompressedData), TestSuite::Compare::Container); + CORRADE_COMPARE_AS(imageData.suffix(CompressedPixelStorageData[testCaseInstanceId()].offset), + CompressedPixelStorageData[testCaseInstanceId()].data, + TestSuite::Compare::Container); #endif } namespace { - constexpr UnsignedByte Zero[4*4*4*6] = {}; - - /* Just 12x12x6 zeros compressed using RGBA DXT3 by the driver */ - constexpr UnsignedByte CompressedZero[9*16*6] = {}; - - constexpr UnsignedByte SubData[] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, - - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f - }; - - const auto SubDataStorage = PixelStorage{}.setSkip({0, 0, 1}); - const std::size_t SubDataOffset = 16; - - /* Just 4x4x4 0x00 - 0xff compressed using RGBA DXT3 by the driver */ - constexpr UnsignedByte CompressedSubData[] = { - 0, 17, 17, 34, 34, 51, 51, 67, - 232, 57, 0, 0, 213, 255, 170, 2, - 68, 84, 85, 101, 102, 118, 119, 119, - 239, 123, 8, 66, 213, 255, 170, 2, - 136, 136, 153, 153, 170, 170, 187, 187, - 247, 189, 16, 132, 213, 255, 170, 2, - 203, 204, 220, 221, 237, 238, 254, 255, - 255, 255, 24, 190, 213, 255, 170, 2 - }; - - constexpr UnsignedByte SubDataComplete[] = { + constexpr UnsignedByte Zero[4*4*4*6]{}; + constexpr UnsignedByte SubDataComplete[]{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -628,6 +743,134 @@ namespace { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +} + +void CubeMapTextureArrayGLTest::subImage() { + setTestCaseDescription(SubPixelStorageData[testCaseInstanceId()].name); + + #ifndef MAGNUM_TARGET_GLES + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::texture_cube_map_array::string() + std::string(" is not supported.")); + #else + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::EXT::texture_cube_map_array::string() + std::string(" is not supported.")); + #endif + + CubeMapTextureArray texture; + texture.setImage(0, TextureFormat::RGBA8, + ImageView3D(PixelFormat::RGBA, PixelType::UnsignedByte, {4, 4, 6}, Zero)); + texture.setSubImage(0, Vector3i(1), ImageView3D{ + SubPixelStorageData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, {2, 2, 4}, + SubPixelStorageData[testCaseInstanceId()].dataSparse}); + + MAGNUM_VERIFY_NO_ERROR(); + + /** @todo How to test this on ES? */ + #ifndef MAGNUM_TARGET_GLES + Image3D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte}); + + MAGNUM_VERIFY_NO_ERROR(); + + CORRADE_COMPARE(image.size(), Vector3i(4, 4, 6)); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()), + Containers::arrayView(SubDataComplete), TestSuite::Compare::Container); + #endif +} + +void CubeMapTextureArrayGLTest::subImageBuffer() { + setTestCaseDescription(SubPixelStorageData[testCaseInstanceId()].name); + + #ifndef MAGNUM_TARGET_GLES + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::texture_cube_map_array::string() + std::string(" is not supported.")); + #else + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::EXT::texture_cube_map_array::string() + std::string(" is not supported.")); + #endif + + CubeMapTextureArray texture; + texture.setImage(0, TextureFormat::RGBA8, + ImageView3D(PixelFormat::RGBA, PixelType::UnsignedByte, {4, 4, 6}, Zero)); + texture.setSubImage(0, Vector3i(1), BufferImage3D{ + SubPixelStorageData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, {2, 2, 4}, + SubPixelStorageData[testCaseInstanceId()].dataSparse, + BufferUsage::StaticDraw}); + + MAGNUM_VERIFY_NO_ERROR(); + + /** @todo How to test this on ES? */ + #ifndef MAGNUM_TARGET_GLES + BufferImage3D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); + const auto imageData = image.buffer().data(); + + MAGNUM_VERIFY_NO_ERROR(); + + CORRADE_COMPARE(image.size(), Vector3i(4, 4, 6)); + CORRADE_COMPARE_AS(imageData, Containers::arrayView(SubDataComplete), + TestSuite::Compare::Container); + #endif +} + +#ifndef MAGNUM_TARGET_GLES +void CubeMapTextureArrayGLTest::subImageQuery() { + setTestCaseDescription(SubPixelStorageData[testCaseInstanceId()].name); + + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::texture_cube_map_array::string() + std::string(" is not supported.")); + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); + + CubeMapTextureArray texture; + texture.setStorage(1, TextureFormat::RGBA8, {4, 4, 6}) + .setSubImage(0, {}, ImageView3D{PixelFormat::RGBA, PixelType::UnsignedByte, {4, 4, 6}, SubDataComplete}); + + MAGNUM_VERIFY_NO_ERROR(); + + Image3D image = texture.subImage(0, Range3Di::fromSize(Vector3i{1}, {2, 2, 4}), + {SubPixelStorageData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte}); + + MAGNUM_VERIFY_NO_ERROR(); + + CORRADE_COMPARE(image.size(), Vector3i(2, 2, 4)); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(SubPixelStorageData[testCaseInstanceId()].offset), + SubPixelStorageData[testCaseInstanceId()].data, + TestSuite::Compare::Container); +} + +void CubeMapTextureArrayGLTest::subImageQueryBuffer() { + setTestCaseDescription(SubPixelStorageData[testCaseInstanceId()].name); + + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::texture_cube_map_array::string() + std::string(" is not supported.")); + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); + + CubeMapTextureArray texture; + texture.setStorage(1, TextureFormat::RGBA8, {4, 4, 6}) + .setSubImage(0, {}, ImageView3D{PixelFormat::RGBA, PixelType::UnsignedByte, {4, 4, 6}, SubDataComplete}); + + MAGNUM_VERIFY_NO_ERROR(); + + BufferImage3D image = texture.subImage(0, Range3Di::fromSize(Vector3i{1}, {2, 2, 4}), + {SubPixelStorageData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); + const auto imageData = image.buffer().data(); + + MAGNUM_VERIFY_NO_ERROR(); + + CORRADE_COMPARE(image.size(), Vector3i(2, 2, 4)); + CORRADE_COMPARE_AS(imageData.suffix(SubPixelStorageData[testCaseInstanceId()].offset), + SubPixelStorageData[testCaseInstanceId()].data, + TestSuite::Compare::Container); +} +#endif + +namespace { + /* Just 12x12x6 zeros compressed using RGBA DXT3 by the driver */ + constexpr UnsignedByte CompressedZero[9*16*6]{}; /* Combination of CompressedZero and CompressedSubData */ constexpr UnsignedByte CompressedSubDataComplete[] = { @@ -691,36 +934,9 @@ namespace { }; } -void CubeMapTextureArrayGLTest::subImage() { - #ifndef MAGNUM_TARGET_GLES - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::ARB::texture_cube_map_array::string() + std::string(" is not supported.")); - #else - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::EXT::texture_cube_map_array::string() + std::string(" is not supported.")); - #endif - - CubeMapTextureArray texture; - texture.setImage(0, TextureFormat::RGBA8, - ImageView3D(PixelFormat::RGBA, PixelType::UnsignedByte, {4, 4, 6}, Zero)); - texture.setSubImage(0, Vector3i(1), ImageView3D{SubDataStorage, - PixelFormat::RGBA, PixelType::UnsignedByte, {2, 2, 4}, unsafeSuffix(SubData, SubDataOffset)}); - - MAGNUM_VERIFY_NO_ERROR(); - - /** @todo How to test this on ES? */ - #ifndef MAGNUM_TARGET_GLES - Image3D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte}); - - MAGNUM_VERIFY_NO_ERROR(); - - CORRADE_COMPARE(image.size(), Vector3i(4, 4, 6)); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()), - Containers::arrayView(SubDataComplete), TestSuite::Compare::Container); - #endif -} - void CubeMapTextureArrayGLTest::compressedSubImage() { + setTestCaseDescription(CompressedSubPixelStorageData[testCaseInstanceId()].name); + #ifndef MAGNUM_TARGET_GLES if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::texture_cube_map_array::string() + std::string(" is not supported.")); @@ -732,26 +948,8 @@ void CubeMapTextureArrayGLTest::compressedSubImage() { CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); #ifndef MAGNUM_TARGET_GLES - /* Compressed pixel storage for array textures is underspecified. If the - extension is supported, first test with default values to ensure we are - not that far off, then continue as usual */ - if(Context::current().isExtensionSupported()) { - CubeMapTextureArray texture; - texture.setCompressedImage(0, CompressedImageView3D{CompressedPixelFormat::RGBAS3tcDxt3, - {12, 12, 6}, CompressedZero}); - texture.setCompressedSubImage(0, {4, 4, 1}, CompressedImageView3D{CompressedPixelFormat::RGBAS3tcDxt3, Vector3i{4}, CompressedSubData}); - - MAGNUM_VERIFY_NO_ERROR(); - - CompressedImage3D image = texture.compressedImage(0, {}); - - MAGNUM_VERIFY_NO_ERROR(); - - CORRADE_COMPARE(image.size(), (Vector3i{12, 12, 6})); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()), - Containers::arrayView(CompressedSubDataComplete), - TestSuite::Compare::Container); - } + if(CompressedPixelStorageData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); #endif CubeMapTextureArray texture; @@ -759,9 +957,10 @@ void CubeMapTextureArrayGLTest::compressedSubImage() { {12, 12, 6}, CompressedZero}); texture.setCompressedSubImage(0, {4, 4, 1}, CompressedImageView3D{ #ifndef MAGNUM_TARGET_GLES - _compressedSubDataStorage, + CompressedSubPixelStorageData[testCaseInstanceId()].storage, #endif - CompressedPixelFormat::RGBAS3tcDxt3, Vector3i{4}, unsafeSuffix(CompressedSubData, _compressedSubDataOffset)}); + CompressedPixelFormat::RGBAS3tcDxt3, Vector3i{4}, + CompressedSubPixelStorageData[testCaseInstanceId()].dataSparse}); MAGNUM_VERIFY_NO_ERROR(); @@ -773,7 +972,7 @@ void CubeMapTextureArrayGLTest::compressedSubImage() { CORRADE_COMPARE(image.size(), (Vector3i{12, 12, 6})); { - CORRADE_EXPECT_FAIL_IF(Context::current().isExtensionSupported() && (Context::current().detectedDriver() & Context::DetectedDriver::NVidia), + CORRADE_EXPECT_FAIL_IF(CompressedPixelStorageData[testCaseInstanceId()].storage != CompressedPixelStorage{} && (Context::current().detectedDriver() & Context::DetectedDriver::NVidia), "Non-default compressed pixel storage for cube map textures behaves weirdly on NVidia for client-memory images"); CORRADE_COMPARE_AS(Containers::arrayCast(image.data()), @@ -783,37 +982,9 @@ void CubeMapTextureArrayGLTest::compressedSubImage() { #endif } -void CubeMapTextureArrayGLTest::subImageBuffer() { - #ifndef MAGNUM_TARGET_GLES - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::ARB::texture_cube_map_array::string() + std::string(" is not supported.")); - #else - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::EXT::texture_cube_map_array::string() + std::string(" is not supported.")); - #endif - - CubeMapTextureArray texture; - texture.setImage(0, TextureFormat::RGBA8, - ImageView3D(PixelFormat::RGBA, PixelType::UnsignedByte, {4, 4, 6}, Zero)); - texture.setSubImage(0, Vector3i(1), BufferImage3D{SubDataStorage, - PixelFormat::RGBA, PixelType::UnsignedByte, {2, 2, 4}, unsafeSuffix(SubData, SubDataOffset), BufferUsage::StaticDraw}); - - MAGNUM_VERIFY_NO_ERROR(); - - /** @todo How to test this on ES? */ - #ifndef MAGNUM_TARGET_GLES - BufferImage3D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); - const auto imageData = image.buffer().data(); - - MAGNUM_VERIFY_NO_ERROR(); - - CORRADE_COMPARE(image.size(), Vector3i(4, 4, 6)); - CORRADE_COMPARE_AS(imageData, Containers::arrayView(SubDataComplete), - TestSuite::Compare::Container); - #endif -} - void CubeMapTextureArrayGLTest::compressedSubImageBuffer() { + setTestCaseDescription(CompressedSubPixelStorageData[testCaseInstanceId()].name); + #ifndef MAGNUM_TARGET_GLES if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::texture_cube_map_array::string() + std::string(" is not supported.")); @@ -824,14 +995,21 @@ void CubeMapTextureArrayGLTest::compressedSubImageBuffer() { if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); + #ifndef MAGNUM_TARGET_GLES + if(CompressedPixelStorageData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); + #endif + CubeMapTextureArray texture; texture.setCompressedImage(0, CompressedImageView3D{CompressedPixelFormat::RGBAS3tcDxt3, {12, 12, 6}, CompressedZero}); texture.setCompressedSubImage(0, {4, 4, 1}, CompressedBufferImage3D{ #ifndef MAGNUM_TARGET_GLES - _compressedSubDataStorage, + CompressedSubPixelStorageData[testCaseInstanceId()].storage, #endif - CompressedPixelFormat::RGBAS3tcDxt3, Vector3i{4}, unsafeSuffix(CompressedSubData, _compressedSubDataOffset), BufferUsage::StaticDraw}); + CompressedPixelFormat::RGBAS3tcDxt3, Vector3i{4}, + CompressedSubPixelStorageData[testCaseInstanceId()].dataSparse, + BufferUsage::StaticDraw}); MAGNUM_VERIFY_NO_ERROR(); @@ -849,35 +1027,19 @@ void CubeMapTextureArrayGLTest::compressedSubImageBuffer() { } #ifndef MAGNUM_TARGET_GLES -void CubeMapTextureArrayGLTest::subImageQuery() { - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::ARB::texture_cube_map_array::string() + std::string(" is not supported.")); - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); - - CubeMapTextureArray texture; - texture.setStorage(1, TextureFormat::RGBA8, {4, 4, 6}) - .setSubImage(0, {}, ImageView3D{PixelFormat::RGBA, PixelType::UnsignedByte, {4, 4, 6}, SubDataComplete}); - - MAGNUM_VERIFY_NO_ERROR(); - - Image3D image = texture.subImage(0, Range3Di::fromSize(Vector3i{1}, {2, 2, 4}), - {SubDataStorage, PixelFormat::RGBA, PixelType::UnsignedByte}); - - MAGNUM_VERIFY_NO_ERROR(); - - CORRADE_COMPARE(image.size(), Vector3i(2, 2, 4)); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(SubDataOffset), - Containers::arrayView(SubData), TestSuite::Compare::Container); -} - void CubeMapTextureArrayGLTest::compressedSubImageQuery() { + setTestCaseDescription(CompressedSubPixelStorageData[testCaseInstanceId()].name); + if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::texture_cube_map_array::string() + std::string(" is not supported.")); + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::internalformat_query2::string() + std::string(" is not supported.")); if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); + if(CompressedPixelStorageData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); CubeMapTextureArray texture; texture.setStorage(1, TextureFormat::CompressedRGBAS3tcDxt3, {12, 12, 6}) @@ -885,59 +1047,29 @@ void CubeMapTextureArrayGLTest::compressedSubImageQuery() { MAGNUM_VERIFY_NO_ERROR(); - /* Test also without compressed pixel storage to ensure that both size - computations work */ - if(Context::current().isExtensionSupported()) { - CompressedImage3D image = texture.compressedSubImage(0, Range3Di::fromSize({4, 4, 1}, Vector3i{4}), {}); - - MAGNUM_VERIFY_NO_ERROR(); - - CORRADE_COMPARE(image.size(), Vector3i{4}); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()), - Containers::arrayView(CompressedSubData), - TestSuite::Compare::Container); - } - - CompressedImage3D image = texture.compressedSubImage(0, Range3Di::fromSize({4, 4, 1}, Vector3i{4}), {_compressedSubDataStorage}); + CompressedImage3D image = texture.compressedSubImage(0, Range3Di::fromSize({4, 4, 1}, Vector3i{4}), {CompressedSubPixelStorageData[testCaseInstanceId()].storage}); MAGNUM_VERIFY_NO_ERROR(); CORRADE_COMPARE(image.size(), Vector3i{4}); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(_compressedSubDataOffset), - Containers::arrayView(CompressedSubData), + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(CompressedSubPixelStorageData[testCaseInstanceId()].offset), + CompressedSubPixelStorageData[testCaseInstanceId()].data, TestSuite::Compare::Container); } -void CubeMapTextureArrayGLTest::subImageQueryBuffer() { - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::ARB::texture_cube_map_array::string() + std::string(" is not supported.")); - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); - - CubeMapTextureArray texture; - texture.setStorage(1, TextureFormat::RGBA8, {4, 4, 6}) - .setSubImage(0, {}, ImageView3D{PixelFormat::RGBA, PixelType::UnsignedByte, {4, 4, 6}, SubDataComplete}); - - MAGNUM_VERIFY_NO_ERROR(); - - BufferImage3D image = texture.subImage(0, Range3Di::fromSize(Vector3i{1}, {2, 2, 4}), - {SubDataStorage, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); - const auto imageData = image.buffer().data(); - - MAGNUM_VERIFY_NO_ERROR(); - - CORRADE_COMPARE(image.size(), Vector3i(2, 2, 4)); - CORRADE_COMPARE_AS(imageData.suffix(SubDataOffset), - Containers::arrayView(SubData), TestSuite::Compare::Container); -} - void CubeMapTextureArrayGLTest::compressedSubImageQueryBuffer() { + setTestCaseDescription(CompressedSubPixelStorageData[testCaseInstanceId()].name); + if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::texture_cube_map_array::string() + std::string(" is not supported.")); + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::internalformat_query2::string() + std::string(" is not supported.")); if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); + if(CompressedPixelStorageData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); CubeMapTextureArray texture; texture.setStorage(1, TextureFormat::CompressedRGBAS3tcDxt3, {12, 12, 6}) @@ -945,27 +1077,14 @@ void CubeMapTextureArrayGLTest::compressedSubImageQueryBuffer() { MAGNUM_VERIFY_NO_ERROR(); - /* Test also without compressed pixel storage to ensure that both size - computations work */ - if(Context::current().isExtensionSupported()) { - CompressedBufferImage3D image = texture.compressedSubImage(0, Range3Di::fromSize({4, 4, 1}, Vector3i{4}), {}, BufferUsage::StaticRead); - const auto imageData = image.buffer().data(); - - MAGNUM_VERIFY_NO_ERROR(); - - CORRADE_COMPARE(image.size(), Vector3i{4}); - CORRADE_COMPARE_AS(imageData, Containers::arrayView(CompressedSubData), - TestSuite::Compare::Container); - } - - CompressedBufferImage3D image = texture.compressedSubImage(0, Range3Di::fromSize({4, 4, 1}, Vector3i{4}), {_compressedSubDataStorage}, BufferUsage::StaticRead); + CompressedBufferImage3D image = texture.compressedSubImage(0, Range3Di::fromSize({4, 4, 1}, Vector3i{4}), {CompressedSubPixelStorageData[testCaseInstanceId()].storage}, BufferUsage::StaticRead); const auto imageData = image.buffer().data(); MAGNUM_VERIFY_NO_ERROR(); CORRADE_COMPARE(image.size(), Vector3i{4}); - CORRADE_COMPARE_AS(imageData.suffix(_compressedSubDataOffset), - Containers::arrayView(CompressedSubData), + CORRADE_COMPARE_AS(imageData.suffix(CompressedSubPixelStorageData[testCaseInstanceId()].offset), + CompressedSubPixelStorageData[testCaseInstanceId()].data, TestSuite::Compare::Container); } #endif diff --git a/src/Magnum/Test/CubeMapTextureGLTest.cpp b/src/Magnum/Test/CubeMapTextureGLTest.cpp index b1ee025c7..b6d019029 100644 --- a/src/Magnum/Test/CubeMapTextureGLTest.cpp +++ b/src/Magnum/Test/CubeMapTextureGLTest.cpp @@ -75,46 +75,208 @@ struct CubeMapTextureGLTest: OpenGLTester { void storage(); void image(); - void compressedImage(); #ifndef MAGNUM_TARGET_GLES2 void imageBuffer(); - void compressedImageBuffer(); #endif - void immutableCompressedImage(); + void subImage(); + #ifndef MAGNUM_TARGET_GLES2 + void subImageBuffer(); + #endif #ifndef MAGNUM_TARGET_GLES - void fullImageQuery(); - void compressedFullImageQuery(); - void fullImageQueryBuffer(); - void compressedFullImageQueryBuffer(); + void subImageQuery(); + void subImageQueryBuffer(); #endif - void subImage(); + void compressedImage(); + #ifndef MAGNUM_TARGET_GLES2 + void compressedImageBuffer(); + #endif + void immutableCompressedImage(); void compressedSubImage(); #ifndef MAGNUM_TARGET_GLES2 - void subImageBuffer(); void compressedSubImageBuffer(); #endif #ifndef MAGNUM_TARGET_GLES - void subImageQuery(); void compressedSubImageQuery(); - void subImageQueryBuffer(); void compressedSubImageQueryBuffer(); #endif + #ifndef MAGNUM_TARGET_GLES + void fullImageQuery(); + void fullImageQueryBuffer(); + + void compressedFullImageQuery(); + void compressedFullImageQueryBuffer(); + #endif + void generateMipmap(); void invalidateImage(); void invalidateSubImage(); +}; + +namespace { + constexpr UnsignedByte Data[]{ + 0, 0, 0, 0, 0, 0, 0, 0, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; + + enum: std::size_t { PixelStorageDataCount = 2 }; + + const struct { + const char* name; + Containers::ArrayView data; + PixelStorage storage; + Containers::ArrayView dataSparse; + std::size_t offset; + } PixelStorageData[PixelStorageDataCount]{ + {"default pixel storage", + Containers::arrayView(Data).suffix(8), {}, + Containers::arrayView(Data).suffix(8), 0}, + #if !defined(MAGNUM_TARGET_GLES2) || !defined(MAGNUM_TARGET_WEBGL) + {"skip Y", + Containers::arrayView(Data).suffix(8), PixelStorage{}.setSkip({0, 1, 0}), + Data, 8} + #endif + }; + + /* Just 4x4 0x00 - 0x3f compressed using RGBA DXT3 by the driver */ + constexpr UnsignedByte CompressedData[]{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 17, 17, 34, 34, 51, 51, 67, + 232, 57, 0, 0, 213, 255, 170, 2 + }; -private: - PixelStorage _dataStorage; - std::size_t _dataOffset; + enum: std::size_t { CompressedPixelStorageDataCount = + #ifndef MAGNUM_TARGET_GLES + 2 + #else + 1 + #endif + }; + + const struct { + const char* name; + Containers::ArrayView data; + #ifndef MAGNUM_TARGET_GLES + CompressedPixelStorage storage; + #endif + Containers::ArrayView dataSparse; + std::size_t offset; + } CompressedPixelStorageData[CompressedPixelStorageDataCount]{ + {"default pixel storage", + Containers::arrayView(CompressedData).suffix(16), + #ifndef MAGNUM_TARGET_GLES + {}, + #endif + Containers::arrayView(CompressedData).suffix(16), 0}, + #ifndef MAGNUM_TARGET_GLES + {"skip Y", + Containers::arrayView(CompressedData).suffix(16), + CompressedPixelStorage{} + .setCompressedBlockSize({4, 4, 1}) + .setCompressedBlockDataSize(16) + .setSkip({0, 4, 0}), + CompressedData, 16} + #endif + }; #ifndef MAGNUM_TARGET_GLES - CompressedPixelStorage _compressedDataStorage, _compressedFullDataStorage; + constexpr UnsignedByte FullData[]{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, + + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, + 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, + + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, + 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f + }; + + enum: std::size_t { FullPixelStorageDataCount = 2 }; + + const struct { + const char* name; + Containers::ArrayView data; + PixelStorage storage; + std::size_t offset; + } FullPixelStorageData[FullPixelStorageDataCount]{ + {"default pixel storage", + Containers::arrayView(FullData).suffix(16), {}, 0}, + #if !defined(MAGNUM_TARGET_GLES2) || !defined(MAGNUM_TARGET_WEBGL) + {"skip Z", + Containers::arrayView(FullData).suffix(16), PixelStorage{}.setSkip({0, 0, 1}), 16} + #endif + }; + + /* Just 4x4 0x00 - 0x3f compressed using RGBA DXT3 by the driver, repeated + six times */ + constexpr UnsignedByte CompressedFullData[]{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + + 0, 17, 17, 34, 34, 51, 51, 67, + 232, 57, 0, 0, 213, 255, 170, 2, + 0, 17, 17, 34, 34, 51, 51, 67, + 232, 57, 0, 0, 213, 255, 170, 2, + 0, 17, 17, 34, 34, 51, 51, 67, + 232, 57, 0, 0, 213, 255, 170, 2, + + 0, 17, 17, 34, 34, 51, 51, 67, + 232, 57, 0, 0, 213, 255, 170, 2, + 0, 17, 17, 34, 34, 51, 51, 67, + 232, 57, 0, 0, 213, 255, 170, 2, + 0, 17, 17, 34, 34, 51, 51, 67, + 232, 57, 0, 0, 213, 255, 170, 2 + }; + + enum: std::size_t { CompressedFullPixelStorageDataCount = + #ifndef MAGNUM_TARGET_GLES + 2 + #else + 1 + #endif + }; + + const struct { + const char* name; + Containers::ArrayView data; + #ifndef MAGNUM_TARGET_GLES + CompressedPixelStorage storage; + #endif + std::size_t offset; + } CompressedFullPixelStorageData[CompressedFullPixelStorageDataCount]{ + {"default pixel storage", + Containers::arrayView(CompressedFullData).suffix(16*4), + #ifndef MAGNUM_TARGET_GLES + {}, + #endif + 0}, + #ifndef MAGNUM_TARGET_GLES + {"skip Z", + Containers::arrayView(CompressedFullData).suffix(16*4), + CompressedPixelStorage{} + .setCompressedBlockSize({4, 4, 1}) + .setCompressedBlockDataSize(16) + .setSkip({0, 0, 4}), 16*4} + #endif + }; #endif - std::size_t _compressedDataOffset, _compressedFullDataOffset; -}; + +} CubeMapTextureGLTest::CubeMapTextureGLTest() { addTests({&CubeMapTextureGLTest::construct, @@ -143,74 +305,51 @@ CubeMapTextureGLTest::CubeMapTextureGLTest() { &CubeMapTextureGLTest::samplingBorder, #endif - &CubeMapTextureGLTest::storage, + &CubeMapTextureGLTest::storage}); - &CubeMapTextureGLTest::image, - &CubeMapTextureGLTest::compressedImage, - #ifndef MAGNUM_TARGET_GLES2 - &CubeMapTextureGLTest::imageBuffer, - &CubeMapTextureGLTest::compressedImageBuffer, - #endif - &CubeMapTextureGLTest::immutableCompressedImage, - #ifndef MAGNUM_TARGET_GLES - &CubeMapTextureGLTest::fullImageQuery, - &CubeMapTextureGLTest::compressedFullImageQuery, - &CubeMapTextureGLTest::fullImageQueryBuffer, - &CubeMapTextureGLTest::compressedFullImageQueryBuffer, - #endif + addInstancedTests({ + &CubeMapTextureGLTest::image, + #ifndef MAGNUM_TARGET_GLES2 + &CubeMapTextureGLTest::imageBuffer, + #endif + #ifndef MAGNUM_TARGET_GLES + &CubeMapTextureGLTest::fullImageQuery, + &CubeMapTextureGLTest::fullImageQueryBuffer, + #endif + &CubeMapTextureGLTest::subImage, + #ifndef MAGNUM_TARGET_GLES2 + &CubeMapTextureGLTest::subImageBuffer, + #endif + #ifndef MAGNUM_TARGET_GLES + &CubeMapTextureGLTest::subImageQuery, + &CubeMapTextureGLTest::subImageQueryBuffer + #endif + }, PixelStorageDataCount); - &CubeMapTextureGLTest::subImage, - &CubeMapTextureGLTest::compressedSubImage, - #ifndef MAGNUM_TARGET_GLES2 - &CubeMapTextureGLTest::subImageBuffer, - &CubeMapTextureGLTest::compressedSubImageBuffer, - #endif - #ifndef MAGNUM_TARGET_GLES - &CubeMapTextureGLTest::subImageQuery, - &CubeMapTextureGLTest::compressedSubImageQuery, - &CubeMapTextureGLTest::subImageQueryBuffer, - &CubeMapTextureGLTest::compressedSubImageQueryBuffer, - #endif + addInstancedTests({ + &CubeMapTextureGLTest::compressedImage, + #ifndef MAGNUM_TARGET_GLES2 + &CubeMapTextureGLTest::compressedImageBuffer, + #endif + &CubeMapTextureGLTest::immutableCompressedImage, + #ifndef MAGNUM_TARGET_GLES + &CubeMapTextureGLTest::compressedFullImageQuery, + &CubeMapTextureGLTest::compressedFullImageQueryBuffer, + #endif + &CubeMapTextureGLTest::compressedSubImage, + #ifndef MAGNUM_TARGET_GLES2 + &CubeMapTextureGLTest::compressedSubImageBuffer, + #endif + #ifndef MAGNUM_TARGET_GLES + &CubeMapTextureGLTest::compressedSubImageQuery, + &CubeMapTextureGLTest::compressedSubImageQueryBuffer + #endif + }, CompressedPixelStorageDataCount); - &CubeMapTextureGLTest::generateMipmap, + addTests({&CubeMapTextureGLTest::generateMipmap, &CubeMapTextureGLTest::invalidateImage, &CubeMapTextureGLTest::invalidateSubImage}); - - _dataStorage = PixelStorage{}.setSkip({0, 1, 0}); - _dataOffset = 8; - #ifdef MAGNUM_TARGET_GLES2 - #ifndef MAGNUM_TARGET_WEBGL - if(!Context::current().isExtensionSupported()) - #endif - { - _dataStorage = {}; - _dataOffset = 0; - } - #endif - - #ifndef MAGNUM_TARGET_GLES - if(Context::current().isExtensionSupported()) - { - _compressedDataStorage = CompressedPixelStorage{} - .setCompressedBlockSize({4, 4, 1}) - .setCompressedBlockDataSize(16) - .setSkip({0, 4, 0}); - _compressedFullDataStorage = CompressedPixelStorage{} - .setCompressedBlockSize({4, 4, 1}) - .setCompressedBlockDataSize(16) - .setSkip({0, 0, 4}); - _compressedDataOffset = 16; - _compressedFullDataOffset = 16*4; - } else - #endif - { - #ifndef MAGNUM_TARGET_GLES - _compressedDataStorage = {}; - #endif - _compressedDataOffset = 0; - _compressedFullDataOffset = 0; - } } namespace { @@ -455,336 +594,369 @@ void CubeMapTextureGLTest::storage() { #endif } -namespace { - constexpr UnsignedByte Data[] = { 0x00, 0x01, 0x02, 0x03, - 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, - 0x0c, 0x0d, 0x0e, 0x0f }; +void CubeMapTextureGLTest::image() { + setTestCaseDescription(PixelStorageData[testCaseInstanceId()].name); - /* Just 4x4 0x00 - 0x3f compressed using RGBA DXT3 by the driver */ - constexpr UnsignedByte CompressedData[] = { - 0, 17, 17, 34, 34, 51, 51, 67, - 232, 57, 0, 0, 213, 255, 170, 2 - }; -} + #ifdef MAGNUM_TARGET_GLES2 + if(PixelStorageData[testCaseInstanceId()].storage != PixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::EXT::unpack_subimage::string() + std::string(" is not supported.")); + #endif -void CubeMapTextureGLTest::image() { CubeMapTexture texture; texture.setImage(CubeMapCoordinate::PositiveX, 0, TextureFormat::RGBA8, - ImageView2D{_dataStorage, PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data, _dataOffset)}); + ImageView2D{PixelStorageData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), + PixelStorageData[testCaseInstanceId()].dataSparse}); MAGNUM_VERIFY_NO_ERROR(); /** @todo How to test this on ES? */ #ifndef MAGNUM_TARGET_GLES Image2D image = texture.image(CubeMapCoordinate::PositiveX, 0, - {_dataStorage, PixelFormat::RGBA, PixelType::UnsignedByte}); + {PixelStorageData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte}); MAGNUM_VERIFY_NO_ERROR(); CORRADE_COMPARE(image.size(), Vector2i(2)); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(_dataOffset), - Containers::arrayView(Data), TestSuite::Compare::Container); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(PixelStorageData[testCaseInstanceId()].offset), + PixelStorageData[testCaseInstanceId()].data, + TestSuite::Compare::Container); #endif } -void CubeMapTextureGLTest::compressedImage() { - #ifndef MAGNUM_TARGET_WEBGL - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); - #else - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::WEBGL::compressed_texture_s3tc::string() + std::string(" is not supported.")); - #endif - - const CompressedImageView2D view{ - #ifndef MAGNUM_TARGET_GLES - _compressedDataStorage, - #endif - CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, unsafeSuffix(CompressedData, _compressedDataOffset)}; +#ifndef MAGNUM_TARGET_GLES2 +void CubeMapTextureGLTest::imageBuffer() { + setTestCaseDescription(PixelStorageData[testCaseInstanceId()].name); CubeMapTexture texture; - texture.setCompressedImage(CubeMapCoordinate::PositiveX, 0, view) - .setCompressedImage(CubeMapCoordinate::NegativeX, 0, view) - .setCompressedImage(CubeMapCoordinate::PositiveY, 0, view) - .setCompressedImage(CubeMapCoordinate::NegativeY, 0, view) - .setCompressedImage(CubeMapCoordinate::PositiveZ, 0, view) - .setCompressedImage(CubeMapCoordinate::NegativeZ, 0, view); + texture.setImage(CubeMapCoordinate::PositiveX, 0, TextureFormat::RGBA8, + BufferImage2D{PixelStorageData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), + PixelStorageData[testCaseInstanceId()].dataSparse, + BufferUsage::StaticDraw}); MAGNUM_VERIFY_NO_ERROR(); + /** @todo How to test this on ES? */ #ifndef MAGNUM_TARGET_GLES - CompressedImage2D image = texture.compressedImage(CubeMapCoordinate::PositiveX, 0, {_compressedDataStorage}); + BufferImage2D image = texture.image(CubeMapCoordinate::PositiveX, 0, + {PixelStorageData[testCaseInstanceId()].storage, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); + const auto imageData = image.buffer().data(); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), Vector2i{4}); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(_compressedDataOffset), - Containers::arrayView(CompressedData), TestSuite::Compare::Container); + CORRADE_COMPARE(image.size(), Vector2i(2)); + CORRADE_COMPARE_AS(imageData.suffix(PixelStorageData[testCaseInstanceId()].offset), + PixelStorageData[testCaseInstanceId()].data, + TestSuite::Compare::Container); #endif } +#endif + +namespace { + constexpr UnsignedByte Zero[4*4*4]{}; + + constexpr UnsignedByte SubDataComplete[]{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0, 0, 0, 0, + 0, 0, 0, 0, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; +} + +void CubeMapTextureGLTest::subImage() { + setTestCaseDescription(PixelStorageData[testCaseInstanceId()].name); + + #ifdef MAGNUM_TARGET_GLES2 + if(PixelStorageData[testCaseInstanceId()].storage != PixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::EXT::unpack_subimage::string() + std::string(" is not supported.")); + #endif -#ifndef MAGNUM_TARGET_GLES2 -void CubeMapTextureGLTest::imageBuffer() { CubeMapTexture texture; - texture.setImage(CubeMapCoordinate::PositiveX, 0, TextureFormat::RGBA8, BufferImage2D{ - _dataStorage, PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data, _dataOffset), BufferUsage::StaticDraw}); + texture.setImage(CubeMapCoordinate::PositiveX, 0, TextureFormat::RGBA8, + ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero)); + texture.setImage(CubeMapCoordinate::NegativeX, 0, TextureFormat::RGBA8, + ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero)); + texture.setImage(CubeMapCoordinate::PositiveY, 0, TextureFormat::RGBA8, + ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero)); + texture.setImage(CubeMapCoordinate::NegativeY, 0, TextureFormat::RGBA8, + ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero)); + texture.setImage(CubeMapCoordinate::PositiveZ, 0, TextureFormat::RGBA8, + ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero)); + texture.setImage(CubeMapCoordinate::NegativeZ, 0, TextureFormat::RGBA8, + ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero)); + texture.setSubImage(CubeMapCoordinate::PositiveX, 0, Vector2i(1), ImageView2D{ + PixelStorageData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), + PixelStorageData[testCaseInstanceId()].dataSparse}); MAGNUM_VERIFY_NO_ERROR(); /** @todo How to test this on ES? */ #ifndef MAGNUM_TARGET_GLES - BufferImage2D image = texture.image(CubeMapCoordinate::PositiveX, 0, - {_dataStorage, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); - const auto imageData = image.buffer().data(); + Image2D image = texture.image(CubeMapCoordinate::PositiveX, 0, {PixelFormat::RGBA, PixelType::UnsignedByte}); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), Vector2i(2)); - CORRADE_COMPARE_AS(imageData.suffix(_dataOffset), - Containers::arrayView(Data), TestSuite::Compare::Container); + CORRADE_COMPARE(image.size(), Vector2i(4)); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()), + Containers::arrayView(SubDataComplete), TestSuite::Compare::Container); #endif } -void CubeMapTextureGLTest::compressedImageBuffer() { - #ifndef MAGNUM_TARGET_WEBGL - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); - #else - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::WEBGL::compressed_texture_s3tc::string() + std::string(" is not supported.")); - #endif - - CompressedBufferImage2D buffer{ - #ifndef MAGNUM_TARGET_GLES - _compressedDataStorage, - #endif - CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, unsafeSuffix(CompressedData, _compressedDataOffset), BufferUsage::StaticDraw}; +#ifndef MAGNUM_TARGET_GLES2 +void CubeMapTextureGLTest::subImageBuffer() { + setTestCaseDescription(PixelStorageData[testCaseInstanceId()].name); CubeMapTexture texture; - texture.setCompressedImage(CubeMapCoordinate::PositiveX, 0, buffer) - .setCompressedImage(CubeMapCoordinate::NegativeX, 0, buffer) - .setCompressedImage(CubeMapCoordinate::PositiveY, 0, buffer) - .setCompressedImage(CubeMapCoordinate::NegativeY, 0, buffer) - .setCompressedImage(CubeMapCoordinate::PositiveZ, 0, buffer) - .setCompressedImage(CubeMapCoordinate::NegativeZ, 0, buffer); + texture.setImage(CubeMapCoordinate::PositiveX, 0, TextureFormat::RGBA8, + ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero)); + texture.setImage(CubeMapCoordinate::NegativeX, 0, TextureFormat::RGBA8, + ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero)); + texture.setImage(CubeMapCoordinate::PositiveY, 0, TextureFormat::RGBA8, + ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero)); + texture.setImage(CubeMapCoordinate::NegativeY, 0, TextureFormat::RGBA8, + ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero)); + texture.setImage(CubeMapCoordinate::PositiveZ, 0, TextureFormat::RGBA8, + ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero)); + texture.setImage(CubeMapCoordinate::NegativeZ, 0, TextureFormat::RGBA8, + ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero)); + texture.setSubImage(CubeMapCoordinate::PositiveX, 0, Vector2i(1), BufferImage2D{ + PixelStorageData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), + PixelStorageData[testCaseInstanceId()].dataSparse, + BufferUsage::StaticDraw}); MAGNUM_VERIFY_NO_ERROR(); + /** @todo How to test this on ES? */ #ifndef MAGNUM_TARGET_GLES - CompressedBufferImage2D image = texture.compressedImage(CubeMapCoordinate::PositiveX, 0, - {_compressedDataStorage}, BufferUsage::StaticRead); + BufferImage2D image = texture.image(CubeMapCoordinate::PositiveX, 0, {PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); const auto imageData = image.buffer().data(); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), Vector2i{4}); - CORRADE_COMPARE_AS(imageData.suffix(_compressedDataOffset), - Containers::arrayView(CompressedData), TestSuite::Compare::Container); + CORRADE_COMPARE(image.size(), Vector2i(4)); + CORRADE_COMPARE_AS(imageData, Containers::arrayView(SubDataComplete), + TestSuite::Compare::Container); #endif } #endif -void CubeMapTextureGLTest::immutableCompressedImage() { - #ifndef MAGNUM_TARGET_GLES - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::ARB::texture_storage::string() + std::string(" is not supported.")); - #elif defined(MAGNUM_TARGET_GLES2) - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::EXT::texture_storage::string() + std::string(" is not supported.")); - #endif - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); +#ifndef MAGNUM_TARGET_GLES +void CubeMapTextureGLTest::subImageQuery() { + setTestCaseDescription(PixelStorageData[testCaseInstanceId()].name); - /* Testing that GL_TEXTURE_COMPRESSED_IMAGE_SIZE is consistent and returns - the same value regardless whether the texture is immutable or not. (Not - the case, at least on NVidia 358.16, compare with compressedImage() test - case that just calls setImage() six times instead of setStorage() and - gets value that's six times smaller. I couldn't find anything in the - specs so I suspect it's a bug). */ - - const CompressedImageView2D view{ - #ifndef MAGNUM_TARGET_GLES - _compressedDataStorage, - #endif - CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, unsafeSuffix(CompressedData, _compressedDataOffset)}; + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); + /* I'm too lazy to call setSubImage() six times */ + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::direct_state_access::string() + std::string(" is not supported.")); CubeMapTexture texture; - texture.setStorage(1, TextureFormat::CompressedRGBAS3tcDxt3, Vector2i{4}) - .setCompressedSubImage(CubeMapCoordinate::PositiveX, 0, {}, view) - .setCompressedSubImage(CubeMapCoordinate::NegativeX, 0, {}, view) - .setCompressedSubImage(CubeMapCoordinate::PositiveY, 0, {}, view) - .setCompressedSubImage(CubeMapCoordinate::NegativeY, 0, {}, view) - .setCompressedSubImage(CubeMapCoordinate::PositiveZ, 0, {}, view) - .setCompressedSubImage(CubeMapCoordinate::NegativeZ, 0, {}, view); + texture.setStorage(1, TextureFormat::RGBA8, Vector2i{4}) + .setSubImage(0, {}, ImageView3D{PixelFormat::RGBA, PixelType::UnsignedByte, {4, 4, 1}, SubDataComplete}); MAGNUM_VERIFY_NO_ERROR(); - #ifndef MAGNUM_TARGET_GLES - CompressedImage2D image = texture.compressedImage(CubeMapCoordinate::NegativeY, 0, {}); + Image3D image = texture.subImage(0, Range3Di::fromSize({1, 1, 0}, {2, 2, 1}), + {PixelStorageData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte}); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), Vector2i{4}); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()), - Containers::arrayView(CompressedData), TestSuite::Compare::Container); - #endif + CORRADE_COMPARE(image.size(), Vector3i(2, 2, 1)); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(PixelStorageData[testCaseInstanceId()].offset), + PixelStorageData[testCaseInstanceId()].data, + TestSuite::Compare::Container); } -#ifndef MAGNUM_TARGET_GLES -namespace { - constexpr UnsignedByte FullData[] = { 0x00, 0x01, 0x02, 0x03, - 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, - 0x0c, 0x0d, 0x0e, 0x0f, - - 0x10, 0x11, 0x12, 0x13, - 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, - 0x1c, 0x1d, 0x1e, 0x1f, - - 0x20, 0x21, 0x22, 0x23, - 0x24, 0x25, 0x26, 0x27, - 0x28, 0x29, 0x2a, 0x2b, - 0x2c, 0x2d, 0x2e, 0x2f, - - 0x30, 0x31, 0x32, 0x33, - 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x3a, 0x3b, - 0x3c, 0x3d, 0x3e, 0x3f, - - 0x40, 0x41, 0x42, 0x43, - 0x44, 0x45, 0x46, 0x47, - 0x48, 0x49, 0x4a, 0x4b, - 0x4c, 0x4d, 0x4e, 0x4f, - - 0x50, 0x51, 0x52, 0x53, - 0x54, 0x55, 0x56, 0x57, - 0x58, 0x59, 0x5a, 0x5b, - 0x5c, 0x5d, 0x5e, 0x5f }; - - const auto FullDataStorage = PixelStorage{}.setSkip({0, 0, 1}); - const auto FullDataOffset = 16; - - /* Just 4x4 0x00 - 0x3f compressed using RGBA DXT3 by the driver, repeated - six times */ - constexpr UnsignedByte CompressedFullData[] = { - 0, 17, 17, 34, 34, 51, 51, 67, - 232, 57, 0, 0, 213, 255, 170, 2, - 0, 17, 17, 34, 34, 51, 51, 67, - 232, 57, 0, 0, 213, 255, 170, 2, - 0, 17, 17, 34, 34, 51, 51, 67, - 232, 57, 0, 0, 213, 255, 170, 2, - - 0, 17, 17, 34, 34, 51, 51, 67, - 232, 57, 0, 0, 213, 255, 170, 2, - 0, 17, 17, 34, 34, 51, 51, 67, - 232, 57, 0, 0, 213, 255, 170, 2, - 0, 17, 17, 34, 34, 51, 51, 67, - 232, 57, 0, 0, 213, 255, 170, 2 - }; -} +void CubeMapTextureGLTest::subImageQueryBuffer() { + setTestCaseDescription(PixelStorageData[testCaseInstanceId()].name); -void CubeMapTextureGLTest::fullImageQuery() { + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); + /* I'm too lazy to call setSubImage() six times */ if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::direct_state_access::string() + std::string(" is not supported.")); CubeMapTexture texture; - texture.setStorage(1, TextureFormat::RGBA8, Vector2i{2, 2}) - .setSubImage(0, {}, ImageView3D{PixelFormat::RGBA, PixelType::UnsignedByte, {2, 2, 6}, FullData}); + texture.setStorage(1, TextureFormat::RGBA8, Vector2i{4}) + .setSubImage(0, {}, ImageView3D{PixelFormat::RGBA, PixelType::UnsignedByte, {4, 4, 1}, SubDataComplete}); MAGNUM_VERIFY_NO_ERROR(); - Image3D image = texture.image(0, - {FullDataStorage, PixelFormat::RGBA, PixelType::UnsignedByte}); + BufferImage3D image = texture.subImage(0, Range3Di::fromSize({1, 1, 0}, {2, 2, 1}), + {PixelStorageData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); + const auto imageData = image.buffer().data(); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), Vector3i(2, 2, 6)); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(FullDataOffset), - Containers::arrayView(FullData), TestSuite::Compare::Container); + CORRADE_COMPARE(image.size(), Vector3i(2, 2, 1)); + CORRADE_COMPARE_AS(imageData.suffix(PixelStorageData[testCaseInstanceId()].offset), + PixelStorageData[testCaseInstanceId()].data, + TestSuite::Compare::Container); } +#endif -void CubeMapTextureGLTest::compressedFullImageQuery() { - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::ARB::direct_state_access::string() + std::string(" is not supported.")); +void CubeMapTextureGLTest::compressedImage() { + setTestCaseDescription(CompressedPixelStorageData[testCaseInstanceId()].name); + + #ifndef MAGNUM_TARGET_WEBGL if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); + #else + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::WEBGL::compressed_texture_s3tc::string() + std::string(" is not supported.")); + #endif + + #ifndef MAGNUM_TARGET_GLES + if(CompressedPixelStorageData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); + #endif + + const CompressedImageView2D view{ + #ifndef MAGNUM_TARGET_GLES + CompressedPixelStorageData[testCaseInstanceId()].storage, + #endif + CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, + CompressedPixelStorageData[testCaseInstanceId()].dataSparse}; CubeMapTexture texture; - texture.setStorage(1, TextureFormat::CompressedRGBAS3tcDxt3, Vector2i{4}) - .setCompressedSubImage(0, {}, CompressedImageView3D{CompressedPixelFormat::RGBAS3tcDxt3, {4, 4, 6}, CompressedFullData}); + texture.setCompressedImage(CubeMapCoordinate::PositiveX, 0, view) + .setCompressedImage(CubeMapCoordinate::NegativeX, 0, view) + .setCompressedImage(CubeMapCoordinate::PositiveY, 0, view) + .setCompressedImage(CubeMapCoordinate::NegativeY, 0, view) + .setCompressedImage(CubeMapCoordinate::PositiveZ, 0, view) + .setCompressedImage(CubeMapCoordinate::NegativeZ, 0, view); MAGNUM_VERIFY_NO_ERROR(); - CompressedImage3D image = texture.compressedImage(0, {_compressedFullDataStorage}); + #ifndef MAGNUM_TARGET_GLES + CompressedImage2D image = texture.compressedImage(CubeMapCoordinate::PositiveX, 0, {CompressedPixelStorageData[testCaseInstanceId()].storage}); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), (Vector3i{4, 4, 6})); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(_compressedFullDataOffset), - Containers::arrayView(CompressedFullData), TestSuite::Compare::Container); + CORRADE_COMPARE(image.size(), Vector2i{4}); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(CompressedPixelStorageData[testCaseInstanceId()].offset), + CompressedPixelStorageData[testCaseInstanceId()].data, + TestSuite::Compare::Container); + #endif } -void CubeMapTextureGLTest::fullImageQueryBuffer() { - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::ARB::direct_state_access::string() + std::string(" is not supported.")); +#ifndef MAGNUM_TARGET_GLES2 +void CubeMapTextureGLTest::compressedImageBuffer() { + setTestCaseDescription(CompressedPixelStorageData[testCaseInstanceId()].name); + + #ifndef MAGNUM_TARGET_WEBGL + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); + #else + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::WEBGL::compressed_texture_s3tc::string() + std::string(" is not supported.")); + #endif + + #ifndef MAGNUM_TARGET_GLES + if(CompressedPixelStorageData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); + #endif + + CompressedBufferImage2D buffer{ + #ifndef MAGNUM_TARGET_GLES + CompressedPixelStorageData[testCaseInstanceId()].storage, + #endif + CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, + CompressedPixelStorageData[testCaseInstanceId()].dataSparse, + BufferUsage::StaticDraw}; CubeMapTexture texture; - texture.setStorage(1, TextureFormat::RGBA8, Vector2i{2}) - .setSubImage(0, {}, BufferImage3D{PixelFormat::RGBA, PixelType::UnsignedByte, {2, 2, 6}, FullData, BufferUsage::StaticDraw}); + texture.setCompressedImage(CubeMapCoordinate::PositiveX, 0, buffer) + .setCompressedImage(CubeMapCoordinate::NegativeX, 0, buffer) + .setCompressedImage(CubeMapCoordinate::PositiveY, 0, buffer) + .setCompressedImage(CubeMapCoordinate::NegativeY, 0, buffer) + .setCompressedImage(CubeMapCoordinate::PositiveZ, 0, buffer) + .setCompressedImage(CubeMapCoordinate::NegativeZ, 0, buffer); MAGNUM_VERIFY_NO_ERROR(); - BufferImage3D image = texture.image(0, - {FullDataStorage, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); + #ifndef MAGNUM_TARGET_GLES + CompressedBufferImage2D image = texture.compressedImage(CubeMapCoordinate::PositiveX, 0, + {CompressedPixelStorageData[testCaseInstanceId()].storage}, BufferUsage::StaticRead); + const auto imageData = image.buffer().data(); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), Vector3i(2, 2, 6)); - const auto imageData = image.buffer().data(); - CORRADE_COMPARE_AS(imageData.suffix(FullDataOffset), - Containers::arrayView(FullData), TestSuite::Compare::Container); + CORRADE_COMPARE(image.size(), Vector2i{4}); + CORRADE_COMPARE_AS(imageData.suffix(CompressedPixelStorageData[testCaseInstanceId()].offset), + CompressedPixelStorageData[testCaseInstanceId()].data, + TestSuite::Compare::Container); + #endif } +#endif -void CubeMapTextureGLTest::compressedFullImageQueryBuffer() { - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::ARB::direct_state_access::string() + std::string(" is not supported.")); +void CubeMapTextureGLTest::immutableCompressedImage() { + setTestCaseDescription(CompressedPixelStorageData[testCaseInstanceId()].name); + + #ifndef MAGNUM_TARGET_GLES + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::texture_storage::string() + std::string(" is not supported.")); + #elif defined(MAGNUM_TARGET_GLES2) + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::EXT::texture_storage::string() + std::string(" is not supported.")); + #endif if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); + #ifndef MAGNUM_TARGET_GLES + if(CompressedPixelStorageData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); + #endif + + /* Testing that GL_TEXTURE_COMPRESSED_IMAGE_SIZE is consistent and returns + the same value regardless whether the texture is immutable or not. (Not + the case, at least on NVidia 358.16, compare with compressedImage() test + case that just calls setImage() six times instead of setStorage() and + gets value that's six times smaller. I couldn't find anything in the + specs so I suspect it's a bug). */ + + const CompressedImageView2D view{ + #ifndef MAGNUM_TARGET_GLES + CompressedPixelStorageData[testCaseInstanceId()].storage, + #endif + CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, + CompressedPixelStorageData[testCaseInstanceId()].dataSparse}; + CubeMapTexture texture; texture.setStorage(1, TextureFormat::CompressedRGBAS3tcDxt3, Vector2i{4}) - .setCompressedSubImage(0, {}, CompressedBufferImage3D{CompressedPixelFormat::RGBAS3tcDxt3, {4, 4, 6}, CompressedFullData, BufferUsage::StaticDraw}); + .setCompressedSubImage(CubeMapCoordinate::PositiveX, 0, {}, view) + .setCompressedSubImage(CubeMapCoordinate::NegativeX, 0, {}, view) + .setCompressedSubImage(CubeMapCoordinate::PositiveY, 0, {}, view) + .setCompressedSubImage(CubeMapCoordinate::NegativeY, 0, {}, view) + .setCompressedSubImage(CubeMapCoordinate::PositiveZ, 0, {}, view) + .setCompressedSubImage(CubeMapCoordinate::NegativeZ, 0, {}, view); MAGNUM_VERIFY_NO_ERROR(); - CompressedBufferImage3D image = texture.compressedImage(0, {_compressedFullDataStorage}, BufferUsage::StaticRead); + #ifndef MAGNUM_TARGET_GLES + CompressedImage2D image = texture.compressedImage(CubeMapCoordinate::NegativeY, 0, {CompressedPixelStorageData[testCaseInstanceId()].storage}); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), (Vector3i{4, 4, 6})); - const auto imageData = image.buffer().data(); - CORRADE_COMPARE_AS(imageData.suffix(_compressedFullDataOffset), - Containers::arrayView(CompressedFullData), TestSuite::Compare::Container); + CORRADE_COMPARE(image.size(), Vector2i{4}); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(CompressedPixelStorageData[testCaseInstanceId()].offset), + CompressedPixelStorageData[testCaseInstanceId()].data, + TestSuite::Compare::Container); + #endif } -#endif namespace { - constexpr UnsignedByte Zero[4*4*4] = {}; - /* Just 12x12 zeros compressed using RGBA DXT3 by the driver */ - constexpr UnsignedByte CompressedZero[9*16] = {}; - - constexpr UnsignedByte SubDataComplete[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0, 0, 0, 0, - 0, 0, 0, 0, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; + constexpr UnsignedByte CompressedZero[9*16]{}; /* Combination of CompressedZero and CompressedData */ - constexpr UnsignedByte CompressedSubDataComplete[] = { + constexpr UnsignedByte CompressedSubDataComplete[]{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -808,38 +980,9 @@ namespace { }; } -void CubeMapTextureGLTest::subImage() { - CubeMapTexture texture; - texture.setImage(CubeMapCoordinate::PositiveX, 0, TextureFormat::RGBA8, - ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero)); - texture.setImage(CubeMapCoordinate::NegativeX, 0, TextureFormat::RGBA8, - ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero)); - texture.setImage(CubeMapCoordinate::PositiveY, 0, TextureFormat::RGBA8, - ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero)); - texture.setImage(CubeMapCoordinate::NegativeY, 0, TextureFormat::RGBA8, - ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero)); - texture.setImage(CubeMapCoordinate::PositiveZ, 0, TextureFormat::RGBA8, - ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero)); - texture.setImage(CubeMapCoordinate::NegativeZ, 0, TextureFormat::RGBA8, - ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero)); - texture.setSubImage(CubeMapCoordinate::PositiveX, 0, Vector2i(1), ImageView2D{ - _dataStorage, PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data, _dataOffset)}); - - MAGNUM_VERIFY_NO_ERROR(); - - /** @todo How to test this on ES? */ - #ifndef MAGNUM_TARGET_GLES - Image2D image = texture.image(CubeMapCoordinate::PositiveX, 0, {PixelFormat::RGBA, PixelType::UnsignedByte}); - - MAGNUM_VERIFY_NO_ERROR(); - - CORRADE_COMPARE(image.size(), Vector2i(4)); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()), - Containers::arrayView(SubDataComplete), TestSuite::Compare::Container); - #endif -} - void CubeMapTextureGLTest::compressedSubImage() { + setTestCaseDescription(CompressedPixelStorageData[testCaseInstanceId()].name); + #ifndef MAGNUM_TARGET_WEBGL if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); @@ -849,37 +992,8 @@ void CubeMapTextureGLTest::compressedSubImage() { #endif #ifndef MAGNUM_TARGET_GLES - /* Compressed pixel storage for array textures is underspecified. If the - extension is supported, first test with default values to ensure we are - not that far off, then continue as usual */ - if(Context::current().isExtensionSupported()) { - CubeMapTexture texture; - texture.setCompressedImage(CubeMapCoordinate::PositiveX, 0, - CompressedImageView2D{CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{12}, CompressedZero}); - texture.setCompressedImage(CubeMapCoordinate::NegativeX, 0, - CompressedImageView2D{CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{12}, CompressedZero}); - texture.setCompressedImage(CubeMapCoordinate::PositiveY, 0, - CompressedImageView2D{CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{12}, CompressedZero}); - texture.setCompressedImage(CubeMapCoordinate::NegativeY, 0, - CompressedImageView2D{CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{12}, CompressedZero}); - texture.setCompressedImage(CubeMapCoordinate::PositiveZ, 0, - CompressedImageView2D{CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{12}, CompressedZero}); - texture.setCompressedImage(CubeMapCoordinate::NegativeZ, 0, - CompressedImageView2D{CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{12}, CompressedZero}); - texture.setCompressedSubImage(CubeMapCoordinate::PositiveX, 0, Vector2i{4}, CompressedImageView2D{ - CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, CompressedData}); - - MAGNUM_VERIFY_NO_ERROR(); - - CompressedImage2D image = texture.compressedImage(CubeMapCoordinate::PositiveX, 0, {}); - - MAGNUM_VERIFY_NO_ERROR(); - - CORRADE_COMPARE(image.size(), Vector2i{12}); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()), - Containers::arrayView(CompressedSubDataComplete), - TestSuite::Compare::Container); - } + if(CompressedPixelStorageData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); #endif CubeMapTexture texture; @@ -897,9 +1011,10 @@ void CubeMapTextureGLTest::compressedSubImage() { CompressedImageView2D{CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{12}, CompressedZero}); texture.setCompressedSubImage(CubeMapCoordinate::PositiveX, 0, Vector2i{4}, CompressedImageView2D{ #ifndef MAGNUM_TARGET_GLES - _compressedDataStorage, + CompressedPixelStorageData[testCaseInstanceId()].storage, #endif - CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, unsafeSuffix(CompressedData, _compressedDataOffset)}); + CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, + CompressedPixelStorageData[testCaseInstanceId()].dataSparse}); MAGNUM_VERIFY_NO_ERROR(); @@ -911,7 +1026,7 @@ void CubeMapTextureGLTest::compressedSubImage() { CORRADE_COMPARE(image.size(), Vector2i{12}); { - CORRADE_EXPECT_FAIL_IF(Context::current().isExtensionSupported() && Context::current().isExtensionSupported() && (Context::current().detectedDriver() & Context::DetectedDriver::NVidia), + CORRADE_EXPECT_FAIL_IF(CompressedPixelStorageData[testCaseInstanceId()].storage != CompressedPixelStorage{} && Context::current().isExtensionSupported() && (Context::current().detectedDriver() & Context::DetectedDriver::NVidia), "Non-default compressed pixel storage for cube map textures behaves weirdly on NVidia for client-memory images when using ARB_direct_state_access"); CORRADE_COMPARE_AS(Containers::arrayCast(image.data()), @@ -922,39 +1037,9 @@ void CubeMapTextureGLTest::compressedSubImage() { } #ifndef MAGNUM_TARGET_GLES2 -void CubeMapTextureGLTest::subImageBuffer() { - CubeMapTexture texture; - texture.setImage(CubeMapCoordinate::PositiveX, 0, TextureFormat::RGBA8, - ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero)); - texture.setImage(CubeMapCoordinate::NegativeX, 0, TextureFormat::RGBA8, - ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero)); - texture.setImage(CubeMapCoordinate::PositiveY, 0, TextureFormat::RGBA8, - ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero)); - texture.setImage(CubeMapCoordinate::NegativeY, 0, TextureFormat::RGBA8, - ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero)); - texture.setImage(CubeMapCoordinate::PositiveZ, 0, TextureFormat::RGBA8, - ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero)); - texture.setImage(CubeMapCoordinate::NegativeZ, 0, TextureFormat::RGBA8, - ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero)); - texture.setSubImage(CubeMapCoordinate::PositiveX, 0, Vector2i(1), BufferImage2D{ - _dataStorage, PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data, _dataOffset), BufferUsage::StaticDraw}); - - MAGNUM_VERIFY_NO_ERROR(); - - /** @todo How to test this on ES? */ - #ifndef MAGNUM_TARGET_GLES - BufferImage2D image = texture.image(CubeMapCoordinate::PositiveX, 0, {PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); - const auto imageData = image.buffer().data(); - - MAGNUM_VERIFY_NO_ERROR(); - - CORRADE_COMPARE(image.size(), Vector2i(4)); - CORRADE_COMPARE_AS(imageData, Containers::arrayView(SubDataComplete), - TestSuite::Compare::Container); - #endif -} - void CubeMapTextureGLTest::compressedSubImageBuffer() { + setTestCaseDescription(CompressedPixelStorageData[testCaseInstanceId()].name); + #ifndef MAGNUM_TARGET_WEBGL if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); @@ -963,6 +1048,11 @@ void CubeMapTextureGLTest::compressedSubImageBuffer() { CORRADE_SKIP(Extensions::GL::WEBGL::compressed_texture_s3tc::string() + std::string(" is not supported.")); #endif + #ifndef MAGNUM_TARGET_GLES + if(CompressedPixelStorageData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); + #endif + CubeMapTexture texture; texture.setCompressedImage(CubeMapCoordinate::PositiveX, 0, CompressedImageView2D{CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{12}, CompressedZero}); @@ -978,9 +1068,11 @@ void CubeMapTextureGLTest::compressedSubImageBuffer() { CompressedImageView2D{CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{12}, CompressedZero}); texture.setCompressedSubImage(CubeMapCoordinate::PositiveX, 0, Vector2i{4}, CompressedBufferImage2D{ #ifndef MAGNUM_TARGET_GLES - _compressedDataStorage, + CompressedPixelStorageData[testCaseInstanceId()].storage, #endif - CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, unsafeSuffix(CompressedData, _compressedDataOffset), BufferUsage::StaticDraw}); + CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, + CompressedPixelStorageData[testCaseInstanceId()].dataSparse, + BufferUsage::StaticDraw}); MAGNUM_VERIFY_NO_ERROR(); @@ -999,30 +1091,38 @@ void CubeMapTextureGLTest::compressedSubImageBuffer() { #endif #ifndef MAGNUM_TARGET_GLES -void CubeMapTextureGLTest::subImageQuery() { +void CubeMapTextureGLTest::compressedSubImageQuery() { + setTestCaseDescription(CompressedPixelStorageData[testCaseInstanceId()].name); + if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); /* I'm too lazy to call setSubImage() six times */ if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::direct_state_access::string() + std::string(" is not supported.")); + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); + if(CompressedPixelStorageData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); CubeMapTexture texture; - texture.setStorage(1, TextureFormat::RGBA8, Vector2i{4}) - .setSubImage(0, {}, ImageView3D{PixelFormat::RGBA, PixelType::UnsignedByte, {4, 4, 1}, SubDataComplete}); + texture.setStorage(1, TextureFormat::CompressedRGBAS3tcDxt3, Vector2i{12}) + .setCompressedSubImage(0, {}, CompressedImageView3D{CompressedPixelFormat::RGBAS3tcDxt3, {12, 12, 1}, CompressedSubDataComplete}); MAGNUM_VERIFY_NO_ERROR(); - Image3D image = texture.subImage(0, Range3Di::fromSize({1, 1, 0}, {2, 2, 1}), - {_dataStorage, PixelFormat::RGBA, PixelType::UnsignedByte}); + CompressedImage3D image = texture.compressedSubImage(0, Range3Di::fromSize({4, 4, 0}, {4, 4, 1}), {CompressedPixelStorageData[testCaseInstanceId()].storage}); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), Vector3i(2, 2, 1)); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(_dataOffset), - Containers::arrayView(Data), TestSuite::Compare::Container); + CORRADE_COMPARE(image.size(), (Vector3i{4, 4, 1})); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(CompressedPixelStorageData[testCaseInstanceId()].offset), + CompressedPixelStorageData[testCaseInstanceId()].data, + TestSuite::Compare::Container); } -void CubeMapTextureGLTest::compressedSubImageQuery() { +void CubeMapTextureGLTest::compressedSubImageQueryBuffer() { + setTestCaseDescription(CompressedPixelStorageData[testCaseInstanceId()].name); + if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); /* I'm too lazy to call setSubImage() six times */ @@ -1030,95 +1130,136 @@ void CubeMapTextureGLTest::compressedSubImageQuery() { CORRADE_SKIP(Extensions::GL::ARB::direct_state_access::string() + std::string(" is not supported.")); if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); + if(CompressedPixelStorageData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); CubeMapTexture texture; texture.setStorage(1, TextureFormat::CompressedRGBAS3tcDxt3, Vector2i{12}) - .setCompressedSubImage(0, {}, CompressedImageView3D{CompressedPixelFormat::RGBAS3tcDxt3, {12, 12, 1}, CompressedSubDataComplete}); + .setCompressedSubImage(0, {}, CompressedImageView3D{CompressedPixelFormat::RGBAS3tcDxt3, {12, 12, 1}, CompressedSubDataComplete}); MAGNUM_VERIFY_NO_ERROR(); - /* Test also without compressed pixel storage to ensure that both size - computations work */ - if(Context::current().isExtensionSupported()) { - CompressedImage3D image = texture.compressedSubImage(0, Range3Di::fromSize({4, 4, 0}, {4, 4, 1}), {}); + CompressedBufferImage3D image = texture.compressedSubImage(0, Range3Di::fromSize({4, 4, 0}, {4, 4, 1}), {CompressedPixelStorageData[testCaseInstanceId()].storage}, BufferUsage::StaticRead); + const auto imageData = image.buffer().data(); - MAGNUM_VERIFY_NO_ERROR(); + MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), (Vector3i{4, 4, 1})); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()), - Containers::arrayView(CompressedData), - TestSuite::Compare::Container); - } + CORRADE_COMPARE(image.size(), (Vector3i{4, 4, 1})); + CORRADE_COMPARE_AS(imageData.suffix(CompressedPixelStorageData[testCaseInstanceId()].offset), + CompressedPixelStorageData[testCaseInstanceId()].data, + TestSuite::Compare::Container); +} +#endif - CompressedImage3D image = texture.compressedSubImage(0, Range3Di::fromSize({4, 4, 0}, {4, 4, 1}), {_compressedDataStorage}); +#ifndef MAGNUM_TARGET_GLES +void CubeMapTextureGLTest::fullImageQuery() { + setTestCaseDescription(FullPixelStorageData[testCaseInstanceId()].name); + + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::direct_state_access::string() + std::string(" is not supported.")); + + CubeMapTexture texture; + texture.setStorage(1, TextureFormat::RGBA8, Vector2i{2, 2}) + .setSubImage(0, {}, ImageView3D{ + PixelFormat::RGBA, PixelType::UnsignedByte, {2, 2, 6}, + FullPixelStorageData[testCaseInstanceId()].data}); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), (Vector3i{4, 4, 1})); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(_compressedDataOffset), - Containers::arrayView(CompressedData), TestSuite::Compare::Container); + Image3D image = texture.image(0, + {FullPixelStorageData[testCaseInstanceId()].storage, PixelFormat::RGBA, PixelType::UnsignedByte}); + + MAGNUM_VERIFY_NO_ERROR(); + + CORRADE_COMPARE(image.size(), Vector3i(2, 2, 6)); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(FullPixelStorageData[testCaseInstanceId()].offset), + FullPixelStorageData[testCaseInstanceId()].data, + TestSuite::Compare::Container); } -void CubeMapTextureGLTest::subImageQueryBuffer() { - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); - /* I'm too lazy to call setSubImage() six times */ +void CubeMapTextureGLTest::fullImageQueryBuffer() { + setTestCaseDescription(FullPixelStorageData[testCaseInstanceId()].name); + if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::direct_state_access::string() + std::string(" is not supported.")); CubeMapTexture texture; - texture.setStorage(1, TextureFormat::RGBA8, Vector2i{4}) - .setSubImage(0, {}, ImageView3D{PixelFormat::RGBA, PixelType::UnsignedByte, {4, 4, 1}, SubDataComplete}); + texture.setStorage(1, TextureFormat::RGBA8, Vector2i{2}) + .setSubImage(0, {}, BufferImage3D{ + PixelFormat::RGBA, PixelType::UnsignedByte, {2, 2, 6}, + FullPixelStorageData[testCaseInstanceId()].data, + BufferUsage::StaticDraw}); MAGNUM_VERIFY_NO_ERROR(); - BufferImage3D image = texture.subImage(0, Range3Di::fromSize({1, 1, 0}, {2, 2, 1}), - {_dataStorage, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); - const auto imageData = image.buffer().data(); + BufferImage3D image = texture.image(0, + {FullPixelStorageData[testCaseInstanceId()].storage, PixelFormat::RGBA, + PixelType::UnsignedByte}, BufferUsage::StaticRead); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), Vector3i(2, 2, 1)); - CORRADE_COMPARE_AS(imageData.suffix(_dataOffset), - Containers::arrayView(Data), TestSuite::Compare::Container); + CORRADE_COMPARE(image.size(), Vector3i(2, 2, 6)); + const auto imageData = image.buffer().data(); + CORRADE_COMPARE_AS(imageData.suffix(FullPixelStorageData[testCaseInstanceId()].offset), + FullPixelStorageData[testCaseInstanceId()].data, TestSuite::Compare::Container); } -void CubeMapTextureGLTest::compressedSubImageQueryBuffer() { - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); - /* I'm too lazy to call setSubImage() six times */ +void CubeMapTextureGLTest::compressedFullImageQuery() { + setTestCaseDescription(CompressedFullPixelStorageData[testCaseInstanceId()].name); + if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::direct_state_access::string() + std::string(" is not supported.")); if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); + if(CompressedPixelStorageData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); CubeMapTexture texture; - texture.setStorage(1, TextureFormat::CompressedRGBAS3tcDxt3, Vector2i{12}) - .setCompressedSubImage(0, {}, CompressedImageView3D{CompressedPixelFormat::RGBAS3tcDxt3, {12, 12, 1}, CompressedSubDataComplete}); + texture.setStorage(1, TextureFormat::CompressedRGBAS3tcDxt3, Vector2i{4}) + .setCompressedSubImage(0, {}, CompressedImageView3D{ + CompressedPixelFormat::RGBAS3tcDxt3, {4, 4, 6}, + CompressedFullPixelStorageData[testCaseInstanceId()].data}); MAGNUM_VERIFY_NO_ERROR(); - /* Test also without compressed pixel storage to ensure that both size - computations work */ - if(Context::current().isExtensionSupported()) { - CompressedBufferImage3D image = texture.compressedSubImage(0, Range3Di::fromSize({4, 4, 0}, {4, 4, 1}), {}, BufferUsage::StaticRead); - const auto imageData = image.buffer().data(); + CompressedImage3D image = texture.compressedImage(0, {CompressedFullPixelStorageData[testCaseInstanceId()].storage}); - MAGNUM_VERIFY_NO_ERROR(); + MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), (Vector3i{4, 4, 1})); - CORRADE_COMPARE_AS(imageData, Containers::arrayView(CompressedData), - TestSuite::Compare::Container); - } + CORRADE_COMPARE(image.size(), (Vector3i{4, 4, 6})); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(CompressedFullPixelStorageData[testCaseInstanceId()].offset), + CompressedFullPixelStorageData[testCaseInstanceId()].data, + TestSuite::Compare::Container); +} - CompressedBufferImage3D image = texture.compressedSubImage(0, Range3Di::fromSize({4, 4, 0}, {4, 4, 1}), {_compressedDataStorage}, BufferUsage::StaticRead); - const auto imageData = image.buffer().data(); +void CubeMapTextureGLTest::compressedFullImageQueryBuffer() { + setTestCaseDescription(CompressedFullPixelStorageData[testCaseInstanceId()].name); + + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::direct_state_access::string() + std::string(" is not supported.")); + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); + if(CompressedPixelStorageData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); + + CubeMapTexture texture; + texture.setStorage(1, TextureFormat::CompressedRGBAS3tcDxt3, Vector2i{4}) + .setCompressedSubImage(0, {}, CompressedBufferImage3D{ + CompressedPixelFormat::RGBAS3tcDxt3, {4, 4, 6}, + CompressedFullPixelStorageData[testCaseInstanceId()].data, + BufferUsage::StaticDraw}); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), (Vector3i{4, 4, 1})); - CORRADE_COMPARE_AS(imageData.suffix(_compressedDataOffset), - Containers::arrayView(CompressedData), TestSuite::Compare::Container); + CompressedBufferImage3D image = texture.compressedImage(0, {CompressedFullPixelStorageData[testCaseInstanceId()].storage}, BufferUsage::StaticRead); + + MAGNUM_VERIFY_NO_ERROR(); + + CORRADE_COMPARE(image.size(), (Vector3i{4, 4, 6})); + const auto imageData = image.buffer().data(); + CORRADE_COMPARE_AS(imageData.suffix(CompressedFullPixelStorageData[testCaseInstanceId()].offset), + CompressedFullPixelStorageData[testCaseInstanceId()].data, + TestSuite::Compare::Container); } #endif diff --git a/src/Magnum/Test/RectangleTextureGLTest.cpp b/src/Magnum/Test/RectangleTextureGLTest.cpp index c4f7125fe..ac20a0355 100644 --- a/src/Magnum/Test/RectangleTextureGLTest.cpp +++ b/src/Magnum/Test/RectangleTextureGLTest.cpp @@ -75,6 +75,32 @@ struct RectangleTextureGLTest: OpenGLTester { void invalidateSubImage(); }; +namespace { + constexpr UnsignedByte Data[]{ + 0, 0, 0, 0, 0, 0, 0, 0, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; + + enum: std::size_t { PixelStorageDataCount = 2 }; + + const struct { + const char* name; + Containers::ArrayView data; + PixelStorage storage; + Containers::ArrayView dataSparse; + std::size_t offset; + } PixelStorageData[PixelStorageDataCount]{ + {"default pixel storage", + Containers::arrayView(Data).suffix(8), {}, + Containers::arrayView(Data).suffix(8), 0}, + #if !defined(MAGNUM_TARGET_GLES2) || !defined(MAGNUM_TARGET_WEBGL) + {"skip Y", + Containers::arrayView(Data).suffix(8), PixelStorage{}.setSkip({0, 1, 0}), + Data, 8} + #endif + }; +} + RectangleTextureGLTest::RectangleTextureGLTest() { addTests({&RectangleTextureGLTest::construct, &RectangleTextureGLTest::wrap, @@ -88,33 +114,28 @@ RectangleTextureGLTest::RectangleTextureGLTest() { &RectangleTextureGLTest::samplingSwizzle, &RectangleTextureGLTest::samplingDepthStencilMode, - &RectangleTextureGLTest::storage, + &RectangleTextureGLTest::storage}); - &RectangleTextureGLTest::image, - &RectangleTextureGLTest::compressedImage, - &RectangleTextureGLTest::imageBuffer, - &RectangleTextureGLTest::compressedImageBuffer, + addInstancedTests({ + &RectangleTextureGLTest::image, + &RectangleTextureGLTest::imageBuffer, + &RectangleTextureGLTest::subImage, + &RectangleTextureGLTest::subImageBuffer, + &RectangleTextureGLTest::subImageQuery, + &RectangleTextureGLTest::subImageQueryBuffer}, + PixelStorageDataCount); - &RectangleTextureGLTest::subImage, + addTests({&RectangleTextureGLTest::compressedImage, + &RectangleTextureGLTest::compressedImageBuffer, &RectangleTextureGLTest::compressedSubImage, - &RectangleTextureGLTest::subImageBuffer, &RectangleTextureGLTest::compressedSubImageBuffer, - &RectangleTextureGLTest::subImageQuery, &RectangleTextureGLTest::compressedSubImageQuery, - &RectangleTextureGLTest::subImageQueryBuffer, &RectangleTextureGLTest::compressedSubImageQueryBuffer, &RectangleTextureGLTest::invalidateImage, &RectangleTextureGLTest::invalidateSubImage}); } -namespace { - template Containers::ArrayView unsafeSuffix(const T(&data)[size], std::size_t offset) { - static_assert(sizeof(T) == 1, ""); - return {data - offset, size + offset}; - } -} - void RectangleTextureGLTest::construct() { if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::texture_rectangle::string() + std::string(" is not supported.")); @@ -276,67 +297,61 @@ void RectangleTextureGLTest::storage() { MAGNUM_VERIFY_NO_ERROR(); } -namespace { - constexpr UnsignedByte Data[] = { 0x00, 0x01, 0x02, 0x03, - 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, - 0x0c, 0x0d, 0x0e, 0x0f }; - - const auto DataStorage = PixelStorage{}.setSkip({0, 1, 0}); - const auto DataOffset = 8; -} - void RectangleTextureGLTest::image() { + setTestCaseDescription(PixelStorageData[testCaseInstanceId()].name); + if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::texture_rectangle::string() + std::string(" is not supported.")); RectangleTexture texture; texture.setImage(TextureFormat::RGBA8, ImageView2D{ - DataStorage, PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data, DataOffset)}); + PixelStorageData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), + PixelStorageData[testCaseInstanceId()].dataSparse}); MAGNUM_VERIFY_NO_ERROR(); - Image2D image = texture.image({DataStorage, PixelFormat::RGBA, PixelType::UnsignedByte}); + Image2D image = texture.image({PixelStorageData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte}); MAGNUM_VERIFY_NO_ERROR(); CORRADE_COMPARE(image.size(), Vector2i(2)); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(DataOffset), - Containers::arrayView(Data), TestSuite::Compare::Container); -} - -void RectangleTextureGLTest::compressedImage() { - CORRADE_SKIP("No rectangle texture compression format exists."); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(PixelStorageData[testCaseInstanceId()].offset), + PixelStorageData[testCaseInstanceId()].data, + TestSuite::Compare::Container); } void RectangleTextureGLTest::imageBuffer() { + setTestCaseDescription(PixelStorageData[testCaseInstanceId()].name); + if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::texture_rectangle::string() + std::string(" is not supported.")); RectangleTexture texture; texture.setImage(TextureFormat::RGBA8, BufferImage2D{ - DataStorage, PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data, DataOffset), BufferUsage::StaticDraw}); + PixelStorageData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), + PixelStorageData[testCaseInstanceId()].dataSparse, + BufferUsage::StaticDraw}); MAGNUM_VERIFY_NO_ERROR(); - BufferImage2D image = texture.image({DataStorage, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); + BufferImage2D image = texture.image({PixelStorageData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); const auto imageData = image.buffer().data(); MAGNUM_VERIFY_NO_ERROR(); CORRADE_COMPARE(image.size(), Vector2i(2)); - CORRADE_COMPARE_AS(imageData.suffix(DataOffset), - Containers::arrayView(Data), TestSuite::Compare::Container); -} - -void RectangleTextureGLTest::compressedImageBuffer() { - CORRADE_SKIP("No rectangle texture compression format exists."); + CORRADE_COMPARE_AS(imageData.suffix(PixelStorageData[testCaseInstanceId()].offset), + PixelStorageData[testCaseInstanceId()].data, + TestSuite::Compare::Container); } namespace { - constexpr UnsignedByte Zero[4*4*4] = {}; - - constexpr UnsignedByte SubDataComplete[] = { + constexpr UnsignedByte Zero[4*4*4]{}; + constexpr UnsignedByte SubDataComplete[]{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0, 0, 0, 0, 0, 0, 0, 0, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0, 0, 0, 0, @@ -345,6 +360,8 @@ namespace { } void RectangleTextureGLTest::subImage() { + setTestCaseDescription(PixelStorageData[testCaseInstanceId()].name); + if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::texture_rectangle::string() + std::string(" is not supported.")); @@ -352,7 +369,9 @@ void RectangleTextureGLTest::subImage() { texture.setImage(TextureFormat::RGBA8, ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero)); texture.setSubImage(Vector2i(1), ImageView2D{ - DataStorage, PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data, DataOffset)}); + PixelStorageData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), + PixelStorageData[testCaseInstanceId()].dataSparse}); MAGNUM_VERIFY_NO_ERROR(); @@ -365,11 +384,9 @@ void RectangleTextureGLTest::subImage() { Containers::arrayView(SubDataComplete), TestSuite::Compare::Container); } -void RectangleTextureGLTest::compressedSubImage() { - CORRADE_SKIP("No rectangle texture compression format exists."); -} - void RectangleTextureGLTest::subImageBuffer() { + setTestCaseDescription(PixelStorageData[testCaseInstanceId()].name); + if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::texture_rectangle::string() + std::string(" is not supported.")); @@ -377,7 +394,10 @@ void RectangleTextureGLTest::subImageBuffer() { texture.setImage(TextureFormat::RGBA8, ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero)); texture.setSubImage(Vector2i(1), BufferImage2D{ - DataStorage, PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data, DataOffset), BufferUsage::StaticDraw}); + PixelStorageData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), + PixelStorageData[testCaseInstanceId()].dataSparse, + BufferUsage::StaticDraw}); MAGNUM_VERIFY_NO_ERROR(); @@ -391,11 +411,9 @@ void RectangleTextureGLTest::subImageBuffer() { TestSuite::Compare::Container); } -void RectangleTextureGLTest::compressedSubImageBuffer() { - CORRADE_SKIP("No rectangle texture compression format exists."); -} - void RectangleTextureGLTest::subImageQuery() { + setTestCaseDescription(PixelStorageData[testCaseInstanceId()].name); + if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::texture_rectangle::string() + std::string(" is not supported.")); if(!Context::current().isExtensionSupported()) @@ -408,20 +426,20 @@ void RectangleTextureGLTest::subImageQuery() { MAGNUM_VERIFY_NO_ERROR(); Image2D image = texture.subImage(Range2Di::fromSize(Vector2i{1}, Vector2i{2}), - {DataStorage, PixelFormat::RGBA, PixelType::UnsignedByte}); + {PixelStorageData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte}); MAGNUM_VERIFY_NO_ERROR(); CORRADE_COMPARE(image.size(), Vector2i{2}); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(DataOffset), - Containers::arrayView(Data), TestSuite::Compare::Container); -} - -void RectangleTextureGLTest::compressedSubImageQuery() { - CORRADE_SKIP("No rectangle texture compression format exists."); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(PixelStorageData[testCaseInstanceId()].offset), + PixelStorageData[testCaseInstanceId()].data, + TestSuite::Compare::Container); } void RectangleTextureGLTest::subImageQueryBuffer() { + setTestCaseDescription(PixelStorageData[testCaseInstanceId()].name); + if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::texture_rectangle::string() + std::string(" is not supported.")); if(!Context::current().isExtensionSupported()) @@ -434,14 +452,36 @@ void RectangleTextureGLTest::subImageQueryBuffer() { MAGNUM_VERIFY_NO_ERROR(); BufferImage2D image = texture.subImage(Range2Di::fromSize(Vector2i{1}, Vector2i{2}), - {DataStorage, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); + {PixelStorageData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); const auto imageData = image.buffer().data(); MAGNUM_VERIFY_NO_ERROR(); CORRADE_COMPARE(image.size(), Vector2i{2}); - CORRADE_COMPARE_AS(imageData.suffix(DataOffset), - Containers::arrayView(Data), TestSuite::Compare::Container); + CORRADE_COMPARE_AS(imageData.suffix(PixelStorageData[testCaseInstanceId()].offset), + PixelStorageData[testCaseInstanceId()].data, + TestSuite::Compare::Container); +} + +void RectangleTextureGLTest::compressedImage() { + CORRADE_SKIP("No rectangle texture compression format exists."); +} + +void RectangleTextureGLTest::compressedImageBuffer() { + CORRADE_SKIP("No rectangle texture compression format exists."); +} + +void RectangleTextureGLTest::compressedSubImage() { + CORRADE_SKIP("No rectangle texture compression format exists."); +} + +void RectangleTextureGLTest::compressedSubImageBuffer() { + CORRADE_SKIP("No rectangle texture compression format exists."); +} + +void RectangleTextureGLTest::compressedSubImageQuery() { + CORRADE_SKIP("No rectangle texture compression format exists."); } void RectangleTextureGLTest::compressedSubImageQueryBuffer() { diff --git a/src/Magnum/Test/TextureArrayGLTest.cpp b/src/Magnum/Test/TextureArrayGLTest.cpp index 738f0277b..dd6ef5930 100644 --- a/src/Magnum/Test/TextureArrayGLTest.cpp +++ b/src/Magnum/Test/TextureArrayGLTest.cpp @@ -74,28 +74,21 @@ struct TextureArrayGLTest: OpenGLTester { #endif void samplingSRGBDecode2D(); - #ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES void samplingSwizzle1D(); #endif void samplingSwizzle2D(); - #else - void samplingMaxLevel2D(); - void samplingCompare2D(); - #endif #ifndef MAGNUM_TARGET_GLES void samplingBorderInteger1D(); #endif - #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) + #ifndef MAGNUM_TARGET_WEBGL void samplingBorderInteger2D(); #endif #ifndef MAGNUM_TARGET_GLES void samplingDepthStencilMode1D(); #endif - #ifndef MAGNUM_TARGET_GLES2 void samplingDepthStencilMode2D(); - #endif #ifdef MAGNUM_TARGET_GLES void samplingBorder2D(); #endif @@ -107,35 +100,35 @@ struct TextureArrayGLTest: OpenGLTester { #ifndef MAGNUM_TARGET_GLES void image1D(); - void compressedImage1D(); void image1DBuffer(); - void compressedImage1DBuffer(); - #endif - #ifndef MAGNUM_TARGET_GLES2 - void image2D(); - void compressedImage2D(); - void image2DBuffer(); - void compressedImage2DBuffer(); - #endif - - #ifndef MAGNUM_TARGET_GLES void subImage1D(); - void compressedSubImage1D(); void subImage1DBuffer(); - void compressedSubImage1DBuffer(); void subImage1DQuery(); - void compressedSubImage1DQuery(); void subImage1DQueryBuffer(); + + void compressedImage1D(); + void compressedImage1DBuffer(); + void compressedSubImage1D(); + void compressedSubImage1DBuffer(); + void compressedSubImage1DQuery(); void compressedSubImage1DQueryBuffer(); #endif + + void image2D(); + void image2DBuffer(); void subImage2D(); - void compressedSubImage2D(); void subImage2DBuffer(); - void compressedSubImage2DBuffer(); #ifndef MAGNUM_TARGET_GLES void subImage2DQuery(); - void compressedSubImage2DQuery(); void subImage2DQueryBuffer(); + #endif + + void compressedImage2D(); + void compressedImage2DBuffer(); + void compressedSubImage2D(); + void compressedSubImage2DBuffer(); + #ifndef MAGNUM_TARGET_GLES + void compressedSubImage2DQuery(); void compressedSubImage2DQueryBuffer(); #endif @@ -153,12 +146,102 @@ struct TextureArrayGLTest: OpenGLTester { void invalidateSubImage1D(); #endif void invalidateSubImage2D(); +}; +namespace { #ifndef MAGNUM_TARGET_GLES - CompressedPixelStorage _compressedDataStorage2D; - #endif - std::size_t _compressedDataOffset2D; -}; + constexpr UnsignedByte Data1D[]{ + 0, 0, 0, 0, 0, 0, 0, 0, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f + }; + + enum: std::size_t { PixelStorage1DDataCount = 2 }; + + const struct { + const char* name; + Containers::ArrayView data; + PixelStorage storage; + Containers::ArrayView dataSparse; + std::size_t offset; + } PixelStorage1DData[PixelStorage1DDataCount]{ + {"default pixel storage", + Containers::arrayView(Data1D).suffix(8), {}, + Containers::arrayView(Data1D).suffix(8), 0}, + {"skip Y", + Containers::arrayView(Data1D).suffix(8), PixelStorage{}.setSkip({0, 1, 0}), + Data1D, 8}}; + #endif + + constexpr UnsignedByte Data2D[]{ + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f + }; + + enum: std::size_t { PixelStorage2DDataCount = 2 }; + + const struct { + const char* name; + Containers::ArrayView data; + PixelStorage storage; + Containers::ArrayView dataSparse; + std::size_t offset; + } PixelStorage2DData[PixelStorage2DDataCount]{ + {"default pixel storage", + Containers::arrayView(Data2D).suffix(16), {}, + Containers::arrayView(Data2D).suffix(16), 0}, + {"skip Z", + Containers::arrayView(Data2D).suffix(16), PixelStorage{}.setSkip({0, 0, 1}), + Data2D, 16}}; + + /* Just 4x4x3 0x00 - 0x7f compressed using RGBA DXT3 by the driver */ + constexpr UnsignedByte CompressedData2D[]{ + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 17, 17, 34, 34, 51, 51, 67, + 232, 57, 0, 0, 213, 255, 170, 2, + 68, 84, 85, 101, 102, 118, 119, 119, + 239, 123, 8, 66, 213, 255, 170, 2 + }; + + enum: std::size_t { CompressedPixelStorage2DDataCount = + #ifndef MAGNUM_TARGET_GLES + 2 + #else + 1 + #endif + }; + + const struct { + const char* name; + Containers::ArrayView data; + #ifndef MAGNUM_TARGET_GLES + CompressedPixelStorage storage; + #endif + Containers::ArrayView dataSparse; + std::size_t offset; + } CompressedPixelStorage2DData[CompressedPixelStorage2DDataCount]{ + {"default pixel storage", + Containers::arrayView(CompressedData2D).suffix(16), + #ifndef MAGNUM_TARGET_GLES + {}, + #endif + Containers::arrayView(CompressedData2D).suffix(16), 0}, + #ifndef MAGNUM_TARGET_GLES + {"skip Y", + Containers::arrayView(CompressedData2D).suffix(16), + CompressedPixelStorage{} + .setCompressedBlockSize({4, 4, 1}) + .setCompressedBlockDataSize(16) + .setSkip({0, 0, 1}), CompressedData2D, 16} + #endif + }; + +} TextureArrayGLTest::TextureArrayGLTest() { addTests({ @@ -194,27 +277,21 @@ TextureArrayGLTest::TextureArrayGLTest() { #endif &TextureArrayGLTest::samplingSRGBDecode2D, - #ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES &TextureArrayGLTest::samplingSwizzle1D, #endif &TextureArrayGLTest::samplingSwizzle2D, - #else - &TextureArrayGLTest::samplingMaxLevel2D, - #endif #ifndef MAGNUM_TARGET_GLES &TextureArrayGLTest::samplingBorderInteger1D, #endif - #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) + #ifndef MAGNUM_TARGET_WEBGL &TextureArrayGLTest::samplingBorderInteger2D, #endif #ifndef MAGNUM_TARGET_GLES &TextureArrayGLTest::samplingDepthStencilMode1D, #endif - #ifndef MAGNUM_TARGET_GLES2 &TextureArrayGLTest::samplingDepthStencilMode2D, - #endif #ifdef MAGNUM_TARGET_GLES &TextureArrayGLTest::samplingBorder2D, #endif @@ -222,40 +299,49 @@ TextureArrayGLTest::TextureArrayGLTest() { #ifndef MAGNUM_TARGET_GLES &TextureArrayGLTest::storage1D, #endif - &TextureArrayGLTest::storage2D, + &TextureArrayGLTest::storage2D}); - #ifndef MAGNUM_TARGET_GLES + #ifndef MAGNUM_TARGET_GLES + addInstancedTests({ &TextureArrayGLTest::image1D, - &TextureArrayGLTest::compressedImage1D, &TextureArrayGLTest::image1DBuffer, - &TextureArrayGLTest::compressedImage1DBuffer, - #endif - &TextureArrayGLTest::image2D, - &TextureArrayGLTest::compressedImage2D, - &TextureArrayGLTest::image2DBuffer, - &TextureArrayGLTest::compressedImage2DBuffer, - - #ifndef MAGNUM_TARGET_GLES &TextureArrayGLTest::subImage1D, - &TextureArrayGLTest::compressedSubImage1D, &TextureArrayGLTest::subImage1DBuffer, - &TextureArrayGLTest::compressedSubImage1DBuffer, &TextureArrayGLTest::subImage1DQuery, - &TextureArrayGLTest::compressedSubImage1DQuery, - &TextureArrayGLTest::subImage1DQueryBuffer, - &TextureArrayGLTest::compressedSubImage1DQueryBuffer, - #endif + &TextureArrayGLTest::subImage1DQueryBuffer}, + PixelStorage1DDataCount); + + addTests({&TextureArrayGLTest::compressedImage1D, + &TextureArrayGLTest::compressedImage1DBuffer, + &TextureArrayGLTest::compressedSubImage1D, + &TextureArrayGLTest::compressedSubImage1DBuffer, + &TextureArrayGLTest::compressedSubImage1DQuery, + &TextureArrayGLTest::compressedSubImage1DQueryBuffer}); + #endif + + addInstancedTests({ + &TextureArrayGLTest::image2D, + &TextureArrayGLTest::image2DBuffer, &TextureArrayGLTest::subImage2D, - &TextureArrayGLTest::compressedSubImage2D, &TextureArrayGLTest::subImage2DBuffer, - &TextureArrayGLTest::compressedSubImage2DBuffer, #ifndef MAGNUM_TARGET_GLES &TextureArrayGLTest::subImage2DQuery, + &TextureArrayGLTest::subImage2DQueryBuffer + #endif + }, PixelStorage2DDataCount); + + addInstancedTests({ + &TextureArrayGLTest::compressedImage2D, + &TextureArrayGLTest::compressedImage2DBuffer, + &TextureArrayGLTest::compressedSubImage2D, + &TextureArrayGLTest::compressedSubImage2DBuffer, + #ifndef MAGNUM_TARGET_GLES &TextureArrayGLTest::compressedSubImage2DQuery, - &TextureArrayGLTest::subImage2DQueryBuffer, - &TextureArrayGLTest::compressedSubImage2DQueryBuffer, + &TextureArrayGLTest::compressedSubImage2DQueryBuffer #endif + }, CompressedPixelStorage2DDataCount); + addTests({ #ifndef MAGNUM_TARGET_GLES &TextureArrayGLTest::generateMipmap1D, #endif @@ -270,31 +356,7 @@ TextureArrayGLTest::TextureArrayGLTest() { &TextureArrayGLTest::invalidateSubImage1D, #endif &TextureArrayGLTest::invalidateSubImage2D - }); - - #ifndef MAGNUM_TARGET_GLES - if(Context::current().isExtensionSupported()) - { - _compressedDataStorage2D = CompressedPixelStorage{} - .setCompressedBlockSize({4, 4, 1}) - .setCompressedBlockDataSize(16) - .setSkip({0, 0, 1}); - _compressedDataOffset2D = 16; - } else - #endif - { - #ifndef MAGNUM_TARGET_GLES - _compressedDataStorage2D = {}; - #endif - _compressedDataOffset2D = 0; - } -} - -namespace { - template Containers::ArrayView unsafeSuffix(const T(&data)[size], std::size_t offset) { - static_assert(sizeof(T) == 1, ""); - return {data - offset, size + offset}; - } + }); } #ifndef MAGNUM_TARGET_GLES @@ -414,7 +476,7 @@ void TextureArrayGLTest::bind2D() { MAGNUM_VERIFY_NO_ERROR(); } -#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) +#ifndef MAGNUM_TARGET_WEBGL #ifndef MAGNUM_TARGET_GLES void TextureArrayGLTest::bindImage1D() { if(!Context::current().isExtensionSupported()) @@ -743,204 +805,56 @@ void TextureArrayGLTest::storage2D() { #endif } -namespace { - constexpr UnsignedByte Data1D[] = { 0x00, 0x01, 0x02, 0x03, - 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, - 0x0c, 0x0d, 0x0e, 0x0f }; - - const auto DataStorage1D = PixelStorage{}.setSkip({0, 1, 0}); - const std::size_t DataOffset1D = 8; -} - #ifndef MAGNUM_TARGET_GLES void TextureArrayGLTest::image1D() { + setTestCaseDescription(PixelStorage1DData[testCaseInstanceId()].name); + if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported.")); Texture1DArray texture; - texture.setImage(0, TextureFormat::RGBA8, ImageView2D{DataStorage1D, - PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data1D, DataOffset1D)}); + texture.setImage(0, TextureFormat::RGBA8, ImageView2D{ + PixelStorage1DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), PixelStorage1DData[testCaseInstanceId()].dataSparse}); MAGNUM_VERIFY_NO_ERROR(); - Image2D image = texture.image(0, {DataStorage1D, PixelFormat::RGBA, PixelType::UnsignedByte}); + Image2D image = texture.image(0, {PixelStorage1DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte}); MAGNUM_VERIFY_NO_ERROR(); CORRADE_COMPARE(image.size(), Vector2i(2)); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(DataOffset1D), - Containers::arrayView(Data1D), TestSuite::Compare::Container); -} - -void TextureArrayGLTest::compressedImage1D() { - CORRADE_SKIP("No 1D texture compression format exists."); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(PixelStorage1DData[testCaseInstanceId()].offset), + PixelStorage1DData[testCaseInstanceId()].data, + TestSuite::Compare::Container); } void TextureArrayGLTest::image1DBuffer() { + setTestCaseDescription(PixelStorage1DData[testCaseInstanceId()].name); + if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported.")); Texture1DArray texture; - texture.setImage(0, TextureFormat::RGBA8, BufferImage2D{DataStorage1D, - PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data1D, DataOffset1D), BufferUsage::StaticDraw}); + texture.setImage(0, TextureFormat::RGBA8, BufferImage2D{ + PixelStorage1DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), PixelStorage1DData[testCaseInstanceId()].dataSparse, + BufferUsage::StaticDraw}); MAGNUM_VERIFY_NO_ERROR(); BufferImage2D image = texture.image(0, - {DataStorage1D, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); + {PixelStorage1DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); const auto imageData = image.buffer().data(); MAGNUM_VERIFY_NO_ERROR(); CORRADE_COMPARE(image.size(), Vector2i(2)); - CORRADE_COMPARE_AS(imageData.suffix(DataOffset1D), - Containers::arrayView(Data1D), TestSuite::Compare::Container); -} - -void TextureArrayGLTest::compressedImage1DBuffer() { - CORRADE_SKIP("No 1D texture compression format exists."); -} -#endif - -namespace { - constexpr UnsignedByte Data2D[] = { 0x00, 0x01, 0x02, 0x03, - 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, - 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, - 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, - 0x1c, 0x1d, 0x1e, 0x1f }; - - const auto DataStorage2D = PixelStorage{}.setSkip({0, 0, 1}); - const std::size_t DataOffset2D = 16; - - /* Just 4x4x2 0x00 - 0x7f compressed using RGBA DXT3 by the driver */ - constexpr UnsignedByte CompressedData2D[] = { - 0, 17, 17, 34, 34, 51, 51, 67, - 232, 57, 0, 0, 213, 255, 170, 2, - 68, 84, 85, 101, 102, 118, 119, 119, - 239, 123, 8, 66, 213, 255, 170, 2 - }; -} - -void TextureArrayGLTest::image2D() { - #ifndef MAGNUM_TARGET_GLES - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported.")); - #endif - - Texture2DArray texture; - texture.setImage(0, TextureFormat::RGBA8, ImageView3D{DataStorage2D, - PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), unsafeSuffix(Data2D, DataOffset2D)}); - - MAGNUM_VERIFY_NO_ERROR(); - - /** @todo How to test this on ES? */ - #ifndef MAGNUM_TARGET_GLES - Image3D image = texture.image(0, {DataStorage2D, PixelFormat::RGBA, PixelType::UnsignedByte}); - - MAGNUM_VERIFY_NO_ERROR(); - - CORRADE_COMPARE(image.size(), Vector3i(2)); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(DataOffset2D), - Containers::arrayView(Data2D), TestSuite::Compare::Container); - #endif -} - -void TextureArrayGLTest::compressedImage2D() { - #ifndef MAGNUM_TARGET_GLES - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported.")); - #endif - #ifndef MAGNUM_TARGET_WEBGL - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); - #else - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::WEBGL::compressed_texture_s3tc::string() + std::string(" is not supported.")); - #endif - - Texture2DArray texture; - texture.setCompressedImage(0, CompressedImageView3D{ - #ifndef MAGNUM_TARGET_GLES - _compressedDataStorage2D, - #endif - CompressedPixelFormat::RGBAS3tcDxt3, {4, 4, 2}, unsafeSuffix(CompressedData2D, _compressedDataOffset2D)}); - - MAGNUM_VERIFY_NO_ERROR(); - - #ifndef MAGNUM_TARGET_GLES - CompressedImage3D image = texture.compressedImage(0, {_compressedDataStorage2D}); - - MAGNUM_VERIFY_NO_ERROR(); - - CORRADE_COMPARE(image.size(), (Vector3i{4, 4, 2})); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(_compressedDataOffset2D), - Containers::arrayView(CompressedData2D), - TestSuite::Compare::Container); - #endif -} - -void TextureArrayGLTest::image2DBuffer() { - #ifndef MAGNUM_TARGET_GLES - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported.")); - #endif - - Texture2DArray texture; - texture.setImage(0, TextureFormat::RGBA8, BufferImage3D{DataStorage2D, - PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), unsafeSuffix(Data2D, DataOffset2D), BufferUsage::StaticDraw}); - - MAGNUM_VERIFY_NO_ERROR(); - - /** @todo How to test this on ES? */ - #ifndef MAGNUM_TARGET_GLES - BufferImage3D image = texture.image(0, {DataStorage2D, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); - const auto imageData = image.buffer().data(); - - MAGNUM_VERIFY_NO_ERROR(); - - CORRADE_COMPARE(image.size(), Vector3i(2)); - CORRADE_COMPARE_AS(imageData.suffix(DataOffset2D), - Containers::arrayView(Data2D), TestSuite::Compare::Container); - #endif -} - -void TextureArrayGLTest::compressedImage2DBuffer() { - #ifndef MAGNUM_TARGET_GLES - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported.")); - #endif - #ifndef MAGNUM_TARGET_WEBGL - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); - #else - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::WEBGL::compressed_texture_s3tc::string() + std::string(" is not supported.")); - #endif - - Texture2DArray texture; - texture.setCompressedImage(0, CompressedImageView3D{ - #ifndef MAGNUM_TARGET_GLES - _compressedDataStorage2D, - #endif - CompressedPixelFormat::RGBAS3tcDxt3, {4, 4, 2}, unsafeSuffix(CompressedData2D, _compressedDataOffset2D)}); - - MAGNUM_VERIFY_NO_ERROR(); - - #ifndef MAGNUM_TARGET_GLES - CompressedBufferImage3D image = texture.compressedImage(0, {_compressedDataStorage2D}, BufferUsage::StaticRead); - const auto imageData = image.buffer().data(); - - MAGNUM_VERIFY_NO_ERROR(); - - CORRADE_COMPARE(image.size(), (Vector3i{4, 4, 2})); - CORRADE_COMPARE_AS(imageData.suffix(_compressedDataOffset2D), - Containers::arrayView(CompressedData2D), + CORRADE_COMPARE_AS(imageData.suffix(PixelStorage1DData[testCaseInstanceId()].offset), + PixelStorage1DData[testCaseInstanceId()].data, TestSuite::Compare::Container); - #endif } namespace { @@ -953,16 +867,18 @@ namespace { }; } -#ifndef MAGNUM_TARGET_GLES void TextureArrayGLTest::subImage1D() { + setTestCaseDescription(PixelStorage1DData[testCaseInstanceId()].name); + if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported.")); Texture1DArray texture; texture.setImage(0, TextureFormat::RGBA8, ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero1D)); - texture.setSubImage(0, Vector2i(1), ImageView2D{DataStorage1D, - PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data1D, DataOffset1D)}); + texture.setSubImage(0, Vector2i(1), ImageView2D{ + PixelStorage1DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), PixelStorage1DData[testCaseInstanceId()].dataSparse}); MAGNUM_VERIFY_NO_ERROR(); @@ -972,22 +888,24 @@ void TextureArrayGLTest::subImage1D() { CORRADE_COMPARE(image.size(), Vector2i(4)); CORRADE_COMPARE_AS(Containers::arrayCast(image.data()), - Containers::arrayView(SubData1DComplete), TestSuite::Compare::Container); -} - -void TextureArrayGLTest::compressedSubImage1D() { - CORRADE_SKIP("No 1D texture compression format exists."); + Containers::arrayView(SubData1DComplete), + TestSuite::Compare::Container); } void TextureArrayGLTest::subImage1DBuffer() { + setTestCaseDescription(PixelStorage1DData[testCaseInstanceId()].name); + if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported.")); Texture1DArray texture; texture.setImage(0, TextureFormat::RGBA8, ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero1D)); - texture.setSubImage(0, Vector2i(1), BufferImage2D{DataStorage1D, - PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data1D, DataOffset1D), BufferUsage::StaticDraw}); + texture.setSubImage(0, Vector2i(1), BufferImage2D{ + PixelStorage1DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), + PixelStorage1DData[testCaseInstanceId()].dataSparse, + BufferUsage::StaticDraw}); MAGNUM_VERIFY_NO_ERROR(); @@ -1001,11 +919,9 @@ void TextureArrayGLTest::subImage1DBuffer() { TestSuite::Compare::Container); } -void TextureArrayGLTest::compressedSubImage1DBuffer() { - CORRADE_SKIP("No 1D texture compression format exists."); -} - void TextureArrayGLTest::subImage1DQuery() { + setTestCaseDescription(PixelStorage1DData[testCaseInstanceId()].name); + if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported.")); if(!Context::current().isExtensionSupported()) @@ -1018,20 +934,20 @@ void TextureArrayGLTest::subImage1DQuery() { MAGNUM_VERIFY_NO_ERROR(); Image2D image = texture.subImage(0, Range2Di::fromSize(Vector2i{1}, Vector2i{2}), - {DataStorage1D, PixelFormat::RGBA, PixelType::UnsignedByte}); + {PixelStorage1DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte}); MAGNUM_VERIFY_NO_ERROR(); CORRADE_COMPARE(image.size(), Vector2i{2}); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(DataOffset1D), - Containers::arrayView(Data1D), TestSuite::Compare::Container); -} - -void TextureArrayGLTest::compressedSubImage1DQuery() { - CORRADE_SKIP("No 1D texture compression format exists."); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(PixelStorage1DData[testCaseInstanceId()].offset), + PixelStorage1DData[testCaseInstanceId()].data, + TestSuite::Compare::Container); } void TextureArrayGLTest::subImage1DQueryBuffer() { + setTestCaseDescription(PixelStorage1DData[testCaseInstanceId()].name); + if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported.")); if(!Context::current().isExtensionSupported()) @@ -1044,28 +960,109 @@ void TextureArrayGLTest::subImage1DQueryBuffer() { MAGNUM_VERIFY_NO_ERROR(); BufferImage2D image = texture.subImage(0, Range2Di::fromSize(Vector2i{1}, Vector2i{2}), - {DataStorage1D, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); + {PixelStorage1DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); const auto imageData = image.buffer().data(); MAGNUM_VERIFY_NO_ERROR(); CORRADE_COMPARE(image.size(), Vector2i{2}); - CORRADE_COMPARE_AS(imageData.suffix(DataOffset1D), - Containers::arrayView(Data1D), TestSuite::Compare::Container); + CORRADE_COMPARE_AS(imageData.suffix(PixelStorage1DData[testCaseInstanceId()].offset), + PixelStorage1DData[testCaseInstanceId()].data, + TestSuite::Compare::Container); } -void TextureArrayGLTest::compressedSubImage1DQueryBuffer() { +void TextureArrayGLTest::compressedImage1D() { CORRADE_SKIP("No 1D texture compression format exists."); } -#endif -namespace { - constexpr UnsignedByte Zero2D[4*4*4*4] = {}; +void TextureArrayGLTest::compressedImage1DBuffer() { + CORRADE_SKIP("No 1D texture compression format exists."); +} - /* Just 12x4x4 zeros compressed using RGBA DXT3 by the driver */ - constexpr UnsignedByte CompressedZero2D[3*4*16] = {}; +void TextureArrayGLTest::compressedSubImage1D() { + CORRADE_SKIP("No 1D texture compression format exists."); +} + +void TextureArrayGLTest::compressedSubImage1DBuffer() { + CORRADE_SKIP("No 1D texture compression format exists."); +} + +void TextureArrayGLTest::compressedSubImage1DQuery() { + CORRADE_SKIP("No 1D texture compression format exists."); +} + +void TextureArrayGLTest::compressedSubImage1DQueryBuffer() { + CORRADE_SKIP("No 1D texture compression format exists."); +} +#endif + +void TextureArrayGLTest::image2D() { + setTestCaseDescription(PixelStorage2DData[testCaseInstanceId()].name); + + #ifndef MAGNUM_TARGET_GLES + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported.")); + #endif - constexpr UnsignedByte SubData2DComplete[] = { + Texture2DArray texture; + texture.setImage(0, TextureFormat::RGBA8, ImageView3D{ + PixelStorage2DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), + PixelStorage2DData[testCaseInstanceId()].dataSparse}); + + MAGNUM_VERIFY_NO_ERROR(); + + /** @todo How to test this on ES? */ + #ifndef MAGNUM_TARGET_GLES + Image3D image = texture.image(0, {PixelStorage2DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte}); + + MAGNUM_VERIFY_NO_ERROR(); + + CORRADE_COMPARE(image.size(), Vector3i(2)); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(PixelStorage2DData[testCaseInstanceId()].offset), + PixelStorage2DData[testCaseInstanceId()].data, + TestSuite::Compare::Container); + #endif +} + +void TextureArrayGLTest::image2DBuffer() { + setTestCaseDescription(PixelStorage2DData[testCaseInstanceId()].name); + + #ifndef MAGNUM_TARGET_GLES + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported.")); + #endif + + Texture2DArray texture; + texture.setImage(0, TextureFormat::RGBA8, BufferImage3D{ + PixelStorage2DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), + PixelStorage2DData[testCaseInstanceId()].dataSparse, + BufferUsage::StaticDraw}); + + MAGNUM_VERIFY_NO_ERROR(); + + /** @todo How to test this on ES? */ + #ifndef MAGNUM_TARGET_GLES + BufferImage3D image = texture.image(0, {PixelStorage2DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); + const auto imageData = image.buffer().data(); + + MAGNUM_VERIFY_NO_ERROR(); + + CORRADE_COMPARE(image.size(), Vector3i(2)); + CORRADE_COMPARE_AS(imageData.suffix(PixelStorage2DData[testCaseInstanceId()].offset), + PixelStorage2DData[testCaseInstanceId()].data, + TestSuite::Compare::Container); + #endif +} + +namespace { + constexpr UnsignedByte Zero2D[4*4*4*4]{}; + + constexpr UnsignedByte SubData2DComplete[]{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -1086,40 +1083,11 @@ namespace { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - - /* Combination of CompressedZero2D and CompressedData2D */ - constexpr UnsignedByte CompressedSubData2DComplete[] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 17, 17, 34, 34, 51, 51, 67, - 232, 57, 0, 0, 213, 255, 170, 2, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 68, 84, 85, 101, 102, 118, 119, 119, - 239, 123, 8, 66, 213, 255, 170, 2, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 - }; } void TextureArrayGLTest::subImage2D() { + setTestCaseDescription(PixelStorage2DData[testCaseInstanceId()].name); + #ifndef MAGNUM_TARGET_GLES if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported.")); @@ -1128,8 +1096,10 @@ void TextureArrayGLTest::subImage2D() { Texture2DArray texture; texture.setImage(0, TextureFormat::RGBA8, ImageView3D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(4), Zero2D)); - texture.setSubImage(0, Vector3i(1), ImageView3D{DataStorage2D, - PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), unsafeSuffix(Data2D, DataOffset2D)}); + texture.setSubImage(0, Vector3i(1), ImageView3D{ + PixelStorage2DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), + PixelStorage2DData[testCaseInstanceId()].dataSparse}); MAGNUM_VERIFY_NO_ERROR(); @@ -1146,7 +1116,96 @@ void TextureArrayGLTest::subImage2D() { #endif } -void TextureArrayGLTest::compressedSubImage2D() { +void TextureArrayGLTest::subImage2DBuffer() { + setTestCaseDescription(PixelStorage2DData[testCaseInstanceId()].name); + + #ifndef MAGNUM_TARGET_GLES + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported.")); + #endif + + Texture2DArray texture; + texture.setImage(0, TextureFormat::RGBA8, + ImageView3D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(4), Zero2D)); + texture.setSubImage(0, Vector3i(1), BufferImage3D{ + PixelStorage2DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), + PixelStorage2DData[testCaseInstanceId()].dataSparse, + BufferUsage::StaticDraw}); + + MAGNUM_VERIFY_NO_ERROR(); + + /** @todo How to test this on ES? */ + #ifndef MAGNUM_TARGET_GLES + BufferImage3D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); + const auto imageData = image.buffer().data(); + + MAGNUM_VERIFY_NO_ERROR(); + + CORRADE_COMPARE(image.size(), Vector3i(4)); + CORRADE_COMPARE_AS(imageData, Containers::arrayView(SubData2DComplete), + TestSuite::Compare::Container); + #endif +} + +#ifndef MAGNUM_TARGET_GLES +void TextureArrayGLTest::subImage2DQuery() { + setTestCaseDescription(PixelStorage2DData[testCaseInstanceId()].name); + + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported.")); + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); + + Texture2DArray texture; + texture.setStorage(1, TextureFormat::RGBA8, Vector3i{4}) + .setSubImage(0, {}, ImageView3D{PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i{4}, SubData2DComplete}); + + MAGNUM_VERIFY_NO_ERROR(); + + Image3D image = texture.subImage(0, Range3Di::fromSize(Vector3i{1}, Vector3i{2}), + {PixelStorage2DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte}); + + MAGNUM_VERIFY_NO_ERROR(); + + CORRADE_COMPARE(image.size(), Vector3i{2}); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(PixelStorage2DData[testCaseInstanceId()].offset), + PixelStorage2DData[testCaseInstanceId()].data, + TestSuite::Compare::Container); +} + +void TextureArrayGLTest::subImage2DQueryBuffer() { + setTestCaseDescription(PixelStorage2DData[testCaseInstanceId()].name); + + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported.")); + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); + + Texture2DArray texture; + texture.setStorage(1, TextureFormat::RGBA8, Vector3i{4}) + .setSubImage(0, {}, ImageView3D{PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i{4}, SubData2DComplete}); + + MAGNUM_VERIFY_NO_ERROR(); + + BufferImage3D image = texture.subImage(0, Range3Di::fromSize(Vector3i{1}, Vector3i{2}), + {PixelStorage2DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); + const auto imageData = image.buffer().data(); + + MAGNUM_VERIFY_NO_ERROR(); + + CORRADE_COMPARE(image.size(), Vector3i{2}); + CORRADE_COMPARE_AS(imageData.suffix(PixelStorage2DData[testCaseInstanceId()].offset), + PixelStorage2DData[testCaseInstanceId()].data, + TestSuite::Compare::Container); +} +#endif + +void TextureArrayGLTest::compressedImage2D() { + setTestCaseDescription(CompressedPixelStorage2DData[testCaseInstanceId()].name); + #ifndef MAGNUM_TARGET_GLES if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported.")); @@ -1160,85 +1219,115 @@ void TextureArrayGLTest::compressedSubImage2D() { #endif #ifndef MAGNUM_TARGET_GLES - /* Compressed pixel storage for array textures is underspecified. If the - extension is supported, first test with default values to ensure we are - not that far off, then continue as usual */ - if(Context::current().isExtensionSupported()) { - Texture2DArray texture; - texture.setCompressedImage(0, CompressedImageView3D{CompressedPixelFormat::RGBAS3tcDxt3, - Vector3i{12, 4, 4}, CompressedZero2D}); - texture.setCompressedSubImage(0, {4, 0, 1}, CompressedImageView3D{CompressedPixelFormat::RGBAS3tcDxt3, {4, 4, 2}, CompressedData2D}); - - MAGNUM_VERIFY_NO_ERROR(); - - CompressedImage3D image = texture.compressedImage(0, {}); - - MAGNUM_VERIFY_NO_ERROR(); - - CORRADE_COMPARE(image.size(), (Vector3i{12, 4, 4})); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()), - Containers::arrayView(CompressedSubData2DComplete), - TestSuite::Compare::Container); - } + if(CompressedPixelStorage2DData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); #endif Texture2DArray texture; - texture.setCompressedImage(0, CompressedImageView3D{CompressedPixelFormat::RGBAS3tcDxt3, - Vector3i{12, 4, 4}, CompressedZero2D}); - texture.setCompressedSubImage(0, {4, 0, 1}, CompressedImageView3D{ + texture.setCompressedImage(0, CompressedImageView3D{ #ifndef MAGNUM_TARGET_GLES - _compressedDataStorage2D, + CompressedPixelStorage2DData[testCaseInstanceId()].storage, #endif - CompressedPixelFormat::RGBAS3tcDxt3, {4, 4, 2}, unsafeSuffix(CompressedData2D, _compressedDataOffset2D)}); + CompressedPixelFormat::RGBAS3tcDxt3, {4, 4, 2}, + CompressedPixelStorage2DData[testCaseInstanceId()].dataSparse}); MAGNUM_VERIFY_NO_ERROR(); #ifndef MAGNUM_TARGET_GLES - CompressedImage3D image = texture.compressedImage(0, {}); + CompressedImage3D image = texture.compressedImage(0, {CompressedPixelStorage2DData[testCaseInstanceId()].storage}); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), (Vector3i{12, 4, 4})); - - { - CORRADE_EXPECT_FAIL_IF(Context::current().isExtensionSupported() && (Context::current().detectedDriver() & Context::DetectedDriver::NVidia), - "Non-default compressed pixel storage for array textures behaves weirdly on NVidia"); - - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()), - Containers::arrayView(CompressedSubData2DComplete), - TestSuite::Compare::Container); - } + CORRADE_COMPARE(image.size(), (Vector3i{4, 4, 2})); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(CompressedPixelStorage2DData[testCaseInstanceId()].offset), + CompressedPixelStorage2DData[testCaseInstanceId()].data, + TestSuite::Compare::Container); #endif } -void TextureArrayGLTest::subImage2DBuffer() { +void TextureArrayGLTest::compressedImage2DBuffer() { + setTestCaseDescription(CompressedPixelStorage2DData[testCaseInstanceId()].name); + #ifndef MAGNUM_TARGET_GLES if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported.")); #endif + #ifndef MAGNUM_TARGET_WEBGL + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); + #else + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::WEBGL::compressed_texture_s3tc::string() + std::string(" is not supported.")); + #endif + + #ifndef MAGNUM_TARGET_GLES + if(CompressedPixelStorage2DData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); + #endif Texture2DArray texture; - texture.setImage(0, TextureFormat::RGBA8, - ImageView3D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(4), Zero2D)); - texture.setSubImage(0, Vector3i(1), BufferImage3D{DataStorage2D, - PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), unsafeSuffix(Data2D, DataOffset2D), BufferUsage::StaticDraw}); + texture.setCompressedImage(0, CompressedBufferImage3D{ + #ifndef MAGNUM_TARGET_GLES + CompressedPixelStorage2DData[testCaseInstanceId()].storage, + #endif + CompressedPixelFormat::RGBAS3tcDxt3, {4, 4, 2}, + CompressedPixelStorage2DData[testCaseInstanceId()].dataSparse, + BufferUsage::StaticDraw}); MAGNUM_VERIFY_NO_ERROR(); - /** @todo How to test this on ES? */ #ifndef MAGNUM_TARGET_GLES - BufferImage3D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); + CompressedBufferImage3D image = texture.compressedImage(0, {CompressedPixelStorage2DData[testCaseInstanceId()].storage}, BufferUsage::StaticRead); const auto imageData = image.buffer().data(); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), Vector3i(4)); - CORRADE_COMPARE_AS(imageData, Containers::arrayView(SubData2DComplete), + CORRADE_COMPARE(image.size(), (Vector3i{4, 4, 2})); + CORRADE_COMPARE_AS(imageData.suffix(CompressedPixelStorage2DData[testCaseInstanceId()].offset), + CompressedPixelStorage2DData[testCaseInstanceId()].data, TestSuite::Compare::Container); #endif } -void TextureArrayGLTest::compressedSubImage2DBuffer() { +namespace { + /* Just 12x4x4 zeros compressed using RGBA DXT3 by the driver */ + constexpr UnsignedByte CompressedZero2D[3*4*16]{}; + + /* Combination of CompressedZero2D and CompressedData2D */ + constexpr UnsignedByte CompressedSubData2DComplete[]{ + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 17, 17, 34, 34, 51, 51, 67, + 232, 57, 0, 0, 213, 255, 170, 2, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 68, 84, 85, 101, 102, 118, 119, 119, + 239, 123, 8, 66, 213, 255, 170, 2, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 + }; +} + +void TextureArrayGLTest::compressedSubImage2D() { + setTestCaseDescription(CompressedPixelStorage2DData[testCaseInstanceId()].name); + #ifndef MAGNUM_TARGET_GLES if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported.")); @@ -1252,26 +1341,8 @@ void TextureArrayGLTest::compressedSubImage2DBuffer() { #endif #ifndef MAGNUM_TARGET_GLES - /* Compressed pixel storage for array textures is underspecified. If the - extension is supported, first test with default values to ensure we are - not that far off, then continue as usual */ - if(Context::current().isExtensionSupported()) { - Texture2DArray texture; - texture.setCompressedImage(0, CompressedImageView3D{CompressedPixelFormat::RGBAS3tcDxt3, - Vector3i{12, 4, 4}, CompressedZero2D}); - texture.setCompressedSubImage(0, {4, 0, 1}, CompressedImageView3D{CompressedPixelFormat::RGBAS3tcDxt3, {4, 4, 2}, CompressedData2D}); - - MAGNUM_VERIFY_NO_ERROR(); - - CompressedBufferImage3D image = texture.compressedImage(0, {}, BufferUsage::StaticRead); - const auto imageData = image.buffer().data(); - - MAGNUM_VERIFY_NO_ERROR(); - - CORRADE_COMPARE(image.size(), (Vector3i{12, 4, 4})); - CORRADE_COMPARE_AS(imageData, Containers::arrayView(CompressedSubData2DComplete), - TestSuite::Compare::Container); - } + if(CompressedPixelStorage2DData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); #endif Texture2DArray texture; @@ -1279,60 +1350,89 @@ void TextureArrayGLTest::compressedSubImage2DBuffer() { Vector3i{12, 4, 4}, CompressedZero2D}); texture.setCompressedSubImage(0, {4, 0, 1}, CompressedImageView3D{ #ifndef MAGNUM_TARGET_GLES - _compressedDataStorage2D, + CompressedPixelStorage2DData[testCaseInstanceId()].storage, #endif - CompressedPixelFormat::RGBAS3tcDxt3, {4, 4, 2}, unsafeSuffix(CompressedData2D, _compressedDataOffset2D)}); + CompressedPixelFormat::RGBAS3tcDxt3, {4, 4, 2}, + CompressedPixelStorage2DData[testCaseInstanceId()].dataSparse}); MAGNUM_VERIFY_NO_ERROR(); #ifndef MAGNUM_TARGET_GLES - CompressedBufferImage3D image = texture.compressedImage(0, {}, BufferUsage::StaticRead); - const auto imageData = image.buffer().data(); + CompressedImage3D image = texture.compressedImage(0, {}); MAGNUM_VERIFY_NO_ERROR(); CORRADE_COMPARE(image.size(), (Vector3i{12, 4, 4})); { - CORRADE_EXPECT_FAIL_IF(Context::current().isExtensionSupported() && (Context::current().detectedDriver() & Context::DetectedDriver::NVidia), + CORRADE_EXPECT_FAIL_IF(CompressedPixelStorage2DData[testCaseInstanceId()].storage != CompressedPixelStorage{} && (Context::current().detectedDriver() & Context::DetectedDriver::NVidia), "Non-default compressed pixel storage for array textures behaves weirdly on NVidia"); - CORRADE_COMPARE_AS(imageData, Containers::arrayView(CompressedSubData2DComplete), + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()), + Containers::arrayView(CompressedSubData2DComplete), TestSuite::Compare::Container); } #endif } -#ifndef MAGNUM_TARGET_GLES -void TextureArrayGLTest::subImage2DQuery() { +void TextureArrayGLTest::compressedSubImage2DBuffer() { + setTestCaseDescription(CompressedPixelStorage2DData[testCaseInstanceId()].name); + + #ifndef MAGNUM_TARGET_GLES if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported.")); - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); + #endif + #ifndef MAGNUM_TARGET_WEBGL + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); + #else + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::WEBGL::compressed_texture_s3tc::string() + std::string(" is not supported.")); + #endif + + #ifndef MAGNUM_TARGET_GLES + if(CompressedPixelStorage2DData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); + #endif Texture2DArray texture; - texture.setStorage(1, TextureFormat::RGBA8, Vector3i{4}) - .setSubImage(0, {}, ImageView3D{PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i{4}, SubData2DComplete}); + texture.setCompressedImage(0, CompressedImageView3D{CompressedPixelFormat::RGBAS3tcDxt3, + Vector3i{12, 4, 4}, CompressedZero2D}); + texture.setCompressedSubImage(0, {4, 0, 1}, CompressedBufferImage3D{ + #ifndef MAGNUM_TARGET_GLES + CompressedPixelStorage2DData[testCaseInstanceId()].storage, + #endif + CompressedPixelFormat::RGBAS3tcDxt3, {4, 4, 2}, + CompressedPixelStorage2DData[testCaseInstanceId()].dataSparse, + BufferUsage::StaticDraw}); MAGNUM_VERIFY_NO_ERROR(); - Image3D image = texture.subImage(0, Range3Di::fromSize(Vector3i{1}, Vector3i{2}), - {DataStorage2D, PixelFormat::RGBA, PixelType::UnsignedByte}); + #ifndef MAGNUM_TARGET_GLES + CompressedBufferImage3D image = texture.compressedImage(0, {}, BufferUsage::StaticRead); + const auto imageData = image.buffer().data(); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), Vector3i{2}); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(DataOffset2D), - Containers::arrayView(Data2D), TestSuite::Compare::Container); + CORRADE_COMPARE(image.size(), (Vector3i{12, 4, 4})); + CORRADE_COMPARE_AS(imageData, + Containers::arrayView(CompressedSubData2DComplete), + TestSuite::Compare::Container); + #endif } +#ifndef MAGNUM_TARGET_GLES void TextureArrayGLTest::compressedSubImage2DQuery() { + setTestCaseDescription(CompressedPixelStorage2DData[testCaseInstanceId()].name); + if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported.")); if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); + if(CompressedPixelStorage2DData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); Texture2DArray texture; texture.setStorage(1, TextureFormat::CompressedRGBAS3tcDxt3, {12, 4, 4}) @@ -1341,59 +1441,27 @@ void TextureArrayGLTest::compressedSubImage2DQuery() { MAGNUM_VERIFY_NO_ERROR(); - /* Test also without compressed pixel storage to ensure that both size - computations work */ - if(Context::current().isExtensionSupported()) { - CompressedImage3D image = texture.compressedSubImage(0, Range3Di::fromSize({4, 0, 1}, {4, 4, 2}), {}); - - MAGNUM_VERIFY_NO_ERROR(); - - CORRADE_COMPARE(image.size(), (Vector3i{4, 4, 2})); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()), - Containers::arrayView(CompressedData2D), - TestSuite::Compare::Container); - } - - CompressedImage3D image = texture.compressedSubImage(0, Range3Di::fromSize({4, 0, 1}, {4, 4, 2}), {_compressedDataStorage2D}); + CompressedImage3D image = texture.compressedSubImage(0, Range3Di::fromSize({4, 0, 1}, {4, 4, 2}), {CompressedPixelStorage2DData[testCaseInstanceId()].storage}); MAGNUM_VERIFY_NO_ERROR(); CORRADE_COMPARE(image.size(), (Vector3i{4, 4, 2})); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(_compressedDataOffset2D), - Containers::arrayView(CompressedData2D), + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(CompressedPixelStorage2DData[testCaseInstanceId()].offset), + CompressedPixelStorage2DData[testCaseInstanceId()].data, TestSuite::Compare::Container); } -void TextureArrayGLTest::subImage2DQueryBuffer() { - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported.")); - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); - - Texture2DArray texture; - texture.setStorage(1, TextureFormat::RGBA8, Vector3i{4}) - .setSubImage(0, {}, ImageView3D{PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i{4}, SubData2DComplete}); - - MAGNUM_VERIFY_NO_ERROR(); - - BufferImage3D image = texture.subImage(0, Range3Di::fromSize(Vector3i{1}, Vector3i{2}), - {DataStorage2D, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); - const auto imageData = image.buffer().data(); - - MAGNUM_VERIFY_NO_ERROR(); - - CORRADE_COMPARE(image.size(), Vector3i{2}); - CORRADE_COMPARE_AS(imageData.suffix(DataOffset2D), - Containers::arrayView(Data2D), TestSuite::Compare::Container); -} - void TextureArrayGLTest::compressedSubImage2DQueryBuffer() { + setTestCaseDescription(CompressedPixelStorage2DData[testCaseInstanceId()].name); + if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported.")); if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); + if(CompressedPixelStorage2DData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); Texture2DArray texture; texture.setStorage(1, TextureFormat::CompressedRGBAS3tcDxt3, {12, 4, 4}) @@ -1404,18 +1472,16 @@ void TextureArrayGLTest::compressedSubImage2DQueryBuffer() { CompressedBufferImage3D image = texture.compressedSubImage(0, Range3Di::fromSize({4, 0, 1}, {4, 4, 2}), { #ifndef MAGNUM_TARGET_GLES - _compressedDataStorage2D + CompressedPixelStorage2DData[testCaseInstanceId()].storage #endif }, BufferUsage::StaticRead); - - MAGNUM_VERIFY_NO_ERROR(); const auto imageData = image.buffer().data(); MAGNUM_VERIFY_NO_ERROR(); CORRADE_COMPARE(image.size(), (Vector3i{4, 4, 2})); - CORRADE_COMPARE_AS(imageData.suffix(_compressedDataOffset2D), - Containers::arrayView(CompressedData2D), + CORRADE_COMPARE_AS(imageData.suffix(CompressedPixelStorage2DData[testCaseInstanceId()].offset), + CompressedPixelStorage2DData[testCaseInstanceId()].data, TestSuite::Compare::Container); } diff --git a/src/Magnum/Test/TextureGLTest.cpp b/src/Magnum/Test/TextureGLTest.cpp index 9faf98d53..035606d7d 100644 --- a/src/Magnum/Test/TextureGLTest.cpp +++ b/src/Magnum/Test/TextureGLTest.cpp @@ -123,57 +123,69 @@ struct TextureGLTest: OpenGLTester { #ifndef MAGNUM_TARGET_GLES void image1D(); - void compressedImage1D(); - #endif - #ifndef MAGNUM_TARGET_GLES2 void image1DBuffer(); + void subImage1D(); + void subImage1DBuffer(); + void subImage1DQuery(); + void subImage1DQueryBuffer(); + + void compressedImage1D(); void compressedImage1DBuffer(); + void compressedSubImage1D(); + void compressedSubImage1DBuffer(); + void compressedSubImage1DQuery(); + void compressedSubImage1DQueryBuffer(); #endif + void image2D(); - void compressedImage2D(); #ifndef MAGNUM_TARGET_GLES2 void image2DBuffer(); - void compressedImage2DBuffer(); #endif - void image3D(); - void compressedImage3D(); + void subImage2D(); #ifndef MAGNUM_TARGET_GLES2 - void image3DBuffer(); - void compressedImage3DBuffer(); + void subImage2DBuffer(); #endif - #ifndef MAGNUM_TARGET_GLES - void subImage1D(); - void compressedSubImage1D(); - void subImage1DBuffer(); - void compressedSubImage1DBuffer(); - void subImage1DQuery(); - void compressedSubImage1DQuery(); - void subImage1DQueryBuffer(); - void compressedSubImage1DQueryBuffer(); + void subImage2DQuery(); + void subImage2DQueryBuffer(); + #endif + + void compressedImage2D(); + #ifndef MAGNUM_TARGET_GLES2 + void compressedImage2DBuffer(); #endif - void subImage2D(); void compressedSubImage2D(); #ifndef MAGNUM_TARGET_GLES2 - void subImage2DBuffer(); void compressedSubImage2DBuffer(); #endif #ifndef MAGNUM_TARGET_GLES - void subImage2DQuery(); void compressedSubImage2DQuery(); - void subImage2DQueryBuffer(); void compressedSubImage2DQueryBuffer(); #endif + + void image3D(); + #ifndef MAGNUM_TARGET_GLES2 + void image3DBuffer(); + #endif void subImage3D(); - void compressedSubImage3D(); #ifndef MAGNUM_TARGET_GLES2 void subImage3DBuffer(); - void compressedSubImage3DBuffer(); #endif #ifndef MAGNUM_TARGET_GLES void subImage3DQuery(); - void compressedSubImage3DQuery(); void subImage3DQueryBuffer(); + #endif + + void compressedImage3D(); + #ifndef MAGNUM_TARGET_GLES2 + void compressedImage3DBuffer(); + #endif + void compressedSubImage3D(); + #ifndef MAGNUM_TARGET_GLES2 + void compressedSubImage3DBuffer(); + #endif + #ifndef MAGNUM_TARGET_GLES + void compressedSubImage3DQuery(); void compressedSubImage3DQueryBuffer(); #endif @@ -194,15 +206,191 @@ struct TextureGLTest: OpenGLTester { #endif void invalidateSubImage2D(); void invalidateSubImage3D(); +}; - PixelStorage _dataStorage2D, _dataStorage3D; - std::size_t _dataOffset2D, _dataOffset3D; - +namespace { #ifndef MAGNUM_TARGET_GLES - CompressedPixelStorage _compressedDataStorage2D, _compressedDataStorage3D; - #endif - std::size_t _compressedDataOffset2D, _compressedDataOffset3D; -}; + constexpr UnsignedByte Data1D[]{ + 0, 0, 0, 0, + 0x00, 0x01, 0x02, 0x03, + 0x04, 0x05, 0x06, 0x07 + }; + + enum: std::size_t { PixelStorage1DDataCount = 2 }; + + const struct { + const char* name; + Containers::ArrayView data; + PixelStorage storage; + Containers::ArrayView dataSparse; + std::size_t offset; + } PixelStorage1DData[PixelStorage1DDataCount]{ + {"default pixel storage", + Containers::arrayView(Data1D).suffix(4), {}, + Containers::arrayView(Data1D).suffix(4), 0}, + {"skip X", + Containers::arrayView(Data1D).suffix(4), PixelStorage{}.setSkip({1, 0, 0}), + Data1D, 4}}; + #endif + + constexpr UnsignedByte Data2D[]{ + 0, 0, 0, 0, 0, 0, 0, 0, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f + }; + + enum: std::size_t { PixelStorage2DDataCount = + #if !defined(MAGNUM_TARGET_GLES2) || !defined(MAGNUM_TARGET_WEBGL) + 2 + #else + 1 + #endif + }; + + const struct { + const char* name; + Containers::ArrayView data; + PixelStorage storage; + Containers::ArrayView dataSparse; + std::size_t offset; + } PixelStorage2DData[PixelStorage2DDataCount]{ + {"default pixel storage", + Containers::arrayView(Data2D).suffix(8), {}, + Containers::arrayView(Data2D).suffix(8), 0}, + #if !defined(MAGNUM_TARGET_GLES2) || !defined(MAGNUM_TARGET_WEBGL) + {"skip Y", + Containers::arrayView(Data2D).suffix(8), PixelStorage{}.setSkip({0, 1, 0}), + Data2D, 8} + #endif + }; + + /* Just 4x8 0x00 - 0x3f compressed using RGBA DXT3 by the driver */ + constexpr UnsignedByte CompressedData2D[]{ + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 17, 17, 34, 34, 51, 51, 67, + 232, 57, 0, 0, 213, 255, 170, 2 + }; + + enum: std::size_t { CompressedPixelStorage2DDataCount = + #ifndef MAGNUM_TARGET_GLES + 2 + #else + 1 + #endif + }; + + const struct { + const char* name; + Containers::ArrayView data; + #ifndef MAGNUM_TARGET_GLES + CompressedPixelStorage storage; + #endif + Containers::ArrayView dataSparse; + std::size_t offset; + } CompressedPixelStorage2DData[CompressedPixelStorage2DDataCount]{ + {"default pixel storage", + Containers::arrayView(CompressedData2D).suffix(16), + #ifndef MAGNUM_TARGET_GLES + {}, + #endif + Containers::arrayView(CompressedData2D).suffix(16), 0}, + #ifndef MAGNUM_TARGET_GLES + {"skip Y", + Containers::arrayView(CompressedData2D).suffix(16), + CompressedPixelStorage{} + .setCompressedBlockSize({4, 4, 1}) + .setCompressedBlockDataSize(16) + .setSkip({0, 4, 0}), CompressedData2D, 16} + #endif + }; + + constexpr UnsignedByte Data3D[]{ + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }; + + enum: std::size_t { PixelStorage3DDataCount = + #if !defined(MAGNUM_TARGET_GLES2) || !defined(MAGNUM_TARGET_WEBGL) + 2 + #else + 1 + #endif + }; + + const struct { + const char* name; + Containers::ArrayView data; + PixelStorage storage; + Containers::ArrayView dataSparse; + std::size_t offset; + } PixelStorage3DData[PixelStorage3DDataCount]{ + {"default pixel storage", + Containers::arrayView(Data3D).suffix(16), {}, + Containers::arrayView(Data3D).suffix(16), 0}, + #if !defined(MAGNUM_TARGET_GLES2) || !defined(MAGNUM_TARGET_WEBGL) + {"skip Z", + Containers::arrayView(Data3D).suffix(16), PixelStorage{}.setSkip({0, 0, 1}), + Data3D, 16} + #endif + }; + + /* Just 4x4x8 0x00 - 0xff compressed using RGBA BPTC Unorm by the driver */ + constexpr UnsignedByte CompressedData3D[]{ + 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + + 144, 224, 128, 3, 80, 0, 129, 170, + 84, 253, 73, 36, 109, 100, 107, 255, + 144, 232, 161, 135, 94, 244, 129, 170, + 84, 253, 65, 34, 109, 100, 107, 255, + + 144, 240, 194, 11, 47, 248, 130, 170, + 84, 253, 65, 34, 109, 100, 107, 251, + 144, 247, 223, 143, 63, 252, 131, 170, + 84, 253, 73, 34, 109, 100, 91, 251 + }; + + enum: std::size_t { CompressedPixelStorage3DDataCount = + #ifndef MAGNUM_TARGET_GLES + 2 + #else + 1 + #endif + }; + + const struct { + const char* name; + Containers::ArrayView data; + #ifndef MAGNUM_TARGET_GLES + CompressedPixelStorage storage; + #endif + Containers::ArrayView dataSparse; + std::size_t offset; + } CompressedPixelStorage3DData[CompressedPixelStorage3DDataCount]{ + {"default pixel storage", + Containers::arrayView(CompressedData3D).suffix(16*4), + #ifndef MAGNUM_TARGET_GLES + {}, + #endif + Containers::arrayView(CompressedData3D).suffix(16*4), {}}, + #ifndef MAGNUM_TARGET_GLES + {"skip Z", + Containers::arrayView(CompressedData3D).suffix(16*4), + CompressedPixelStorage{} + .setCompressedBlockSize({4, 4, 4}) + .setCompressedBlockDataSize(16*4) + .setSkip({0, 0, 4}), CompressedData3D, 16*4} + #endif + }; +} TextureGLTest::TextureGLTest() { addTests({ @@ -279,62 +467,87 @@ TextureGLTest::TextureGLTest() { &TextureGLTest::storage1D, #endif &TextureGLTest::storage2D, - &TextureGLTest::storage3D, + &TextureGLTest::storage3D}); - #ifndef MAGNUM_TARGET_GLES + #ifndef MAGNUM_TARGET_GLES + addInstancedTests({ &TextureGLTest::image1D, - &TextureGLTest::compressedImage1D, &TextureGLTest::image1DBuffer, - &TextureGLTest::compressedImage1DBuffer, - #endif + &TextureGLTest::subImage1D, + &TextureGLTest::subImage1DBuffer, + &TextureGLTest::subImage1DQuery, + &TextureGLTest::subImage1DQueryBuffer}, + PixelStorage1DDataCount); + + addTests({&TextureGLTest::compressedImage1D, + &TextureGLTest::compressedImage1DBuffer, + &TextureGLTest::compressedSubImage1D, + &TextureGLTest::compressedSubImage1DBuffer, + &TextureGLTest::compressedSubImage1DQuery, + &TextureGLTest::compressedSubImage1DQueryBuffer}); + #endif + + addInstancedTests({ &TextureGLTest::image2D, - &TextureGLTest::compressedImage2D, #ifndef MAGNUM_TARGET_GLES2 &TextureGLTest::image2DBuffer, - &TextureGLTest::compressedImage2DBuffer, #endif - &TextureGLTest::image3D, - &TextureGLTest::compressedImage3D, + &TextureGLTest::subImage2D, #ifndef MAGNUM_TARGET_GLES2 - &TextureGLTest::image3DBuffer, - &TextureGLTest::compressedImage3DBuffer, + &TextureGLTest::subImage2DBuffer, #endif - #ifndef MAGNUM_TARGET_GLES - &TextureGLTest::subImage1D, - &TextureGLTest::compressedSubImage1D, - &TextureGLTest::subImage1DBuffer, - &TextureGLTest::compressedSubImage1DBuffer, - &TextureGLTest::subImage1DQuery, - &TextureGLTest::compressedSubImage1DQuery, - &TextureGLTest::subImage1DQueryBuffer, - &TextureGLTest::compressedSubImage1DQueryBuffer, + &TextureGLTest::subImage2DQuery, + &TextureGLTest::subImage2DQueryBuffer, + #endif + }, PixelStorage2DDataCount); + + addInstancedTests({ + &TextureGLTest::compressedImage2D, + #ifndef MAGNUM_TARGET_GLES2 + &TextureGLTest::compressedImage2DBuffer, #endif - &TextureGLTest::subImage2D, &TextureGLTest::compressedSubImage2D, #ifndef MAGNUM_TARGET_GLES2 - &TextureGLTest::subImage2DBuffer, &TextureGLTest::compressedSubImage2DBuffer, #endif #ifndef MAGNUM_TARGET_GLES - &TextureGLTest::subImage2DQuery, &TextureGLTest::compressedSubImage2DQuery, - &TextureGLTest::subImage2DQueryBuffer, - &TextureGLTest::compressedSubImage2DQueryBuffer, + &TextureGLTest::compressedSubImage2DQueryBuffer + #endif + }, CompressedPixelStorage2DDataCount); + + addInstancedTests({ + &TextureGLTest::image3D, + #ifndef MAGNUM_TARGET_GLES2 + &TextureGLTest::image3DBuffer, #endif &TextureGLTest::subImage3D, - &TextureGLTest::compressedSubImage3D, #ifndef MAGNUM_TARGET_GLES2 &TextureGLTest::subImage3DBuffer, - &TextureGLTest::compressedSubImage3DBuffer, #endif #ifndef MAGNUM_TARGET_GLES &TextureGLTest::subImage3DQuery, - &TextureGLTest::compressedSubImage3DQuery, &TextureGLTest::subImage3DQueryBuffer, - &TextureGLTest::compressedSubImage3DQueryBuffer, #endif + }, PixelStorage3DDataCount); + + addInstancedTests({ + &TextureGLTest::compressedImage3D, + #ifndef MAGNUM_TARGET_GLES2 + &TextureGLTest::compressedImage3DBuffer, + #endif + &TextureGLTest::compressedSubImage3D, + #ifndef MAGNUM_TARGET_GLES2 + &TextureGLTest::compressedSubImage3DBuffer, + #endif + #ifndef MAGNUM_TARGET_GLES + &TextureGLTest::compressedSubImage3DQuery, + &TextureGLTest::compressedSubImage3DQueryBuffer + #endif + }, CompressedPixelStorage3DDataCount); + addTests({ #ifndef MAGNUM_TARGET_GLES &TextureGLTest::generateMipmap1D, #endif @@ -353,49 +566,6 @@ TextureGLTest::TextureGLTest() { &TextureGLTest::invalidateSubImage2D, &TextureGLTest::invalidateSubImage3D, }); - - _dataStorage2D = PixelStorage{}.setSkip({0, 1, 0}); - _dataStorage3D = PixelStorage{}.setSkip({0, 0, 1}); - _dataOffset2D = 8; - _dataOffset3D = 16; - #ifdef MAGNUM_TARGET_GLES2 - #ifndef MAGNUM_TARGET_WEBGL - if(!Context::current().isExtensionSupported()) - #endif - { - _dataStorage2D = _dataStorage3D = {}; - _dataOffset2D = _dataOffset3D = 0; - } - #endif - - #ifndef MAGNUM_TARGET_GLES - if(Context::current().isExtensionSupported()) - { - _compressedDataStorage2D = CompressedPixelStorage{} - .setCompressedBlockSize({4, 4, 1}) - .setCompressedBlockDataSize(16) - .setSkip({0, 4, 0}); - _compressedDataStorage3D = CompressedPixelStorage{} - .setCompressedBlockSize({4, 4, 4}) - .setCompressedBlockDataSize(16*4) - .setSkip({0, 0, 4}); - _compressedDataOffset2D = 16; - _compressedDataOffset3D = 16*4; - } else - #endif - { - #ifndef MAGNUM_TARGET_GLES - _compressedDataStorage2D = _compressedDataStorage3D = {}; - #endif - _compressedDataOffset2D = _compressedDataOffset3D = 0; - } -} - -namespace { - template Containers::ArrayView unsafeSuffix(const T(&data)[size], std::size_t offset) { - static_assert(sizeof(T) == 1, ""); - return {data - offset, size + offset}; - } } #ifndef MAGNUM_TARGET_GLES @@ -1033,417 +1203,451 @@ void TextureGLTest::storage3D() { } namespace { - constexpr UnsignedByte Data1D[] = { 0x00, 0x01, 0x02, 0x03, - 0x04, 0x05, 0x06, 0x07 }; - const auto DataStorage1D = PixelStorage{}.setSkip({1, 0, 0}); - const std::size_t DataOffset1D = 4; } #ifndef MAGNUM_TARGET_GLES void TextureGLTest::image1D() { + setTestCaseDescription(PixelStorage1DData[testCaseInstanceId()].name); + Texture1D texture; - texture.setImage(0, TextureFormat::RGBA8, ImageView1D{DataStorage1D, - PixelFormat::RGBA, PixelType::UnsignedByte, 2, unsafeSuffix(Data1D, DataOffset1D)}); + texture.setImage(0, TextureFormat::RGBA8, ImageView1D{ + PixelStorage1DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, 2, + PixelStorage1DData[testCaseInstanceId()].dataSparse}); MAGNUM_VERIFY_NO_ERROR(); - Image1D image = texture.image(0, {DataStorage1D, PixelFormat::RGBA, PixelType::UnsignedByte}); + Image1D image = texture.image(0, {PixelStorage1DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte}); MAGNUM_VERIFY_NO_ERROR(); CORRADE_COMPARE(image.size(), 2); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(DataOffset1D), - Containers::arrayView(Data1D), TestSuite::Compare::Container); -} - -void TextureGLTest::compressedImage1D() { - CORRADE_SKIP("No 1D texture compression format exists."); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(PixelStorage1DData[testCaseInstanceId()].offset), + PixelStorage1DData[testCaseInstanceId()].data, + TestSuite::Compare::Container); } void TextureGLTest::image1DBuffer() { + setTestCaseDescription(PixelStorage1DData[testCaseInstanceId()].name); + Texture1D texture; - texture.setImage(0, TextureFormat::RGBA8, BufferImage1D{DataStorage1D, - PixelFormat::RGBA, PixelType::UnsignedByte, 2, unsafeSuffix(Data1D, DataOffset1D), BufferUsage::StaticDraw}); + texture.setImage(0, TextureFormat::RGBA8, BufferImage1D{ + PixelStorage1DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, 2, + PixelStorage1DData[testCaseInstanceId()].dataSparse, + BufferUsage::StaticDraw}); MAGNUM_VERIFY_NO_ERROR(); BufferImage1D image = texture.image(0, - {DataStorage1D, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticDraw); + {PixelStorage1DData[testCaseInstanceId()].storage, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticDraw); const auto imageData = image.buffer().data(); MAGNUM_VERIFY_NO_ERROR(); CORRADE_COMPARE(image.size(), 2); - CORRADE_COMPARE_AS(imageData.suffix(DataOffset1D), - Containers::arrayView(Data1D), TestSuite::Compare::Container); -} - -void TextureGLTest::compressedImage1DBuffer() { - CORRADE_SKIP("No 1D texture compression format exists."); + CORRADE_COMPARE_AS(imageData.suffix(PixelStorage1DData[testCaseInstanceId()].offset), + PixelStorage1DData[testCaseInstanceId()].data, + TestSuite::Compare::Container); } -#endif namespace { - constexpr UnsignedByte Data2D[] = { 0x00, 0x01, 0x02, 0x03, - 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, - 0x0c, 0x0d, 0x0e, 0x0f }; - - /* Just 4x4 0x00 - 0x3f compressed using RGBA DXT3 by the driver */ - constexpr UnsignedByte CompressedData2D[] = { - 0, 17, 17, 34, 34, 51, 51, 67, - 232, 57, 0, 0, 213, 255, 170, 2 + constexpr UnsignedByte Zero1D[4*4] = {}; + constexpr UnsignedByte SubData1DComplete[]{ + 0, 0, 0, 0, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0, 0, 0, 0 }; } -void TextureGLTest::image2D() { - Texture2D texture; - texture.setImage(0, TextureFormat::RGBA8, ImageView2D{_dataStorage2D, - PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data2D, _dataOffset2D)}); +void TextureGLTest::subImage1D() { + setTestCaseDescription(PixelStorage1DData[testCaseInstanceId()].name); + + Texture1D texture; + texture.setImage(0, TextureFormat::RGBA8, + ImageView1D(PixelFormat::RGBA, PixelType::UnsignedByte, 4, Zero1D)); + texture.setSubImage(0, 1, ImageView1D{ + PixelStorage1DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, 2, + PixelStorage1DData[testCaseInstanceId()].dataSparse}); MAGNUM_VERIFY_NO_ERROR(); - /** @todo How to test this on ES? */ - #ifndef MAGNUM_TARGET_GLES - Image2D image = texture.image(0, {_dataStorage2D, PixelFormat::RGBA, PixelType::UnsignedByte}); + Image1D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte}); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), Vector2i(2)); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(_dataOffset2D), - Containers::arrayView(Data2D), TestSuite::Compare::Container); - #endif + CORRADE_COMPARE(image.size(), 4); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()), + Containers::arrayView(SubData1DComplete), + TestSuite::Compare::Container); } -void TextureGLTest::compressedImage2D() { - #ifndef MAGNUM_TARGET_WEBGL - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); - #else - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::WEBGL::compressed_texture_s3tc::string() + std::string(" is not supported.")); - #endif +void TextureGLTest::subImage1DBuffer() { + setTestCaseDescription(PixelStorage1DData[testCaseInstanceId()].name); - Texture2D texture; - texture.setCompressedImage(0, CompressedImageView2D{ - #ifndef MAGNUM_TARGET_GLES - _compressedDataStorage2D, - #endif - CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, unsafeSuffix(CompressedData2D, _compressedDataOffset2D)}); + Texture1D texture; + texture.setImage(0, TextureFormat::RGBA8, + ImageView1D(PixelFormat::RGBA, PixelType::UnsignedByte, 4, Zero1D)); + texture.setSubImage(0, 1, BufferImage1D{ + PixelStorage1DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, 2, + PixelStorage1DData[testCaseInstanceId()].dataSparse, + BufferUsage::StaticDraw}); MAGNUM_VERIFY_NO_ERROR(); - #ifndef MAGNUM_TARGET_GLES - CompressedImage2D image = texture.compressedImage(0, {_compressedDataStorage2D}); + BufferImage1D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); + const auto imageData = image.buffer().data(); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), Vector2i{4}); - - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(_compressedDataOffset2D), - Containers::arrayView(CompressedData2D), + CORRADE_COMPARE(image.size(), 4); + CORRADE_COMPARE_AS(imageData, Containers::arrayView(SubData1DComplete), TestSuite::Compare::Container); - #endif } -#ifndef MAGNUM_TARGET_GLES2 -void TextureGLTest::image2DBuffer() { - Texture2D texture; - texture.setImage(0, TextureFormat::RGBA8, BufferImage2D{_dataStorage2D, - PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data2D, _dataOffset2D), BufferUsage::StaticDraw}); +void TextureGLTest::subImage1DQuery() { + setTestCaseDescription(PixelStorage1DData[testCaseInstanceId()].name); + + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); + + Texture1D texture; + texture.setStorage(1, TextureFormat::RGBA8, 4) + .setSubImage(0, {}, ImageView1D{PixelFormat::RGBA, PixelType::UnsignedByte, 4, SubData1DComplete}); MAGNUM_VERIFY_NO_ERROR(); - /** @todo How to test this on ES? */ - #ifndef MAGNUM_TARGET_GLES - BufferImage2D image = texture.image(0, - {_dataStorage2D, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); - const auto imageData = image.buffer().data(); + Image1D image = texture.subImage(0, Range1Di::fromSize(1, 2), + {PixelStorage1DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte}); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), Vector2i(2)); - CORRADE_COMPARE_AS(imageData.suffix(_dataOffset2D), - Containers::arrayView(Data2D), TestSuite::Compare::Container); - #endif + CORRADE_COMPARE(image.size(), 2); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(PixelStorage1DData[testCaseInstanceId()].offset), + PixelStorage1DData[testCaseInstanceId()].data, + TestSuite::Compare::Container); } -void TextureGLTest::compressedImage2DBuffer() { - #ifndef MAGNUM_TARGET_WEBGL - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); - #else - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::WEBGL::compressed_texture_s3tc::string() + std::string(" is not supported.")); - #endif +void TextureGLTest::subImage1DQueryBuffer() { + setTestCaseDescription(PixelStorage1DData[testCaseInstanceId()].name); - Texture2D texture; - texture.setCompressedImage(0, CompressedBufferImage2D{ - #ifndef MAGNUM_TARGET_GLES - _compressedDataStorage2D, - #endif - CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, unsafeSuffix(CompressedData2D, _compressedDataOffset2D), BufferUsage::StaticDraw}); + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); + + Texture1D texture; + texture.setStorage(1, TextureFormat::RGBA8, 4) + .setSubImage(0, {}, ImageView1D{PixelFormat::RGBA, PixelType::UnsignedByte, 4, SubData1DComplete}); MAGNUM_VERIFY_NO_ERROR(); - #ifndef MAGNUM_TARGET_GLES - CompressedBufferImage2D image = texture.compressedImage(0, {_compressedDataStorage2D}, BufferUsage::StaticRead); + BufferImage1D image = texture.subImage(0, Range1Di::fromSize(1, 2), + {PixelStorage1DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); const auto imageData = image.buffer().data(); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), Vector2i{4}); - CORRADE_COMPARE_AS(imageData.suffix(_compressedDataOffset2D), - Containers::arrayView(CompressedData2D), + CORRADE_COMPARE(image.size(), 2); + CORRADE_COMPARE_AS(imageData.suffix(PixelStorage1DData[testCaseInstanceId()].offset), + PixelStorage1DData[testCaseInstanceId()].data, TestSuite::Compare::Container); - #endif } -#endif -namespace { - constexpr UnsignedByte Data3D[] = { 0x00, 0x01, 0x02, 0x03, - 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, - 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, - 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, - 0x1c, 0x1d, 0x1e, 0x1f }; +void TextureGLTest::compressedImage1D() { + CORRADE_SKIP("No 1D texture compression format exists."); +} - #ifndef MAGNUM_TARGET_GLES - /* Just 4x4x4 0x00 - 0xff compressed using RGBA BPTC Unorm by the driver */ - constexpr UnsignedByte CompressedData3D[] = { - 144, 224, 128, 3, 80, 0, 129, 170, - 84, 253, 73, 36, 109, 100, 107, 255, - 144, 232, 161, 135, 94, 244, 129, 170, - 84, 253, 65, 34, 109, 100, 107, 255, - 144, 240, 194, 11, 47, 248, 130, 170, - 84, 253, 65, 34, 109, 100, 107, 251, - 144, 247, 223, 143, 63, 252, 131, 170, - 84, 253, 73, 34, 109, 100, 91, 251 - }; - #endif +void TextureGLTest::compressedImage1DBuffer() { + CORRADE_SKIP("No 1D texture compression format exists."); } -void TextureGLTest::image3D() { +void TextureGLTest::compressedSubImage1D() { + CORRADE_SKIP("No 1D texture compression format exists."); +} + +void TextureGLTest::compressedSubImage1DBuffer() { + CORRADE_SKIP("No 1D texture compression format exists."); +} + +void TextureGLTest::compressedSubImage1DQuery() { + CORRADE_SKIP("No 1D texture compression format exists."); +} + +void TextureGLTest::compressedSubImage1DQueryBuffer() { + CORRADE_SKIP("No 1D texture compression format exists."); +} +#endif + +void TextureGLTest::image2D() { + setTestCaseDescription(PixelStorage2DData[testCaseInstanceId()].name); + #ifdef MAGNUM_TARGET_GLES2 - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::OES::texture_3D::string() + std::string(" is not supported.")); + if(PixelStorage2DData[testCaseInstanceId()].storage != PixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::EXT::unpack_subimage::string() + std::string(" is not supported.")); #endif - Texture3D texture; - texture.setImage(0, TextureFormat::RGBA8, ImageView3D{_dataStorage3D, - PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), unsafeSuffix(Data3D, _dataOffset3D)}); + Texture2D texture; + texture.setImage(0, TextureFormat::RGBA8, ImageView2D{ + PixelStorage2DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), + PixelStorage2DData[testCaseInstanceId()].dataSparse}); MAGNUM_VERIFY_NO_ERROR(); /** @todo How to test this on ES? */ #ifndef MAGNUM_TARGET_GLES - Image3D image = texture.image(0, {_dataStorage3D, PixelFormat::RGBA, PixelType::UnsignedByte}); + Image2D image = texture.image(0, {PixelStorage2DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte}); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), Vector3i(2)); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(_dataOffset3D), - Containers::arrayView(Data3D), TestSuite::Compare::Container); + CORRADE_COMPARE(image.size(), Vector2i(2)); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(PixelStorage2DData[testCaseInstanceId()].offset), + PixelStorage2DData[testCaseInstanceId()].data, + TestSuite::Compare::Container); #endif } -void TextureGLTest::compressedImage3D() { - #ifdef MAGNUM_TARGET_GLES - /** @todo ASTC HDR, when available on any ES driver */ - CORRADE_SKIP("No 3D texture compression format available on OpenGL ES."); - #else - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::ARB::texture_compression_bptc::string() + std::string(" is not supported.")); +#ifndef MAGNUM_TARGET_GLES2 +void TextureGLTest::image2DBuffer() { + setTestCaseDescription(PixelStorage2DData[testCaseInstanceId()].name); - Texture3D texture; - texture.setCompressedImage(0, CompressedImageView3D{_compressedDataStorage3D, - CompressedPixelFormat::RGBABptcUnorm, Vector3i{4}, unsafeSuffix(CompressedData3D, _compressedDataOffset3D)}); + Texture2D texture; + texture.setImage(0, TextureFormat::RGBA8, BufferImage2D{ + PixelStorage2DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), + PixelStorage2DData[testCaseInstanceId()].dataSparse, + BufferUsage::StaticDraw}); MAGNUM_VERIFY_NO_ERROR(); - CompressedImage3D image = texture.compressedImage(0, {_compressedDataStorage3D}); + /** @todo How to test this on ES? */ + #ifndef MAGNUM_TARGET_GLES + BufferImage2D image = texture.image(0, + {PixelStorage2DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); + const auto imageData = image.buffer().data(); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), Vector3i{4}); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(_compressedDataOffset3D), - Containers::arrayView(CompressedData3D), + CORRADE_COMPARE(image.size(), Vector2i(2)); + CORRADE_COMPARE_AS(imageData.suffix(PixelStorage2DData[testCaseInstanceId()].offset), + PixelStorage2DData[testCaseInstanceId()].data, TestSuite::Compare::Container); #endif } +#endif -#ifndef MAGNUM_TARGET_GLES2 -void TextureGLTest::image3DBuffer() { - Texture3D texture; - texture.setImage(0, TextureFormat::RGBA8, BufferImage3D{_dataStorage3D, - PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), unsafeSuffix(Data3D, _dataOffset3D), BufferUsage::StaticDraw}); +namespace { + constexpr UnsignedByte Zero2D[4*4*4]{}; + + constexpr UnsignedByte SubData2DComplete[]{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0, 0, 0, 0, + 0, 0, 0, 0, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; +} + +void TextureGLTest::subImage2D() { + setTestCaseDescription(PixelStorage2DData[testCaseInstanceId()].name); + + #ifdef MAGNUM_TARGET_GLES2 + if(PixelStorage2DData[testCaseInstanceId()].storage != PixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::EXT::unpack_subimage::string() + std::string(" is not supported.")); + #endif + + Texture2D texture; + texture.setImage(0, TextureFormat::RGBA8, + ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero2D)); + texture.setSubImage(0, Vector2i(1), ImageView2D{PixelStorage2DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), + PixelStorage2DData[testCaseInstanceId()].dataSparse}); MAGNUM_VERIFY_NO_ERROR(); /** @todo How to test this on ES? */ #ifndef MAGNUM_TARGET_GLES - BufferImage3D image = texture.image(0, - {_dataStorage3D, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); - const auto imageData = image.buffer().data(); + Image2D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte}); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), Vector3i(2)); - CORRADE_COMPARE_AS(imageData.suffix(_dataOffset3D), - Containers::arrayView(Data3D), TestSuite::Compare::Container); + CORRADE_COMPARE(image.size(), Vector2i(4)); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()), + Containers::arrayView(SubData2DComplete), + TestSuite::Compare::Container); #endif } -void TextureGLTest::compressedImage3DBuffer() { - #ifdef MAGNUM_TARGET_GLES - /** @todo ASTC HDR, when available on any ES driver */ - CORRADE_SKIP("No 3D texture compression format available on OpenGL ES."); - #else - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::ARB::texture_compression_bptc::string() + std::string(" is not supported.")); +#ifndef MAGNUM_TARGET_GLES2 +void TextureGLTest::subImage2DBuffer() { + setTestCaseDescription(PixelStorage2DData[testCaseInstanceId()].name); - Texture3D texture; - texture.setCompressedImage(0, CompressedBufferImage3D{_compressedDataStorage3D, - CompressedPixelFormat::RGBABptcUnorm, Vector3i{4}, unsafeSuffix(CompressedData3D, _compressedDataOffset3D), BufferUsage::StaticDraw}); + Texture2D texture; + texture.setImage(0, TextureFormat::RGBA8, + ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero2D)); + texture.setSubImage(0, Vector2i(1), BufferImage2D{PixelStorage2DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), + PixelStorage2DData[testCaseInstanceId()].dataSparse, + BufferUsage::StaticDraw}); MAGNUM_VERIFY_NO_ERROR(); - CompressedBufferImage3D image = texture.compressedImage(0, {_compressedDataStorage3D}, BufferUsage::StaticRead); + /** @todo How to test this on ES? */ + #ifndef MAGNUM_TARGET_GLES + BufferImage2D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); const auto imageData = image.buffer().data(); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), Vector3i{4}); - CORRADE_COMPARE_AS(imageData.suffix(_compressedDataOffset3D), - Containers::arrayView(CompressedData3D), + CORRADE_COMPARE(image.size(), Vector2i(4)); + CORRADE_COMPARE_AS(imageData, Containers::arrayView(SubData2DComplete), TestSuite::Compare::Container); #endif } #endif -namespace { - constexpr UnsignedByte Zero1D[4*4] = {}; - constexpr UnsignedByte SubData1DComplete[] = { - 0, 0, 0, 0, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0, 0, 0, 0 - }; -} - #ifndef MAGNUM_TARGET_GLES -void TextureGLTest::subImage1D() { - Texture1D texture; - texture.setImage(0, TextureFormat::RGBA8, - ImageView1D(PixelFormat::RGBA, PixelType::UnsignedByte, 4, Zero1D)); - texture.setSubImage(0, 1, ImageView1D{DataStorage1D, - PixelFormat::RGBA, PixelType::UnsignedByte, 2, unsafeSuffix(Data1D, DataOffset1D)}); +void TextureGLTest::subImage2DQuery() { + setTestCaseDescription(PixelStorage2DData[testCaseInstanceId()].name); + + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); + + Texture2D texture; + texture.setStorage(1, TextureFormat::RGBA8, Vector2i{4}) + .setSubImage(0, {}, ImageView2D{PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i{4}, SubData2DComplete}); MAGNUM_VERIFY_NO_ERROR(); - Image1D image = texture.image(0, {DataStorage1D, PixelFormat::RGBA, PixelType::UnsignedByte}); + Image2D image = texture.subImage(0, Range2Di::fromSize(Vector2i{1}, Vector2i{2}), + {PixelStorage2DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte}); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), 4); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(DataOffset1D), - Containers::arrayView(SubData1DComplete), + CORRADE_COMPARE(image.size(), Vector2i{2}); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(PixelStorage2DData[testCaseInstanceId()].offset), + PixelStorage2DData[testCaseInstanceId()].data, TestSuite::Compare::Container); } -void TextureGLTest::compressedSubImage1D() { - CORRADE_SKIP("No 1D texture compression format exists."); -} +void TextureGLTest::subImage2DQueryBuffer() { + setTestCaseDescription(PixelStorage2DData[testCaseInstanceId()].name); -void TextureGLTest::subImage1DBuffer() { - Texture1D texture; - texture.setImage(0, TextureFormat::RGBA8, - ImageView1D(PixelFormat::RGBA, PixelType::UnsignedByte, 4, Zero1D)); - texture.setSubImage(0, 1, BufferImage1D{DataStorage1D, - PixelFormat::RGBA, PixelType::UnsignedByte, 2, unsafeSuffix(Data1D, DataOffset1D), BufferUsage::StaticDraw}); + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); + + Texture2D texture; + texture.setStorage(1, TextureFormat::RGBA8, Vector2i{4}) + .setSubImage(0, {}, ImageView2D{PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i{4}, SubData2DComplete}); MAGNUM_VERIFY_NO_ERROR(); - BufferImage1D image = texture.image(0, {DataStorage1D, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); + BufferImage2D image = texture.subImage(0, Range2Di::fromSize(Vector2i{1}, Vector2i{2}), + {PixelStorage2DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); const auto imageData = image.buffer().data(); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), 4); - CORRADE_COMPARE_AS(imageData.suffix(DataOffset1D), - Containers::arrayView(SubData1DComplete), + CORRADE_COMPARE(image.size(), Vector2i{2}); + CORRADE_COMPARE_AS(imageData.suffix(PixelStorage2DData[testCaseInstanceId()].offset), + PixelStorage2DData[testCaseInstanceId()].data, TestSuite::Compare::Container); } +#endif -void TextureGLTest::compressedSubImage1DBuffer() { - CORRADE_SKIP("No 1D texture compression format exists."); -} +void TextureGLTest::compressedImage2D() { + setTestCaseDescription(CompressedPixelStorage2DData[testCaseInstanceId()].name); -void TextureGLTest::subImage1DQuery() { - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); + #ifndef MAGNUM_TARGET_WEBGL + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); + #else + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::WEBGL::compressed_texture_s3tc::string() + std::string(" is not supported.")); + #endif - Texture1D texture; - texture.setStorage(1, TextureFormat::RGBA8, 4) - .setSubImage(0, {}, ImageView1D{PixelFormat::RGBA, PixelType::UnsignedByte, 4, SubData1DComplete}); + #ifndef MAGNUM_TARGET_GLES + if(CompressedPixelStorage2DData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); + #endif + + Texture2D texture; + texture.setCompressedImage(0, CompressedImageView2D{ + #ifndef MAGNUM_TARGET_GLES + CompressedPixelStorage2DData[testCaseInstanceId()].storage, + #endif + CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, + CompressedPixelStorage2DData[testCaseInstanceId()].dataSparse}); MAGNUM_VERIFY_NO_ERROR(); - Image1D image = texture.subImage(0, Range1Di::fromSize(1, 2), - {DataStorage1D, PixelFormat::RGBA, PixelType::UnsignedByte}); + #ifndef MAGNUM_TARGET_GLES + CompressedImage2D image = texture.compressedImage(0, {CompressedPixelStorage2DData[testCaseInstanceId()].storage}); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), 2); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(DataOffset1D), - Containers::arrayView(Data1D), TestSuite::Compare::Container); -} + CORRADE_COMPARE(image.size(), Vector2i{4}); -void TextureGLTest::compressedSubImage1DQuery() { - CORRADE_SKIP("No 1D texture compression format exists."); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(CompressedPixelStorage2DData[testCaseInstanceId()].offset), + CompressedPixelStorage2DData[testCaseInstanceId()].data, + TestSuite::Compare::Container); + #endif } -void TextureGLTest::subImage1DQueryBuffer() { - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); +#ifndef MAGNUM_TARGET_GLES2 +void TextureGLTest::compressedImage2DBuffer() { + setTestCaseDescription(CompressedPixelStorage2DData[testCaseInstanceId()].name); - Texture1D texture; - texture.setStorage(1, TextureFormat::RGBA8, 4) - .setSubImage(0, {}, ImageView1D{PixelFormat::RGBA, PixelType::UnsignedByte, 4, SubData1DComplete}); + #ifndef MAGNUM_TARGET_WEBGL + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); + #else + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::WEBGL::compressed_texture_s3tc::string() + std::string(" is not supported.")); + #endif + + #ifndef MAGNUM_TARGET_GLES + if(CompressedPixelStorage2DData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); + #endif + + Texture2D texture; + texture.setCompressedImage(0, CompressedBufferImage2D{ + #ifndef MAGNUM_TARGET_GLES + CompressedPixelStorage2DData[testCaseInstanceId()].storage, + #endif + CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, + CompressedPixelStorage2DData[testCaseInstanceId()].dataSparse, + BufferUsage::StaticDraw}); MAGNUM_VERIFY_NO_ERROR(); - BufferImage1D image = texture.subImage(0, Range1Di::fromSize(1, 2), - {DataStorage1D, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); + #ifndef MAGNUM_TARGET_GLES + CompressedBufferImage2D image = texture.compressedImage(0, {CompressedPixelStorage2DData[testCaseInstanceId()].storage}, BufferUsage::StaticRead); const auto imageData = image.buffer().data(); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), 2); - CORRADE_COMPARE_AS(imageData.suffix(DataOffset1D), - Containers::arrayView(Data1D), TestSuite::Compare::Container); -} - -void TextureGLTest::compressedSubImage1DQueryBuffer() { - CORRADE_SKIP("No 1D texture compression format exists."); + CORRADE_COMPARE(image.size(), Vector2i{4}); + CORRADE_COMPARE_AS(imageData.suffix(CompressedPixelStorage2DData[testCaseInstanceId()].offset), + CompressedPixelStorage2DData[testCaseInstanceId()].data, + TestSuite::Compare::Container); + #endif } #endif namespace { - constexpr UnsignedByte Zero2D[4*4*4] = {}; - /* Just 12x4 zeros compressed using RGBA DXT3 by the driver */ - constexpr UnsignedByte CompressedZero2D[3*16] = {}; - - constexpr UnsignedByte SubData2DComplete[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0, 0, 0, 0, - 0, 0, 0, 0, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; + constexpr UnsignedByte CompressedZero2D[3*16]{}; /* Combination of CompressedZero2D and CompressedData2D */ - constexpr UnsignedByte CompressedSubData2DComplete[] = { + constexpr UnsignedByte CompressedSubData2DComplete[]{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 17, 34, 34, 51, 51, 67, @@ -1453,29 +1657,50 @@ namespace { }; } -void TextureGLTest::subImage2D() { +void TextureGLTest::compressedSubImage2D() { + setTestCaseDescription(CompressedPixelStorage2DData[testCaseInstanceId()].name); + + #ifndef MAGNUM_TARGET_WEBGL + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); + #else + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::WEBGL::compressed_texture_s3tc::string() + std::string(" is not supported.")); + #endif + + #ifndef MAGNUM_TARGET_GLES + if(CompressedPixelStorage2DData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); + #endif + Texture2D texture; - texture.setImage(0, TextureFormat::RGBA8, - ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero2D)); - texture.setSubImage(0, Vector2i(1), ImageView2D{_dataStorage2D, - PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data2D, _dataOffset2D)}); + texture.setCompressedImage(0, CompressedImageView2D{CompressedPixelFormat::RGBAS3tcDxt3, + {12, 4}, CompressedZero2D}); + texture.setCompressedSubImage(0, {4, 0}, CompressedImageView2D{ + #ifndef MAGNUM_TARGET_GLES + CompressedPixelStorage2DData[testCaseInstanceId()].storage, + #endif + CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, + CompressedPixelStorage2DData[testCaseInstanceId()].dataSparse}); MAGNUM_VERIFY_NO_ERROR(); - /** @todo How to test this on ES? */ #ifndef MAGNUM_TARGET_GLES - Image2D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte}); + CompressedImage2D image = texture.compressedImage(0, {}); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), Vector2i(4)); + CORRADE_COMPARE(image.size(), (Vector2i{12, 4})); CORRADE_COMPARE_AS(Containers::arrayCast(image.data()), - Containers::arrayView(SubData2DComplete), + Containers::arrayView(CompressedSubData2DComplete), TestSuite::Compare::Container); #endif } -void TextureGLTest::compressedSubImage2D() { +#ifndef MAGNUM_TARGET_GLES2 +void TextureGLTest::compressedSubImage2DBuffer() { + setTestCaseDescription(CompressedPixelStorage2DData[testCaseInstanceId()].name); + #ifndef MAGNUM_TARGET_WEBGL if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); @@ -1484,204 +1709,364 @@ void TextureGLTest::compressedSubImage2D() { CORRADE_SKIP(Extensions::GL::WEBGL::compressed_texture_s3tc::string() + std::string(" is not supported.")); #endif + #ifndef MAGNUM_TARGET_GLES + if(CompressedPixelStorage2DData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); + #endif + Texture2D texture; texture.setCompressedImage(0, CompressedImageView2D{CompressedPixelFormat::RGBAS3tcDxt3, {12, 4}, CompressedZero2D}); - texture.setCompressedSubImage(0, {4, 0}, CompressedImageView2D{ + texture.setCompressedSubImage(0, {4, 0}, CompressedBufferImage2D{ #ifndef MAGNUM_TARGET_GLES - _compressedDataStorage2D, + CompressedPixelStorage2DData[testCaseInstanceId()].storage, #endif - CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, unsafeSuffix(CompressedData2D, _compressedDataOffset2D)}); + CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, + CompressedPixelStorage2DData[testCaseInstanceId()].dataSparse, + BufferUsage::StaticDraw}); MAGNUM_VERIFY_NO_ERROR(); #ifndef MAGNUM_TARGET_GLES - CompressedImage2D image = texture.compressedImage(0, {}); + CompressedBufferImage2D image = texture.compressedImage(0, {}, BufferUsage::StaticRead); + const auto imageData = image.buffer().data(); MAGNUM_VERIFY_NO_ERROR(); CORRADE_COMPARE(image.size(), (Vector2i{12, 4})); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()), + CORRADE_COMPARE_AS(imageData, Containers::arrayView(CompressedSubData2DComplete), TestSuite::Compare::Container); #endif -} +} +#endif + +#ifndef MAGNUM_TARGET_GLES +void TextureGLTest::compressedSubImage2DQuery() { + setTestCaseDescription(CompressedPixelStorage2DData[testCaseInstanceId()].name); + + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); + if(CompressedPixelStorage2DData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); + + Texture2D texture; + texture.setStorage(1, TextureFormat::CompressedRGBAS3tcDxt3, {12, 4}) + .setCompressedSubImage(0, {}, CompressedImageView2D{CompressedPixelFormat::RGBAS3tcDxt3, {12, 4}, CompressedSubData2DComplete}); + + MAGNUM_VERIFY_NO_ERROR(); + + CompressedImage2D image = texture.compressedSubImage(0, Range2Di::fromSize({4, 0}, Vector2i{4}), + {CompressedPixelStorage2DData[testCaseInstanceId()].storage}); + + MAGNUM_VERIFY_NO_ERROR(); + + CORRADE_COMPARE(image.size(), Vector2i{4}); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(CompressedPixelStorage2DData[testCaseInstanceId()].offset), + CompressedPixelStorage2DData[testCaseInstanceId()].data, + TestSuite::Compare::Container); +} + +void TextureGLTest::compressedSubImage2DQueryBuffer() { + setTestCaseDescription(CompressedPixelStorage2DData[testCaseInstanceId()].name); + + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); + if(CompressedPixelStorage2DData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); + + Texture2D texture; + texture.setStorage(1, TextureFormat::CompressedRGBAS3tcDxt3, {12, 4}) + .setCompressedSubImage(0, {}, CompressedImageView2D{CompressedPixelFormat::RGBAS3tcDxt3, {12, 4}, CompressedSubData2DComplete}); + + MAGNUM_VERIFY_NO_ERROR(); + + CompressedBufferImage2D image = texture.compressedSubImage(0, Range2Di::fromSize({4, 0}, Vector2i{4}), + {CompressedPixelStorage2DData[testCaseInstanceId()].storage}, BufferUsage::StaticRead); + const auto imageData = image.buffer().data(); + + MAGNUM_VERIFY_NO_ERROR(); + + CORRADE_COMPARE(image.size(), Vector2i{4}); + CORRADE_COMPARE_AS(imageData.suffix(CompressedPixelStorage2DData[testCaseInstanceId()].offset), + CompressedPixelStorage2DData[testCaseInstanceId()].data, + TestSuite::Compare::Container); +} +#endif + +void TextureGLTest::image3D() { + setTestCaseDescription(PixelStorage3DData[testCaseInstanceId()].name); + + #ifdef MAGNUM_TARGET_GLES2 + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::OES::texture_3D::string() + std::string(" is not supported.")); + if(PixelStorage3DData[testCaseInstanceId()].storage != PixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::EXT::unpack_subimage::string() + std::string(" is not supported.")); + #endif + + Texture3D texture; + texture.setImage(0, TextureFormat::RGBA8, ImageView3D{ + PixelStorage3DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), + PixelStorage3DData[testCaseInstanceId()].dataSparse}); + + MAGNUM_VERIFY_NO_ERROR(); + + /** @todo How to test this on ES? */ + #ifndef MAGNUM_TARGET_GLES + Image3D image = texture.image(0, {PixelStorage3DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte}); + + MAGNUM_VERIFY_NO_ERROR(); + + CORRADE_COMPARE(image.size(), Vector3i(2)); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(PixelStorage3DData[testCaseInstanceId()].offset), + PixelStorage3DData[testCaseInstanceId()].data, + TestSuite::Compare::Container); + #endif +} + +#ifndef MAGNUM_TARGET_GLES2 +void TextureGLTest::image3DBuffer() { + setTestCaseDescription(PixelStorage3DData[testCaseInstanceId()].name); + + Texture3D texture; + texture.setImage(0, TextureFormat::RGBA8, BufferImage3D{ + PixelStorage3DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), + PixelStorage3DData[testCaseInstanceId()].dataSparse, + BufferUsage::StaticDraw}); + + MAGNUM_VERIFY_NO_ERROR(); + + /** @todo How to test this on ES? */ + #ifndef MAGNUM_TARGET_GLES + BufferImage3D image = texture.image(0, + {PixelStorage3DData[testCaseInstanceId()].storage, PixelFormat::RGBA, PixelType::UnsignedByte}, + BufferUsage::StaticRead); + const auto imageData = image.buffer().data(); + + MAGNUM_VERIFY_NO_ERROR(); + + CORRADE_COMPARE(image.size(), Vector3i(2)); + CORRADE_COMPARE_AS(imageData.suffix(PixelStorage3DData[testCaseInstanceId()].offset), + PixelStorage3DData[testCaseInstanceId()].data, + TestSuite::Compare::Container); + #endif +} +#endif + +namespace { + constexpr UnsignedByte Zero3D[4*4*4*4]{}; + + constexpr UnsignedByte SubData3DComplete[]{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0, 0, 0, 0, + 0, 0, 0, 0, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0, 0, 0, 0, + 0, 0, 0, 0, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; +} + +void TextureGLTest::subImage3D() { + setTestCaseDescription(PixelStorage3DData[testCaseInstanceId()].name); + + #ifdef MAGNUM_TARGET_GLES2 + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::OES::texture_3D::string() + std::string(" is not supported.")); + if(PixelStorage3DData[testCaseInstanceId()].storage != PixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::EXT::unpack_subimage::string() + std::string(" is not supported.")); + #endif -#ifndef MAGNUM_TARGET_GLES2 -void TextureGLTest::subImage2DBuffer() { - Texture2D texture; + Texture3D texture; texture.setImage(0, TextureFormat::RGBA8, - ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero2D)); - texture.setSubImage(0, Vector2i(1), BufferImage2D{_dataStorage2D, - PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data2D, _dataOffset2D), BufferUsage::StaticDraw}); + ImageView3D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(4), Zero3D)); + texture.setSubImage(0, Vector3i(1), ImageView3D{PixelStorage3DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), + PixelStorage3DData[testCaseInstanceId()].dataSparse}); MAGNUM_VERIFY_NO_ERROR(); /** @todo How to test this on ES? */ #ifndef MAGNUM_TARGET_GLES - BufferImage2D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); - const auto imageData = image.buffer().data(); + Image3D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte}); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), Vector2i(4)); - CORRADE_COMPARE_AS(imageData, Containers::arrayView(SubData2DComplete), + CORRADE_COMPARE(image.size(), Vector3i(4)); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()), + Containers::arrayView(SubData3DComplete), TestSuite::Compare::Container); #endif } -void TextureGLTest::compressedSubImage2DBuffer() { - #ifndef MAGNUM_TARGET_WEBGL - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); - #else - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::WEBGL::compressed_texture_s3tc::string() + std::string(" is not supported.")); - #endif +#ifndef MAGNUM_TARGET_GLES2 +void TextureGLTest::subImage3DBuffer() { + setTestCaseDescription(PixelStorage3DData[testCaseInstanceId()].name); - Texture2D texture; - texture.setCompressedImage(0, CompressedImageView2D{CompressedPixelFormat::RGBAS3tcDxt3, - {12, 4}, CompressedZero2D}); - texture.setCompressedSubImage(0, {4, 0}, CompressedBufferImage2D{ - #ifndef MAGNUM_TARGET_GLES - _compressedDataStorage2D, - #endif - CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, unsafeSuffix(CompressedData2D, _compressedDataOffset2D), BufferUsage::StaticDraw}); + Texture3D texture; + texture.setImage(0, TextureFormat::RGBA8, + ImageView3D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(4), Zero3D)); + texture.setSubImage(0, Vector3i(1), BufferImage3D{ + PixelStorage3DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), + PixelStorage3DData[testCaseInstanceId()].dataSparse, + BufferUsage::StaticDraw}); MAGNUM_VERIFY_NO_ERROR(); + /** @todo How to test this on ES? */ #ifndef MAGNUM_TARGET_GLES - CompressedBufferImage2D image = texture.compressedImage(0, {}, BufferUsage::StaticRead); + BufferImage3D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); const auto imageData = image.buffer().data(); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), (Vector2i{12, 4})); - CORRADE_COMPARE_AS(imageData, Containers::arrayView(CompressedSubData2DComplete), + CORRADE_COMPARE(image.size(), Vector3i(4)); + CORRADE_COMPARE_AS(imageData, Containers::arrayView(SubData3DComplete), TestSuite::Compare::Container); #endif } #endif #ifndef MAGNUM_TARGET_GLES -void TextureGLTest::subImage2DQuery() { +void TextureGLTest::subImage3DQuery() { + setTestCaseDescription(PixelStorage3DData[testCaseInstanceId()].name); + if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); - Texture2D texture; - texture.setStorage(1, TextureFormat::RGBA8, Vector2i{4}) - .setSubImage(0, {}, ImageView2D{PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i{4}, SubData2DComplete}); + Texture3D texture; + texture.setStorage(1, TextureFormat::RGBA8, Vector3i{4}) + .setSubImage(0, {}, ImageView3D{PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i{4}, SubData3DComplete}); MAGNUM_VERIFY_NO_ERROR(); - Image2D image = texture.subImage(0, Range2Di::fromSize(Vector2i{1}, Vector2i{2}), - {_dataStorage2D, PixelFormat::RGBA, PixelType::UnsignedByte}); + Image3D image = texture.subImage(0, Range3Di::fromSize(Vector3i{1}, Vector3i{2}), + {PixelStorage3DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte}); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), Vector2i{2}); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(_dataOffset2D), - Containers::arrayView(Data2D), TestSuite::Compare::Container); + CORRADE_COMPARE(image.size(), Vector3i{2}); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(PixelStorage3DData[testCaseInstanceId()].offset), + PixelStorage3DData[testCaseInstanceId()].data, + TestSuite::Compare::Container); } -void TextureGLTest::compressedSubImage2DQuery() { +void TextureGLTest::subImage3DQueryBuffer() { + setTestCaseDescription(PixelStorage3DData[testCaseInstanceId()].name); + if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); - Texture2D texture; - texture.setStorage(1, TextureFormat::CompressedRGBAS3tcDxt3, {12, 4}) - .setCompressedSubImage(0, {}, CompressedImageView2D{CompressedPixelFormat::RGBAS3tcDxt3, {12, 4}, CompressedSubData2DComplete}); + Texture3D texture; + texture.setStorage(1, TextureFormat::RGBA8, Vector3i{4}) + .setSubImage(0, {}, ImageView3D{PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i{4}, SubData3DComplete}); MAGNUM_VERIFY_NO_ERROR(); - /* Test also without compressed pixel storage to ensure that both size - computations work */ - if(Context::current().isExtensionSupported()) { - CompressedImage2D image = texture.compressedSubImage(0, Range2Di::fromSize({4, 0}, Vector2i{4}), {}); - - MAGNUM_VERIFY_NO_ERROR(); - - CORRADE_COMPARE(image.size(), Vector2i{4}); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()), - Containers::arrayView(CompressedData2D), - TestSuite::Compare::Container); - } - - CompressedImage2D image = texture.compressedSubImage(0, Range2Di::fromSize({4, 0}, Vector2i{4}), {_compressedDataStorage2D}); + BufferImage3D image = texture.subImage(0, Range3Di::fromSize(Vector3i{1}, Vector3i{2}), + {PixelStorage3DData[testCaseInstanceId()].storage, + PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); + const auto imageData = image.buffer().data(); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), Vector2i{4}); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(_compressedDataOffset2D), - Containers::arrayView(CompressedData2D), + CORRADE_COMPARE(image.size(), Vector3i{2}); + CORRADE_COMPARE_AS(imageData.suffix(PixelStorage3DData[testCaseInstanceId()].offset), + PixelStorage3DData[testCaseInstanceId()].data, TestSuite::Compare::Container); } +#endif -void TextureGLTest::subImage2DQueryBuffer() { - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); +void TextureGLTest::compressedImage3D() { + setTestCaseDescription(CompressedPixelStorage3DData[testCaseInstanceId()].name); - Texture2D texture; - texture.setStorage(1, TextureFormat::RGBA8, Vector2i{4}) - .setSubImage(0, {}, ImageView2D{PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i{4}, SubData2DComplete}); + #ifdef MAGNUM_TARGET_GLES + /** @todo ASTC HDR, when available on any ES driver */ + CORRADE_SKIP("No 3D texture compression format available on OpenGL ES."); + #else + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::texture_compression_bptc::string() + std::string(" is not supported.")); + if(CompressedPixelStorage3DData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); + + Texture3D texture; + texture.setCompressedImage(0, CompressedImageView3D{ + CompressedPixelStorage3DData[testCaseInstanceId()].storage, + CompressedPixelFormat::RGBABptcUnorm, Vector3i{4}, + CompressedPixelStorage3DData[testCaseInstanceId()].dataSparse}); MAGNUM_VERIFY_NO_ERROR(); - BufferImage2D image = texture.subImage(0, Range2Di::fromSize(Vector2i{1}, Vector2i{2}), - {_dataStorage2D, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); - const auto imageData = image.buffer().data(); + CompressedImage3D image = texture.compressedImage(0, {CompressedPixelStorage3DData[testCaseInstanceId()].storage}); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), Vector2i{2}); - CORRADE_COMPARE_AS(imageData.suffix(_dataOffset2D), - Containers::arrayView(Data2D), TestSuite::Compare::Container); + CORRADE_COMPARE(image.size(), Vector3i{4}); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(CompressedPixelStorage3DData[testCaseInstanceId()].offset), + CompressedPixelStorage3DData[testCaseInstanceId()].data, + TestSuite::Compare::Container); + #endif } -void TextureGLTest::compressedSubImage2DQueryBuffer() { - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported.")); - - Texture2D texture; - texture.setStorage(1, TextureFormat::CompressedRGBAS3tcDxt3, {12, 4}) - .setCompressedSubImage(0, {}, CompressedImageView2D{CompressedPixelFormat::RGBAS3tcDxt3, {12, 4}, CompressedSubData2DComplete}); - - MAGNUM_VERIFY_NO_ERROR(); +#ifndef MAGNUM_TARGET_GLES2 +void TextureGLTest::compressedImage3DBuffer() { + setTestCaseDescription(CompressedPixelStorage3DData[testCaseInstanceId()].name); - /* Test also without compressed pixel storage to ensure that both size - computations work */ - if(Context::current().isExtensionSupported()) { - CompressedBufferImage2D image = texture.compressedSubImage(0, Range2Di::fromSize({4, 0}, Vector2i{4}), {}, BufferUsage::StaticRead); - const auto imageData = image.buffer().data(); + #ifdef MAGNUM_TARGET_GLES + /** @todo ASTC HDR, when available on any ES driver */ + CORRADE_SKIP("No 3D texture compression format available on OpenGL ES."); + #else + if(!Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::texture_compression_bptc::string() + std::string(" is not supported.")); + if(CompressedPixelStorage3DData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); - MAGNUM_VERIFY_NO_ERROR(); + Texture3D texture; + texture.setCompressedImage(0, CompressedBufferImage3D{ + CompressedPixelStorage3DData[testCaseInstanceId()].storage, + CompressedPixelFormat::RGBABptcUnorm, Vector3i{4}, + CompressedPixelStorage3DData[testCaseInstanceId()].dataSparse, + BufferUsage::StaticDraw}); - CORRADE_COMPARE(image.size(), Vector2i{4}); - CORRADE_COMPARE_AS(imageData, Containers::arrayView(CompressedData2D), - TestSuite::Compare::Container); - } + MAGNUM_VERIFY_NO_ERROR(); - CompressedBufferImage2D image = texture.compressedSubImage(0, Range2Di::fromSize({4, 0}, Vector2i{4}), {_compressedDataStorage2D}, BufferUsage::StaticRead); + CompressedBufferImage3D image = texture.compressedImage(0, {CompressedPixelStorage3DData[testCaseInstanceId()].storage}, BufferUsage::StaticRead); const auto imageData = image.buffer().data(); MAGNUM_VERIFY_NO_ERROR(); - CORRADE_COMPARE(image.size(), Vector2i{4}); - CORRADE_COMPARE_AS(imageData.suffix(_compressedDataOffset2D), - Containers::arrayView(CompressedData2D), + CORRADE_COMPARE(image.size(), Vector3i{4}); + CORRADE_COMPARE_AS(imageData.suffix(CompressedPixelStorage3DData[testCaseInstanceId()].offset), + CompressedPixelStorage3DData[testCaseInstanceId()].data, TestSuite::Compare::Container); + #endif } #endif namespace { - constexpr UnsignedByte Zero3D[4*4*4*4] = {}; - /* Just 12x4x4 zeros compressed using RGBA BPTC Unorm by the driver */ - constexpr UnsignedByte CompressedZero3D[3*4*16] = { + constexpr UnsignedByte CompressedZero3D[3*4*16]{ 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -1698,33 +2083,10 @@ namespace { 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - constexpr UnsignedByte SubData3DComplete[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0, 0, 0, 0, - 0, 0, 0, 0, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0, 0, 0, 0, - 0, 0, 0, 0, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - - #ifndef MAGNUM_TARGET_GLES /* Combination of CompressedZero3D and CompressedData3D. Note that, in contrast to array textures, the data are ordered in "cubes" instead of slices. */ - constexpr UnsignedByte CompressedSubData3DComplete[] = { + constexpr UnsignedByte CompressedSubData3DComplete[]{ 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -1744,49 +2106,26 @@ namespace { 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - #endif -} - -void TextureGLTest::subImage3D() { - #ifdef MAGNUM_TARGET_GLES2 - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::OES::texture_3D::string() + std::string(" is not supported.")); - #endif - - Texture3D texture; - texture.setImage(0, TextureFormat::RGBA8, - ImageView3D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(4), Zero3D)); - texture.setSubImage(0, Vector3i(1), ImageView3D{_dataStorage3D, - PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), unsafeSuffix(Data3D, _dataOffset3D)}); - - MAGNUM_VERIFY_NO_ERROR(); - - /** @todo How to test this on ES? */ - #ifndef MAGNUM_TARGET_GLES - Image3D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte}); - - MAGNUM_VERIFY_NO_ERROR(); - - CORRADE_COMPARE(image.size(), Vector3i(4)); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()), - Containers::arrayView(SubData3DComplete), - TestSuite::Compare::Container); - #endif } void TextureGLTest::compressedSubImage3D() { + setTestCaseDescription(CompressedPixelStorage3DData[testCaseInstanceId()].name); + #ifdef MAGNUM_TARGET_GLES /** @todo ASTC HDR, when available on any ES driver */ CORRADE_SKIP("No 3D texture compression format available on OpenGL ES."); #else if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::texture_compression_bptc::string() + std::string(" is not supported.")); + if(CompressedPixelStorage3DData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); Texture3D texture; texture.setCompressedImage(0, CompressedImageView3D{CompressedPixelFormat::RGBABptcUnorm, {12, 4, 4}, CompressedZero3D}); - texture.setCompressedSubImage(0, {4, 0, 0}, CompressedImageView3D{_compressedDataStorage3D, - CompressedPixelFormat::RGBABptcUnorm, Vector3i{4}, unsafeSuffix(CompressedData3D, _compressedDataOffset3D)}); + texture.setCompressedSubImage(0, {4, 0, 0}, CompressedImageView3D{CompressedPixelStorage3DData[testCaseInstanceId()].storage, + CompressedPixelFormat::RGBABptcUnorm, Vector3i{4}, + CompressedPixelStorage3DData[testCaseInstanceId()].dataSparse}); MAGNUM_VERIFY_NO_ERROR(); @@ -1797,7 +2136,7 @@ void TextureGLTest::compressedSubImage3D() { CORRADE_COMPARE(image.size(), (Vector3i{12, 4, 4})); { - CORRADE_EXPECT_FAIL_IF(!Context::current().isExtensionSupported() && (Context::current().detectedDriver() & Context::DetectedDriver::NVidia), + CORRADE_EXPECT_FAIL_IF(CompressedPixelStorage3DData[testCaseInstanceId()].storage == CompressedPixelStorage{} && (Context::current().detectedDriver() & Context::DetectedDriver::NVidia), "Default compressed pixel storage behaves weirdly with BPTC compression on NVidia"); CORRADE_COMPARE_AS(Containers::arrayCast(image.data()), @@ -1808,41 +2147,24 @@ void TextureGLTest::compressedSubImage3D() { } #ifndef MAGNUM_TARGET_GLES2 -void TextureGLTest::subImage3DBuffer() { - Texture3D texture; - texture.setImage(0, TextureFormat::RGBA8, - ImageView3D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(4), Zero3D)); - texture.setSubImage(0, Vector3i(1), BufferImage3D{_dataStorage3D, - PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), unsafeSuffix(Data3D, _dataOffset3D), BufferUsage::StaticDraw}); - - MAGNUM_VERIFY_NO_ERROR(); - - /** @todo How to test this on ES? */ - #ifndef MAGNUM_TARGET_GLES - BufferImage3D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); - const auto imageData = image.buffer().data(); - - MAGNUM_VERIFY_NO_ERROR(); - - CORRADE_COMPARE(image.size(), Vector3i(4)); - CORRADE_COMPARE_AS(imageData, Containers::arrayView(SubData3DComplete), - TestSuite::Compare::Container); - #endif -} - void TextureGLTest::compressedSubImage3DBuffer() { + setTestCaseDescription(CompressedPixelStorage3DData[testCaseInstanceId()].name); + #ifdef MAGNUM_TARGET_GLES /** @todo ASTC HDR, when available on any ES driver */ CORRADE_SKIP("No 3D texture compression format available on OpenGL ES."); #else if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::texture_compression_bptc::string() + std::string(" is not supported.")); + if(CompressedPixelStorage3DData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); Texture3D texture; texture.setCompressedImage(0, CompressedImageView3D{CompressedPixelFormat::RGBABptcUnorm, {12, 4, 4}, CompressedZero3D}); - texture.setCompressedSubImage(0, {4, 0, 0}, CompressedImageView3D{_compressedDataStorage3D, - CompressedPixelFormat::RGBABptcUnorm, Vector3i{4}, unsafeSuffix(CompressedData3D, _compressedDataOffset3D)}); + texture.setCompressedSubImage(0, {4, 0, 0}, CompressedImageView3D{CompressedPixelStorage3DData[testCaseInstanceId()].storage, + CompressedPixelFormat::RGBABptcUnorm, Vector3i{4}, + CompressedPixelStorage3DData[testCaseInstanceId()].dataSparse}); MAGNUM_VERIFY_NO_ERROR(); @@ -1854,7 +2176,7 @@ void TextureGLTest::compressedSubImage3DBuffer() { CORRADE_COMPARE(image.size(), (Vector3i{12, 4, 4})); { - CORRADE_EXPECT_FAIL_IF(!Context::current().isExtensionSupported() && (Context::current().detectedDriver() & Context::DetectedDriver::NVidia), + CORRADE_EXPECT_FAIL_IF(CompressedPixelStorage3DData[testCaseInstanceId()].storage == CompressedPixelStorage{} && (Context::current().detectedDriver() & Context::DetectedDriver::NVidia), "Default compressed pixel storage behaves weirdly with BPTC compression on NVidia"); CORRADE_COMPARE_AS(imageData, @@ -1866,31 +2188,15 @@ void TextureGLTest::compressedSubImage3DBuffer() { #endif #ifndef MAGNUM_TARGET_GLES -void TextureGLTest::subImage3DQuery() { - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); - - Texture3D texture; - texture.setStorage(1, TextureFormat::RGBA8, Vector3i{4}) - .setSubImage(0, {}, ImageView3D{PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i{4}, SubData3DComplete}); - - MAGNUM_VERIFY_NO_ERROR(); - - Image3D image = texture.subImage(0, Range3Di::fromSize(Vector3i{1}, Vector3i{2}), - {_dataStorage3D, PixelFormat::RGBA, PixelType::UnsignedByte}); - - MAGNUM_VERIFY_NO_ERROR(); - - CORRADE_COMPARE(image.size(), Vector3i{2}); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(_dataOffset3D), - Containers::arrayView(Data3D), TestSuite::Compare::Container); -} - void TextureGLTest::compressedSubImage3DQuery() { + setTestCaseDescription(CompressedPixelStorage3DData[testCaseInstanceId()].name); + if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::texture_compression_bptc::string() + std::string(" is not supported.")); + if(CompressedPixelStorage3DData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); Texture3D texture; texture.setStorage(1, TextureFormat::CompressedRGBABptcUnorm, {12, 4, 4}) @@ -1898,64 +2204,32 @@ void TextureGLTest::compressedSubImage3DQuery() { MAGNUM_VERIFY_NO_ERROR(); - /* Test also without compressed pixel storage to ensure that both size - computations work */ - if(Context::current().isExtensionSupported()) { - CompressedImage3D image = texture.compressedSubImage(0, Range3Di::fromSize({4, 0, 0}, Vector3i{4}), {}); - - MAGNUM_VERIFY_NO_ERROR(); - - CORRADE_COMPARE(image.size(), (Vector3i{4})); - - CORRADE_EXPECT_FAIL_IF(Context::current().detectedDriver() & Context::DetectedDriver::NVidia, - "Default compressed pixel storage behaves weirdly with BPTC compression on NVidia"); - - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()), - Containers::arrayView(CompressedData3D), - TestSuite::Compare::Container); - } - - CompressedImage3D image = texture.compressedSubImage(0, Range3Di::fromSize({4, 0, 0}, Vector3i{4}), {_compressedDataStorage3D}); + CompressedImage3D image = texture.compressedSubImage(0, Range3Di::fromSize({4, 0, 0}, Vector3i{4}), + {CompressedPixelStorage3DData[testCaseInstanceId()].storage}); MAGNUM_VERIFY_NO_ERROR(); CORRADE_COMPARE(image.size(), (Vector3i{4})); { - CORRADE_EXPECT_FAIL_IF(!Context::current().isExtensionSupported() && (Context::current().detectedDriver() & Context::DetectedDriver::NVidia), + CORRADE_EXPECT_FAIL_IF(CompressedPixelStorage3DData[testCaseInstanceId()].storage == CompressedPixelStorage{} && (Context::current().detectedDriver() & Context::DetectedDriver::NVidia), "Default compressed pixel storage behaves weirdly with BPTC compression on NVidia"); - CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(_compressedDataOffset3D), - Containers::arrayView(CompressedData3D), TestSuite::Compare::Container); + CORRADE_COMPARE_AS(Containers::arrayCast(image.data()).suffix(CompressedPixelStorage3DData[testCaseInstanceId()].offset), + CompressedPixelStorage3DData[testCaseInstanceId()].data, + TestSuite::Compare::Container); } } -void TextureGLTest::subImage3DQueryBuffer() { - if(!Context::current().isExtensionSupported()) - CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); - - Texture3D texture; - texture.setStorage(1, TextureFormat::RGBA8, Vector3i{4}) - .setSubImage(0, {}, ImageView3D{PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i{4}, SubData3DComplete}); - - MAGNUM_VERIFY_NO_ERROR(); - - BufferImage3D image = texture.subImage(0, Range3Di::fromSize(Vector3i{1}, Vector3i{2}), - {_dataStorage3D, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead); - const auto imageData = image.buffer().data(); - - MAGNUM_VERIFY_NO_ERROR(); - - CORRADE_COMPARE(image.size(), Vector3i{2}); - CORRADE_COMPARE_AS(imageData.suffix(_dataOffset3D), - Containers::arrayView(Data3D), TestSuite::Compare::Container); -} - void TextureGLTest::compressedSubImage3DQueryBuffer() { + setTestCaseDescription(CompressedPixelStorage3DData[testCaseInstanceId()].name); + if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::get_texture_sub_image::string() + std::string(" is not supported.")); if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::texture_compression_bptc::string() + std::string(" is not supported.")); + if(CompressedPixelStorage3DData[testCaseInstanceId()].storage != CompressedPixelStorage{} && !Context::current().isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::ARB::compressed_texture_pixel_storage::string() + std::string(" is not supported.")); Texture3D texture; texture.setStorage(1, TextureFormat::CompressedRGBABptcUnorm, {12, 4, 4}) @@ -1963,24 +2237,8 @@ void TextureGLTest::compressedSubImage3DQueryBuffer() { MAGNUM_VERIFY_NO_ERROR(); - /* Test also without compressed pixel storage to ensure that both size - computations work */ - if(Context::current().isExtensionSupported()) { - CompressedBufferImage3D image = texture.compressedSubImage(0, Range3Di::fromSize({4, 0, 0}, Vector3i{4}), {}, BufferUsage::StaticRead); - const auto imageData = image.buffer().data(); - - MAGNUM_VERIFY_NO_ERROR(); - - CORRADE_COMPARE(image.size(), Vector3i{4}); - - CORRADE_EXPECT_FAIL_IF(Context::current().detectedDriver() & Context::DetectedDriver::NVidia, - "Default compressed pixel storage behaves weirdly with BPTC compression on NVidia"); - - CORRADE_COMPARE_AS(imageData, Containers::arrayView(CompressedData3D), - TestSuite::Compare::Container); - } - - CompressedBufferImage3D image = texture.compressedSubImage(0, Range3Di::fromSize({4, 0, 0}, Vector3i{4}), {_compressedDataStorage3D}, BufferUsage::StaticRead); + CompressedBufferImage3D image = texture.compressedSubImage(0, Range3Di::fromSize({4, 0, 0}, Vector3i{4}), + {CompressedPixelStorage3DData[testCaseInstanceId()].storage}, BufferUsage::StaticRead); const auto imageData = image.buffer().data(); MAGNUM_VERIFY_NO_ERROR(); @@ -1988,15 +2246,17 @@ void TextureGLTest::compressedSubImage3DQueryBuffer() { CORRADE_COMPARE(image.size(), Vector3i{4}); { - CORRADE_EXPECT_FAIL_IF(!Context::current().isExtensionSupported() && (Context::current().detectedDriver() & Context::DetectedDriver::NVidia), + CORRADE_EXPECT_FAIL_IF(CompressedPixelStorage3DData[testCaseInstanceId()].storage == CompressedPixelStorage{} && (Context::current().detectedDriver() & Context::DetectedDriver::NVidia), "Default compressed pixel storage behaves weirdly with BPTC compression on NVidia"); - CORRADE_COMPARE_AS(imageData.suffix(_compressedDataOffset3D), - Containers::arrayView(CompressedData3D), + CORRADE_COMPARE_AS(imageData.suffix(CompressedPixelStorage3DData[testCaseInstanceId()].offset), + CompressedPixelStorage3DData[testCaseInstanceId()].data, TestSuite::Compare::Container); } } +#endif +#ifndef MAGNUM_TARGET_GLES void TextureGLTest::generateMipmap1D() { if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::GL::ARB::framebuffer_object::string() + std::string(" is not supported."));