diff options
Diffstat (limited to 'src/floor-mesh.hpp')
| -rw-r--r-- | src/floor-mesh.hpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/floor-mesh.hpp b/src/floor-mesh.hpp new file mode 100644 index 00000000..41351fd9 --- /dev/null +++ b/src/floor-mesh.hpp @@ -0,0 +1,37 @@ +#pragma once +#include "tile.hpp" +#include <array> +#include <Corrade/Containers/ArrayViewStl.h> +#include <Magnum/Magnum.h> +#include <Magnum/Math/Vector2.h> +#include <Magnum/GL/Mesh.h> +#include <Magnum/GL/Buffer.h> + +namespace Magnum::Examples { + +struct tile_shader; +struct chunk; + +struct floor_mesh final +{ + floor_mesh(); + floor_mesh(floor_mesh&&) = delete; + floor_mesh(const floor_mesh&) = delete; + + void draw(tile_shader& shader, chunk& c); + +private: + struct vertex_data final { Vector2 texcoords; }; + using quad_data = std::array<vertex_data, 4>; + + static std::array<std::array<UnsignedShort, 6>, TILE_COUNT> make_index_array(); + static std::array<std::array<Vector3, 4>, TILE_COUNT> make_position_array(); + + GL::Mesh _mesh; + GL::Buffer _vertex_buffer{std::array<quad_data, TILE_COUNT>{}, Magnum::GL::BufferUsage::DynamicDraw}, + _index_buffer{make_index_array()}, _positions_buffer{make_position_array()}; + + static void set_tile(quad_data& data, tile& x); +}; + +} // namespace Magnum::Examples |
