diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-02 15:29:41 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-02 15:29:41 +0200 |
commit | 445caf6184cafbce361670ea6028ff76317976bc (patch) | |
tree | 0ff8c2c33211f7a738de8f6f5d6cec79aa776f36 /floor-mesh.cpp | |
parent | f339fa747348e742859701331b529f86d7bd8453 (diff) |
a
Diffstat (limited to 'floor-mesh.cpp')
-rw-r--r-- | floor-mesh.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/floor-mesh.cpp b/floor-mesh.cpp index 32e5bb8e..e9dd57b1 100644 --- a/floor-mesh.cpp +++ b/floor-mesh.cpp @@ -1,6 +1,6 @@ #include "floor-mesh.hpp" #include "tile-atlas.hpp" -#include "tile-shader.hpp" +#include "shaders/tile-shader.hpp" #include "tile.hpp" #include "chunk.hpp" #include <Magnum/GL/MeshView.h> @@ -19,7 +19,6 @@ void floor_mesh::set_tile(tile& x, const local_coords pt) { CORRADE_INTERNAL_ASSERT(x.ground_image); - constexpr float X = TILE_SIZE[0], Y = TILE_SIZE[1]; 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++) @@ -31,14 +30,18 @@ void floor_mesh::draw(tile_shader& shader, chunk& c) c.foreach_tile([&](tile& x, std::size_t, local_coords pt) { set_tile(x, pt); }); - _vertex_buffer.setData(_vertex_data, Magnum::GL::BufferUsage::DynamicDraw); #if 1 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) { mesh.setIndexRange((int)(i*quad_index_count), 0, quad_index_count*TILE_COUNT - 1); - x.ground_image.atlas->texture().bind(0); + if (auto* atlas = x.ground_image.atlas.get(); atlas != last_tile_atlas) + { + atlas->texture().bind(0); + last_tile_atlas = atlas; + } shader.draw(mesh); }); #else @@ -52,7 +55,7 @@ static auto make_index_array() constexpr auto quad_index_count = std::tuple_size_v<decltype(tile_atlas::indices(0))>; std::array<std::array<UnsignedShort, quad_index_count>, TILE_COUNT> array; // NOLINT(cppcoreguidelines-pro-type-member-init) - for (std::size_t i = 0, k = 0; i < std::size(array); i++) + for (std::size_t i = 0; i < std::size(array); i++) array[i] = tile_atlas::indices(i); return array; } |