mirror of https://github.com/mosra/magnum.git
Browse Source
Similarly to pixel formats, there is now generic Magnum::MeshPrimitive and Magnum::MeshIndexType, which is convertible to GL::MeshPrimitive and GL::MeshIndexType using GL::meshPrimitive() and GL::meshIndexType(). In addition, the following is done: * The original GL::Mesh::IndexType is now GL::MeshIndexType, original name is now just a typedef. * GL::Mesh::indexSize() is deprecated in favor of Magnum::meshIndexTypeSize() and GL::Mesh::indexTypeSize(). * New GL::Mesh::indexType() and GL::MeshView::mesh() getters (not sure why they were omitted) * GL::Mesh::indexType(), GL::Mesh::indexTypeSize(), GL::MeshView::setIndexRange() now expect that the mesh is indexed (useful property in my opinion, also avoids getting random results). * The extra MeshPrimitive::LinesAdjacency etc. are still present for backwards compatibility, but marked as deprecated. Use GL::MeshPrimitive values instead.pull/233/head
17 changed files with 867 additions and 274 deletions
@ -0,0 +1,165 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 |
||||
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 "Mesh.h" |
||||
|
||||
#include <Corrade/Utility/Assert.h> |
||||
#include <Corrade/Utility/Debug.h> |
||||
|
||||
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(); /* LCOV_EXCL_LINE */ |
||||
} |
||||
|
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
Debug& operator<<(Debug& debug, MeshPrimitive value) { |
||||
switch(value) { |
||||
/* LCOV_EXCL_START */ |
||||
#define _c(value) case MeshPrimitive::value: return debug << "MeshPrimitive::" #value; |
||||
_c(Points) |
||||
_c(Lines) |
||||
_c(LineLoop) |
||||
_c(LineStrip) |
||||
_c(Triangles) |
||||
_c(TriangleStrip) |
||||
_c(TriangleFan) |
||||
#undef _c |
||||
|
||||
/* Here mainly to suppress compiler warnings about unhandled cases and
|
||||
also to check that there are no accidentally conflicting values. */ |
||||
#if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL) && !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) |
||||
CORRADE_IGNORE_DEPRECATED_PUSH |
||||
#define _c(value) case MeshPrimitive::value: return debug << "GL::MeshPrimitive::" #value; |
||||
_c(LinesAdjacency) |
||||
_c(LineStripAdjacency) |
||||
_c(TrianglesAdjacency) |
||||
_c(TriangleStripAdjacency) |
||||
_c(Patches) |
||||
#undef _c |
||||
CORRADE_IGNORE_DEPRECATED_POP |
||||
#endif |
||||
/* LCOV_EXCL_STOP */ |
||||
} |
||||
|
||||
return debug << "MeshPrimitive(" << Debug::nospace << reinterpret_cast<void*>(GLenum(value)) << Debug::nospace << ")"; |
||||
} |
||||
|
||||
Debug& operator<<(Debug& debug, MeshIndexType value) { |
||||
switch(value) { |
||||
/* LCOV_EXCL_START */ |
||||
#define _c(value) case MeshIndexType::value: return debug << "MeshIndexType::" #value; |
||||
_c(UnsignedByte) |
||||
_c(UnsignedShort) |
||||
_c(UnsignedInt) |
||||
#undef _c |
||||
/* LCOV_EXCL_STOP */ |
||||
} |
||||
|
||||
return debug << "MeshIndexType(" << Debug::nospace << reinterpret_cast<void*>(GLenum(value)) << Debug::nospace << ")"; |
||||
} |
||||
#endif |
||||
|
||||
} |
||||
|
||||
namespace Corrade { namespace Utility { |
||||
|
||||
std::string ConfigurationValue<Magnum::MeshPrimitive>::toString(Magnum::MeshPrimitive value, ConfigurationValueFlags) { |
||||
switch(value) { |
||||
/* LCOV_EXCL_START */ |
||||
#define _c(value) case Magnum::MeshPrimitive::value: return #value; |
||||
_c(Points) |
||||
_c(Lines) |
||||
_c(LineLoop) |
||||
_c(LineStrip) |
||||
_c(Triangles) |
||||
_c(TriangleStrip) |
||||
_c(TriangleFan) |
||||
#undef _c |
||||
|
||||
#if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL) && !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) |
||||
CORRADE_IGNORE_DEPRECATED_PUSH |
||||
case Magnum::MeshPrimitive::LinesAdjacency: |
||||
case Magnum::MeshPrimitive::LineStripAdjacency: |
||||
case Magnum::MeshPrimitive::TrianglesAdjacency: |
||||
case Magnum::MeshPrimitive::TriangleStripAdjacency: |
||||
case Magnum::MeshPrimitive::Patches: |
||||
return {}; |
||||
CORRADE_IGNORE_DEPRECATED_POP |
||||
#endif |
||||
/* LCOV_EXCL_STOP */ |
||||
} |
||||
|
||||
return {}; |
||||
} |
||||
|
||||
Magnum::MeshPrimitive ConfigurationValue<Magnum::MeshPrimitive>::fromString(const std::string& stringValue, ConfigurationValueFlags) { |
||||
/* LCOV_EXCL_START */ |
||||
#define _c(value) if(stringValue == #value) return Magnum::MeshPrimitive::value; |
||||
_c(LineStrip) |
||||
_c(LineLoop) |
||||
_c(Lines) |
||||
_c(Triangles) |
||||
_c(TriangleStrip) |
||||
_c(TriangleFan) |
||||
#undef _c |
||||
/* LCOV_EXCL_STOP */ |
||||
|
||||
return Magnum::MeshPrimitive::Points; |
||||
} |
||||
|
||||
std::string ConfigurationValue<Magnum::MeshIndexType>::toString(Magnum::MeshIndexType value, ConfigurationValueFlags) { |
||||
switch(value) { |
||||
/* LCOV_EXCL_START */ |
||||
#define _c(value) case Magnum::MeshIndexType::value: return #value; |
||||
_c(UnsignedByte) |
||||
_c(UnsignedShort) |
||||
_c(UnsignedInt) |
||||
#undef _c |
||||
/* LCOV_EXCL_STOP */ |
||||
} |
||||
|
||||
return {}; |
||||
} |
||||
|
||||
Magnum::MeshIndexType ConfigurationValue<Magnum::MeshIndexType>::fromString(const std::string& stringValue, ConfigurationValueFlags) { |
||||
/* LCOV_EXCL_START */ |
||||
#define _c(value) if(stringValue == #value) return Magnum::MeshIndexType::value; |
||||
_c(UnsignedByte) |
||||
_c(UnsignedShort) |
||||
_c(UnsignedInt) |
||||
#undef _c |
||||
/* LCOV_EXCL_STOP */ |
||||
|
||||
return Magnum::MeshIndexType::UnsignedInt; |
||||
} |
||||
|
||||
}} |
||||
@ -0,0 +1,98 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 |
||||
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/Configuration.h> |
||||
|
||||
#include "Magnum/Mesh.h" |
||||
|
||||
namespace Magnum { namespace Test { |
||||
|
||||
struct MeshTest: TestSuite::Tester { |
||||
explicit MeshTest(); |
||||
|
||||
void indexTypeSize(); |
||||
|
||||
void debugPrimitive(); |
||||
void debugIndexType(); |
||||
void configurationPrimitive(); |
||||
void configurationIndexType(); |
||||
}; |
||||
|
||||
MeshTest::MeshTest() { |
||||
addTests({&MeshTest::indexTypeSize, |
||||
|
||||
&MeshTest::debugPrimitive, |
||||
&MeshTest::debugIndexType, |
||||
&MeshTest::configurationPrimitive, |
||||
&MeshTest::configurationIndexType}); |
||||
} |
||||
|
||||
void MeshTest::indexTypeSize() { |
||||
CORRADE_COMPARE(meshIndexTypeSize(MeshIndexType::UnsignedByte), 1); |
||||
CORRADE_COMPARE(meshIndexTypeSize(MeshIndexType::UnsignedShort), 2); |
||||
CORRADE_COMPARE(meshIndexTypeSize(MeshIndexType::UnsignedInt), 4); |
||||
} |
||||
|
||||
void MeshTest::debugPrimitive() { |
||||
std::ostringstream o; |
||||
Debug(&o) << MeshPrimitive::TriangleFan << MeshPrimitive(0xdead); |
||||
CORRADE_COMPARE(o.str(), "MeshPrimitive::TriangleFan MeshPrimitive(0xdead)\n"); |
||||
} |
||||
|
||||
void MeshTest::debugIndexType() { |
||||
std::ostringstream o; |
||||
Debug(&o) << MeshIndexType::UnsignedShort << MeshIndexType(0xdead); |
||||
CORRADE_COMPARE(o.str(), "MeshIndexType::UnsignedShort MeshIndexType(0xdead)\n"); |
||||
} |
||||
|
||||
void MeshTest::configurationPrimitive() { |
||||
Utility::Configuration c; |
||||
|
||||
c.setValue("primitive", MeshPrimitive::LineStrip); |
||||
CORRADE_COMPARE(c.value("primitive"), "LineStrip"); |
||||
CORRADE_COMPARE(c.value<MeshPrimitive>("primitive"), MeshPrimitive::LineStrip); |
||||
|
||||
c.setValue("invalid", MeshPrimitive(0xdead)); |
||||
CORRADE_COMPARE(c.value("invalid"), ""); |
||||
CORRADE_COMPARE(c.value<MeshPrimitive>("invalid"), MeshPrimitive::Points); |
||||
} |
||||
|
||||
void MeshTest::configurationIndexType() { |
||||
Utility::Configuration c; |
||||
|
||||
c.setValue("type", MeshIndexType::UnsignedShort); |
||||
CORRADE_COMPARE(c.value("type"), "UnsignedShort"); |
||||
CORRADE_COMPARE(c.value<MeshIndexType>("type"), MeshIndexType::UnsignedShort); |
||||
|
||||
c.setValue("invalid", MeshIndexType(0xdead)); |
||||
CORRADE_COMPARE(c.value("invalid"), ""); |
||||
CORRADE_COMPARE(c.value<MeshIndexType>("invalid"), MeshIndexType::UnsignedInt); |
||||
} |
||||
|
||||
}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Test::MeshTest) |
||||
Loading…
Reference in new issue