diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-02 00:56:41 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-02 00:56:41 +0200 |
commit | d0a3b0d4401917dd02ad27b4f9a4b91699569e36 (patch) | |
tree | edd4472c39d4da226ea931691574e030eb663747 /tile-mesh.hpp | |
parent | 742579ca2fce1effe942928f5b94401e1e723f34 (diff) |
a
Diffstat (limited to 'tile-mesh.hpp')
-rw-r--r-- | tile-mesh.hpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tile-mesh.hpp b/tile-mesh.hpp new file mode 100644 index 00000000..eef3b0a9 --- /dev/null +++ b/tile-mesh.hpp @@ -0,0 +1,39 @@ +#pragma once +#include "tile-atlas.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 tile_image; + +class tile_mesh final +{ + static constexpr std::size_t index_count = std::tuple_size_v<decltype(tile_atlas{}.indices(0))>; + static constexpr std::array<UnsignedShort, index_count> _indices = + tile_atlas::indices(0); + + struct vertex_data final { + Vector3 position; + Vector2 texcoords; + }; + std::array<vertex_data, 4> _vertex_data = {}; + GL::Mesh _mesh; + GL::Buffer _vertex_buffer{_vertex_data, Magnum::GL::BufferUsage::DynamicDraw}, + _index_buffer{_indices, Magnum::GL::BufferUsage::StaticDraw}; + +public: + tile_mesh(); + tile_mesh(tile_mesh&&) = delete; + tile_mesh(const tile_mesh&) = delete; + + void draw_quad(tile_shader& shader, tile_image& img, const std::array<Vector3, 4>& positions); + void draw_floor_quad(tile_shader& shader, tile_image& img, Vector3 center); +}; + +} // namespace Magnum::Examples |