From dc248316938e3667ebf7f218da86da6bd89f6071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 18 Dec 2019 20:53:28 +0100 Subject: [PATCH] MeshTools: we know the final size beforehand. --- src/Magnum/MeshTools/Subdivide.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Magnum/MeshTools/Subdivide.h b/src/Magnum/MeshTools/Subdivide.h index 5cfc614f4..ce09d1b98 100644 --- a/src/Magnum/MeshTools/Subdivide.h +++ b/src/Magnum/MeshTools/Subdivide.h @@ -49,10 +49,13 @@ duplicate vertices in the mesh is up to user. template void subdivide(std::vector& indices, std::vector& vertices, Interpolator interpolator) { CORRADE_ASSERT(!(indices.size()%3), "MeshTools::subdivide(): index count is not divisible by 3!", ); - std::size_t indexCount = indices.size(); + /* For each triangle it'll generate three new vertices and three more + triangles */ indices.reserve(indices.size()*4); + vertices.reserve(vertices.size() + indices.size()); /* Subdivide each face to four new */ + std::size_t indexCount = indices.size(); for(std::size_t i = 0; i != indexCount; i += 3) { /* Interpolate each side */ UnsignedInt newVertices[3];