From 08411a4a5b340aa63f8e427f6523a7b309e1d035 Mon Sep 17 00:00:00 2001 From: Marc Gilleron Date: Tue, 10 May 2016 04:42:30 +0200 Subject: [PATCH] Index meshes --- voxel_mesher.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/voxel_mesher.cpp b/voxel_mesher.cpp index 8a567ea..9309941 100644 --- a/voxel_mesher.cpp +++ b/voxel_mesher.cpp @@ -319,12 +319,16 @@ Ref VoxelMesher::build(const VoxelBuffer & buffer) { } // Commit mesh - Ref mesh_ref = _surface_tool[0].commit(); - _surface_tool[0].clear(); - for (unsigned int i = 1; i < MAX_MATERIALS; ++i) { + Ref mesh_ref; + for (unsigned int i = 0; i < MAX_MATERIALS; ++i) { if (_materials[i].is_valid()) { SurfaceTool & st = _surface_tool[i]; - st.commit(mesh_ref); + + // Index mesh to reduce memory usage and make upload to VRAM faster + // TODO actually, we could make it indexed from the ground up without using SurfaceTool, so we also save time! + st.index(); + + mesh_ref = st.commit(mesh_ref); st.clear(); } }