mirror of https://github.com/mosra/magnum.git
Browse Source
I was slowly getting cancer from having to write the unreadably awful VK_FORMAT_R666G666B666A666_SRGB all the time. Besides that: - All pixel formats are documented to show what's guaranteed for them by the spec. Pretty useful I'd say. - The old hasVkFormat() and vkFormat() converters operating on a VkFormat are deprecated in favor of new hasPixelFormat() and pixelFormat() that use the PixelFormat enum. Similarly as done in the GL wrapper. - All APIs that took a VkFormat before take a PixelFormat now, together with having conveinience overloads for Magnum::PixelFormat and Magnum::CompressedPixelFormat. Again similarly as done in the GL wrapper, also the first step on being able to *directly* use data imported with the Trade library with Vulkan.pull/494/head
31 changed files with 2993 additions and 880 deletions
@ -0,0 +1,248 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||
2020 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "PixelFormat.h" |
||||
|
||||
#include <Corrade/Containers/ArrayView.h> |
||||
#include <Corrade/Utility/Debug.h> |
||||
|
||||
#include "Magnum/PixelFormat.h" |
||||
|
||||
namespace Magnum { namespace Vk { |
||||
|
||||
namespace { |
||||
|
||||
constexpr PixelFormat PixelFormatMapping[] { |
||||
/* GCC 4.8 doesn't like just a {} for default enum values */ |
||||
#define _c(input) PixelFormat::input, |
||||
#define _s(input) PixelFormat{}, |
||||
#include "Magnum/Vk/Implementation/pixelFormatMapping.hpp" |
||||
#undef _s |
||||
#undef _c |
||||
}; |
||||
|
||||
constexpr PixelFormat CompressedPixelFormatMapping[] { |
||||
/* GCC 4.8 doesn't like just a {} for default enum values */ |
||||
#define _c(input, format) PixelFormat::Compressed ## format, |
||||
#define _s(input) PixelFormat{}, |
||||
#include "Magnum/Vk/Implementation/compressedPixelFormatMapping.hpp" |
||||
#undef _s |
||||
#undef _c |
||||
}; |
||||
|
||||
} |
||||
|
||||
Debug& operator<<(Debug& debug, const PixelFormat value) { |
||||
debug << "Vk::PixelFormat" << Debug::nospace; |
||||
|
||||
switch(value) { |
||||
/* LCOV_EXCL_START */ |
||||
#define _c(value) case Vk::PixelFormat::value: return debug << "::" << Debug::nospace << #value; |
||||
_c(R8Unorm) |
||||
_c(RG8Unorm) |
||||
_c(RGB8Unorm) |
||||
_c(RGBA8Unorm) |
||||
_c(R8Snorm) |
||||
_c(RG8Snorm) |
||||
_c(RGB8Snorm) |
||||
_c(RGBA8Snorm) |
||||
_c(R8Srgb) |
||||
_c(RG8Srgb) |
||||
_c(RGB8Srgb) |
||||
_c(RGBA8Srgb) |
||||
_c(R8UI) |
||||
_c(RG8UI) |
||||
_c(RGB8UI) |
||||
_c(RGBA8UI) |
||||
_c(R8I) |
||||
_c(RG8I) |
||||
_c(RGB8I) |
||||
_c(RGBA8I) |
||||
_c(R16Unorm) |
||||
_c(RG16Unorm) |
||||
_c(RGB16Unorm) |
||||
_c(RGBA16Unorm) |
||||
_c(R16Snorm) |
||||
_c(RG16Snorm) |
||||
_c(RGB16Snorm) |
||||
_c(RGBA16Snorm) |
||||
_c(R16UI) |
||||
_c(RG16UI) |
||||
_c(RGB16UI) |
||||
_c(RGBA16UI) |
||||
_c(R16I) |
||||
_c(RG16I) |
||||
_c(RGB16I) |
||||
_c(RGBA16I) |
||||
_c(R32UI) |
||||
_c(RG32UI) |
||||
_c(RGB32UI) |
||||
_c(RGBA32UI) |
||||
_c(R32I) |
||||
_c(RG32I) |
||||
_c(RGB32I) |
||||
_c(RGBA32I) |
||||
_c(R16F) |
||||
_c(RG16F) |
||||
_c(RGB16F) |
||||
_c(RGBA16F) |
||||
_c(R32F) |
||||
_c(RG32F) |
||||
_c(RGB32F) |
||||
_c(RGBA32F) |
||||
_c(Depth16Unorm) |
||||
_c(Depth24Unorm) |
||||
_c(Depth32F) |
||||
_c(Stencil8UI) |
||||
_c(Depth16UnormStencil8UI) |
||||
_c(Depth24UnormStencil8UI) |
||||
_c(Depth32FStencil8UI) |
||||
_c(CompressedBc1RGBUnorm) |
||||
_c(CompressedBc1RGBSrgb) |
||||
_c(CompressedBc1RGBAUnorm) |
||||
_c(CompressedBc1RGBASrgb) |
||||
_c(CompressedBc2RGBAUnorm) |
||||
_c(CompressedBc2RGBASrgb) |
||||
_c(CompressedBc3RGBAUnorm) |
||||
_c(CompressedBc3RGBASrgb) |
||||
_c(CompressedBc4RUnorm) |
||||
_c(CompressedBc4RSnorm) |
||||
_c(CompressedBc5RGUnorm) |
||||
_c(CompressedBc5RGSnorm) |
||||
_c(CompressedBc6hRGBUfloat) |
||||
_c(CompressedBc6hRGBSfloat) |
||||
_c(CompressedBc7RGBAUnorm) |
||||
_c(CompressedBc7RGBASrgb) |
||||
_c(CompressedEacR11Unorm) |
||||
_c(CompressedEacR11Snorm) |
||||
_c(CompressedEacRG11Unorm) |
||||
_c(CompressedEacRG11Snorm) |
||||
_c(CompressedEtc2RGB8Unorm) |
||||
_c(CompressedEtc2RGB8Srgb) |
||||
_c(CompressedEtc2RGB8A1Unorm) |
||||
_c(CompressedEtc2RGB8A1Srgb) |
||||
_c(CompressedEtc2RGBA8Unorm) |
||||
_c(CompressedEtc2RGBA8Srgb) |
||||
_c(CompressedAstc4x4RGBAUnorm) |
||||
_c(CompressedAstc4x4RGBASrgb) |
||||
_c(CompressedAstc4x4RGBAF) |
||||
_c(CompressedAstc5x4RGBAUnorm) |
||||
_c(CompressedAstc5x4RGBASrgb) |
||||
_c(CompressedAstc5x4RGBAF) |
||||
_c(CompressedAstc5x5RGBAUnorm) |
||||
_c(CompressedAstc5x5RGBASrgb) |
||||
_c(CompressedAstc5x5RGBAF) |
||||
_c(CompressedAstc6x5RGBAUnorm) |
||||
_c(CompressedAstc6x5RGBASrgb) |
||||
_c(CompressedAstc6x5RGBAF) |
||||
_c(CompressedAstc6x6RGBAUnorm) |
||||
_c(CompressedAstc6x6RGBASrgb) |
||||
_c(CompressedAstc6x6RGBAF) |
||||
_c(CompressedAstc8x5RGBAUnorm) |
||||
_c(CompressedAstc8x5RGBASrgb) |
||||
_c(CompressedAstc8x5RGBAF) |
||||
_c(CompressedAstc8x6RGBAUnorm) |
||||
_c(CompressedAstc8x6RGBASrgb) |
||||
_c(CompressedAstc8x6RGBAF) |
||||
_c(CompressedAstc8x8RGBAUnorm) |
||||
_c(CompressedAstc8x8RGBASrgb) |
||||
_c(CompressedAstc8x8RGBAF) |
||||
_c(CompressedAstc10x5RGBAUnorm) |
||||
_c(CompressedAstc10x5RGBASrgb) |
||||
_c(CompressedAstc10x5RGBAF) |
||||
_c(CompressedAstc10x6RGBAUnorm) |
||||
_c(CompressedAstc10x6RGBASrgb) |
||||
_c(CompressedAstc10x6RGBAF) |
||||
_c(CompressedAstc10x8RGBAUnorm) |
||||
_c(CompressedAstc10x8RGBASrgb) |
||||
_c(CompressedAstc10x8RGBAF) |
||||
_c(CompressedAstc10x10RGBAUnorm) |
||||
_c(CompressedAstc10x10RGBASrgb) |
||||
_c(CompressedAstc10x10RGBAF) |
||||
_c(CompressedAstc12x10RGBAUnorm) |
||||
_c(CompressedAstc12x10RGBASrgb) |
||||
_c(CompressedAstc12x10RGBAF) |
||||
_c(CompressedAstc12x12RGBAUnorm) |
||||
_c(CompressedAstc12x12RGBASrgb) |
||||
_c(CompressedAstc12x12RGBAF) |
||||
_c(CompressedPvrtcRGBA2bppUnorm) |
||||
_c(CompressedPvrtcRGBA2bppSrgb) |
||||
_c(CompressedPvrtcRGBA4bppUnorm) |
||||
_c(CompressedPvrtcRGBA4bppSrgb) |
||||
_c(CompressedPvrtc2RGBA2bppUnorm) |
||||
_c(CompressedPvrtc2RGBA2bppSrgb) |
||||
_c(CompressedPvrtc2RGBA4bppUnorm) |
||||
_c(CompressedPvrtc2RGBA4bppSrgb) |
||||
#undef _c |
||||
/* LCOV_EXCL_STOP */ |
||||
} |
||||
|
||||
/* Vulkan docs have the values in decimal, so not converting to hex */ |
||||
return debug << "(" << Debug::nospace << Int(value) << Debug::nospace << ")"; |
||||
} |
||||
|
||||
bool hasPixelFormat(const Magnum::PixelFormat format) { |
||||
if(isPixelFormatImplementationSpecific(format)) |
||||
return true; |
||||
|
||||
CORRADE_ASSERT(UnsignedInt(format) - 1 < Containers::arraySize(PixelFormatMapping), |
||||
"Vk::hasPixelFormat(): invalid format" << format, {}); |
||||
return UnsignedInt(PixelFormatMapping[UnsignedInt(format) - 1]); |
||||
} |
||||
|
||||
bool hasPixelFormat(const Magnum::CompressedPixelFormat format) { |
||||
if(isCompressedPixelFormatImplementationSpecific(format)) |
||||
return true; |
||||
|
||||
CORRADE_ASSERT(UnsignedInt(format) - 1 < Containers::arraySize(CompressedPixelFormatMapping), |
||||
"Vk::hasPixelFormat(): invalid format" << format, {}); |
||||
return UnsignedInt(CompressedPixelFormatMapping[UnsignedInt(format) - 1]); |
||||
} |
||||
|
||||
PixelFormat pixelFormat(const Magnum::PixelFormat format) { |
||||
if(isPixelFormatImplementationSpecific(format)) |
||||
return pixelFormatUnwrap<PixelFormat>(format); |
||||
|
||||
CORRADE_ASSERT(UnsignedInt(format) - 1 < Containers::arraySize(PixelFormatMapping), |
||||
"Vk::pixelFormat(): invalid format" << format, {}); |
||||
const PixelFormat out = PixelFormatMapping[UnsignedInt(format) - 1]; |
||||
CORRADE_ASSERT(UnsignedInt(out), |
||||
"Vk::pixelFormat(): unsupported format" << format, {}); |
||||
return out; |
||||
} |
||||
|
||||
PixelFormat pixelFormat(const Magnum::CompressedPixelFormat format) { |
||||
if(isCompressedPixelFormatImplementationSpecific(format)) |
||||
return compressedPixelFormatUnwrap<PixelFormat>(format); |
||||
|
||||
CORRADE_ASSERT(UnsignedInt(format) - 1 < Containers::arraySize(CompressedPixelFormatMapping), |
||||
"Vk::pixelFormat(): invalid format" << format, {}); |
||||
const PixelFormat out = CompressedPixelFormatMapping[UnsignedInt(format) - 1]; |
||||
CORRADE_ASSERT(UnsignedInt(out), |
||||
"Vk::pixelFormat(): unsupported format" << format, {}); |
||||
return out; |
||||
} |
||||
|
||||
}} |
||||
@ -0,0 +1,274 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||
2020 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include <sstream> |
||||
#include <Corrade/TestSuite/Tester.h> |
||||
#include <Corrade/Utility/DebugStl.h> |
||||
|
||||
#include "Magnum/PixelFormat.h" |
||||
#include "Magnum/Vk/PixelFormat.h" |
||||
|
||||
namespace Magnum { namespace Vk { namespace Test { namespace { |
||||
|
||||
struct PixelFormatTest: TestSuite::Tester { |
||||
explicit PixelFormatTest(); |
||||
|
||||
void mapPixelFormat(); |
||||
void mapPixelFormatImplementationSpecific(); |
||||
void mapPixelFormatUnsupported(); |
||||
void mapPixelFormatInvalid(); |
||||
|
||||
void mapCompressedPixelFormat(); |
||||
void mapCompressedPixelFormatImplementationSpecific(); |
||||
void mapCompressedPixelFormatUnsupported(); |
||||
void mapCompressedPixelFormatInvalid(); |
||||
|
||||
void debug(); |
||||
}; |
||||
|
||||
PixelFormatTest::PixelFormatTest() { |
||||
addTests({&PixelFormatTest::mapPixelFormat, |
||||
&PixelFormatTest::mapPixelFormatImplementationSpecific, |
||||
&PixelFormatTest::mapPixelFormatUnsupported, |
||||
&PixelFormatTest::mapPixelFormatInvalid, |
||||
|
||||
&PixelFormatTest::mapCompressedPixelFormat, |
||||
&PixelFormatTest::mapCompressedPixelFormatImplementationSpecific, |
||||
&PixelFormatTest::mapCompressedPixelFormatUnsupported, |
||||
&PixelFormatTest::mapCompressedPixelFormatInvalid, |
||||
|
||||
&PixelFormatTest::debug}); |
||||
} |
||||
|
||||
void PixelFormatTest::mapPixelFormat() { |
||||
/* Touchstone verification. Using Vulkan enums directly to sidestep
|
||||
potential problems in enum mapping as well. */ |
||||
CORRADE_VERIFY(hasPixelFormat(Magnum::PixelFormat::RGBA8Unorm)); |
||||
CORRADE_COMPARE(pixelFormat(Magnum::PixelFormat::RGBA8Unorm), PixelFormat(VK_FORMAT_R8G8B8A8_UNORM)); |
||||
|
||||
/* This goes through the first 16 bits, which should be enough. Going
|
||||
through 32 bits takes 8 seconds, too much. */ |
||||
UnsignedInt firstUnhandled = 0xffff; |
||||
UnsignedInt nextHandled = 1; /* 0 is an invalid format */ |
||||
for(UnsignedInt i = 1; i <= 0xffff; ++i) { |
||||
const auto format = Magnum::PixelFormat(i); |
||||
/* Each case verifies:
|
||||
- that the entries are ordered by number by comparing a function to |
||||
expected result (so insertion here is done in proper place) |
||||
- that there was no gap (unhandled value inside the range) |
||||
- that a particular pixel format maps to a particular vkFormat */ |
||||
#ifdef __GNUC__ |
||||
#pragma GCC diagnostic push |
||||
#pragma GCC diagnostic error "-Wswitch" |
||||
#endif |
||||
switch(format) { |
||||
#define _c(format) \ |
||||
case Magnum::PixelFormat::format: \
|
||||
CORRADE_COMPARE(nextHandled, i); \
|
||||
CORRADE_COMPARE(firstUnhandled, 0xffff); \
|
||||
CORRADE_VERIFY(hasPixelFormat(Magnum::PixelFormat::format)); \
|
||||
CORRADE_COMPARE(pixelFormat(Magnum::PixelFormat::format), PixelFormat::format); \
|
||||
++nextHandled; \
|
||||
continue; |
||||
#define _s(format) \ |
||||
case Magnum::PixelFormat::format: { \
|
||||
CORRADE_COMPARE(nextHandled, i); \
|
||||
CORRADE_COMPARE(firstUnhandled, 0xffff); \
|
||||
CORRADE_VERIFY(!hasPixelFormat(Magnum::PixelFormat::format)); \
|
||||
std::ostringstream out; \
|
||||
{ /* Redirected otherwise graceful assert would abort */ \
|
||||
Error redirectError{&out}; \
|
||||
pixelFormat(Magnum::PixelFormat::format); \
|
||||
} \
|
||||
Debug{Debug::Flag::NoNewlineAtTheEnd} << out.str(); \
|
||||
++nextHandled; \
|
||||
continue; \
|
||||
} |
||||
#include "Magnum/Vk/Implementation/pixelFormatMapping.hpp" |
||||
#undef _s |
||||
#undef _c |
||||
} |
||||
#ifdef __GNUC__ |
||||
#pragma GCC diagnostic pop |
||||
#endif |
||||
|
||||
/* Not handled by any value, remember -- we might either be at the end
|
||||
of the enum range (which is okay) or some value might be unhandled |
||||
here */ |
||||
firstUnhandled = i; |
||||
} |
||||
|
||||
CORRADE_COMPARE(firstUnhandled, 0xffff); |
||||
} |
||||
|
||||
void PixelFormatTest::mapPixelFormatImplementationSpecific() { |
||||
CORRADE_VERIFY(hasPixelFormat(Magnum::pixelFormatWrap(VK_FORMAT_A8B8G8R8_SINT_PACK32))); |
||||
CORRADE_COMPARE(pixelFormat(Magnum::pixelFormatWrap(VK_FORMAT_A8B8G8R8_SINT_PACK32)), |
||||
PixelFormat(VK_FORMAT_A8B8G8R8_SINT_PACK32)); |
||||
} |
||||
|
||||
void PixelFormatTest::mapPixelFormatUnsupported() { |
||||
#ifdef CORRADE_NO_ASSERT |
||||
CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); |
||||
#endif |
||||
|
||||
#if 1 |
||||
CORRADE_SKIP("All pixel formats are supported."); |
||||
#else |
||||
std::ostringstream out; |
||||
Error redirectError{&out}; |
||||
|
||||
pixelFormat(Magnum::PixelFormat::RGB16UI); |
||||
CORRADE_COMPARE(out.str(), "Vk::pixelFormat(): unsupported format PixelFormat::RGB16UI\n"); |
||||
#endif |
||||
} |
||||
|
||||
void PixelFormatTest::mapPixelFormatInvalid() { |
||||
#ifdef CORRADE_NO_ASSERT |
||||
CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); |
||||
#endif |
||||
|
||||
std::ostringstream out; |
||||
Error redirectError{&out}; |
||||
|
||||
hasPixelFormat(Magnum::PixelFormat{}); |
||||
hasPixelFormat(Magnum::PixelFormat(0x123)); |
||||
pixelFormat(Magnum::PixelFormat{}); |
||||
pixelFormat(Magnum::PixelFormat(0x123)); |
||||
CORRADE_COMPARE(out.str(), |
||||
"Vk::hasPixelFormat(): invalid format PixelFormat(0x0)\n" |
||||
"Vk::hasPixelFormat(): invalid format PixelFormat(0x123)\n" |
||||
"Vk::pixelFormat(): invalid format PixelFormat(0x0)\n" |
||||
"Vk::pixelFormat(): invalid format PixelFormat(0x123)\n"); |
||||
} |
||||
|
||||
void PixelFormatTest::mapCompressedPixelFormat() { |
||||
/* Touchstone verification. Using Vulkan enums directly to sidestep
|
||||
potential problems in enum mapping as well. */ |
||||
CORRADE_VERIFY(hasPixelFormat(Magnum::CompressedPixelFormat::Bc1RGBAUnorm)); |
||||
CORRADE_COMPARE(pixelFormat(Magnum::CompressedPixelFormat::Bc1RGBAUnorm), PixelFormat(VK_FORMAT_BC1_RGBA_UNORM_BLOCK)); |
||||
|
||||
/* This goes through the first 16 bits, which should be enough. Going
|
||||
through 32 bits takes 8 seconds, too much. */ |
||||
UnsignedInt firstUnhandled = 0xffff; |
||||
UnsignedInt nextHandled = 1; /* 0 is an invalid format */ |
||||
for(UnsignedInt i = 1; i <= 0xffff; ++i) { |
||||
const auto format = Magnum::CompressedPixelFormat(i); |
||||
/* Each case verifies:
|
||||
- that the entries are ordered by number by comparing a function to |
||||
expected result (so insertion here is done in proper place) |
||||
- that there was no gap (unhandled value inside the range) |
||||
- that a particular pixel format maps to a particular VkFormat */ |
||||
#ifdef __GNUC__ |
||||
#pragma GCC diagnostic push |
||||
#pragma GCC diagnostic error "-Wswitch" |
||||
#endif |
||||
switch(format) { |
||||
#define _c(format, expectedFormat) \ |
||||
case Magnum::CompressedPixelFormat::format: \
|
||||
CORRADE_COMPARE(nextHandled, i); \
|
||||
CORRADE_COMPARE(firstUnhandled, 0xffff); \
|
||||
CORRADE_VERIFY(hasPixelFormat(Magnum::CompressedPixelFormat::format)); \
|
||||
CORRADE_COMPARE(pixelFormat(Magnum::CompressedPixelFormat::format), PixelFormat::Compressed ## expectedFormat); \
|
||||
++nextHandled; \
|
||||
continue; |
||||
#define _s(format) \ |
||||
case Magnum::CompressedPixelFormat::format: { \
|
||||
CORRADE_COMPARE(nextHandled, i); \
|
||||
CORRADE_COMPARE(firstUnhandled, 0xffff); \
|
||||
CORRADE_VERIFY(!hasPixelFormat(Magnum::CompressedPixelFormat::format)); \
|
||||
std::ostringstream out; \
|
||||
{ /* Redirected otherwise graceful assert would abort */ \
|
||||
Error redirectError{&out}; \
|
||||
pixelFormat(Magnum::CompressedPixelFormat::format); \
|
||||
} \
|
||||
Debug{Debug::Flag::NoNewlineAtTheEnd} << out.str(); \
|
||||
++nextHandled; \
|
||||
continue; \
|
||||
} |
||||
#include "Magnum/Vk/Implementation/compressedPixelFormatMapping.hpp" |
||||
#undef _s |
||||
#undef _c |
||||
} |
||||
#ifdef __GNUC__ |
||||
#pragma GCC diagnostic pop |
||||
#endif |
||||
|
||||
/* Not handled by any value, remember -- we might either be at the end
|
||||
of the enum range (which is okay) or some value might be unhandled |
||||
here */ |
||||
firstUnhandled = i; |
||||
} |
||||
|
||||
CORRADE_COMPARE(firstUnhandled, 0xffff); |
||||
} |
||||
|
||||
void PixelFormatTest::mapCompressedPixelFormatImplementationSpecific() { |
||||
CORRADE_VERIFY(hasPixelFormat(Magnum::compressedPixelFormatWrap(VK_FORMAT_ASTC_10x6_UNORM_BLOCK))); |
||||
CORRADE_COMPARE(pixelFormat(Magnum::compressedPixelFormatWrap(VK_FORMAT_ASTC_10x6_UNORM_BLOCK)), |
||||
PixelFormat(VK_FORMAT_ASTC_10x6_UNORM_BLOCK)); |
||||
} |
||||
|
||||
void PixelFormatTest::mapCompressedPixelFormatUnsupported() { |
||||
#ifdef CORRADE_NO_ASSERT |
||||
CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); |
||||
#endif |
||||
|
||||
CORRADE_VERIFY(!hasPixelFormat(Magnum::CompressedPixelFormat::Astc3x3x3RGBAUnorm)); |
||||
|
||||
std::ostringstream out; |
||||
Error redirectError{&out}; |
||||
pixelFormat(Magnum::CompressedPixelFormat::Astc3x3x3RGBAUnorm); |
||||
CORRADE_COMPARE(out.str(), "Vk::pixelFormat(): unsupported format CompressedPixelFormat::Astc3x3x3RGBAUnorm\n"); |
||||
} |
||||
|
||||
void PixelFormatTest::mapCompressedPixelFormatInvalid() { |
||||
#ifdef CORRADE_NO_ASSERT |
||||
CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); |
||||
#endif |
||||
|
||||
std::ostringstream out; |
||||
Error redirectError{&out}; |
||||
|
||||
hasPixelFormat(Magnum::CompressedPixelFormat{}); |
||||
hasPixelFormat(Magnum::CompressedPixelFormat(0x123)); |
||||
pixelFormat(Magnum::CompressedPixelFormat{}); |
||||
pixelFormat(Magnum::CompressedPixelFormat(0x123)); |
||||
CORRADE_COMPARE(out.str(), |
||||
"Vk::hasPixelFormat(): invalid format CompressedPixelFormat(0x0)\n" |
||||
"Vk::hasPixelFormat(): invalid format CompressedPixelFormat(0x123)\n" |
||||
"Vk::pixelFormat(): invalid format CompressedPixelFormat(0x0)\n" |
||||
"Vk::pixelFormat(): invalid format CompressedPixelFormat(0x123)\n"); |
||||
} |
||||
|
||||
void PixelFormatTest::debug() { |
||||
std::ostringstream out; |
||||
Debug{&out} << PixelFormat::RGB16UI << PixelFormat(-10007655); |
||||
CORRADE_COMPARE(out.str(), "Vk::PixelFormat::RGB16UI Vk::PixelFormat(-10007655)\n"); |
||||
} |
||||
|
||||
}}}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Vk::Test::PixelFormatTest) |
||||
@ -0,0 +1,52 @@
|
||||
#ifndef Magnum_Vk_Test_pixelFormatTraits_h |
||||
#define Magnum_Vk_Test_pixelFormatTraits_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||
2020 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "Magnum/PixelFormat.h" |
||||
#include "Magnum/Vk/PixelFormat.h" |
||||
|
||||
namespace Magnum { namespace Vk { namespace Test { namespace { |
||||
|
||||
template<class> struct PixelFormatTraits; |
||||
template<> struct PixelFormatTraits<PixelFormat> { |
||||
static const char* name() { return "PixelFormat"; } |
||||
static PixelFormat format() { return PixelFormat::RGBA8Srgb; } |
||||
static VkFormat expected() { return VK_FORMAT_R8G8B8A8_SRGB; } |
||||
}; |
||||
template<> struct PixelFormatTraits<Magnum::PixelFormat> { |
||||
static const char* name() { return "Magnum::PixelFormat"; } |
||||
static Magnum::PixelFormat format() { return Magnum::PixelFormat::RGBA8Srgb; } |
||||
static VkFormat expected() { return VK_FORMAT_R8G8B8A8_SRGB; } |
||||
}; |
||||
template<> struct PixelFormatTraits<Magnum::CompressedPixelFormat> { |
||||
static const char* name() { return "Magnum::CompressedPixelFormat"; } |
||||
static Magnum::CompressedPixelFormat format() { return Magnum::CompressedPixelFormat::Bc3RGBASrgb; } |
||||
static VkFormat expected() { return VK_FORMAT_BC3_SRGB_BLOCK; } |
||||
}; |
||||
|
||||
}}}} |
||||
|
||||
#endif |
||||
Loading…
Reference in new issue