Browse Source

Trade: use Math::castInto() inside indicesInto().

This code was apparently done before the batch casters were a thing. Now
it's no reason to do the same in two places, additionally in the future
the castInto() could get SIMD-optimized and this can benefit from that.
pull/430/head
Vladimír Vondruš 6 years ago
parent
commit
03b038ccfe
  1. 26
      src/Magnum/Trade/MeshData.cpp

26
src/Magnum/Trade/MeshData.cpp

@ -394,27 +394,19 @@ Containers::StridedArrayView2D<char> MeshData::mutableAttribute(MeshAttribute na
return mutableAttribute(attributeId);
}
namespace {
template<class T> void convertIndices(const Containers::ArrayView<const char> data, const Containers::ArrayView<UnsignedInt> destination) {
const auto input = Containers::arrayCast<const T>(data);
for(std::size_t i = 0; i != input.size(); ++i) destination[i] = input[i];
}
}
void MeshData::indicesInto(const Containers::ArrayView<UnsignedInt> 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<UnsignedByte>(_indices, destination);
case MeshIndexType::UnsignedShort: return convertIndices<UnsignedShort>(_indices, destination);
case MeshIndexType::UnsignedInt: return convertIndices<UnsignedInt>(_indices, destination);
}
CORRADE_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */
auto destination1ui = Containers::arrayCast<2, UnsignedInt>(destination);
if(_indexType == MeshIndexType::UnsignedInt)
return Utility::copy(Containers::arrayCast<const UnsignedInt>(_indices), destination);
else if(_indexType == MeshIndexType::UnsignedShort)
return Math::castInto(Containers::arrayCast<2, const UnsignedShort>(Containers::arrayCast<const UnsignedShort>(_indices)), destination1ui);
else if(_indexType == MeshIndexType::UnsignedByte)
return Math::castInto(Containers::arrayCast<2, const UnsignedByte>(Containers::arrayCast<const UnsignedByte>(_indices)), destination1ui);
else CORRADE_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */
}
Containers::Array<UnsignedInt> MeshData::indicesAsArray() const {

Loading…
Cancel
Save