diff --git a/src/MeshTools/CMakeLists.txt b/src/MeshTools/CMakeLists.txt index e2b347f4b..095431bf7 100644 --- a/src/MeshTools/CMakeLists.txt +++ b/src/MeshTools/CMakeLists.txt @@ -1,5 +1,6 @@ # Files shared between main library and unit test library set(MagnumMeshTools_SRCS + CompressIndices.cpp Tipsify.cpp) set(MagnumMeshTools_HEADERS Clean.h diff --git a/src/MeshTools/CompressIndices.cpp b/src/MeshTools/CompressIndices.cpp new file mode 100644 index 000000000..445f5378f --- /dev/null +++ b/src/MeshTools/CompressIndices.cpp @@ -0,0 +1,61 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "CompressIndices.h" + +#include +#include +#include + +#include "IndexedMesh.h" +#include "SizeTraits.h" + +namespace Magnum { namespace MeshTools { + +#ifndef DOXYGEN_GENERATING_OUTPUT +namespace Implementation { + +std::tuple CompressIndices::operator()() const { + return SizeBasedCall(*std::max_element(indices.begin(), indices.end()))(indices); +} + +void CompressIndices::operator()(IndexedMesh* mesh, Buffer::Usage usage) const { + size_t indexCount; + Type indexType; + char* data; + std::tie(indexCount, indexType, data) = operator()(); + + mesh->setIndexType(indexType); + mesh->setIndexCount(indices.size()); + mesh->indexBuffer()->setData(indexCount*TypeInfo::sizeOf(indexType), data, usage); + + delete[] data; +} + +template std::tuple CompressIndices::Compressor::run(const std::vector& indices) { + /* Create smallest possible version of index buffer */ + char* buffer = new char[indices.size()*sizeof(IndexType)]; + for(size_t i = 0; i != indices.size(); ++i) { + IndexType index = indices[i]; + memcpy(buffer+i*sizeof(IndexType), reinterpret_cast(&index), sizeof(IndexType)); + } + + return std::make_tuple(indices.size(), TypeTraits::indexType(), buffer); +} + +} +#endif + +}} diff --git a/src/MeshTools/CompressIndices.h b/src/MeshTools/CompressIndices.h index 4a6b2ac48..709041000 100644 --- a/src/MeshTools/CompressIndices.h +++ b/src/MeshTools/CompressIndices.h @@ -19,52 +19,33 @@ * @brief Function Magnum::MeshTools::compressIndices() */ -#include -#include -#include +#include +#include "Buffer.h" #include "TypeTraits.h" -#include "SizeTraits.h" -#include "IndexedMesh.h" -namespace Magnum { namespace MeshTools { +#include "magnumMeshToolsVisibility.h" + +namespace Magnum { + +class IndexedMesh; + +namespace MeshTools { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { -class CompressIndices { +class MESHTOOLS_EXPORT CompressIndices { public: CompressIndices(const std::vector& indices): indices(indices) {} - inline std::tuple operator()() const { - return SizeBasedCall(*std::max_element(indices.begin(), indices.end()))(indices); - } - - void operator()(IndexedMesh* mesh, Buffer::Usage usage) const { - size_t indexCount; - Type indexType; - char* data; - std::tie(indexCount, indexType, data) = operator()(); - - mesh->setIndexType(indexType); - mesh->setIndexCount(indices.size()); - mesh->indexBuffer()->setData(indexCount*TypeInfo::sizeOf(indexType), data, usage); + std::tuple operator()() const; - delete[] data; - } + void operator()(IndexedMesh* mesh, Buffer::Usage usage) const; private: struct Compressor { - template static std::tuple run(const std::vector& indices) { - /* Create smallest possible version of index buffer */ - char* buffer = new char[indices.size()*sizeof(IndexType)]; - for(size_t i = 0; i != indices.size(); ++i) { - IndexType index = indices[i]; - memcpy(buffer+i*sizeof(IndexType), reinterpret_cast(&index), sizeof(IndexType)); - } - - return std::make_tuple(indices.size(), TypeTraits::indexType(), buffer); - } + template static std::tuple run(const std::vector& indices); }; const std::vector& indices; diff --git a/src/MeshTools/Test/CMakeLists.txt b/src/MeshTools/Test/CMakeLists.txt index 830207055..0a4608faf 100644 --- a/src/MeshTools/Test/CMakeLists.txt +++ b/src/MeshTools/Test/CMakeLists.txt @@ -1,6 +1,6 @@ corrade_add_test2(MeshToolsCleanTest CleanTest.cpp) corrade_add_test2(MeshToolsCombineIndexedArraysTest CombineIndexedArraysTest.cpp) -corrade_add_test2(MeshToolsCompressIndicesTest CompressIndicesTest.cpp LIBRARIES Magnum) +corrade_add_test2(MeshToolsCompressIndicesTest CompressIndicesTest.cpp LIBRARIES MagnumMeshTools) corrade_add_test2(MeshToolsFlipNormalsTest FlipNormalsTest.cpp LIBRARIES MagnumMeshToolsTestLib) corrade_add_test2(MeshToolsGenerateFlatNormalsTest GenerateFlatNormalsTest.cpp LIBRARIES MagnumMeshToolsTestLib) corrade_add_test2(MeshToolsInterleaveTest InterleaveTest.cpp)