summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/tile-atlas.cpp2
-rw-r--r--src/wireframe-mesh.cpp33
-rw-r--r--src/wireframe-mesh.hpp37
3 files changed, 29 insertions, 43 deletions
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 <Magnum/PixelFormat.h>
#include <Magnum/Trade/ImageData.h>
-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<char>{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 <traits T> wireframe_mesh<T>::wireframe_mesh()
+template <wireframe::traits T> wireframe_mesh<T>::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 <traits T> void wireframe_mesh<T>::draw(tile_shader& shader, T x)
+template <wireframe::traits T> void wireframe_mesh<T>::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<wireframe_traits::null>;
-template struct wireframe_mesh<wireframe_traits::quad>;
+template struct wireframe_mesh<wireframe::null>;
+template struct wireframe_mesh<wireframe::quad>;
} // 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<typename T>
concept traits = requires (const T& x) {
{T::num_vertices} -> std::convertible_to<std::size_t>;
- {T::num_indices} -> std::convertible_to<std::size_t>;
{x.primitive} -> std::convertible_to<GL::MeshPrimitive>;
- {x.make_vertex_positions_array() } -> std::same_as<std::array<Vector3, T::num_vertices>>;
- {x.make_index_array() } -> std::same_as<std::array<UnsignedShort, T::num_indices>>;
+ {x.make_vertex_array() } -> std::same_as<std::array<Vector3, T::num_vertices>>;
};
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<Vector3, 0> make_vertex_positions_array() { return {}; }
- static std::array<UnsignedShort, 0> make_index_array() { return {}; }
+ static std::array<Vector3, 0> 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<Vector3, num_vertices>;
- using index_array = std::array<UnsignedShort, num_indices>;
-
- 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<wireframe_traits::traits T>
+template<wireframe::traits T>
struct wireframe_mesh final
{
wireframe_mesh();
void draw(tile_shader& shader, T traits);
private:
- GL::Buffer _positions_buffer{},
- _texcoords_buffer{std::array<Vector2, T::num_vertices>{}},
- _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<Vector2, T::num_vertices>{}};
+ GL::RectangleTexture _texture = wireframe::null::make_constant_texture();
GL::Mesh _mesh;
};
-extern template struct wireframe_mesh<wireframe_traits::null>;
-extern template struct wireframe_mesh<wireframe_traits::quad>;
+extern template struct wireframe_mesh<wireframe::null>;
+extern template struct wireframe_mesh<wireframe::quad>;
-using wireframe_quad_mesh = wireframe_mesh<wireframe_traits::quad>;
+using wireframe_quad_mesh = wireframe_mesh<wireframe::quad>;
} // namespace Magnum::Examples