Browse Source

MeshTools: making use of index range in compressIndices().

pull/7/head
Vladimír Vondruš 13 years ago
parent
commit
09b115679b
  1. 26
      src/MeshTools/CompressIndices.cpp
  2. 4
      src/MeshTools/CompressIndices.h

26
src/MeshTools/CompressIndices.cpp

@ -40,13 +40,8 @@ template<class T> inline std::tuple<std::size_t, Mesh::IndexType, char*> compres
return std::make_tuple(indices.size(), indexType<T>(), buffer); return std::make_tuple(indices.size(), indexType<T>(), buffer);
} }
} std::tuple<std::size_t, Mesh::IndexType, char*> compressIndicesInternal(const std::vector<std::uint32_t>& indices, std::uint32_t max) {
#endif switch(Math::log(256, max)) {
std::tuple<std::size_t, Mesh::IndexType, char*> compressIndices(const std::vector<std::uint32_t>& indices) {
std::size_t size = *std::max_element(indices.begin(), indices.end());
switch(Math::log(256, size)) {
case 0: case 0:
return compress<GLubyte>(indices); return compress<GLubyte>(indices);
case 1: case 1:
@ -56,18 +51,29 @@ std::tuple<std::size_t, Mesh::IndexType, char*> compressIndices(const std::vecto
return compress<GLuint>(indices); return compress<GLuint>(indices);
default: default:
CORRADE_ASSERT(false, "MeshTools::compressIndices(): no type able to index" << size << "elements.", {}); CORRADE_ASSERT(false, "MeshTools::compressIndices(): no type able to index" << max << "elements.", {});
} }
} }
}
#endif
std::tuple<std::size_t, Mesh::IndexType, char*> compressIndices(const std::vector<std::uint32_t>& indices) {
return compressIndicesInternal(indices, *std::max_element(indices.begin(), indices.end()));
}
void compressIndices(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector<std::uint32_t>& indices) { void compressIndices(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector<std::uint32_t>& indices) {
auto minmax = std::minmax_element(indices.begin(), indices.end());
/** @todo Performance hint when range can be represented by smaller value? */
std::size_t indexCount; std::size_t indexCount;
Mesh::IndexType indexType; Mesh::IndexType indexType;
char* data; char* data;
std::tie(indexCount, indexType, data) = compressIndices(indices); std::tie(indexCount, indexType, data) = compressIndicesInternal(indices, *minmax.second);
mesh->setIndexCount(indices.size()) mesh->setIndexCount(indices.size())
->setIndexBuffer(buffer, 0, indexType); ->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; delete[] data;

4
src/MeshTools/CompressIndices.h

@ -63,8 +63,8 @@ std::tuple<std::size_t, Mesh::IndexType, char*> MAGNUM_MESHTOOLS_EXPORT compress
The same as compressIndices(const std::vector<std::uint32_t>&), but this The same as compressIndices(const std::vector<std::uint32_t>&), but this
function writes the output to given buffer, updates index count and specifies function writes the output to given buffer, updates index count and specifies
index buffer in the mesh, so you don't have to call Mesh::setIndexCount() index buffer with proper index range in the mesh, so you don't have to call
and Mesh::setIndexBuffer() on your own. Mesh::setIndexCount() and Mesh::setIndexBuffer() on your own.
@see MeshTools::interleave() @see MeshTools::interleave()
*/ */

Loading…
Cancel
Save