Browse Source

MeshTools: disallow impl-spec index types in duplicate().

pull/547/head
Vladimír Vondruš 4 years ago
parent
commit
80009edf62
  1. 3
      src/Magnum/MeshTools/Duplicate.cpp
  2. 11
      src/Magnum/MeshTools/Duplicate.h
  3. 20
      src/Magnum/MeshTools/Test/DuplicateTest.cpp

3
src/Magnum/MeshTools/Duplicate.cpp

@ -80,6 +80,9 @@ void duplicateInto(const Containers::StridedArrayView2D<const char>& indices, co
Trade::MeshData duplicate(const Trade::MeshData& data, const Containers::ArrayView<const Trade::MeshAttributeData> extra) {
CORRADE_ASSERT(data.isIndexed(), "MeshTools::duplicate(): mesh data not indexed", (Trade::MeshData{MeshPrimitive::Triangles, 0}));
CORRADE_ASSERT(!isMeshIndexTypeImplementationSpecific(data.indexType()),
"MeshTools::duplicate(): mesh has an implementation-specific index type" << reinterpret_cast<void*>(meshIndexTypeUnwrap(data.indexType())),
(Trade::MeshData{MeshPrimitive{}, 0}));
#ifndef CORRADE_NO_ASSERT
for(std::size_t i = 0; i != data.attributeCount(); ++i) {
const VertexFormat format = data.attributeFormat(i);

11
src/Magnum/MeshTools/Duplicate.h

@ -144,11 +144,12 @@ is done by @ref interleavedLayout(), see its documentation for detailed
behavior description. Note that offset-only @ref Trade::MeshAttributeData
instances are not supported in the @p extra array.
Expects that @p data is indexed and each attribute in @p extra has either the
same amount of elements as @p data vertex count (*not* index count) or has
none. All attributes are expected to not have an implementation-specific
format.
@see @ref isVertexFormatImplementationSpecific(),
Expects that @p data is indexed with a non-implementation-specific index type
and each attribute in @p extra has either the same amount of elements as
@p data vertex count (*not* index count) or has none. All attributes are
expected to not have an implementation-specific format.
@see @ref isMeshIndexTypeImplementationSpecific(),
@ref isVertexFormatImplementationSpecific(),
@ref Trade::MeshData::attributeData()
*/
MAGNUM_MESHTOOLS_EXPORT Trade::MeshData duplicate(const Trade::MeshData& data, Containers::ArrayView<const Trade::MeshAttributeData> extra = {});

20
src/Magnum/MeshTools/Test/DuplicateTest.cpp

@ -59,6 +59,7 @@ struct DuplicateTest: TestSuite::Tester {
template<class T> void duplicateMeshData();
void duplicateMeshDataNotIndexed();
void duplicateMeshDataImplementationSpecificIndexType();
void duplicateMeshDataImplementationSpecificVertexFormat();
void duplicateMeshDataExtra();
void duplicateMeshDataExtraEmpty();
@ -94,6 +95,7 @@ DuplicateTest::DuplicateTest() {
&DuplicateTest::duplicateMeshData<UnsignedShort>,
&DuplicateTest::duplicateMeshData<UnsignedInt>,
&DuplicateTest::duplicateMeshDataNotIndexed,
&DuplicateTest::duplicateMeshDataImplementationSpecificIndexType,
&DuplicateTest::duplicateMeshDataImplementationSpecificVertexFormat,
&DuplicateTest::duplicateMeshDataExtra,
&DuplicateTest::duplicateMeshDataExtraEmpty,
@ -330,6 +332,24 @@ void DuplicateTest::duplicateMeshDataNotIndexed() {
CORRADE_COMPARE(out.str(), "MeshTools::duplicate(): mesh data not indexed\n");
}
void DuplicateTest::duplicateMeshDataImplementationSpecificIndexType() {
#ifdef CORRADE_NO_ASSERT
CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions");
#endif
Trade::MeshData a{MeshPrimitive::Lines,
nullptr, Trade::MeshIndexData{meshIndexTypeWrap(0xcaca), Containers::StridedArrayView1D<const void>{}},
nullptr, {
Trade::MeshAttributeData{Trade::MeshAttribute::Position,
VertexFormat::Vector3, nullptr},
}};
std::ostringstream out;
Error redirectError{&out};
MeshTools::duplicate(a);
CORRADE_COMPARE(out.str(), "MeshTools::duplicate(): mesh has an implementation-specific index type 0xcaca\n");
}
void DuplicateTest::duplicateMeshDataImplementationSpecificVertexFormat() {
#ifdef CORRADE_NO_ASSERT
CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions");

Loading…
Cancel
Save