diff --git a/src/Magnum/Trade/MeshData.cpp b/src/Magnum/Trade/MeshData.cpp index 1db25bcfe..0acefcd55 100644 --- a/src/Magnum/Trade/MeshData.cpp +++ b/src/Magnum/Trade/MeshData.cpp @@ -394,27 +394,19 @@ Containers::StridedArrayView2D MeshData::mutableAttribute(MeshAttribute na return mutableAttribute(attributeId); } -namespace { - -template void convertIndices(const Containers::ArrayView data, const Containers::ArrayView destination) { - const auto input = Containers::arrayCast(data); - for(std::size_t i = 0; i != input.size(); ++i) destination[i] = input[i]; -} - -} - void MeshData::indicesInto(const Containers::ArrayView destination) const { CORRADE_ASSERT(isIndexed(), "Trade::MeshData::indicesInto(): the mesh is not indexed", ); CORRADE_ASSERT(destination.size() == indexCount(), "Trade::MeshData::indicesInto(): expected a view with" << indexCount() << "elements but got" << destination.size(), ); - - switch(_indexType) { - case MeshIndexType::UnsignedByte: return convertIndices(_indices, destination); - case MeshIndexType::UnsignedShort: return convertIndices(_indices, destination); - case MeshIndexType::UnsignedInt: return convertIndices(_indices, destination); - } - - CORRADE_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */ + auto destination1ui = Containers::arrayCast<2, UnsignedInt>(destination); + + if(_indexType == MeshIndexType::UnsignedInt) + return Utility::copy(Containers::arrayCast(_indices), destination); + else if(_indexType == MeshIndexType::UnsignedShort) + return Math::castInto(Containers::arrayCast<2, const UnsignedShort>(Containers::arrayCast(_indices)), destination1ui); + else if(_indexType == MeshIndexType::UnsignedByte) + return Math::castInto(Containers::arrayCast<2, const UnsignedByte>(Containers::arrayCast(_indices)), destination1ui); + else CORRADE_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */ } Containers::Array MeshData::indicesAsArray() const {