summaryrefslogtreecommitdiffhomepage
path: root/src/chunk-scenery.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-08-26 20:43:03 +0200
committerStanislaw Halik <sthalik@misaki.pl>2024-09-20 16:08:45 +0200
commit1efe1e05181a9131cbcf114122513fc91e65014f (patch)
tree36ded0d6dc87bcf8b55e7c2800ebb2be177222a1 /src/chunk-scenery.cpp
parenta0b26eea80f4703c632a60efcc4115e826e36506 (diff)
src/chunk: don't allocate empty ground/wall/scenery meshes
Diffstat (limited to 'src/chunk-scenery.cpp')
-rw-r--r--src/chunk-scenery.cpp19
1 files changed, 12 insertions, 7 deletions
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<const std::array<vertex, 4>>{scenery_vertexes, count};
- auto index_view = ArrayView<const std::array<UnsignedShort, 6>>{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<const std::array<vertex, 4>>{scenery_vertexes, count};
+ auto index_view = ArrayView<const std::array<UnsignedShort, 6>>{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();