diff options
Diffstat (limited to 'draw')
-rw-r--r-- | draw/floor.cpp | 16 | ||||
-rw-r--r-- | draw/wall.cpp | 16 |
2 files changed, 12 insertions, 20 deletions
diff --git a/draw/floor.cpp b/draw/floor.cpp index 1a5c908e..5e645b0f 100644 --- a/draw/floor.cpp +++ b/draw/floor.cpp @@ -14,28 +14,24 @@ floor_mesh::floor_mesh() = default; void floor_mesh::draw(tile_shader& shader, chunk& c) { constexpr auto quad_index_count = 6; - auto [mesh_, ids] = c.ensure_ground_mesh(); - - tile_atlas* last_atlas = nullptr; - std::size_t last_pos = 0; + struct { tile_atlas* atlas = nullptr; std::size_t pos = 0; } last; GL::MeshView mesh{mesh_}; [[maybe_unused]] std::size_t draw_count = 0; const auto do_draw = [&](std::size_t i, tile_atlas* atlas) { - if (atlas == last_atlas) + if (atlas == last.atlas) return; - if (auto len = i - last_pos; last_atlas && len > 0) + if (auto len = i - last.pos; last.atlas && len > 0) { - last_atlas->texture().bind(0); + 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); + mesh.setIndexRange((int)(last.pos*quad_index_count), 0, quad_index_count*TILE_COUNT - 1); shader.draw(mesh); draw_count++; } - last_atlas = atlas; - last_pos = i; + last = { atlas, i }; }; for (std::size_t k = 0; k < TILE_COUNT; k++) diff --git a/draw/wall.cpp b/draw/wall.cpp index 35f83137..dbc9c2ad 100644 --- a/draw/wall.cpp +++ b/draw/wall.cpp @@ -18,26 +18,22 @@ wall_mesh::wall_mesh() = default; void wall_mesh::draw(tile_shader& shader, chunk& c) { auto [mesh_, ids] = c.ensure_wall_mesh(); - - tile_atlas* last_atlas = nullptr; - std::size_t last_pos = 0; + struct { tile_atlas* atlas = nullptr; std::size_t pos = 0; } last; GL::MeshView mesh{mesh_}; - [[maybe_unused]] std::size_t draw_count = 0; const auto do_draw = [&](std::size_t i, tile_atlas* atlas) { - if (atlas == last_atlas) + if (atlas == last.atlas) return; - if (auto len = i - last_pos; last_atlas && len > 0) + if (auto len = i - last.pos; last.atlas && len > 0) { - last_atlas->texture().bind(0); + 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*2 - 1); + mesh.setIndexRange((int)(last.pos*quad_index_count), 0, quad_index_count*TILE_COUNT*2 - 1); shader.draw(mesh); draw_count++; } - last_atlas = atlas; - last_pos = i; + last = { atlas, i }; }; for (std::size_t k = 0; k < TILE_COUNT*2; k++) |