From fc0dbf31301f42eceb33a452e703d6b41dd80756 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 2 Oct 2022 18:41:48 +0200 Subject: a --- floor-mesh.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'floor-mesh.cpp') diff --git a/floor-mesh.cpp b/floor-mesh.cpp index e9dd57b1..5c797ef7 100644 --- a/floor-mesh.cpp +++ b/floor-mesh.cpp @@ -1,5 +1,4 @@ #include "floor-mesh.hpp" -#include "tile-atlas.hpp" #include "shaders/tile-shader.hpp" #include "tile.hpp" #include "chunk.hpp" @@ -9,30 +8,31 @@ namespace Magnum::Examples { floor_mesh::floor_mesh() { - _mesh.setCount((int)(quad_index_count * _index_data.size())) + _mesh.setCount((int)(_index_data.size() * _index_data[0].size())) .addVertexBuffer(_positions_buffer, 0, tile_shader::Position{}) .addVertexBuffer(_vertex_buffer, 0, tile_shader::TextureCoordinates{}) .setIndexBuffer(_index_buffer, 0, GL::MeshIndexType::UnsignedShort); } -void floor_mesh::set_tile(tile& x, const local_coords pt) +void floor_mesh::set_tile(std::array& data, tile& x, const local_coords pt) { CORRADE_INTERNAL_ASSERT(x.ground_image); const auto idx = pt.to_index(); auto texcoords = x.ground_image.atlas->texcoords_for_id(x.ground_image.variant); for (std::size_t i = 0; i < 4; i++) - _vertex_data[idx][i] = { texcoords[i] }; + data[idx][i] = { texcoords[i] }; } void floor_mesh::draw(tile_shader& shader, chunk& c) { + std::array data; c.foreach_tile([&](tile& x, std::size_t, local_coords pt) { - set_tile(x, pt); + set_tile(data, x, pt); }); - _vertex_buffer.setData(_vertex_data, Magnum::GL::BufferUsage::DynamicDraw); + _vertex_buffer.setData(data, Magnum::GL::BufferUsage::DynamicDraw); #if 1 - Magnum::GL::MeshView mesh{ _mesh }; + Magnum::GL::MeshView mesh{_mesh}; mesh.setCount(quad_index_count); tile_atlas* last_tile_atlas = nullptr; c.foreach_tile([&](tile& x, std::size_t i, local_coords) { @@ -52,9 +52,7 @@ void floor_mesh::draw(tile_shader& shader, chunk& c) static auto make_index_array() { - constexpr auto quad_index_count = std::tuple_size_v; - std::array, TILE_COUNT> array; // NOLINT(cppcoreguidelines-pro-type-member-init) - + std::array, TILE_COUNT> array; // NOLINT(cppcoreguidelines-pro-type-member-init) for (std::size_t i = 0; i < std::size(array); i++) array[i] = tile_atlas::indices(i); return array; -- cgit v1.2.3