diff --git a/doc/changelog.dox b/doc/changelog.dox index 2c7aa5a5a..7c942f586 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -50,6 +50,11 @@ See also: @ref Color3us, @ref Color4us convenience typedefs for half-float, 8- and 16-bit integer vector and color types - New @ref VertexFormat enum for vertex formats and related utilities +- New @ref MeshPrimitive::Instances, @ref MeshPrimitive::Faces and + @ref MeshPrimitive::Edges primitive types for describing per-instance, + per-face and per-edge data. Those don't map to any common GPU API, but can + be used by various importers to provide access to mesh data that is not + necessarily GPU-friendly. @subsubsection changelog-latest-new-audio Audio library diff --git a/src/Magnum/GL/Mesh.cpp b/src/Magnum/GL/Mesh.cpp index 80980bd5e..d26778434 100644 --- a/src/Magnum/GL/Mesh.cpp +++ b/src/Magnum/GL/Mesh.cpp @@ -54,7 +54,10 @@ constexpr MeshPrimitive PrimitiveMapping[]{ MeshPrimitive::LineStrip, MeshPrimitive::Triangles, MeshPrimitive::TriangleStrip, - MeshPrimitive::TriangleFan + MeshPrimitive::TriangleFan, + MeshPrimitive(~UnsignedInt{}), /* Instances */ + MeshPrimitive(~UnsignedInt{}), /* Faces */ + MeshPrimitive(~UnsignedInt{}) /* Edges */ }; constexpr MeshIndexType IndexTypeMapping[]{ diff --git a/src/Magnum/GL/Test/MeshTest.cpp b/src/Magnum/GL/Test/MeshTest.cpp index 2cbe8422d..9569b6fcb 100644 --- a/src/Magnum/GL/Test/MeshTest.cpp +++ b/src/Magnum/GL/Test/MeshTest.cpp @@ -191,7 +191,10 @@ void MeshTest::mapPrimitiveImplementationSpecific() { } void MeshTest::mapPrimitiveUnsupported() { - CORRADE_SKIP("All primitive types are supported."); + std::ostringstream out; + Error redirectError{&out}; + meshPrimitive(Magnum::MeshPrimitive::Instances); + CORRADE_COMPARE(out.str(), "GL::meshPrimitive(): unsupported primitive MeshPrimitive::Instances\n"); } void MeshTest::mapPrimitiveInvalid() { diff --git a/src/Magnum/Implementation/meshPrimitiveMapping.hpp b/src/Magnum/Implementation/meshPrimitiveMapping.hpp index 0f503c8a4..5275a0ead 100644 --- a/src/Magnum/Implementation/meshPrimitiveMapping.hpp +++ b/src/Magnum/Implementation/meshPrimitiveMapping.hpp @@ -32,4 +32,7 @@ _c(LineStrip) _c(Triangles) _c(TriangleStrip) _c(TriangleFan) +_c(Instances) +_c(Faces) +_c(Edges) #endif diff --git a/src/Magnum/Mesh.h b/src/Magnum/Mesh.h index 791ba69d6..4e8016572 100644 --- a/src/Magnum/Mesh.h +++ b/src/Magnum/Mesh.h @@ -135,7 +135,48 @@ enum class MeshPrimitive: UnsignedInt { * @def_vk_keyword{PRIMITIVE_TOPOLOGY_TRIANGLE_FAN,PrimitiveTopology}. Not * supported on D3D or Metal. */ - TriangleFan + TriangleFan, + + /** + * Per-instance data. + * @m_since_latest + * + * Has no direct mapping to GPU APIs, but can be used to annotate + * @ref Trade::MeshData containing per-instance data (such as colors, + * transformations or texture layers) and then used to populate an instance + * buffer. Index buffer has no defined meaning for instance data. + */ + Instances, + + /** + * Per-face data. + * @m_since_latest + * + * Can be used to annotate @ref Trade::MeshData containing data that are + * per-face, as opposed to per-vertex. Has no direct mapping to common GPU + * APIs, there it either has to be converted to per-vertex (which usually + * involves slightly duplicating the original per-vertex data) or accessed + * via a direct buffer/texture fetch from a shader using e.g. + * @glsl gl_VertexID @ce. Index buffer can be used to deduplicate per-face + * data. + */ + Faces, + + /** + * Per-edge data. + * @m_since_latest + * + * Can be used to annotate @ref Trade::MeshData containing data that are + * per-edge, as opposed to per-vertex. This is different from + * @ref MeshPrimitive::Lines as it has just one entry per line segment, + * instead of two. Has no direct mapping to common GPU APIs, there it has + * to be converted to per-vertex (which usually involves slightly + * duplicating the original per-vertex data). Index buffer can be used to + * deduplicate per-face data. Can also be used for example to describe a + * half-edge mesh representation. + * @see @ref Trade::meshAttributeCustom() + */ + Edges }; /** @debugoperatorenum{MeshPrimitive} */ diff --git a/src/Magnum/Vk/Enums.cpp b/src/Magnum/Vk/Enums.cpp index cacdb8953..edfdff101 100644 --- a/src/Magnum/Vk/Enums.cpp +++ b/src/Magnum/Vk/Enums.cpp @@ -43,7 +43,10 @@ constexpr VkPrimitiveTopology PrimitiveTopologyMapping[]{ VK_PRIMITIVE_TOPOLOGY_LINE_STRIP, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, - VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN + VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN, + VkPrimitiveTopology(~UnsignedInt{}), /* Instances */ + VkPrimitiveTopology(~UnsignedInt{}), /* Faces */ + VkPrimitiveTopology(~UnsignedInt{}) /* Edges */ }; constexpr VkIndexType IndexTypeMapping[]{