summaryrefslogtreecommitdiffhomepage
path: root/draw/wireframe-mesh.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-09 07:09:23 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-09 07:09:23 +0200
commit5b97a6de06e7c44e7960159dc98c54860170203b (patch)
treed251705c2db0f7c9f53127e7dcc3e8c7d3737afa /draw/wireframe-mesh.cpp
parent1f1951218e715e12eaf5d8cd338b6e5459872acb (diff)
a
Diffstat (limited to 'draw/wireframe-mesh.cpp')
-rw-r--r--draw/wireframe-mesh.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/draw/wireframe-mesh.cpp b/draw/wireframe-mesh.cpp
index 1425df60..35103055 100644
--- a/draw/wireframe-mesh.cpp
+++ b/draw/wireframe-mesh.cpp
@@ -1,7 +1,7 @@
#include "wireframe-mesh.hpp"
#include "shaders/tile-shader.hpp"
+#include <Corrade/Containers/ArrayViewStl.h>
#include <Corrade/Containers/Array.h>
-#include <Magnum/GL/Renderer.h>
#include <Magnum/GL/TextureFormat.h>
#include <Magnum/ImageFlags.h>
#include <Magnum/ImageView.h>
@@ -15,8 +15,7 @@ namespace Magnum::Examples::wireframe
GL::RectangleTexture mesh_base::make_constant_texture()
{
const Vector4ub data[] = { {255, 255, 255, 255} };
- Trade::ImageData2D img{PixelStorage{}.setImageHeight(1).setRowLength(1).setAlignment(1),
- PixelFormat::RGBA8Unorm, {1, 1}, {},
+ Trade::ImageData2D img{PixelFormat::RGBA8Unorm, {1, 1}, {},
Containers::arrayView(data, 1), {}, {}};
GL::RectangleTexture tex;
tex.setWrapping(GL::SamplerWrapping::ClampToEdge)
@@ -28,13 +27,18 @@ GL::RectangleTexture mesh_base::make_constant_texture()
return tex;
}
-mesh_base::mesh_base(GL::MeshPrimitive primitive, std::size_t num_vertices) :
- _texcoords_buffer{std::vector<Vector2>{num_vertices}}
+mesh_base::mesh_base(GL::MeshPrimitive primitive, Containers::ArrayView<const void> index_data,
+ std::size_t num_vertices, std::size_t num_indexes) :
+ _vertex_buffer{Containers::Array<Vector3>{ValueInit, num_vertices}},
+ _texcoords_buffer{Containers::Array<Vector2>{ValueInit, num_vertices}},
+ _index_buffer{num_indexes == 0 ? GL::Buffer{NoCreate} : GL::Buffer{index_data}}
{
- _mesh.setCount((int)num_vertices)
+ _mesh.setCount((int)(num_indexes > 0 ? num_indexes : num_vertices))
.setPrimitive(primitive)
.addVertexBuffer(_vertex_buffer, 0, tile_shader::Position{})
.addVertexBuffer(_texcoords_buffer, 0, tile_shader::TextureCoordinates{});
+ if (num_indexes > 0)
+ _mesh.setIndexBuffer(_index_buffer, 0, GL::MeshIndexType::UnsignedShort);
}
void mesh_base::draw(tile_shader& shader)