Browse Source

Be strict for missing values in pixel format switches.

pull/370/head
Vladimír Vondruš 7 years ago
parent
commit
619b4a3cb7
  1. 14
      src/Magnum/DebugTools/CompareImage.cpp
  2. 14
      src/Magnum/GL/AbstractTexture.cpp
  3. 37
      src/Magnum/GL/PixelFormat.cpp
  4. 14
      src/Magnum/GL/Test/PixelFormatTest.cpp
  5. 21
      src/Magnum/PixelFormat.cpp
  6. 14
      src/Magnum/Vk/Test/EnumsTest.cpp

14
src/Magnum/DebugTools/CompareImage.cpp

@ -102,6 +102,10 @@ std::tuple<Containers::Array<Float>, Float, Float> calculateImageDelta(const Pix
CORRADE_ASSERT(!isPixelFormatImplementationSpecific(expected.format()), CORRADE_ASSERT(!isPixelFormatImplementationSpecific(expected.format()),
"DebugTools::CompareImage: can't compare implementation-specific pixel formats", {}); "DebugTools::CompareImage: can't compare implementation-specific pixel formats", {});
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#endif
Float max{Constants::nan()}; Float max{Constants::nan()};
switch(expected.format()) { switch(expected.format()) {
#define _c(format, size, T) \ #define _c(format, size, T) \
@ -157,6 +161,9 @@ std::tuple<Containers::Array<Float>, Float, Float> calculateImageDelta(const Pix
CORRADE_ASSERT(false, CORRADE_ASSERT(false,
"DebugTools::CompareImage: half-float formats are not supported yet", {}); "DebugTools::CompareImage: half-float formats are not supported yet", {});
} }
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
CORRADE_ASSERT(max == max, CORRADE_ASSERT(max == max,
"DebugTools::CompareImage: unknown format" << expected.format(), {}); "DebugTools::CompareImage: unknown format" << expected.format(), {});
@ -225,6 +232,10 @@ namespace {
void printPixelAt(Debug& out, const Containers::StridedArrayView3D<const char>& pixels, const Vector2i& pos, const PixelFormat format) { void printPixelAt(Debug& out, const Containers::StridedArrayView3D<const char>& pixels, const Vector2i& pos, const PixelFormat format) {
const char* const pixel = &pixels[pos.y()][pos.x()][0]; const char* const pixel = &pixels[pos.y()][pos.x()][0];
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#endif
switch(format) { switch(format) {
#define _c(format, size, T) \ #define _c(format, size, T) \
case PixelFormat::format: \ case PixelFormat::format: \
@ -284,6 +295,9 @@ void printPixelAt(Debug& out, const Containers::StridedArrayView3D<const char>&
/* Already handled by a printing assert before */ /* Already handled by a printing assert before */
CORRADE_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */ CORRADE_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */
} }
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
} }
} }

14
src/Magnum/GL/AbstractTexture.cpp

@ -539,6 +539,10 @@ void AbstractTexture::bindInternal() {
namespace { namespace {
PixelFormat pixelFormatForInternalFormat(const TextureFormat internalFormat) { PixelFormat pixelFormatForInternalFormat(const TextureFormat internalFormat) {
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#endif
switch(internalFormat) { switch(internalFormat) {
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) #if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
case TextureFormat::Red: case TextureFormat::Red:
@ -806,11 +810,18 @@ PixelFormat pixelFormatForInternalFormat(const TextureFormat internalFormat) {
#endif #endif
return PixelFormat::DepthStencil; return PixelFormat::DepthStencil;
} }
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
CORRADE_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */ CORRADE_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */
} }
PixelType pixelTypeForInternalFormat(const TextureFormat internalFormat) { PixelType pixelTypeForInternalFormat(const TextureFormat internalFormat) {
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#endif
switch(internalFormat) { switch(internalFormat) {
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) #if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
case TextureFormat::Red: case TextureFormat::Red:
@ -1053,6 +1064,9 @@ PixelType pixelTypeForInternalFormat(const TextureFormat internalFormat) {
return PixelType::Float32UnsignedInt248Rev; return PixelType::Float32UnsignedInt248Rev;
#endif #endif
} }
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
CORRADE_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */ CORRADE_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */
} }

37
src/Magnum/GL/PixelFormat.cpp

@ -88,6 +88,10 @@ PixelType pixelType(const Magnum::PixelFormat format, const UnsignedInt extra) {
UnsignedInt pixelSize(const PixelFormat format, const PixelType type) { UnsignedInt pixelSize(const PixelFormat format, const PixelType type) {
std::size_t size = 0; std::size_t size = 0;
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#endif
switch(type) { switch(type) {
case PixelType::UnsignedByte: case PixelType::UnsignedByte:
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
@ -144,7 +148,14 @@ UnsignedInt pixelSize(const PixelFormat format, const PixelType type) {
return 8; return 8;
#endif #endif
} }
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#endif
switch(format) { switch(format) {
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) #if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
case PixelFormat::Red: case PixelFormat::Red:
@ -207,12 +218,19 @@ UnsignedInt pixelSize(const PixelFormat format, const PixelType type) {
case PixelFormat::DepthStencil: case PixelFormat::DepthStencil:
CORRADE_ASSERT(false, "GL::pixelSize(): invalid" << type << "specified for" << format, 0); CORRADE_ASSERT(false, "GL::pixelSize(): invalid" << type << "specified for" << format, 0);
} }
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
CORRADE_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */ CORRADE_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */
} }
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
Debug& operator<<(Debug& debug, const PixelFormat value) { Debug& operator<<(Debug& debug, const PixelFormat value) {
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#endif
switch(value) { switch(value) {
/* LCOV_EXCL_START */ /* LCOV_EXCL_START */
#define _c(value) case PixelFormat::value: return debug << "GL::PixelFormat::" #value; #define _c(value) case PixelFormat::value: return debug << "GL::PixelFormat::" #value;
@ -266,11 +284,18 @@ Debug& operator<<(Debug& debug, const PixelFormat value) {
#undef _c #undef _c
/* LCOV_EXCL_STOP */ /* LCOV_EXCL_STOP */
} }
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
return debug << "GL::PixelFormat(" << Debug::nospace << reinterpret_cast<void*>(GLenum(value)) << Debug::nospace << ")"; return debug << "GL::PixelFormat(" << Debug::nospace << reinterpret_cast<void*>(GLenum(value)) << Debug::nospace << ")";
} }
Debug& operator<<(Debug& debug, const PixelType value) { Debug& operator<<(Debug& debug, const PixelType value) {
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#endif
switch(value) { switch(value) {
/* LCOV_EXCL_START */ /* LCOV_EXCL_START */
#define _c(value) case PixelType::value: return debug << "GL::PixelType::" #value; #define _c(value) case PixelType::value: return debug << "GL::PixelType::" #value;
@ -323,6 +348,9 @@ Debug& operator<<(Debug& debug, const PixelType value) {
#undef _c #undef _c
/* LCOV_EXCL_STOP */ /* LCOV_EXCL_STOP */
} }
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
return debug << "GL::PixelType(" << Debug::nospace << reinterpret_cast<void*>(GLenum(value)) << Debug::nospace << ")"; return debug << "GL::PixelType(" << Debug::nospace << reinterpret_cast<void*>(GLenum(value)) << Debug::nospace << ")";
} }
@ -363,6 +391,10 @@ CompressedPixelFormat compressedPixelFormat(const Magnum::CompressedPixelFormat
} }
Debug& operator<<(Debug& debug, const CompressedPixelFormat value) { Debug& operator<<(Debug& debug, const CompressedPixelFormat value) {
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#endif
switch(value) { switch(value) {
/* LCOV_EXCL_START */ /* LCOV_EXCL_START */
#define _c(value) case CompressedPixelFormat::value: return debug << "GL::CompressedPixelFormat::" #value; #define _c(value) case CompressedPixelFormat::value: return debug << "GL::CompressedPixelFormat::" #value;
@ -429,6 +461,9 @@ Debug& operator<<(Debug& debug, const CompressedPixelFormat value) {
#undef _c #undef _c
/* LCOV_EXCL_STOP */ /* LCOV_EXCL_STOP */
} }
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
return debug << "GL::CompressedPixelFormat(" << Debug::nospace << reinterpret_cast<void*>(GLenum(value)) << Debug::nospace << ")"; return debug << "GL::CompressedPixelFormat(" << Debug::nospace << reinterpret_cast<void*>(GLenum(value)) << Debug::nospace << ")";
} }

14
src/Magnum/GL/Test/PixelFormatTest.cpp

@ -99,6 +99,10 @@ void PixelFormatTest::mapFormatType() {
- that there was no gap (unhandled value inside the range) - that there was no gap (unhandled value inside the range)
- that a particular pixel format maps to a particular GL format - that a particular pixel format maps to a particular GL format
- that a particular pixel type maps to a particular GL type */ - that a particular pixel type maps to a particular GL type */
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#endif
switch(format) { switch(format) {
#define _c(format, expectedFormat, expectedType) \ #define _c(format, expectedFormat, expectedType) \
case Magnum::PixelFormat::format: \ case Magnum::PixelFormat::format: \
@ -122,6 +126,9 @@ void PixelFormatTest::mapFormatType() {
#undef _s #undef _s
#undef _c #undef _c
} }
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
/* Not handled by any value, remember -- we might either be at the end /* 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 of the enum range (which is okay) or some value might be unhandled
@ -234,6 +241,10 @@ void PixelFormatTest::mapCompressedFormat() {
- that there was no gap (unhandled value inside the range) - that there was no gap (unhandled value inside the range)
- that a particular pixel format maps to a particular GL format - that a particular pixel format maps to a particular GL format
- that a particular pixel type maps to a particular GL type */ - that a particular pixel type maps to a particular GL type */
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#endif
switch(format) { switch(format) {
#define _c(format, expectedFormat) \ #define _c(format, expectedFormat) \
case Magnum::CompressedPixelFormat::format: \ case Magnum::CompressedPixelFormat::format: \
@ -255,6 +266,9 @@ void PixelFormatTest::mapCompressedFormat() {
#undef _s #undef _s
#undef _c #undef _c
} }
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
/* Not handled by any value, remember -- we might either be at the end /* 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 of the enum range (which is okay) or some value might be unhandled

21
src/Magnum/PixelFormat.cpp

@ -34,6 +34,10 @@ UnsignedInt pixelSize(const PixelFormat format) {
CORRADE_ASSERT(!(UnsignedInt(format) & (1 << 31)), CORRADE_ASSERT(!(UnsignedInt(format) & (1 << 31)),
"pixelSize(): can't determine pixel size of an implementation-specific format", {}); "pixelSize(): can't determine pixel size of an implementation-specific format", {});
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#endif
switch(format) { switch(format) {
case PixelFormat::R8Unorm: case PixelFormat::R8Unorm:
case PixelFormat::R8Snorm: case PixelFormat::R8Snorm:
@ -92,6 +96,9 @@ UnsignedInt pixelSize(const PixelFormat format) {
case PixelFormat::RGBA32F: case PixelFormat::RGBA32F:
return 16; return 16;
} }
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
CORRADE_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */ CORRADE_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */
} }
@ -102,6 +109,10 @@ Debug& operator<<(Debug& debug, const PixelFormat value) {
return debug << "PixelFormat::ImplementationSpecific(" << Debug::nospace << reinterpret_cast<void*>(pixelFormatUnwrap(value)) << Debug::nospace << ")"; return debug << "PixelFormat::ImplementationSpecific(" << Debug::nospace << reinterpret_cast<void*>(pixelFormatUnwrap(value)) << Debug::nospace << ")";
} }
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#endif
switch(value) { switch(value) {
/* LCOV_EXCL_START */ /* LCOV_EXCL_START */
#define _c(value) case PixelFormat::value: return debug << "PixelFormat::" #value; #define _c(value) case PixelFormat::value: return debug << "PixelFormat::" #value;
@ -156,6 +167,9 @@ Debug& operator<<(Debug& debug, const PixelFormat value) {
#undef _c #undef _c
/* LCOV_EXCL_STOP */ /* LCOV_EXCL_STOP */
} }
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
return debug << "PixelFormat(" << Debug::nospace << reinterpret_cast<void*>(UnsignedInt(value)) << Debug::nospace << ")"; return debug << "PixelFormat(" << Debug::nospace << reinterpret_cast<void*>(UnsignedInt(value)) << Debug::nospace << ")";
} }
@ -167,6 +181,10 @@ Debug& operator<<(Debug& debug, const CompressedPixelFormat value) {
return debug << "CompressedPixelFormat::ImplementationSpecific(" << Debug::nospace << reinterpret_cast<void*>(compressedPixelFormatUnwrap(value)) << Debug::nospace << ")"; return debug << "CompressedPixelFormat::ImplementationSpecific(" << Debug::nospace << reinterpret_cast<void*>(compressedPixelFormatUnwrap(value)) << Debug::nospace << ")";
} }
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#endif
switch(value) { switch(value) {
/* LCOV_EXCL_START */ /* LCOV_EXCL_START */
#define _c(value) case CompressedPixelFormat::value: return debug << "CompressedPixelFormat::" #value; #define _c(value) case CompressedPixelFormat::value: return debug << "CompressedPixelFormat::" #value;
@ -187,6 +205,9 @@ Debug& operator<<(Debug& debug, const CompressedPixelFormat value) {
#undef _c #undef _c
/* LCOV_EXCL_STOP */ /* LCOV_EXCL_STOP */
} }
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
return debug << "CompressedPixelFormat(" << Debug::nospace << reinterpret_cast<void*>(UnsignedInt(value)) << Debug::nospace << ")"; return debug << "CompressedPixelFormat(" << Debug::nospace << reinterpret_cast<void*>(UnsignedInt(value)) << Debug::nospace << ")";
} }

14
src/Magnum/Vk/Test/EnumsTest.cpp

@ -190,6 +190,10 @@ void EnumsTest::mapVkFormat() {
- that there was no gap (unhandled value inside the range) - that there was no gap (unhandled value inside the range)
- that a particular pixel format maps to a particular GL format - that a particular pixel format maps to a particular GL format
- that a particular pixel type maps to a particular GL type */ - that a particular pixel type maps to a particular GL type */
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#endif
switch(format) { switch(format) {
#define _c(format, expectedFormat) \ #define _c(format, expectedFormat) \
case Magnum::PixelFormat::format: \ case Magnum::PixelFormat::format: \
@ -211,6 +215,9 @@ void EnumsTest::mapVkFormat() {
#undef _s #undef _s
#undef _c #undef _c
} }
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
/* Not handled by any value, remember -- we might either be at the end /* 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 of the enum range (which is okay) or some value might be unhandled
@ -267,6 +274,10 @@ void EnumsTest::mapVkFormatCompressed() {
- that there was no gap (unhandled value inside the range) - that there was no gap (unhandled value inside the range)
- that a particular pixel format maps to a particular GL format - that a particular pixel format maps to a particular GL format
- that a particular pixel type maps to a particular GL type */ - that a particular pixel type maps to a particular GL type */
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#endif
switch(format) { switch(format) {
#define _c(format, expectedFormat) \ #define _c(format, expectedFormat) \
case Magnum::CompressedPixelFormat::format: \ case Magnum::CompressedPixelFormat::format: \
@ -288,6 +299,9 @@ void EnumsTest::mapVkFormatCompressed() {
#undef _s #undef _s
#undef _c #undef _c
} }
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
/* Not handled by any value, remember -- we might either be at the end /* 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 of the enum range (which is okay) or some value might be unhandled

Loading…
Cancel
Save