diff --git a/doc/changelog-old.dox b/doc/changelog-old.dox index 62b757b7c..051cb66a2 100644 --- a/doc/changelog-old.dox +++ b/doc/changelog-old.dox @@ -272,7 +272,7 @@ Released 2018-05-01, tagged as function is deprecated, use @ref Magnum::MeshIndexType / @ref GL::MeshIndexType and @ref meshIndexTypeSize() instead - The `GL::Mesh::indexSize()` function is deprecated, use - @ref GL::Mesh::indexTypeSize() instead + @cpp GL::Mesh::indexTypeSize() @ce instead - The `Sampler` class and the `Sampler::Filter`, `Sampler::Mipmap`, `Sampler::Wrapping`, `Sampler::CompareMode`, `Sampler::CompareFunction` and `Sampler::DepthStencilMode` enums are deprecated, use @ref GL::Sampler, diff --git a/doc/changelog.dox b/doc/changelog.dox index fe5cc6bc4..67bd15b96 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -1075,6 +1075,9 @@ See also: and [mosra/magnum#596](https://github.com/mosra/magnum/pull/596). - @cpp GL::MeshView::setIndexRange() @ce is deprecated in favor of @ref GL::MeshView::setIndexOffset() that has a much less confusing name +- @cpp GL::Mesh::indexTypeSize() @ce is deprecated in favor of a standalone + @ref GL::meshIndexTypeSize() utility that you can call on the enum returned + from @ref GL::Mesh::indexType() - The @cpp Array @ce, @cpp Array1D @ce, @cpp Array2D @ce and @cpp Array3D @ce types that were used exclusively for specifying @ref SamplerWrapping in various texture APIs are deprecated in favor of @@ -3119,7 +3122,8 @@ Released 2019-10-24, tagged as (and root include path) which were deprecated in 2018.04 and everything related to this change: - @cpp GL::Mesh::IndexType @ce and @cpp GL::Mesh::indexSize() @ce, - use @ref GL::MeshIndexType and @ref GL::Mesh::indexTypeSize() instead + use @ref GL::MeshIndexType and @cpp GL::Mesh::indexTypeSize() @ce + instead - Removed @cpp Primitives::Capsule2D @ce, @cpp Primitives::Capsule3D @ce, @cpp Primitives::Circle @ce, @cpp Primitives::Crosshair2D @ce, @cpp Primitives::Crosshair3D @ce, @cpp Primitives::Cube @ce, diff --git a/src/Magnum/GL/Mesh.cpp b/src/Magnum/GL/Mesh.cpp index f435d0479..24179c83c 100644 --- a/src/Magnum/GL/Mesh.cpp +++ b/src/Magnum/GL/Mesh.cpp @@ -107,6 +107,16 @@ MeshIndexType meshIndexType(const Magnum::MeshIndexType type) { return IndexTypeMapping[UnsignedInt(type) - 1]; } +UnsignedInt meshIndexTypeSize(const MeshIndexType type) { + switch(type) { + case MeshIndexType::UnsignedByte: return 1; + case MeshIndexType::UnsignedShort: return 2; + case MeshIndexType::UnsignedInt: return 4; + } + + CORRADE_ASSERT_UNREACHABLE("GL::meshIndexTypeSize(): invalid type" << type, {}); +} + #ifndef DOXYGEN_GENERATING_OUTPUT Debug& operator<<(Debug& debug, const MeshPrimitive value) { debug << "GL::MeshPrimitive" << Debug::nospace; @@ -354,17 +364,13 @@ MeshIndexType Mesh::indexType() const { return _indexType; } +#ifdef MAGNUM_BUILD_DEPRECATED UnsignedInt Mesh::indexTypeSize() const { CORRADE_ASSERT(_indexBuffer.id(), "Mesh::indexTypeSize(): mesh is not indexed", {}); - switch(_indexType) { - case MeshIndexType::UnsignedByte: return 1; - case MeshIndexType::UnsignedShort: return 2; - case MeshIndexType::UnsignedInt: return 4; - } - - CORRADE_INTERNAL_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */ + return meshIndexTypeSize(_indexType); } +#endif Mesh& Mesh::addVertexBufferInstanced(Buffer& buffer, const UnsignedInt divisor, const GLintptr offset, const GLsizei stride, const DynamicAttribute& attribute) { for(UnsignedInt i = 0; i != attribute.vectors(); ++i) diff --git a/src/Magnum/GL/Mesh.h b/src/Magnum/GL/Mesh.h index 017765311..289bc30fb 100644 --- a/src/Magnum/GL/Mesh.h +++ b/src/Magnum/GL/Mesh.h @@ -26,7 +26,7 @@ */ /** @file - * @brief Class @ref Magnum::GL::Mesh, enum @ref Magnum::GL::MeshPrimitive, @ref Magnum::GL::MeshIndexType, function @ref Magnum::GL::meshPrimitive(), @ref Magnum::GL::meshIndexType() + * @brief Class @ref Magnum::GL::Mesh, enum @ref Magnum::GL::MeshPrimitive, @ref Magnum::GL::MeshIndexType, function @ref Magnum::GL::meshPrimitive(), @ref Magnum::GL::meshIndexType(), @ref Magnum::GL::meshIndexTypeSize() */ #include @@ -221,6 +221,14 @@ cast to @ref MeshIndexType. */ MAGNUM_GL_EXPORT MeshIndexType meshIndexType(Magnum::MeshIndexType type); +/** +@brief Size of given mesh index type +@m_since_latest + +@see @ref Magnum::meshIndexTypeSize() +*/ +MAGNUM_GL_EXPORT UnsignedInt meshIndexTypeSize(MeshIndexType type); + namespace Implementation { struct MeshState; @@ -653,13 +661,16 @@ class MAGNUM_GL_EXPORT Mesh: public AbstractObject { */ MeshIndexType indexType() const; + #ifdef MAGNUM_BUILD_DEPRECATED /** * @brief Index type size * * Expects that the mesh is indexed. - * @see @ref isIndexed(), @ref meshIndexTypeSize(Magnum::MeshIndexType) + * @m_deprecated_since_latest Use @ref meshIndexTypeSize() on the value + * returned from @ref indexType() instead. */ - UnsignedInt indexTypeSize() const; + CORRADE_DEPRECATED("use meshIndexTypeSize() on indexType() instead") UnsignedInt indexTypeSize() const; + #endif /** @brief Primitive type */ MeshPrimitive primitive() const { return _primitive; } diff --git a/src/Magnum/GL/MeshView.cpp b/src/Magnum/GL/MeshView.cpp index 4483a4800..596237143 100644 --- a/src/Magnum/GL/MeshView.cpp +++ b/src/Magnum/GL/MeshView.cpp @@ -59,7 +59,7 @@ void MeshView::draw(AbstractShaderProgram&& shader, std::initializer_list void MeshGLTest::setIndexBuffer() { MAGNUM_VERIFY_NO_GL_ERROR(); CORRADE_COMPARE(mesh.indexType(), MeshIndexType::UnsignedByte); - CORRADE_COMPARE(mesh.indexTypeSize(), 1); const auto value = Checker(MultipleShader{}, #ifndef MAGNUM_TARGET_GLES2 @@ -2556,7 +2555,6 @@ template void MeshGLTest::setIndexBufferRange() { MAGNUM_VERIFY_NO_GL_ERROR(); CORRADE_COMPARE(mesh.indexType(), GL::MeshIndexType::UnsignedShort); - CORRADE_COMPARE(mesh.indexTypeSize(), 2); const auto value = Checker(MultipleShader{}, #ifndef MAGNUM_TARGET_GLES2 @@ -2590,7 +2588,6 @@ void MeshGLTest::setIndexBufferUnsignedInt() { MAGNUM_VERIFY_NO_GL_ERROR(); CORRADE_COMPARE(mesh.indexType(), GL::MeshIndexType::UnsignedInt); - CORRADE_COMPARE(mesh.indexTypeSize(), 4); const auto value = Checker(MultipleShader{}, #ifndef MAGNUM_TARGET_GLES2 diff --git a/src/Magnum/GL/Test/MeshTest.cpp b/src/Magnum/GL/Test/MeshTest.cpp index ed1103167..6efec9c7b 100644 --- a/src/Magnum/GL/Test/MeshTest.cpp +++ b/src/Magnum/GL/Test/MeshTest.cpp @@ -58,6 +58,9 @@ struct MeshTest: TestSuite::Tester { void mapIndexTypeImplementationSpecific(); void mapIndexTypeInvalid(); + void indexTypeSize(); + void indexTypeSizeInvalid(); + void debugPrimitive(); void debugIndexType(); }; @@ -81,6 +84,9 @@ MeshTest::MeshTest() { &MeshTest::mapIndexTypeImplementationSpecific, &MeshTest::mapIndexTypeInvalid, + &MeshTest::indexTypeSize, + &MeshTest::indexTypeSizeInvalid, + &MeshTest::debugPrimitive, &MeshTest::debugIndexType}); } @@ -264,6 +270,24 @@ void MeshTest::mapIndexTypeInvalid() { "GL::meshIndexType(): invalid type MeshIndexType(0x12)\n"); } +void MeshTest::indexTypeSize() { + CORRADE_COMPARE(meshIndexTypeSize(MeshIndexType::UnsignedByte), 1); + CORRADE_COMPARE(meshIndexTypeSize(MeshIndexType::UnsignedShort), 2); + CORRADE_COMPARE(meshIndexTypeSize(MeshIndexType::UnsignedInt), 4); +} + +void MeshTest::indexTypeSizeInvalid() { + CORRADE_SKIP_IF_NO_ASSERT(); + + std::ostringstream out; + Error redirectError{&out}; + meshIndexTypeSize(MeshIndexType{}); + meshIndexTypeSize(MeshIndexType(0xbadcafe)); + CORRADE_COMPARE(out.str(), + "GL::meshIndexTypeSize(): invalid type GL::MeshIndexType(0x0)\n" + "GL::meshIndexTypeSize(): invalid type GL::MeshIndexType(0xbadcafe)\n"); +} + void MeshTest::debugPrimitive() { std::ostringstream o; Debug(&o) << MeshPrimitive::TriangleFan << MeshPrimitive(0xdead);