summaryrefslogtreecommitdiffhomepage
path: root/draw/floor.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-25 16:37:58 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-25 16:37:58 +0200
commitf1df7c20129a1f1cc47c47e5731efd10f8e49aeb (patch)
tree0241e953981404e50a5c1fcd6d49f583ecf5995e /draw/floor.hpp
parenta00ac8b5fed9d03cb2b3eafb4cd7d04546e341b1 (diff)
rename in draw/
Diffstat (limited to 'draw/floor.hpp')
-rw-r--r--draw/floor.hpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/draw/floor.hpp b/draw/floor.hpp
new file mode 100644
index 00000000..f81a7593
--- /dev/null
+++ b/draw/floor.hpp
@@ -0,0 +1,39 @@
+#pragma once
+#include "tile-defs.hpp"
+#include <array>
+#include <Corrade/Containers/ArrayViewStl.h>
+#include <Magnum/Magnum.h>
+#include <Magnum/Math/Vector2.h>
+#include <Magnum/Math/Vector3.h>
+#include <Magnum/GL/Mesh.h>
+#include <Magnum/GL/Buffer.h>
+
+namespace floormat {
+
+struct tile_shader;
+struct chunk;
+struct tile;
+
+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 floormat