Browse Source

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&.
pull/277/head
Vladimír Vondruš 13 years ago
parent
commit
2ea5b4c9ce
  1. 6
      src/MeshTools/CompressIndices.cpp
  2. 2
      src/MeshTools/CompressIndices.h
  3. 16
      src/MeshTools/Interleave.h

6
src/MeshTools/CompressIndices.cpp

@ -69,7 +69,7 @@ std::tuple<std::size_t, Mesh::IndexType, char*> 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<UnsignedInt>& indices) {
void compressIndices(Mesh& mesh, Buffer& buffer, Buffer::Usage usage, const std::vector<UnsignedInt>& 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;
}

2
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<UnsignedInt>& indices);
void MAGNUM_MESHTOOLS_EXPORT compressIndices(Mesh& mesh, Buffer& buffer, Buffer::Usage usage, const std::vector<UnsignedInt>& indices);
}}

16
src/MeshTools/Interleave.h

@ -60,19 +60,19 @@ class Interleave {
return std::make_tuple(_attributeCount, _stride, _data);
}
template<class ...T> void operator()(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const T&... attributes) {
template<class ...T> 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<class T> typename std::enable_if<!std::is_convertible<T, std::size_t>::value, void>::type operator()(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const T& attribute) {
mesh->setVertexCount(attribute.size());
buffer->setData(attribute, usage);
template<class T> typename std::enable_if<!std::is_convertible<T, std::size_t>::value, void>::type operator()(Mesh& mesh, Buffer& buffer, Buffer::Usage usage, const T& attribute) {
mesh.setVertexCount(attribute.size());
buffer.setData(attribute, usage);
}
template<class T, class ...U> static typename std::enable_if<!std::is_convertible<T, std::size_t>::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<class T, class ...U> inline typename std::enable_if<!std::is_convertible<T, Mesh*>::value, std::tuple<std::size_t, std::size_t, char*>>::type interleave(const T& first, const U&... next) {
template<class T, class ...U> inline typename std::enable_if<!std::is_same<T, Mesh>::value, std::tuple<std::size_t, std::size_t, char*>>::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<class ...T> inline void interleave(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const T&... attributes) {
template<class ...T> inline void interleave(Mesh& mesh, Buffer& buffer, Buffer::Usage usage, const T&... attributes) {
return Implementation::Interleave()(mesh, buffer, usage, attributes...);
}

Loading…
Cancel
Save