diff --git a/src/IndexedMesh.cpp b/src/IndexedMesh.cpp index 099bc3065..dbd2cd321 100644 --- a/src/IndexedMesh.cpp +++ b/src/IndexedMesh.cpp @@ -15,8 +15,6 @@ #include "IndexedMesh.h" -#include - #include "Buffer.h" #include "Context.h" #include "Extensions.h" @@ -26,16 +24,6 @@ namespace Magnum { IndexedMesh::BindIndexBufferImplementation IndexedMesh::bindIndexBufferImplementation = &IndexedMesh::bindIndexBufferImplementationDefault; IndexedMesh::BindIndexedImplementation IndexedMesh::bindIndexedImplementation = &IndexedMesh::bindIndexedImplementationDefault; -std::size_t IndexedMesh::indexSize(IndexType type) { - switch(type) { - case IndexType::UnsignedByte: return 1; - case IndexType::UnsignedShort: return 2; - case IndexType::UnsignedInt: return 4; - } - - CORRADE_INTERNAL_ASSERT(false); -} - IndexedMesh* IndexedMesh::setIndexBuffer(Buffer* buffer) { _indexBuffer = buffer; (this->*bindIndexBufferImplementation)(); @@ -87,44 +75,4 @@ void IndexedMesh::bindIndexedImplementationDefault() { void IndexedMesh::bindIndexedImplementationVAO() {} -#ifndef DOXYGEN_GENERATING_OUTPUT -Debug operator<<(Debug debug, IndexedMesh::IndexType value) { - switch(value) { - #define _c(value) case IndexedMesh::IndexType::value: return debug << "IndexedMesh::IndexType::" #value; - _c(UnsignedByte) - _c(UnsignedShort) - _c(UnsignedInt) - #undef _c - } - - return debug << "IndexedMesh::IndexType::(invalid)"; -} -#endif - } - -namespace Corrade { namespace Utility { - -std::string ConfigurationValue::toString(Magnum::IndexedMesh::IndexType value, ConfigurationValueFlags) { - switch(value) { - #define _c(value) case Magnum::IndexedMesh::IndexType::value: return #value; - _c(UnsignedByte) - _c(UnsignedShort) - _c(UnsignedInt) - #undef _c - } - - return ""; -} - -Magnum::IndexedMesh::IndexType ConfigurationValue::fromString(const std::string& stringValue, ConfigurationValueFlags) { - #define _c(value) if(stringValue == #value) return Magnum::IndexedMesh::IndexType::value; - _c(UnsignedByte) - _c(UnsignedShort) - _c(UnsignedInt) - #undef _c - - return Magnum::IndexedMesh::IndexType::UnsignedInt; -} - -}} diff --git a/src/IndexedMesh.h b/src/IndexedMesh.h index 40d9d5f09..8b9cca1fe 100644 --- a/src/IndexedMesh.h +++ b/src/IndexedMesh.h @@ -72,25 +72,6 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { friend class Context; public: - /** - * @brief Index type - * - * @see setIndexType(), indexSize() - */ - enum class IndexType: GLenum { - UnsignedByte = GL_UNSIGNED_BYTE, /**< Unsigned byte */ - UnsignedShort = GL_UNSIGNED_SHORT, /**< Unsigned short */ - - /** - * Unsigned int - * @requires_gles30 %Extension @es_extension{OES,element_index_uint} - */ - UnsignedInt = GL_UNSIGNED_INT - }; - - /** @brief Size of given index type */ - static std::size_t indexSize(IndexType type); - /** * @brief Constructor * @param primitive Primitive type @@ -196,32 +177,6 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { IndexType _indexType; }; -/** @debugoperator{Magnum::IndexedMesh} */ -Debug MAGNUM_EXPORT operator<<(Debug debug, IndexedMesh::IndexType value); - } -namespace Corrade { namespace Utility { - -/** @configurationvalue{Magnum::IndexedMesh} */ -template<> struct MAGNUM_EXPORT ConfigurationValue { - ConfigurationValue() = delete; - - /** - * @brief Write enum value as string - * - * If the value is invalid, returns empty string. - */ - static std::string toString(Magnum::IndexedMesh::IndexType value, ConfigurationValueFlags); - - /** - * @brief Read enum value as string - * - * If the value is invalid, returns @ref Magnum::IndexedMesh::IndexType "IndexedMesh::IndexType::UnsignedInt". - */ - static Magnum::IndexedMesh::IndexType fromString(const std::string& stringValue, ConfigurationValueFlags); -}; - -}} - #endif diff --git a/src/Mesh.cpp b/src/Mesh.cpp index d069132cb..fab5b9d86 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -37,6 +37,16 @@ Mesh::AttributeLPointerImplementation Mesh::attributeLPointerImplementation = &M Mesh::BindImplementation Mesh::bindImplementation = &Mesh::bindImplementationDefault; Mesh::UnbindImplementation Mesh::unbindImplementation = &Mesh::unbindImplementationDefault; +std::size_t Mesh::indexSize(IndexType type) { + switch(type) { + case IndexType::UnsignedByte: return 1; + case IndexType::UnsignedShort: return 2; + case IndexType::UnsignedInt: return 4; + } + + CORRADE_INTERNAL_ASSERT(false); +} + Mesh::~Mesh() { /* Remove current vao from the state */ GLuint& current = Context::current()->state()->mesh->currentVAO; @@ -271,6 +281,18 @@ Debug operator<<(Debug debug, Mesh::Primitive value) { return debug << "Mesh::Primitive::(invalid)"; } + +Debug operator<<(Debug debug, Mesh::IndexType value) { + switch(value) { + #define _c(value) case Mesh::IndexType::value: return debug << "Mesh::IndexType::" #value; + _c(UnsignedByte) + _c(UnsignedShort) + _c(UnsignedInt) + #undef _c + } + + return debug << "Mesh::IndexType::(invalid)"; +} #endif } @@ -306,4 +328,26 @@ Magnum::Mesh::Primitive ConfigurationValue::fromString( return Magnum::Mesh::Primitive::Points; } +std::string ConfigurationValue::toString(Magnum::Mesh::IndexType value, ConfigurationValueFlags) { + switch(value) { + #define _c(value) case Magnum::Mesh::IndexType::value: return #value; + _c(UnsignedByte) + _c(UnsignedShort) + _c(UnsignedInt) + #undef _c + } + + return ""; +} + +Magnum::Mesh::IndexType ConfigurationValue::fromString(const std::string& stringValue, ConfigurationValueFlags) { + #define _c(value) if(stringValue == #value) return Magnum::Mesh::IndexType::value; + _c(UnsignedByte) + _c(UnsignedShort) + _c(UnsignedInt) + #undef _c + + return Magnum::Mesh::IndexType::UnsignedInt; +} + }} diff --git a/src/Mesh.h b/src/Mesh.h index 5018fa63c..99abd5a3f 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -358,6 +358,25 @@ class MAGNUM_EXPORT Mesh { TriangleFan = GL_TRIANGLE_FAN }; + /** + * @brief Index type + * + * @see setIndexType(), indexSize() + */ + enum class IndexType: GLenum { + UnsignedByte = GL_UNSIGNED_BYTE, /**< Unsigned byte */ + UnsignedShort = GL_UNSIGNED_SHORT, /**< Unsigned short */ + + /** + * Unsigned int + * @requires_gles30 %Extension @es_extension{OES,element_index_uint} + */ + UnsignedInt = GL_UNSIGNED_INT + }; + + /** @brief Size of given index type */ + static std::size_t indexSize(IndexType type); + /** * @brief Constructor * @param primitive Primitive type @@ -753,6 +772,9 @@ class MAGNUM_EXPORT Mesh { /** @debugoperator{Magnum::Mesh} */ Debug MAGNUM_EXPORT operator<<(Debug debug, Mesh::Primitive value); +/** @debugoperator{Magnum::Mesh} */ +Debug MAGNUM_EXPORT operator<<(Debug debug, Mesh::IndexType value); + } namespace Corrade { namespace Utility { @@ -776,6 +798,25 @@ template<> struct MAGNUM_EXPORT ConfigurationValue { static Magnum::Mesh::Primitive fromString(const std::string& stringValue, ConfigurationValueFlags); }; +/** @configurationvalue{Magnum::Mesh} */ +template<> struct MAGNUM_EXPORT ConfigurationValue { + ConfigurationValue() = delete; + + /** + * @brief Write enum value as string + * + * If the value is invalid, returns empty string. + */ + static std::string toString(Magnum::Mesh::IndexType value, ConfigurationValueFlags); + + /** + * @brief Read enum value as string + * + * If the value is invalid, returns @ref Magnum::IndexedMesh::IndexType "IndexedMesh::IndexType::UnsignedInt". + */ + static Magnum::Mesh::IndexType fromString(const std::string& stringValue, ConfigurationValueFlags); +}; + }} #endif diff --git a/src/Test/CMakeLists.txt b/src/Test/CMakeLists.txt index 4364e87d3..44d840117 100644 --- a/src/Test/CMakeLists.txt +++ b/src/Test/CMakeLists.txt @@ -2,7 +2,6 @@ corrade_add_test(AbstractImageTest AbstractImageTest.cpp LIBRARIES Magnum) corrade_add_test(ArrayTest ArrayTest.cpp) corrade_add_test(ColorTest ColorTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MeshTest MeshTest.cpp LIBRARIES Magnum) -corrade_add_test(IndexedMeshTest IndexedMeshTest.cpp LIBRARIES Magnum) corrade_add_test(ResourceManagerTest ResourceManagerTest.cpp LIBRARIES MagnumTestLib) corrade_add_test(SwizzleTest SwizzleTest.cpp LIBRARIES MagnumMathTestLib) diff --git a/src/Test/IndexedMeshTest.cpp b/src/Test/IndexedMeshTest.cpp deleted file mode 100644 index 6d51e341f..000000000 --- a/src/Test/IndexedMeshTest.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include -#include -#include - -#include "IndexedMesh.h" - -using namespace Corrade::Utility; - -namespace Magnum { namespace Test { - -class IndexedMeshTest: public Corrade::TestSuite::Tester { - public: - IndexedMeshTest(); - - void debug(); - void configuration(); -}; - -IndexedMeshTest::IndexedMeshTest() { - addTests(&IndexedMeshTest::debug, - &IndexedMeshTest::configuration); -} - -void IndexedMeshTest::debug() { - std::ostringstream o; - Debug(&o) << IndexedMesh::IndexType::UnsignedShort; - CORRADE_COMPARE(o.str(), "IndexedMesh::IndexType::UnsignedShort\n"); -} - -void IndexedMeshTest::configuration() { - Configuration c; - - c.setValue("type", IndexedMesh::IndexType::UnsignedByte); - CORRADE_COMPARE(c.value("type"), "UnsignedByte"); - CORRADE_COMPARE(c.value("type"), IndexedMesh::IndexType::UnsignedByte); -} - -}} - -CORRADE_TEST_MAIN(Magnum::Test::IndexedMeshTest) diff --git a/src/Test/MeshTest.cpp b/src/Test/MeshTest.cpp index 658febb17..5850c68b5 100644 --- a/src/Test/MeshTest.cpp +++ b/src/Test/MeshTest.cpp @@ -27,22 +27,32 @@ class MeshTest: public Corrade::TestSuite::Tester { public: MeshTest(); - void debug(); - void configuration(); + void debugPrimitive(); + void debugIndexType(); + void configurationPrimitive(); + void configurationIndexType(); }; MeshTest::MeshTest() { - addTests(&MeshTest::debug, - &MeshTest::configuration); + addTests(&MeshTest::debugPrimitive, + &MeshTest::debugIndexType, + &MeshTest::configurationPrimitive, + &MeshTest::configurationIndexType); } -void MeshTest::debug() { +void MeshTest::debugPrimitive() { std::ostringstream o; Debug(&o) << Mesh::Primitive::TriangleFan; CORRADE_COMPARE(o.str(), "Mesh::Primitive::TriangleFan\n"); } -void MeshTest::configuration() { +void MeshTest::debugIndexType() { + std::ostringstream o; + Debug(&o) << Mesh::IndexType::UnsignedShort; + CORRADE_COMPARE(o.str(), "Mesh::IndexType::UnsignedShort\n"); +} + +void MeshTest::configurationPrimitive() { Configuration c; c.setValue("primitive", Mesh::Primitive::LineStrip); @@ -50,6 +60,14 @@ void MeshTest::configuration() { CORRADE_COMPARE(c.value("primitive"), Mesh::Primitive::LineStrip); } +void MeshTest::configurationIndexType() { + Configuration c; + + c.setValue("type", Mesh::IndexType::UnsignedByte); + CORRADE_COMPARE(c.value("type"), "UnsignedByte"); + CORRADE_COMPARE(c.value("type"), Mesh::IndexType::UnsignedByte); +} + }} CORRADE_TEST_MAIN(Magnum::Test::MeshTest)