From 2ea5b4c9ceb7c1cde135bb0824560580f8c671d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 1 Aug 2013 17:37:36 +0200 Subject: [PATCH] Reducing pointer chasings, part 3b: less pointer passing in MeshTools. MeshTools::interleave() might cause porting problems, as the error is now much more verbose if you accidentally pass Mesh* instead of Mesh&. --- src/MeshTools/CompressIndices.cpp | 6 +++--- src/MeshTools/CompressIndices.h | 2 +- src/MeshTools/Interleave.h | 16 ++++++++-------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/MeshTools/CompressIndices.cpp b/src/MeshTools/CompressIndices.cpp index df2e871ed..3735abd2e 100644 --- a/src/MeshTools/CompressIndices.cpp +++ b/src/MeshTools/CompressIndices.cpp @@ -69,7 +69,7 @@ std::tuple compressIndices(const std::vecto return compressIndicesInternal(indices, *std::max_element(indices.begin(), indices.end())); } -void compressIndices(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector& indices) { +void compressIndices(Mesh& mesh, Buffer& buffer, Buffer::Usage usage, const std::vector& indices) { auto minmax = std::minmax_element(indices.begin(), indices.end()); /** @todo Performance hint when range can be represented by smaller value? */ @@ -79,9 +79,9 @@ void compressIndices(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const std: char* data; std::tie(indexCount, indexType, data) = compressIndicesInternal(indices, *minmax.second); - mesh->setIndexCount(indices.size()) + mesh.setIndexCount(indices.size()) .setIndexBuffer(buffer, 0, indexType, *minmax.first, *minmax.second); - buffer->setData(indexCount*Mesh::indexSize(indexType), data, usage); + buffer.setData(indexCount*Mesh::indexSize(indexType), data, usage); delete[] data; } diff --git a/src/MeshTools/CompressIndices.h b/src/MeshTools/CompressIndices.h index 80cd544ef..4acf0ff3b 100644 --- a/src/MeshTools/CompressIndices.h +++ b/src/MeshTools/CompressIndices.h @@ -77,7 +77,7 @@ Mesh::setIndexCount() and Mesh::setIndexBuffer() on your own. @see MeshTools::interleave() */ -void MAGNUM_MESHTOOLS_EXPORT compressIndices(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector& indices); +void MAGNUM_MESHTOOLS_EXPORT compressIndices(Mesh& mesh, Buffer& buffer, Buffer::Usage usage, const std::vector& indices); }} diff --git a/src/MeshTools/Interleave.h b/src/MeshTools/Interleave.h index 8396219ae..82e424d03 100644 --- a/src/MeshTools/Interleave.h +++ b/src/MeshTools/Interleave.h @@ -60,19 +60,19 @@ class Interleave { return std::make_tuple(_attributeCount, _stride, _data); } - template void operator()(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const T&... attributes) { + template void operator()(Mesh& mesh, Buffer& buffer, Buffer::Usage usage, const T&... attributes) { operator()(attributes...); - mesh->setVertexCount(_attributeCount); - buffer->setData(_attributeCount*_stride, _data, usage); + mesh.setVertexCount(_attributeCount); + buffer.setData(_attributeCount*_stride, _data, usage); delete[] _data; } /* Specialization for only one attribute array */ - template typename std::enable_if::value, void>::type operator()(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const T& attribute) { - mesh->setVertexCount(attribute.size()); - buffer->setData(attribute, usage); + template typename std::enable_if::value, void>::type operator()(Mesh& mesh, Buffer& buffer, Buffer::Usage usage, const T& attribute) { + mesh.setVertexCount(attribute.size()); + buffer.setData(attribute, usage); } template static typename std::enable_if::value, std::size_t>::type attributeCount(const T& first, const U&... next) { @@ -180,7 +180,7 @@ See also interleave(Mesh*, Buffer*, Buffer::Usage, const T&...), which writes the interleaved array directly into buffer of given mesh. */ /* enable_if to avoid clash with overloaded function below */ -template inline typename std::enable_if::value, std::tuple>::type interleave(const T& first, const U&... next) { +template inline typename std::enable_if::value, std::tuple>::type interleave(const T& first, const U&... next) { return Implementation::Interleave()(first, next...); } @@ -207,7 +207,7 @@ mesh->setVertexCount(attribute.size()); @see MeshTools::compressIndices() */ -template inline void interleave(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const T&... attributes) { +template inline void interleave(Mesh& mesh, Buffer& buffer, Buffer::Usage usage, const T&... attributes) { return Implementation::Interleave()(mesh, buffer, usage, attributes...); }