From 7d9ceb8832049dedb3058b76c6e0a46449d28191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 25 Aug 2019 17:43:56 +0200 Subject: [PATCH] Added ETC2 and EAC compressed pixel formats to the generic enum. --- doc/changelog.dox | 3 + .../compressedPixelFormatMapping.hpp | 23 ++++ src/Magnum/GL/Test/PixelFormatTest.cpp | 10 +- src/Magnum/PixelFormat.cpp | 10 ++ src/Magnum/PixelFormat.h | 102 +++++++++++++++++- .../compressedFormatMapping.hpp | 10 ++ 6 files changed, 152 insertions(+), 6 deletions(-) diff --git a/doc/changelog.dox b/doc/changelog.dox index 77913b821..df94662e3 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -50,6 +50,9 @@ See also: - New @ref BasicMutableImageView "MutableImageView*D" and @ref BasicMutableCompressedImageView "MutableCompressedImageView*D" types for mutable views onto image data +- Added ETC2 and EAC formats to @ref CompressedPixelFormat as well as their + conversion to corresponding GL/Vulkan in @ref GL::compressedPixelFormat() + and @ref Vk::vkFormat(Magnum::CompressedPixelFormat) @subsubsection changelog-latest-new-audio Audio library diff --git a/src/Magnum/GL/Implementation/compressedPixelFormatMapping.hpp b/src/Magnum/GL/Implementation/compressedPixelFormatMapping.hpp index 0e1bc4cf0..ffe08532a 100644 --- a/src/Magnum/GL/Implementation/compressedPixelFormatMapping.hpp +++ b/src/Magnum/GL/Implementation/compressedPixelFormatMapping.hpp @@ -29,4 +29,27 @@ _c(Bc1RGBUnorm, RGBS3tcDxt1) _c(Bc1RGBAUnorm, RGBAS3tcDxt1) _c(Bc2RGBAUnorm, RGBAS3tcDxt3) _c(Bc3RGBAUnorm, RGBAS3tcDxt5) +#ifndef MAGNUM_TARGET_GLES2 +_c(EacR11Unorm, R11Eac) +_c(EacR11Snorm, SignedR11Eac) +_c(EacRG11Unorm, RG11Eac) +_c(EacRG11Snorm, SignedRG11Eac) +_c(Etc2RGB8Unorm, RGB8Etc2) +_c(Etc2RGB8Srgb, SRGB8Etc2) +_c(Etc2RGB8A1Unorm, RGB8PunchthroughAlpha1Etc2) +_c(Etc2RGB8A1Srgb, SRGB8PunchthroughAlpha1Etc2) +_c(Etc2RGBA8Unorm, RGBA8Etc2Eac) +_c(Etc2RGBA8Srgb, SRGB8Alpha8Etc2Eac) +#else +_s(EacR11Unorm) +_s(EacR11Snorm) +_s(EacRG11Unorm) +_s(EacRG11Snorm) +_s(Etc2RGB8Unorm) +_s(Etc2RGB8Srgb) +_s(Etc2RGB8A1Unorm) +_s(Etc2RGB8A1Srgb) +_s(Etc2RGBA8Unorm) +_s(Etc2RGBA8Srgb) +#endif #endif diff --git a/src/Magnum/GL/Test/PixelFormatTest.cpp b/src/Magnum/GL/Test/PixelFormatTest.cpp index 8896a497e..7ff562e5e 100644 --- a/src/Magnum/GL/Test/PixelFormatTest.cpp +++ b/src/Magnum/GL/Test/PixelFormatTest.cpp @@ -271,15 +271,15 @@ void PixelFormatTest::mapCompressedFormatImplementationSpecific() { CompressedPixelFormat::RGBAS3tcDxt1); } void PixelFormatTest::mapCompressedFormatUnsupported() { - #if 1 - CORRADE_SKIP("All compressed pixel formats are currently supported everywhere."); + #ifndef MAGNUM_TARGET_GLES2 + CORRADE_SKIP("All pixel formats are supported on ES3+."); #else - CORRADE_VERIFY(!hasCompressedPixelFormat(Magnum::CompressedPixelFormat::Bc1RGBAUnorm)); + CORRADE_VERIFY(!hasCompressedPixelFormat(Magnum::CompressedPixelFormat::Etc2RGB8Unorm)); std::ostringstream out; Error redirectError{&out}; - compressedPixelFormat(Magnum::CompressedPixelFormat::Bc1RGBAUnorm); - CORRADE_COMPARE(out.str(), "GL::compressedPixelFormat(): format CompressedPixelFormat::Bc1RGBAUnorm is not supported on this target\n"); + compressedPixelFormat(Magnum::CompressedPixelFormat::Etc2RGB8Unorm); + CORRADE_COMPARE(out.str(), "GL::compressedPixelFormat(): format CompressedPixelFormat::Etc2RGB8Unorm is not supported on this target\n"); #endif } diff --git a/src/Magnum/PixelFormat.cpp b/src/Magnum/PixelFormat.cpp index 68587cfd9..9c354b99e 100644 --- a/src/Magnum/PixelFormat.cpp +++ b/src/Magnum/PixelFormat.cpp @@ -174,6 +174,16 @@ Debug& operator<<(Debug& debug, const CompressedPixelFormat value) { _c(Bc1RGBAUnorm) _c(Bc2RGBAUnorm) _c(Bc3RGBAUnorm) + _c(EacR11Unorm) + _c(EacR11Snorm) + _c(EacRG11Unorm) + _c(EacRG11Snorm) + _c(Etc2RGB8Unorm) + _c(Etc2RGB8Srgb) + _c(Etc2RGB8A1Unorm) + _c(Etc2RGB8A1Srgb) + _c(Etc2RGBA8Unorm) + _c(Etc2RGBA8Srgb) #undef _c /* LCOV_EXCL_STOP */ } diff --git a/src/Magnum/PixelFormat.h b/src/Magnum/PixelFormat.h index 518eb1d23..c1c32d104 100644 --- a/src/Magnum/PixelFormat.h +++ b/src/Magnum/PixelFormat.h @@ -608,7 +608,107 @@ enum class CompressedPixelFormat: UnsignedInt { * @ref GL::TextureFormat::CompressedRGBAS3tcDxt5 / * @def_vk_keyword{FORMAT_BC3_UNORM_BLOCK,Format}. */ - Bc3RGBAUnorm + Bc3RGBAUnorm, + + /** + * [EAC](https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC) + * compressed red component, normalized unsigned 11-bit. + * + * Corresponds to @ref GL::CompressedPixelFormat::R11Eac, + * @ref GL::TextureFormat::CompressedR11Eac / + * @def_vk_keyword{FORMAT_EAC_R11_UNORM_BLOCK,Format}. + */ + EacR11Unorm, + + /** + * [EAC](https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC) + * compressed red component, normalized signed 11-bit. + * + * Corresponds to @ref GL::CompressedPixelFormat::SignedR11Eac, + * @ref GL::TextureFormat::CompressedSignedR11Eac / + * @def_vk_keyword{FORMAT_EAC_R11_SNORM_BLOCK,Format}. + */ + EacR11Snorm, + + /** + * [EAC](https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC) + * compressed red and green component, normalized unsigned 11-bit. + * + * Corresponds to @ref GL::CompressedPixelFormat::RG11Eac, + * @ref GL::TextureFormat::CompressedRG11Eac / + * @def_vk_keyword{FORMAT_EAC_R11G11_UNORM_BLOCK,Format}. + */ + EacRG11Unorm, + + /** + * [EAC](https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC) + * compressed red and green component, normalized signed 11-bit. + * + * Corresponds to @ref GL::CompressedPixelFormat::SignedRG11Eac, + * @ref GL::TextureFormat::CompressedSignedRG11Eac / + * @def_vk_keyword{FORMAT_EAC_R11G11_SNORM_BLOCK,Format}. + */ + EacRG11Snorm, + + /** + * [ETC2](https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC) + * compressed RGB, normalized unsigned byte. + * + * Corresponds to @ref GL::CompressedPixelFormat::RGB8Etc2, + * @ref GL::TextureFormat::CompressedRGB8Etc2 / + * @def_vk_keyword{FORMAT_ETC2_R8G8B8_UNORM_BLOCK,Format}. + */ + Etc2RGB8Unorm, + + /** + * [ETC2](https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC) + * compressed sRGB, normalized unsigned byte. + * + * Corresponds to @ref GL::CompressedPixelFormat::SRGB8Etc2, + * @ref GL::TextureFormat::CompressedSRGB8Etc2 / + * @def_vk_keyword{FORMAT_ETC2_R8G8B8_SRGB_BLOCK,Format}. + */ + Etc2RGB8Srgb, + + /** + * [ETC2](https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC) + * compressed RGB, normalized unsigned byte + a single-bit alpha. + * + * Corresponds to @ref GL::CompressedPixelFormat::RGB8PunchthroughAlpha1Etc2, + * @ref GL::TextureFormat::CompressedRGB8PunchthroughAlpha1Etc2 / + * @def_vk_keyword{FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK,Format}. + */ + Etc2RGB8A1Unorm, + + /** + * [ETC2](https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC) + * compressed sRGB, normalized unsigned byte + a single-bit alpha. + * + * Corresponds to @ref GL::CompressedPixelFormat::SRGB8PunchthroughAlpha1Etc2, + * @ref GL::TextureFormat::CompressedSRGB8PunchthroughAlpha1Etc2 / + * @def_vk_keyword{FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK,Format}. + */ + Etc2RGB8A1Srgb, + + /** + * [ETC2](https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC) + * compressed RGBA, normalized unsigned byte (EAC). + * + * Corresponds to @ref GL::CompressedPixelFormat::RGBA8Etc2Eac, + * @ref GL::TextureFormat::CompressedRGBA8Etc2Eac / + * @def_vk_keyword{FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK,Format}. + */ + Etc2RGBA8Unorm, + + /** + * [ETC2](https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC) + * compressed sRGB + linear alpha, normalized unsigned byte (EAC). + * + * Corresponds to @ref GL::CompressedPixelFormat::SRGB8Alpha8Etc2Eac, + * @ref GL::TextureFormat::CompressedSRGB8Alpha8Etc2Eac / + * @def_vk_keyword{FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK,Format}. + */ + Etc2RGBA8Srgb }; /** @debugoperatorenum{CompressedPixelFormat} */ diff --git a/src/Magnum/Vk/Implementation/compressedFormatMapping.hpp b/src/Magnum/Vk/Implementation/compressedFormatMapping.hpp index 7ee464903..517a9fd72 100644 --- a/src/Magnum/Vk/Implementation/compressedFormatMapping.hpp +++ b/src/Magnum/Vk/Implementation/compressedFormatMapping.hpp @@ -29,4 +29,14 @@ _c(Bc1RGBUnorm, BC1_RGB_UNORM_BLOCK) _c(Bc1RGBAUnorm, BC1_RGBA_UNORM_BLOCK) _c(Bc2RGBAUnorm, BC2_UNORM_BLOCK) _c(Bc3RGBAUnorm, BC3_UNORM_BLOCK) +_c(EacR11Unorm, EAC_R11_UNORM_BLOCK) +_c(EacR11Snorm, EAC_R11_SNORM_BLOCK) +_c(EacRG11Unorm, EAC_R11G11_UNORM_BLOCK) +_c(EacRG11Snorm, EAC_R11G11_SNORM_BLOCK) +_c(Etc2RGB8Unorm, ETC2_R8G8B8_UNORM_BLOCK) +_c(Etc2RGB8Srgb, ETC2_R8G8B8_SRGB_BLOCK) +_c(Etc2RGB8A1Unorm, ETC2_R8G8B8A1_UNORM_BLOCK) +_c(Etc2RGB8A1Srgb, ETC2_R8G8B8A1_SRGB_BLOCK) +_c(Etc2RGBA8Unorm, ETC2_R8G8B8A8_UNORM_BLOCK) +_c(Etc2RGBA8Srgb, ETC2_R8G8B8A8_SRGB_BLOCK) #endif