diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-09 07:09:23 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-09 07:09:23 +0200 |
commit | 5b97a6de06e7c44e7960159dc98c54860170203b (patch) | |
tree | d251705c2db0f7c9f53127e7dcc3e8c7d3737afa /draw/wireframe-mesh.hpp | |
parent | 1f1951218e715e12eaf5d8cd338b6e5459872acb (diff) |
a
Diffstat (limited to 'draw/wireframe-mesh.hpp')
-rw-r--r-- | draw/wireframe-mesh.hpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/draw/wireframe-mesh.hpp b/draw/wireframe-mesh.hpp index 0ae122f5..016a92af 100644 --- a/draw/wireframe-mesh.hpp +++ b/draw/wireframe-mesh.hpp @@ -3,7 +3,7 @@ #include "tile-defs.hpp" #include <array> #include <utility> -#include <Corrade/Containers/ArrayViewStl.h> +#include <Corrade/Containers/ArrayView.h> #include <Magnum/Math/Vector2.h> #include <Magnum/GL/Buffer.h> #include <Magnum/GL/Mesh.h> @@ -19,19 +19,22 @@ namespace wireframe template<typename T> concept traits = requires (const T& x) { {T::num_vertices} -> std::convertible_to<std::size_t>; + {T::num_indexes} -> std::convertible_to<std::size_t>; {x.primitive} -> std::convertible_to<GL::MeshPrimitive>; {x.make_vertex_array() } -> std::convertible_to<Containers::ArrayView<const void>>; + {T::make_index_array() } -> std::convertible_to<Containers::ArrayView<const void>>; {x.on_draw()} -> std::same_as<void>; }; struct mesh_base { static GL::RectangleTexture make_constant_texture(); - GL::Buffer _vertex_buffer, _texcoords_buffer; + GL::Buffer _vertex_buffer, _texcoords_buffer, _index_buffer; GL::RectangleTexture _texture = make_constant_texture(); GL::Mesh _mesh; - mesh_base(GL::MeshPrimitive primitive, std::size_t num_vertices); + mesh_base(GL::MeshPrimitive primitive, Containers::ArrayView<const void> index_data, + std::size_t num_vertices, std::size_t num_indexes); void draw(tile_shader& shader); }; @@ -46,12 +49,13 @@ struct wireframe_mesh final : private wireframe::mesh_base template<wireframe::traits T> wireframe_mesh<T>::wireframe_mesh() : - wireframe::mesh_base{T::primitive, T::num_vertices} -{} + wireframe::mesh_base{T::primitive, T::make_index_array(), T::num_vertices, T::num_indexes} +{ +} template <wireframe::traits T> void wireframe_mesh<T>::draw(tile_shader& shader, T x) { - _vertex_buffer.setData(x.make_vertex_array(), GL::BufferUsage::DynamicDraw); + _vertex_buffer.setSubData(0, x.make_vertex_array()); mesh_base::draw(shader); } |