Browse Source

GL: deprecate Mesh::indexTypeSize() in favor of meshIndexTypeSize().

Because it makes no sense to only be able to query the index type size
on a live mesh.
pull/168/head
Vladimír Vondruš 3 years ago
parent
commit
a7e1394cd9
  1. 2
      doc/changelog-old.dox
  2. 6
      doc/changelog.dox
  3. 20
      src/Magnum/GL/Mesh.cpp
  4. 17
      src/Magnum/GL/Mesh.h
  5. 2
      src/Magnum/GL/MeshView.cpp
  6. 3
      src/Magnum/GL/Test/MeshGLTest.cpp
  7. 24
      src/Magnum/GL/Test/MeshTest.cpp

2
doc/changelog-old.dox

@ -272,7 +272,7 @@ Released 2018-05-01, tagged as
function is deprecated, use @ref Magnum::MeshIndexType / function is deprecated, use @ref Magnum::MeshIndexType /
@ref GL::MeshIndexType and @ref meshIndexTypeSize() instead @ref GL::MeshIndexType and @ref meshIndexTypeSize() instead
- The `GL::Mesh::indexSize()` function is deprecated, use - 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`, - The `Sampler` class and the `Sampler::Filter`, `Sampler::Mipmap`,
`Sampler::Wrapping`, `Sampler::CompareMode`, `Sampler::CompareFunction` and `Sampler::Wrapping`, `Sampler::CompareMode`, `Sampler::CompareFunction` and
`Sampler::DepthStencilMode` enums are deprecated, use @ref GL::Sampler, `Sampler::DepthStencilMode` enums are deprecated, use @ref GL::Sampler,

6
doc/changelog.dox

@ -1075,6 +1075,9 @@ See also:
and [mosra/magnum#596](https://github.com/mosra/magnum/pull/596). and [mosra/magnum#596](https://github.com/mosra/magnum/pull/596).
- @cpp GL::MeshView::setIndexRange() @ce is deprecated in favor of - @cpp GL::MeshView::setIndexRange() @ce is deprecated in favor of
@ref GL::MeshView::setIndexOffset() that has a much less confusing name @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 - The @cpp Array @ce, @cpp Array1D @ce, @cpp Array2D @ce and
@cpp Array3D @ce types that were used exclusively for specifying @cpp Array3D @ce types that were used exclusively for specifying
@ref SamplerWrapping in various texture APIs are deprecated in favor of @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 (and root include path) which were deprecated in 2018.04 and everything
related to this change: related to this change:
- @cpp GL::Mesh::IndexType @ce and @cpp GL::Mesh::indexSize() @ce, - @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, - Removed @cpp Primitives::Capsule2D @ce, @cpp Primitives::Capsule3D @ce,
@cpp Primitives::Circle @ce, @cpp Primitives::Crosshair2D @ce, @cpp Primitives::Circle @ce, @cpp Primitives::Crosshair2D @ce,
@cpp Primitives::Crosshair3D @ce, @cpp Primitives::Cube @ce, @cpp Primitives::Crosshair3D @ce, @cpp Primitives::Cube @ce,

20
src/Magnum/GL/Mesh.cpp

@ -107,6 +107,16 @@ MeshIndexType meshIndexType(const Magnum::MeshIndexType type) {
return IndexTypeMapping[UnsignedInt(type) - 1]; 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 #ifndef DOXYGEN_GENERATING_OUTPUT
Debug& operator<<(Debug& debug, const MeshPrimitive value) { Debug& operator<<(Debug& debug, const MeshPrimitive value) {
debug << "GL::MeshPrimitive" << Debug::nospace; debug << "GL::MeshPrimitive" << Debug::nospace;
@ -354,17 +364,13 @@ MeshIndexType Mesh::indexType() const {
return _indexType; return _indexType;
} }
#ifdef MAGNUM_BUILD_DEPRECATED
UnsignedInt Mesh::indexTypeSize() const { UnsignedInt Mesh::indexTypeSize() const {
CORRADE_ASSERT(_indexBuffer.id(), "Mesh::indexTypeSize(): mesh is not indexed", {}); CORRADE_ASSERT(_indexBuffer.id(), "Mesh::indexTypeSize(): mesh is not indexed", {});
switch(_indexType) { return meshIndexTypeSize(_indexType);
case MeshIndexType::UnsignedByte: return 1;
case MeshIndexType::UnsignedShort: return 2;
case MeshIndexType::UnsignedInt: return 4;
}
CORRADE_INTERNAL_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */
} }
#endif
Mesh& Mesh::addVertexBufferInstanced(Buffer& buffer, const UnsignedInt divisor, const GLintptr offset, const GLsizei stride, const DynamicAttribute& attribute) { 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) for(UnsignedInt i = 0; i != attribute.vectors(); ++i)

17
src/Magnum/GL/Mesh.h

@ -26,7 +26,7 @@
*/ */
/** @file /** @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 <Corrade/Utility/ConfigurationValue.h> #include <Corrade/Utility/ConfigurationValue.h>
@ -221,6 +221,14 @@ cast to @ref MeshIndexType.
*/ */
MAGNUM_GL_EXPORT MeshIndexType meshIndexType(Magnum::MeshIndexType type); 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 { namespace Implementation {
struct MeshState; struct MeshState;
@ -653,13 +661,16 @@ class MAGNUM_GL_EXPORT Mesh: public AbstractObject {
*/ */
MeshIndexType indexType() const; MeshIndexType indexType() const;
#ifdef MAGNUM_BUILD_DEPRECATED
/** /**
* @brief Index type size * @brief Index type size
* *
* Expects that the mesh is indexed. * 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 */ /** @brief Primitive type */
MeshPrimitive primitive() const { return _primitive; } MeshPrimitive primitive() const { return _primitive; }

2
src/Magnum/GL/MeshView.cpp

@ -59,7 +59,7 @@ void MeshView::draw(AbstractShaderProgram&& shader, std::initializer_list<Contai
MeshView& MeshView::setIndexOffset(Int offset) { MeshView& MeshView::setIndexOffset(Int offset) {
CORRADE_ASSERT(_original.get()._indexBuffer.id(), CORRADE_ASSERT(_original.get()._indexBuffer.id(),
"GL::MeshView::setIndexOffset(): mesh is not indexed", *this); "GL::MeshView::setIndexOffset(): mesh is not indexed", *this);
_indexOffset = _original.get()._indexOffset + offset*_original.get().indexTypeSize(); _indexOffset = _original.get()._indexOffset + offset*meshIndexTypeSize(_original.get().indexType());
return *this; return *this;
} }

3
src/Magnum/GL/Test/MeshGLTest.cpp

@ -2524,7 +2524,6 @@ template<class T> void MeshGLTest::setIndexBuffer() {
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(mesh.indexType(), MeshIndexType::UnsignedByte); CORRADE_COMPARE(mesh.indexType(), MeshIndexType::UnsignedByte);
CORRADE_COMPARE(mesh.indexTypeSize(), 1);
const auto value = Checker(MultipleShader{}, const auto value = Checker(MultipleShader{},
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
@ -2556,7 +2555,6 @@ template<class T> void MeshGLTest::setIndexBufferRange() {
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(mesh.indexType(), GL::MeshIndexType::UnsignedShort); CORRADE_COMPARE(mesh.indexType(), GL::MeshIndexType::UnsignedShort);
CORRADE_COMPARE(mesh.indexTypeSize(), 2);
const auto value = Checker(MultipleShader{}, const auto value = Checker(MultipleShader{},
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
@ -2590,7 +2588,6 @@ void MeshGLTest::setIndexBufferUnsignedInt() {
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(mesh.indexType(), GL::MeshIndexType::UnsignedInt); CORRADE_COMPARE(mesh.indexType(), GL::MeshIndexType::UnsignedInt);
CORRADE_COMPARE(mesh.indexTypeSize(), 4);
const auto value = Checker(MultipleShader{}, const auto value = Checker(MultipleShader{},
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2

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

@ -58,6 +58,9 @@ struct MeshTest: TestSuite::Tester {
void mapIndexTypeImplementationSpecific(); void mapIndexTypeImplementationSpecific();
void mapIndexTypeInvalid(); void mapIndexTypeInvalid();
void indexTypeSize();
void indexTypeSizeInvalid();
void debugPrimitive(); void debugPrimitive();
void debugIndexType(); void debugIndexType();
}; };
@ -81,6 +84,9 @@ MeshTest::MeshTest() {
&MeshTest::mapIndexTypeImplementationSpecific, &MeshTest::mapIndexTypeImplementationSpecific,
&MeshTest::mapIndexTypeInvalid, &MeshTest::mapIndexTypeInvalid,
&MeshTest::indexTypeSize,
&MeshTest::indexTypeSizeInvalid,
&MeshTest::debugPrimitive, &MeshTest::debugPrimitive,
&MeshTest::debugIndexType}); &MeshTest::debugIndexType});
} }
@ -264,6 +270,24 @@ void MeshTest::mapIndexTypeInvalid() {
"GL::meshIndexType(): invalid type MeshIndexType(0x12)\n"); "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() { void MeshTest::debugPrimitive() {
std::ostringstream o; std::ostringstream o;
Debug(&o) << MeshPrimitive::TriangleFan << MeshPrimitive(0xdead); Debug(&o) << MeshPrimitive::TriangleFan << MeshPrimitive(0xdead);

Loading…
Cancel
Save