From dee57c44796ce04d1ea11fcee9f24afe8ff924a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 4 Mar 2014 12:58:58 +0100 Subject: [PATCH] MeshTools: add std::vector overload to combineIndexArrays(). So the functions can *really* be used at runtime. --- src/Magnum/MeshTools/CombineIndexedArrays.cpp | 16 ++++++++-------- src/Magnum/MeshTools/CombineIndexedArrays.h | 13 ++++++++++++- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/Magnum/MeshTools/CombineIndexedArrays.cpp b/src/Magnum/MeshTools/CombineIndexedArrays.cpp index 57e918e8b..693c86896 100644 --- a/src/Magnum/MeshTools/CombineIndexedArrays.cpp +++ b/src/Magnum/MeshTools/CombineIndexedArrays.cpp @@ -56,26 +56,24 @@ std::pair, std::vector> interleaveAndCombi /* Combine them */ std::vector combinedIndices; - std::tie(combinedIndices, interleavedArrays) = combineIndexArrays(interleavedArrays, stride); + std::tie(combinedIndices, interleavedArrays) = MeshTools::combineIndexArrays(interleavedArrays, stride); return {combinedIndices, interleavedArrays}; } -} - -std::vector combineIndexArrays(const std::initializer_list>> arrays) { +std::vector combineIndexArrays(const std::reference_wrapper>* const begin, const std::reference_wrapper>* const end) { /* Interleave and combine the arrays */ std::vector combinedIndices; std::vector interleavedCombinedArrays; std::tie(combinedIndices, interleavedCombinedArrays) = Implementation::interleaveAndCombineIndexArrays( /* This will bite me hard once. */ - reinterpret_cast>*>(arrays.begin()), - reinterpret_cast>*>(arrays.end())); + reinterpret_cast>*>(begin), + reinterpret_cast>*>(end)); /* Update the original indices */ - const UnsignedInt stride = arrays.size(); + const UnsignedInt stride = end - begin; const UnsignedInt outputSize = interleavedCombinedArrays.size()/stride; for(UnsignedInt offset = 0; offset != stride; ++offset) { - auto& array = (arrays.begin()+offset)->get(); + auto& array = (begin+offset)->get(); CORRADE_INTERNAL_ASSERT(array.size() >= outputSize); array.resize(outputSize); for(UnsignedInt i = 0; i != outputSize; ++i) @@ -85,6 +83,8 @@ std::vector combineIndexArrays(const std::initializer_list combineIndexArrays(const std::reference_wrapper>* begin, const std::reference_wrapper>* end); +} + /** @brief Combine index arrays @@ -81,7 +85,14 @@ This function calls @ref combineIndexArrays(const std::vector&, Uns internally. See also @ref combineIndexedArrays() which does the vertex data reordering automatically. */ -MAGNUM_MESHTOOLS_EXPORT std::vector combineIndexArrays(std::initializer_list>> arrays); +inline std::vector combineIndexArrays(const std::vector>>& arrays) { + return Implementation::combineIndexArrays(&arrays[0], &arrays[0] + arrays.size()); +} + +/** @overload */ +inline std::vector combineIndexArrays(std::initializer_list>> arrays) { + return Implementation::combineIndexArrays(arrays.begin(), arrays.end()); +} /** @brief Combine index arrays