diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-25 16:37:58 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-25 16:37:58 +0200 |
commit | f1df7c20129a1f1cc47c47e5731efd10f8e49aeb (patch) | |
tree | 0241e953981404e50a5c1fcd6d49f583ecf5995e /draw/wireframe.cpp | |
parent | a00ac8b5fed9d03cb2b3eafb4cd7d04546e341b1 (diff) |
rename in draw/
Diffstat (limited to 'draw/wireframe.cpp')
-rw-r--r-- | draw/wireframe.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/draw/wireframe.cpp b/draw/wireframe.cpp new file mode 100644 index 00000000..4ff99adb --- /dev/null +++ b/draw/wireframe.cpp @@ -0,0 +1,55 @@ +#include "wireframe.hpp" +#include "shaders/tile-shader.hpp" +//#include <Corrade/Containers/ArrayViewStl.h> +#include <Corrade/Containers/Array.h> +#include <Corrade/Containers/ArrayView.h> +#include <Magnum/GL/TextureFormat.h> +//#include <Magnum/ImageFlags.h> +#include <Magnum/ImageView.h> +#include <Magnum/PixelFormat.h> +//#include <Magnum/PixelStorage.h> +#include <Magnum/Trade/ImageData.h> + +namespace floormat::wireframe +{ + +GL::Texture2D mesh_base::make_constant_texture() +{ + const Vector4ub data[] = { {255, 255, 255, 255} }; + Trade::ImageData2D img{PixelFormat::RGBA8Unorm, {1, 1}, {}, + Containers::arrayView(data, 1), {}, {}}; + GL::Texture2D tex; + tex.setWrapping(GL::SamplerWrapping::ClampToEdge) + .setMagnificationFilter(GL::SamplerFilter::Nearest) + .setMinificationFilter(GL::SamplerFilter::Nearest) + .setStorage(1, GL::textureFormat(img.format()), img.size()) + .setSubImage(0, {}, std::move(img)); + return tex; +} + +mesh_base::mesh_base(GL::MeshPrimitive primitive, ArrayView<const void> index_data, + std::size_t num_vertices, std::size_t num_indexes) : + _vertex_buffer{Containers::Array<Vector3>{ValueInit, num_vertices}, GL::BufferUsage::DynamicDraw}, + _texcoords_buffer{Containers::Array<Vector2>{ValueInit, num_vertices}}, + _index_buffer{num_indexes == 0 ? GL::Buffer{NoCreate} : GL::Buffer{index_data}} +{ + _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) +{ + _texture.bind(0); + shader.draw(_mesh); +} + +void mesh_base::set_subdata(ArrayView<const void> array) +{ + _vertex_buffer.setSubData(0, array); +} + +} // namespace floormat::wireframe |