#pragma once #include "tile-defs.hpp" #include #include #include "Magnum/GL/Texture.h" namespace floormat { struct tile_shader; namespace wireframe { template concept traits = requires (const T& x) { {T::num_vertices} -> std::convertible_to; {T::num_indexes} -> std::convertible_to; {x.primitive} -> std::convertible_to; {x.make_vertex_array() } -> std::convertible_to>; {T::make_index_array() } -> std::convertible_to>; {x.on_draw()} -> std::same_as; }; GL::Texture2D make_constant_texture(); struct mesh_base { static void set_line_width(float width); protected: GL::Buffer _vertex_buffer{{}, GL::BufferUsage::DynamicDraw}, _constant_buffer, _index_buffer; GL::Texture2D* _texture; GL::Mesh _mesh; mesh_base(GL::MeshPrimitive primitive, ArrayView index_data, size_t num_vertices, size_t num_indexes, GL::Texture2D* texture); void draw(tile_shader& shader); void set_subdata(ArrayView array); }; } // namespace wireframe template struct wireframe_mesh final : private wireframe::mesh_base { wireframe_mesh(GL::Texture2D& constant_texture); void draw(tile_shader& shader, T traits); }; template wireframe_mesh::wireframe_mesh(GL::Texture2D& constant_texture) : wireframe::mesh_base{T::primitive, T::make_index_array(), T::num_vertices, T::num_indexes, &constant_texture} { } template void wireframe_mesh::draw(tile_shader& shader, T x) { //_texcoord_buffer.setData({nullptr, sizeof(Vector3) * T::num_vertices}, GL::BufferUsage::DynamicDraw); // orphan the buffer set_subdata(x.make_vertex_array()); x.on_draw(); mesh_base::draw(shader); } } // namespace floormat