From 1efe1e05181a9131cbcf114122513fc91e65014f Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 26 Aug 2024 20:43:03 +0200 Subject: src/chunk: don't allocate empty ground/wall/scenery meshes --- src/chunk-scenery.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/chunk-scenery.cpp') diff --git a/src/chunk-scenery.cpp b/src/chunk-scenery.cpp index 2e491d4d..4bf55312 100644 --- a/src/chunk-scenery.cpp +++ b/src/chunk-scenery.cpp @@ -177,13 +177,18 @@ auto chunk::ensure_scenery_mesh(scenery_scratch_buffers buffers) noexcept -> sce i++; } - GL::Mesh mesh{GL::MeshPrimitive::Triangles}; - auto vert_view = ArrayView>{scenery_vertexes, count}; - auto index_view = ArrayView>{scenery_indexes, count}; - mesh.addVertexBuffer(GL::Buffer{vert_view}, 0, tile_shader::Position{}, tile_shader::TextureCoordinates{}, tile_shader::Depth{}) - .setIndexBuffer(GL::Buffer{index_view}, 0, GL::MeshIndexType::UnsignedShort) - .setCount(int32_t(6 * count)); - scenery_mesh = move(mesh); + if (count == 0) + scenery_mesh = GL::Mesh{NoCreate}; + else + { + GL::Mesh mesh{GL::MeshPrimitive::Triangles}; + auto vert_view = ArrayView>{scenery_vertexes, count}; + auto index_view = ArrayView>{scenery_indexes, count}; + mesh.addVertexBuffer(GL::Buffer{vert_view}, 0, tile_shader::Position{}, tile_shader::TextureCoordinates{}, tile_shader::Depth{}) + .setIndexBuffer(GL::Buffer{index_view}, 0, GL::MeshIndexType::UnsignedShort) + .setCount(int32_t(6 * count)); + scenery_mesh = move(mesh); + } } const auto size = _objects.size(); -- cgit v1.2.3