Browse Source

GL, Vk: future-proof mesh primitive and index mapping tables.

The test now explicitly goes through all generic names and checks that
the mapping doesn't blow up.
pull/371/head
Vladimír Vondruš 6 years ago
parent
commit
3f57130547
  1. 44
      src/Magnum/GL/Test/MeshTest.cpp
  2. 45
      src/Magnum/Vk/Test/EnumsTest.cpp

44
src/Magnum/GL/Test/MeshTest.cpp

@ -153,6 +153,28 @@ void MeshTest::mapPrimitive() {
CORRADE_COMPARE(meshPrimitive(Magnum::MeshPrimitive::Triangles), MeshPrimitive::Triangles);
CORRADE_COMPARE(meshPrimitive(Magnum::MeshPrimitive::TriangleStrip), MeshPrimitive::TriangleStrip);
CORRADE_COMPARE(meshPrimitive(Magnum::MeshPrimitive::TriangleFan), MeshPrimitive::TriangleFan);
/* Ensure all generic primitives are handled. This goes through the first
16 bits, which should be enough. Going through 32 bits takes 8 seconds,
too much. */
for(UnsignedInt i = 1; i <= 0xffff; ++i) {
const auto primitive = Magnum::MeshPrimitive(i);
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#endif
switch(primitive) {
#define _c(primitive) \
case Magnum::MeshPrimitive::primitive: \
CORRADE_VERIFY(UnsignedInt(meshPrimitive(Magnum::MeshPrimitive::primitive)) >= 0); \
break;
#include "Magnum/Implementation/meshPrimitiveMapping.hpp"
#undef _c
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
}
}
void MeshTest::mapPrimitiveInvalid() {
@ -168,6 +190,28 @@ void MeshTest::mapIndexType() {
CORRADE_COMPARE(meshIndexType(Magnum::MeshIndexType::UnsignedByte), MeshIndexType::UnsignedByte);
CORRADE_COMPARE(meshIndexType(Magnum::MeshIndexType::UnsignedShort), MeshIndexType::UnsignedShort);
CORRADE_COMPARE(meshIndexType(Magnum::MeshIndexType::UnsignedInt), MeshIndexType::UnsignedInt);
/* Ensure all generic index types are handled. This goes through the first
16 bits, which should be enough. Going through 32 bits takes 8 seconds,
too much. */
for(UnsignedInt i = 1; i <= 0xffff; ++i) {
const auto type = Magnum::MeshIndexType(i);
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#endif
switch(type) {
#define _c(type) \
case Magnum::MeshIndexType::type: \
CORRADE_VERIFY(UnsignedInt(meshIndexType(Magnum::MeshIndexType::type)) >= 0); \
break;
#include "Magnum/Implementation/meshIndexTypeMapping.hpp"
#undef _c
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
}
}
void MeshTest::mapIndexTypeInvalid() {

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

@ -116,6 +116,29 @@ void EnumsTest::mapVkPrimitiveTopology() {
CORRADE_VERIFY(hasVkPrimitiveTopology(Magnum::MeshPrimitive::TriangleFan));
CORRADE_COMPARE(vkPrimitiveTopology(Magnum::MeshPrimitive::TriangleFan), VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN);
/* Ensure all generic primitives are handled. This goes through the first
16 bits, which should be enough. Going through 32 bits takes 8 seconds,
too much. */
for(UnsignedInt i = 1; i <= 0xffff; ++i) {
const auto primitive = Magnum::MeshPrimitive(i);
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#endif
switch(primitive) {
#define _c(primitive) \
case Magnum::MeshPrimitive::primitive: \
if(hasVkPrimitiveTopology(Magnum::MeshPrimitive::primitive)) \
CORRADE_VERIFY(UnsignedInt(vkPrimitiveTopology(Magnum::MeshPrimitive::primitive)) >= 0); \
break;
#include "Magnum/Implementation/meshPrimitiveMapping.hpp"
#undef _c
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
}
}
void EnumsTest::mapVkPrimitiveTopologyUnsupported() {
@ -147,6 +170,28 @@ void EnumsTest::mapVkIndexType() {
CORRADE_VERIFY(hasVkIndexType(Magnum::MeshIndexType::UnsignedInt));
CORRADE_COMPARE(vkIndexType(Magnum::MeshIndexType::UnsignedInt), VK_INDEX_TYPE_UINT32);
/* Ensure all generic index types are handled. This goes through the first
16 bits, which should be enough. Going through 32 bits takes 8 seconds,
too much. */
for(UnsignedInt i = 1; i <= 0xffff; ++i) {
const auto type = Magnum::MeshIndexType(i);
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wswitch"
#endif
switch(type) {
#define _c(type) \
case Magnum::MeshIndexType::type: \
CORRADE_VERIFY(UnsignedInt(vkIndexType(Magnum::MeshIndexType::type)) >= 0); \
break;
#include "Magnum/Implementation/meshIndexTypeMapping.hpp"
#undef _c
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
}
}
void EnumsTest::mapVkIndexTypeUnsupported() {

Loading…
Cancel
Save