diff options
Diffstat (limited to 'src/chunk-scenery.cpp')
| -rw-r--r-- | src/chunk-scenery.cpp | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/chunk-scenery.cpp b/src/chunk-scenery.cpp index 2e491d4d..e928abac 100644 --- a/src/chunk-scenery.cpp +++ b/src/chunk-scenery.cpp @@ -64,6 +64,8 @@ auto make_topo_sort_data(object& e, uint32_t mesh_idx) -> topo_sort_data return data; } +// todo! switch to using a stack as in https://www.geeksforgeeks.org/topological-sorting/ + void topo_dfs(Array<chunk::object_draw_order>& array, size_t& output, size_t i, size_t size) // NOLINT(misc-no-recursion) { using m = typename chunk::topo_sort_data::m; @@ -177,13 +179,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(); |
