diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-18 13:07:33 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-18 13:07:58 +0200 |
commit | 29fdfcd56a57586ecee50485326b916909380f44 (patch) | |
tree | dc7a7999c2633cf251879b7a9dcdafbafc12ffc8 /draw | |
parent | d5fedaffc064b0c97cc6e5e3123b3eb045515b17 (diff) |
a
Diffstat (limited to 'draw')
-rw-r--r-- | draw/floor-mesh.cpp | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/draw/floor-mesh.cpp b/draw/floor-mesh.cpp index 4c23a391..3b253966 100644 --- a/draw/floor-mesh.cpp +++ b/draw/floor-mesh.cpp @@ -39,19 +39,27 @@ void floor_mesh::draw(tile_shader& shader, chunk& c) } _vertex_buffer.setSubData(0, data); Magnum::GL::MeshView mesh{_mesh}; - mesh.setCount(quad_index_count); - const tile_atlas* last_tile_atlas = nullptr; - for (auto& [x, i, pt] : c) { - if (!x.ground_image) - continue; - mesh.setIndexRange((int)(i*quad_index_count), 0, quad_index_count*TILE_COUNT - 1); - if (auto* atlas = x.ground_image.atlas.get(); atlas != last_tile_atlas) + + tile_atlas* last_atlas = nullptr; + std::size_t last_pos = 0; + + const auto do_draw = [&](std::size_t i, tile_atlas* atlas) { + if (atlas == last_atlas) + return; + if (auto len = i - last_pos; last_atlas != nullptr && len > 0) { - atlas->texture().bind(0); - last_tile_atlas = atlas; + last_atlas->texture().bind(0); + mesh.setCount((int)(quad_index_count * len)); + mesh.setIndexRange((int)(last_pos*quad_index_count), 0, quad_index_count*TILE_COUNT - 1); + shader.draw(mesh); } - shader.draw(mesh); - } + last_atlas = atlas; + last_pos = i; + }; + + for (auto& [x, i, pt] : c) + do_draw(i, x.ground_image.atlas.get()); + do_draw(TILE_COUNT, nullptr); } std::array<std::array<UnsignedShort, 6>, TILE_COUNT> floor_mesh::make_index_array() |