From e3b2c9267e7a8da5adca522a48a9f9a8457f89d8 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 9 Oct 2022 05:01:04 +0200 Subject: a --- src/wireframe-mesh.hpp | 48 ++++++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 30 deletions(-) (limited to 'src/wireframe-mesh.hpp') diff --git a/src/wireframe-mesh.hpp b/src/wireframe-mesh.hpp index 26dfb9ec..0ae122f5 100644 --- a/src/wireframe-mesh.hpp +++ b/src/wireframe-mesh.hpp @@ -20,51 +20,39 @@ template concept traits = requires (const T& x) { {T::num_vertices} -> std::convertible_to; {x.primitive} -> std::convertible_to; - {x.make_vertex_array() } -> std::same_as>; + {x.make_vertex_array() } -> std::convertible_to>; + {x.on_draw()} -> std::same_as; }; -struct null final +struct mesh_base { - static constexpr auto primitive = GL::MeshPrimitive::Triangles; - static constexpr std::size_t num_vertices = 0; static GL::RectangleTexture make_constant_texture(); - static std::array make_vertex_array() { return {}; } -}; - -struct quad final -{ - quad(Vector3 center, Vector2 size); - - static constexpr std::size_t num_vertices = 4; - static constexpr GL::MeshPrimitive primitive = GL::MeshPrimitive::LineLoop; - - using vertex_array = std::array; - - vertex_array make_vertex_array() const; + GL::Buffer _vertex_buffer, _texcoords_buffer; + GL::RectangleTexture _texture = make_constant_texture(); + GL::Mesh _mesh; -private: - Vector3 center; - Vector2 size; + mesh_base(GL::MeshPrimitive primitive, std::size_t num_vertices); + void draw(tile_shader& shader); }; } // namespace wireframe template -struct wireframe_mesh final +struct wireframe_mesh final : private wireframe::mesh_base { wireframe_mesh(); void draw(tile_shader& shader, T traits); - -private: - GL::Buffer _vertex_buffer{std::array{}, GL::BufferUsage::DynamicDraw}, - _texcoords_buffer{std::array{}, GL::BufferUsage::DynamicDraw}; - GL::RectangleTexture _texture = wireframe::null::make_constant_texture(); - GL::Mesh _mesh; }; -extern template struct wireframe_mesh; -extern template struct wireframe_mesh; +template +wireframe_mesh::wireframe_mesh() : + wireframe::mesh_base{T::primitive, T::num_vertices} +{} -using wireframe_quad_mesh = wireframe_mesh; +template void wireframe_mesh::draw(tile_shader& shader, T x) +{ + _vertex_buffer.setData(x.make_vertex_array(), GL::BufferUsage::DynamicDraw); + mesh_base::draw(shader); +} } // namespace Magnum::Examples -- cgit v1.2.3