diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-02 03:36:42 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-02 03:36:42 +0200 |
commit | 5193b9575d61d410a932f3f7b0662f01c4d8268b (patch) | |
tree | 718c705e8c6de260565ccbb231ecbf2b42d063ff | |
parent | 35cf1d65b454985c38b1e00a91670663b1583670 (diff) |
MeshView now works
-rw-r--r-- | floor-mesh.cpp | 19 | ||||
-rw-r--r-- | floor-mesh.hpp | 4 | ||||
-rw-r--r-- | main.cpp | 2 |
3 files changed, 20 insertions, 5 deletions
diff --git a/floor-mesh.cpp b/floor-mesh.cpp index ecbcc8bb..db8f076a 100644 --- a/floor-mesh.cpp +++ b/floor-mesh.cpp @@ -3,6 +3,7 @@ #include "tile-shader.hpp" #include "tile.hpp" #include "chunk.hpp" +#include <Magnum/GL/MeshView.h> namespace Magnum::Examples { @@ -24,13 +25,27 @@ void floor_mesh::set_tile(tile& x, const local_coords pt) //auto positions = img.atlas->floor_quad(center, { TILE_SIZE[0], TILE_SIZE[1] }); for (std::size_t i = 0; i < 4; i++) _vertex_data[idx][i] = { texcoords[i] }; - x.ground_image.atlas->texture().bind(0); // TODO } -void floor_mesh::draw(tile_shader& shader) +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{_floor_mesh}; + mesh.setCount(quad_index_count); + c.foreach_tile([&](tile& x, std::size_t i, local_coords) { + mesh.setIndexRange((int)(i*quad_index_count)); + x.ground_image.atlas->texture().bind(0); + shader.draw(mesh); + }); +#else + c[0].ground_image.atlas->texture().bind(0); // TODO shader.draw(_floor_mesh); +#endif } static auto make_index_array() diff --git a/floor-mesh.hpp b/floor-mesh.hpp index a1b0fac5..0667c9e1 100644 --- a/floor-mesh.hpp +++ b/floor-mesh.hpp @@ -12,7 +12,7 @@ namespace Magnum::Examples { struct tile_shader; -struct tile_image; +struct chunk; struct floor_mesh final { @@ -21,7 +21,7 @@ struct floor_mesh final floor_mesh(const floor_mesh&) = delete; void set_tile(tile& x, local_coords pt); - void draw(tile_shader& shader); + void draw(tile_shader& shader, chunk& c); private: struct vertex_data final { @@ -93,7 +93,7 @@ void app::draw_chunk(chunk& c) for (std::size_t j = 0, k = 0; j < N; j++) for (std::size_t i = 0; i < N; i++, k++) _floor_mesh.set_tile(c[k], {i, j}); - _floor_mesh.draw(_shader); + _floor_mesh.draw(_shader, c); } app::app(const Arguments& arguments): |