diff --git a/src/Magnum/Mesh.cpp b/src/Magnum/Mesh.cpp index 60b3fa1ab..f2614dbbf 100644 --- a/src/Magnum/Mesh.cpp +++ b/src/Magnum/Mesh.cpp @@ -32,16 +32,6 @@ namespace Magnum { -UnsignedInt meshIndexTypeSize(MeshIndexType type) { - switch(type) { - case MeshIndexType::UnsignedByte: return 1; - case MeshIndexType::UnsignedShort: return 2; - case MeshIndexType::UnsignedInt: return 4; - } - - CORRADE_ASSERT_UNREACHABLE("meshIndexTypeSize(): invalid type" << type, {}); -} - #ifndef DOXYGEN_GENERATING_OUTPUT namespace { @@ -88,6 +78,16 @@ Debug& operator<<(Debug& debug, const MeshIndexType value) { } #endif +UnsignedInt meshIndexTypeSize(MeshIndexType type) { + switch(type) { + case MeshIndexType::UnsignedByte: return 1; + case MeshIndexType::UnsignedShort: return 2; + case MeshIndexType::UnsignedInt: return 4; + } + + CORRADE_ASSERT_UNREACHABLE("meshIndexTypeSize(): invalid type" << type, {}); +} + } namespace Corrade { namespace Utility { diff --git a/src/Magnum/Mesh.h b/src/Magnum/Mesh.h index 5f1c3ceff..a37924b7f 100644 --- a/src/Magnum/Mesh.h +++ b/src/Magnum/Mesh.h @@ -286,12 +286,12 @@ enum class MeshIndexType: UnsignedByte { UnsignedInt }; -/** @brief Size of given mesh index type */ -MAGNUM_EXPORT UnsignedInt meshIndexTypeSize(MeshIndexType type); - /** @debugoperatorenum{MeshIndexType} */ MAGNUM_EXPORT Debug& operator<<(Debug& debug, MeshIndexType value); +/** @brief Size of given mesh index type */ +MAGNUM_EXPORT UnsignedInt meshIndexTypeSize(MeshIndexType type); + } namespace Corrade { namespace Utility { diff --git a/src/Magnum/Test/MeshTest.cpp b/src/Magnum/Test/MeshTest.cpp index 768f1e989..72e492f2c 100644 --- a/src/Magnum/Test/MeshTest.cpp +++ b/src/Magnum/Test/MeshTest.cpp @@ -37,14 +37,13 @@ struct MeshTest: TestSuite::Tester { explicit MeshTest(); void primitiveMapping(); - void indexTypeMapping(); - void primitiveIsImplementationSpecific(); void primitiveWrap(); void primitiveWrapInvalid(); void primitiveUnwrap(); void primitiveUnwrapInvalid(); + void indexTypeMapping(); void indexTypeSize(); void indexTypeSizeInvalid(); @@ -58,14 +57,13 @@ struct MeshTest: TestSuite::Tester { MeshTest::MeshTest() { addTests({&MeshTest::primitiveMapping, - &MeshTest::indexTypeMapping, - &MeshTest::primitiveIsImplementationSpecific, &MeshTest::primitiveWrap, &MeshTest::primitiveWrapInvalid, &MeshTest::primitiveUnwrap, &MeshTest::primitiveUnwrapInvalid, + &MeshTest::indexTypeMapping, &MeshTest::indexTypeSize, &MeshTest::indexTypeSizeInvalid, @@ -115,44 +113,6 @@ void MeshTest::primitiveMapping() { CORRADE_COMPARE(firstUnhandled, 0xff); } -void MeshTest::indexTypeMapping() { - /* This goes through the first 8 bits, which should be enough. */ - UnsignedInt firstUnhandled = 0xff; - UnsignedInt nextHandled = 1; /* 0 is an invalid type */ - for(UnsignedInt i = 1; i <= 0xff; ++i) { - const auto type = MeshIndexType(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) */ - #ifdef __GNUC__ - #pragma GCC diagnostic push - #pragma GCC diagnostic error "-Wswitch" - #endif - switch(type) { - #define _c(type) \ - case MeshIndexType::type: \ - CORRADE_COMPARE(Utility::ConfigurationValue::toString(MeshIndexType::type, {}), #type); \ - CORRADE_COMPARE(nextHandled, i); \ - CORRADE_COMPARE(firstUnhandled, 0xff); \ - ++nextHandled; \ - continue; - #include "Magnum/Implementation/meshIndexTypeMapping.hpp" - #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, 0xff); -} - void MeshTest::primitiveIsImplementationSpecific() { constexpr bool a = isMeshPrimitiveImplementationSpecific(MeshPrimitive::Lines); constexpr bool b = isMeshPrimitiveImplementationSpecific(MeshPrimitive(0x8000dead)); @@ -196,6 +156,44 @@ void MeshTest::primitiveUnwrapInvalid() { CORRADE_COMPARE(out.str(), "meshPrimitiveUnwrap(): MeshPrimitive::Triangles isn't a wrapped implementation-specific value\n"); } +void MeshTest::indexTypeMapping() { + /* This goes through the first 8 bits, which should be enough. */ + UnsignedInt firstUnhandled = 0xff; + UnsignedInt nextHandled = 1; /* 0 is an invalid type */ + for(UnsignedInt i = 1; i <= 0xff; ++i) { + const auto type = MeshIndexType(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) */ + #ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic error "-Wswitch" + #endif + switch(type) { + #define _c(type) \ + case MeshIndexType::type: \ + CORRADE_COMPARE(Utility::ConfigurationValue::toString(MeshIndexType::type, {}), #type); \ + CORRADE_COMPARE(nextHandled, i); \ + CORRADE_COMPARE(firstUnhandled, 0xff); \ + ++nextHandled; \ + continue; + #include "Magnum/Implementation/meshIndexTypeMapping.hpp" + #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, 0xff); +} + void MeshTest::indexTypeSize() { CORRADE_COMPARE(meshIndexTypeSize(MeshIndexType::UnsignedByte), 1); CORRADE_COMPARE(meshIndexTypeSize(MeshIndexType::UnsignedShort), 2);