From dcac3d7bd83c0cbdddae433e98598289bb1b06cd Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 8 Oct 2022 22:47:54 +0200 Subject: a --- src/tile-atlas.cpp | 2 +- src/wireframe-mesh.cpp | 33 ++++++++++++++------------------- src/wireframe-mesh.hpp | 37 ++++++++++++++----------------------- 3 files changed, 29 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/tile-atlas.cpp b/src/tile-atlas.cpp index 08bc2296..917c60bc 100644 --- a/src/tile-atlas.cpp +++ b/src/tile-atlas.cpp @@ -14,7 +14,7 @@ tile_atlas::tile_atlas(Containers::StringView name, const ImageView2D& image, Ve CORRADE_INTERNAL_ASSERT(dims_[0] > 0 && dims_[1] > 0); CORRADE_INTERNAL_ASSERT(size_ % dims_ == Vector2ui{}); CORRADE_INTERNAL_ASSERT(dims_.product() < 256); - tex_.setWrapping(GL::SamplerWrapping::ClampToBorder) + tex_.setWrapping(GL::SamplerWrapping::ClampToEdge) .setMagnificationFilter(GL::SamplerFilter::Nearest) .setMinificationFilter(GL::SamplerFilter::Linear) .setMaxAnisotropy(0) diff --git a/src/wireframe-mesh.cpp b/src/wireframe-mesh.cpp index 236f27ed..8d5d259f 100644 --- a/src/wireframe-mesh.cpp +++ b/src/wireframe-mesh.cpp @@ -7,15 +7,16 @@ #include #include -namespace Magnum::Examples::wireframe_traits { +namespace Magnum::Examples::wireframe +{ -GL::RectangleTexture wireframe_traits::null::make_constant_texture() +GL::RectangleTexture wireframe::null::make_constant_texture() { Trade::ImageData2D img{PixelFormat::RGBA8UI, {1, 1}, // NOLINT(misc-const-correctness) Containers::Array{Corrade::DirectInit, 4, (char)(unsigned char)255}}; GL::RectangleTexture tex; - tex.setWrapping(GL::SamplerWrapping::Repeat) + tex.setWrapping(GL::SamplerWrapping::ClampToEdge) .setMagnificationFilter(GL::SamplerFilter::Nearest) .setMinificationFilter(GL::SamplerFilter::Nearest) .setMaxAnisotropy(0) @@ -24,7 +25,7 @@ GL::RectangleTexture wireframe_traits::null::make_constant_texture() return tex; } -quad::vertex_array quad::make_vertex_positions_array() const +quad::vertex_array quad::make_vertex_array() const { constexpr auto X = TILE_SIZE[0], Y = TILE_SIZE[1]; constexpr float Z = 0; @@ -38,34 +39,28 @@ quad::vertex_array quad::make_vertex_positions_array() const quad::quad(Vector3 center, Vector2 size) : center(center), size(size) {} -} // namespace Magnum::Examples::wireframe_traits +} // namespace Magnum::Examples::wireframe namespace Magnum::Examples { -using wireframe_traits::traits; - -template wireframe_mesh::wireframe_mesh() +template wireframe_mesh::wireframe_mesh() { _mesh.setCount((int)T::num_vertices) .addVertexBuffer(_texcoords_buffer, 0, tile_shader::TextureCoordinates{}) - .addVertexBuffer(_positions_buffer, 0, tile_shader::Position{}); - if constexpr(T::num_indices > 0) - _mesh.setIndexBuffer(_index_buffer, 0, GL::MeshIndexType::UnsignedShort); - CORRADE_INTERNAL_ASSERT(T::num_indices > 0 == _mesh.isIndexed()); -}; + .addVertexBuffer(_vertex_buffer, 0, tile_shader::Position{}); + CORRADE_INTERNAL_ASSERT(!_mesh.isIndexed()); +} -template void wireframe_mesh::draw(tile_shader& shader, T x) +template void wireframe_mesh::draw(tile_shader& shader, T x) { GL::Renderer::setLineWidth(2); - _positions_buffer.setData(x.make_vertex_positions_array(), GL::BufferUsage::DynamicDraw); - if constexpr(T::num_indices > 0) - _index_buffer.setData(x.make_index_array(), GL::BufferUsage::DynamicDraw); + _vertex_buffer.setData(x.make_vertex_array(), GL::BufferUsage::DynamicDraw); _texture.bind(0); shader.draw(_mesh); } -template struct wireframe_mesh; -template struct wireframe_mesh; +template struct wireframe_mesh; +template struct wireframe_mesh; } // namespace Magnum::Examples diff --git a/src/wireframe-mesh.hpp b/src/wireframe-mesh.hpp index 28619e90..855e673a 100644 --- a/src/wireframe-mesh.hpp +++ b/src/wireframe-mesh.hpp @@ -14,67 +14,58 @@ namespace Magnum::Examples { struct tile_shader; -namespace wireframe_traits { +namespace wireframe +{ template concept traits = requires (const T& x) { {T::num_vertices} -> std::convertible_to; - {T::num_indices} -> std::convertible_to; {x.primitive} -> std::convertible_to; - {x.make_vertex_positions_array() } -> std::same_as>; - {x.make_index_array() } -> std::same_as>; + {x.make_vertex_array() } -> std::same_as>; }; struct null final { static constexpr auto primitive = GL::MeshPrimitive::Triangles; - static constexpr std::size_t num_vertices = 0, num_indices = 0; + static constexpr std::size_t num_vertices = 0; static GL::RectangleTexture make_constant_texture(); - static std::array make_vertex_positions_array() { return {}; } - static std::array make_index_array() { return {}; } + static std::array make_vertex_array() { return {}; } }; struct quad final { - quad(Vector3 center, Vector2 size = {TILE_SIZE[0], TILE_SIZE[1]}); + quad(Vector3 center, Vector2 size); constexpr quad() = default; static constexpr std::size_t num_vertices = 4; - static constexpr std::size_t num_indices = 0; static constexpr GL::MeshPrimitive primitive = GL::MeshPrimitive::LineLoop; using vertex_array = std::array; - using index_array = std::array; - - vertex_array make_vertex_positions_array() const; - static index_array make_index_array() { return {}; } + vertex_array make_vertex_array() const; private: Vector3 center = {}; Vector2 size = { TILE_SIZE[0], TILE_SIZE[1] }; }; -} // namespace wireframe_traits - +} // namespace wireframe -template +template struct wireframe_mesh final { wireframe_mesh(); void draw(tile_shader& shader, T traits); private: - GL::Buffer _positions_buffer{}, - _texcoords_buffer{std::array{}}, - _index_buffer{T::num_indices == 0 ? GL::Buffer{NoCreate} : GL::Buffer{}}; - GL::RectangleTexture _texture = wireframe_traits::null::make_constant_texture(); + GL::Buffer _vertex_buffer{}, _texcoords_buffer{std::array{}}; + GL::RectangleTexture _texture = wireframe::null::make_constant_texture(); GL::Mesh _mesh; }; -extern template struct wireframe_mesh; -extern template struct wireframe_mesh; +extern template struct wireframe_mesh; +extern template struct wireframe_mesh; -using wireframe_quad_mesh = wireframe_mesh; +using wireframe_quad_mesh = wireframe_mesh; } // namespace Magnum::Examples -- cgit v1.2.3