From 0b66b85c20956c9f10195798966b9812d734896f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 13 Apr 2023 12:36:26 +0200 Subject: [PATCH] Primitives: mark primitive data as global where appropriate. --- doc/changelog.dox | 2 ++ src/Magnum/MeshTools/Test/ReferenceTest.cpp | 10 +++++----- src/Magnum/Primitives/Axis.cpp | 8 ++++---- src/Magnum/Primitives/Axis.h | 8 ++++---- src/Magnum/Primitives/Crosshair.cpp | 6 ++++-- src/Magnum/Primitives/Crosshair.h | 8 ++++---- src/Magnum/Primitives/Cube.cpp | 10 +++++----- src/Magnum/Primitives/Cube.h | 13 +++++++------ src/Magnum/Primitives/Plane.cpp | 4 ++-- src/Magnum/Primitives/Plane.h | 11 ++++++----- src/Magnum/Primitives/Square.cpp | 6 +++--- src/Magnum/Primitives/Square.h | 8 ++++---- 12 files changed, 50 insertions(+), 44 deletions(-) diff --git a/doc/changelog.dox b/doc/changelog.dox index f68e3ced6..ad28d9ef2 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -683,6 +683,8 @@ See also: importers to reason about ownership of passed data instead of being forced to allocate a local copy, saving as much as half memory in certain importer implementations +- New @ref Trade::DataFlag::Global flag to annotate data referencing global + memory, such as @ref Primitives::cubeSolid() - @ref Trade::AbstractImageConverter::doConvertToFile() and @ref Trade::AbstractSceneConverter::doConvertToFile() are now @cpp protected @ce instead of @cpp private @ce to allow calling them from diff --git a/src/Magnum/MeshTools/Test/ReferenceTest.cpp b/src/Magnum/MeshTools/Test/ReferenceTest.cpp index d556609bf..0db2574c2 100644 --- a/src/Magnum/MeshTools/Test/ReferenceTest.cpp +++ b/src/Magnum/MeshTools/Test/ReferenceTest.cpp @@ -215,8 +215,8 @@ void ReferenceTest::mutableReferenceNotMutable() { CORRADE_SKIP_IF_NO_ASSERT(); Trade::MeshData cube = Primitives::cubeSolid(); - CORRADE_COMPARE(cube.indexDataFlags(), Trade::DataFlags{}); - CORRADE_COMPARE(cube.vertexDataFlags(), Trade::DataFlags{}); + CORRADE_COMPARE(cube.indexDataFlags(), Trade::DataFlag::Global); + CORRADE_COMPARE(cube.vertexDataFlags(), Trade::DataFlag::Global); std::ostringstream out; Error redirectError{&out}; @@ -226,8 +226,8 @@ void ReferenceTest::mutableReferenceNotMutable() { void ReferenceTest::owned() { Trade::MeshData cube = Primitives::cubeSolid(); - CORRADE_COMPARE(cube.indexDataFlags(), Trade::DataFlags{}); - CORRADE_COMPARE(cube.vertexDataFlags(), Trade::DataFlags{}); + CORRADE_COMPARE(cube.indexDataFlags(), Trade::DataFlag::Global); + CORRADE_COMPARE(cube.vertexDataFlags(), Trade::DataFlag::Global); Trade::MeshData owned = MeshTools::owned(cube); CORRADE_VERIFY(owned.isIndexed()); @@ -258,7 +258,7 @@ void ReferenceTest::owned() { void ReferenceTest::ownedNoIndexData() { Trade::MeshData cube = Primitives::cubeSolidStrip(); CORRADE_VERIFY(!cube.isIndexed()); - CORRADE_COMPARE(cube.vertexDataFlags(), Trade::DataFlags{}); + CORRADE_COMPARE(cube.vertexDataFlags(), Trade::DataFlag::Global); Trade::MeshData owned = MeshTools::owned(cube); CORRADE_VERIFY(!owned.isIndexed()); diff --git a/src/Magnum/Primitives/Axis.cpp b/src/Magnum/Primitives/Axis.cpp index d200f6ff8..dcedac58c 100644 --- a/src/Magnum/Primitives/Axis.cpp +++ b/src/Magnum/Primitives/Axis.cpp @@ -112,14 +112,14 @@ constexpr Trade::MeshAttributeData Attributes3D[]{ Trade::MeshData axis2D() { return Trade::MeshData{MeshPrimitive::Lines, - {}, Indices2D, Trade::MeshIndexData{Indices2D}, - {}, Vertices2D, Trade::meshAttributeDataNonOwningArray(Attributes2D)}; + Trade::DataFlag::Global, Indices2D, Trade::MeshIndexData{Indices2D}, + Trade::DataFlag::Global, Vertices2D, Trade::meshAttributeDataNonOwningArray(Attributes2D)}; } Trade::MeshData axis3D() { return Trade::MeshData{MeshPrimitive::Lines, - {}, Indices3D, Trade::MeshIndexData{Indices3D}, - {}, Vertices3D, Trade::meshAttributeDataNonOwningArray(Attributes3D)}; + Trade::DataFlag::Global, Indices3D, Trade::MeshIndexData{Indices3D}, + Trade::DataFlag::Global, Vertices3D, Trade::meshAttributeDataNonOwningArray(Attributes3D)}; } }} diff --git a/src/Magnum/Primitives/Axis.h b/src/Magnum/Primitives/Axis.h index 03a9e240c..370187ffa 100644 --- a/src/Magnum/Primitives/Axis.h +++ b/src/Magnum/Primitives/Axis.h @@ -41,8 +41,8 @@ Two color-coded arrows for visualizing orientation (XY is RG), going from @cpp 0.0f @ce to @cpp 1.0f @ce on the X and Y axis. @ref MeshPrimitive::Lines with @ref MeshIndexType::UnsignedShort indices, interleaved @ref VertexFormat::Vector2 positions and @ref VertexFormat::Vector3 colors. The -returned instance references data stored in constant memory --- pass the data -through @ref MeshTools::owned() to get a mutable copy, if needed. +returned instance references @ref Trade::DataFlag::Global data --- pass the +mesh through @ref MeshTools::owned() to get a mutable copy, if needed. @image html primitives-axis2d.png width=256px @@ -57,8 +57,8 @@ Three color-coded arrows for visualizing orientation (XYZ is RGB), going from @cpp 0.0f @ce to @cpp 1.0f @ce on the X, Y and Z axis. @ref MeshPrimitive::Lines with @ref MeshIndexType::UnsignedShort indices, interleaved @ref VertexFormat::Vector3 positions and @ref VertexFormat::Vector3 -colors. The returned instance references data stored in constant memory --- -pass the data through @ref MeshTools::owned() to get a mutable copy, if needed. +colors. The returned instance references @ref Trade::DataFlag::Global data --- +pass the mesh through @ref MeshTools::owned() to get a mutable copy, if needed. @image html primitives-axis3d.png width=256px diff --git a/src/Magnum/Primitives/Crosshair.cpp b/src/Magnum/Primitives/Crosshair.cpp index 5079fe9e4..fd1e556e5 100644 --- a/src/Magnum/Primitives/Crosshair.cpp +++ b/src/Magnum/Primitives/Crosshair.cpp @@ -71,12 +71,14 @@ constexpr Trade::MeshAttributeData Attributes3D[]{ } Trade::MeshData crosshair2D() { - return Trade::MeshData{MeshPrimitive::Lines, {}, Vertices2D, + return Trade::MeshData{MeshPrimitive::Lines, + Trade::DataFlag::Global, Vertices2D, Trade::meshAttributeDataNonOwningArray(Attributes2D)}; } Trade::MeshData crosshair3D() { - return Trade::MeshData{MeshPrimitive::Lines, {}, Vertices3D, + return Trade::MeshData{MeshPrimitive::Lines, + Trade::DataFlag::Global, Vertices3D, Trade::meshAttributeDataNonOwningArray(Attributes3D)}; } diff --git a/src/Magnum/Primitives/Crosshair.h b/src/Magnum/Primitives/Crosshair.h index 2eaa61070..525abf059 100644 --- a/src/Magnum/Primitives/Crosshair.h +++ b/src/Magnum/Primitives/Crosshair.h @@ -39,8 +39,8 @@ namespace Magnum { namespace Primitives { 2x2 crosshair (two crossed lines), centered at origin. Non-indexed @ref MeshPrimitive::Lines with @ref VertexFormat::Vector2 positions. The -returned instance references data astored in constant memory --- pass the data -through @ref MeshTools::owned() to get a mutable copy, if needed. +returned instance references @ref Trade::DataFlag::Global data --- pass the +mesh through @ref MeshTools::owned() to get a mutable copy, if needed. @image html primitives-crosshair2d.png width=256px @@ -53,8 +53,8 @@ MAGNUM_PRIMITIVES_EXPORT Trade::MeshData crosshair2D(); 2x2x2 crosshair (three crossed lines), centered at origin. Non-indexed @ref MeshPrimitive::Lines with @ref VertexFormat::Vector3 positions. The -returned instance references data stored in constant memory --- pass the data -through @ref MeshTools::owned() to get a mutable copy, if needed. +returned instance references @ref Trade::DataFlag::Global data --- pass the +mesh through @ref MeshTools::owned() to get a mutable copy, if needed. @image html primitives-crosshair3d.png width=256px diff --git a/src/Magnum/Primitives/Cube.cpp b/src/Magnum/Primitives/Cube.cpp index 3c76934e2..705b4510e 100644 --- a/src/Magnum/Primitives/Cube.cpp +++ b/src/Magnum/Primitives/Cube.cpp @@ -89,8 +89,8 @@ constexpr Trade::MeshAttributeData AttributesSolid[]{ Trade::MeshData cubeSolid() { return Trade::MeshData{MeshPrimitive::Triangles, - {}, IndicesSolid, Trade::MeshIndexData{IndicesSolid}, - {}, VerticesSolid, Trade::meshAttributeDataNonOwningArray(AttributesSolid)}; + Trade::DataFlag::Global, IndicesSolid, Trade::MeshIndexData{IndicesSolid}, + Trade::DataFlag::Global, VerticesSolid, Trade::meshAttributeDataNonOwningArray(AttributesSolid)}; } namespace { @@ -148,7 +148,7 @@ constexpr Trade::MeshAttributeData AttributesSolidStrip[]{ Trade::MeshData cubeSolidStrip() { return Trade::MeshData{MeshPrimitive::TriangleStrip, - {}, VerticesSolidStrip, Trade::meshAttributeDataNonOwningArray(AttributesSolidStrip)}; + Trade::DataFlag::Global, VerticesSolidStrip, Trade::meshAttributeDataNonOwningArray(AttributesSolidStrip)}; } namespace { @@ -185,8 +185,8 @@ constexpr Trade::MeshAttributeData AttributesWireframe[]{ Trade::MeshData cubeWireframe() { return Trade::MeshData{MeshPrimitive::Lines, - {}, IndicesWireframe, Trade::MeshIndexData{IndicesWireframe}, - {}, VerticesWireframe, Trade::meshAttributeDataNonOwningArray(AttributesWireframe)}; + Trade::DataFlag::Global, IndicesWireframe, Trade::MeshIndexData{IndicesWireframe}, + Trade::DataFlag::Global, VerticesWireframe, Trade::meshAttributeDataNonOwningArray(AttributesWireframe)}; } }} diff --git a/src/Magnum/Primitives/Cube.h b/src/Magnum/Primitives/Cube.h index d4c2d35fe..dba88ccc7 100644 --- a/src/Magnum/Primitives/Cube.h +++ b/src/Magnum/Primitives/Cube.h @@ -40,8 +40,8 @@ namespace Magnum { namespace Primitives { 2x2x2 cube, centered at origin. @ref MeshPrimitive::Triangles with @ref MeshIndexType::UnsignedShort indices, interleaved @ref VertexFormat::Vector3 positions and flat @ref VertexFormat::Vector3 -normals. The returned instance references data stored in constant memory --- -pass the data through @ref MeshTools::owned() to get a mutable copy, if needed. +normals. The returned instance references @ref Trade::DataFlag::Global data --- +pass the mesh through @ref MeshTools::owned() to get a mutable copy, if needed. @image html primitives-cubesolid.png width=256px @@ -55,8 +55,8 @@ MAGNUM_PRIMITIVES_EXPORT Trade::MeshData cubeSolid(); 2x2x2 cube, centered at origin. Non-indexed @ref MeshPrimitive::TriangleStrip with @ref VertexFormat::Vector3 positions. No normals or anything else, use @ref cubeSolid() instead if you need these. The returned instance references -data stored in constant memory --- pass the data through @ref MeshTools::owned() -to get a mutable copy, if needed. +@ref Trade::DataFlag::Global data --- pass the mesh through +@ref MeshTools::owned() to get a mutable copy, if needed. Vertex positions of this mesh can be also generated directly in the vertex shader using @glsl gl_VertexID @ce ([source](https://twitter.com/turanszkij/status/1141638406956617730), @@ -73,8 +73,9 @@ MAGNUM_PRIMITIVES_EXPORT Trade::MeshData cubeSolidStrip(); 2x2x2 cube, centered at origin. @ref MeshPrimitive::Lines with @ref MeshIndexType::UnsignedShort indices and @ref VertexFormat::Vector3 -positions. The returned instance references data stored in constant memory --- -pass the data through @ref MeshTools::owned() to get a mutable copy, if needed. +positions. The returned instance references @ref Trade::DataFlag::Global data +--- pass the mesh through @ref MeshTools::owned() to get a mutable copy, if +needed. @image html primitives-cubewireframe.png width=256px diff --git a/src/Magnum/Primitives/Plane.cpp b/src/Magnum/Primitives/Plane.cpp index 99d8a6767..f66f597ec 100644 --- a/src/Magnum/Primitives/Plane.cpp +++ b/src/Magnum/Primitives/Plane.cpp @@ -59,7 +59,7 @@ constexpr Trade::MeshAttributeData AttributesSolid[]{ Trade::MeshData planeSolid() { return Trade::MeshData{MeshPrimitive::TriangleStrip, - {}, VerticesSolid, + Trade::DataFlag::Global, VerticesSolid, Trade::meshAttributeDataNonOwningArray(AttributesSolid)}; } @@ -171,7 +171,7 @@ constexpr Trade::MeshAttributeData AttributesWireframe[]{ Trade::MeshData planeWireframe() { return Trade::MeshData{MeshPrimitive::LineLoop, - {}, VerticesWireframe, + Trade::DataFlag::Global, VerticesWireframe, Trade::meshAttributeDataNonOwningArray(AttributesWireframe)}; } diff --git a/src/Magnum/Primitives/Plane.h b/src/Magnum/Primitives/Plane.h index 0f6e2464d..7eb0a9f11 100644 --- a/src/Magnum/Primitives/Plane.h +++ b/src/Magnum/Primitives/Plane.h @@ -88,9 +88,9 @@ enum class CORRADE_DEPRECATED_ENUM("use PlaneFlags instead") PlaneTextureCoords: @ref MeshPrimitive::TriangleStrip with @ref VertexFormat::Vector3 positions, @ref VertexFormat::Vector3 normals in positive Z direction, optional @ref VertexFormat::Vector4 tangents and optional @ref VertexFormat::Vector2 -texture coordinates. The returned instance may reference data stored in -constant memory --- pass the data through @ref MeshTools::owned() to get a -mutable copy, if needed. +texture coordinates. The returned instance may reference +@ref Trade::DataFlag::Global data --- pass the mesh through +@ref MeshTools::owned() to get a mutable copy, if needed. @image html primitives-planesolid.png width=256px @@ -119,8 +119,9 @@ CORRADE_IGNORE_DEPRECATED_POP 2x2 square on the XY plane, centered at origin. Non-indexed @ref MeshPrimitive::LineLoop on the XY plane with @ref VertexFormat::Vector3 -positions. The returned instance references data stored in constant memory --- -pass the data through @ref MeshTools::owned() to get a mutable copy, if needed. +positions. The returned instance references @ref Trade::DataFlag::Global data +--- pass the mesh through @ref MeshTools::owned() to get a mutable copy, if +needed. @image html primitives-planewireframe.png width=256px diff --git a/src/Magnum/Primitives/Square.cpp b/src/Magnum/Primitives/Square.cpp index cc25a3df6..35a5c7c42 100644 --- a/src/Magnum/Primitives/Square.cpp +++ b/src/Magnum/Primitives/Square.cpp @@ -77,11 +77,11 @@ constexpr Trade::MeshAttributeData AttributesSolidTextureCoords[]{ Trade::MeshData squareSolid(const SquareFlags flags) { if(flags & SquareFlag::TextureCoordinates) return Trade::MeshData{MeshPrimitive::TriangleStrip, - {}, VerticesSolidTextureCoords, + Trade::DataFlag::Global, VerticesSolidTextureCoords, Trade::meshAttributeDataNonOwningArray(AttributesSolidTextureCoords)}; return Trade::MeshData{MeshPrimitive::TriangleStrip, - {}, VerticesSolid, + Trade::DataFlag::Global, VerticesSolid, Trade::meshAttributeDataNonOwningArray(AttributesSolid)}; } @@ -116,7 +116,7 @@ constexpr Trade::MeshAttributeData AttributesWireframe[]{ Trade::MeshData squareWireframe() { return Trade::MeshData{MeshPrimitive::LineLoop, - {}, VerticesWireframe, + Trade::DataFlag::Global, VerticesWireframe, Trade::meshAttributeDataNonOwningArray(AttributesWireframe)}; } diff --git a/src/Magnum/Primitives/Square.h b/src/Magnum/Primitives/Square.h index 56c02360c..86ca317ec 100644 --- a/src/Magnum/Primitives/Square.h +++ b/src/Magnum/Primitives/Square.h @@ -79,7 +79,7 @@ enum class CORRADE_DEPRECATED_ENUM("use SquareFlags instead") SquareTextureCoord 2x2 square, centered at origin. Non-indexed @ref MeshPrimitive::TriangleStrip with interleaved @ref VertexFormat::Vector2 positions and optional @ref VertexFormat::Vector2 texture coordinates. The returned instance -references data stored in constant memory --- pass the data through +references @ref Trade::DataFlag::Global data --- pass the mesh through @ref MeshTools::owned() to get a mutable copy, if needed. @image html primitives-squaresolid.png width=256px @@ -103,9 +103,9 @@ CORRADE_IGNORE_DEPRECATED_POP @brief Wireframe 2D square 2x2 square, centered at origin. Non-indexed @ref MeshPrimitive::LineLoop with -@ref VertexFormat::Vector2 positions. The returned instance references data -stored in constant memory --- pass the data through @ref MeshTools::owned() to -get a mutable copy, if needed. +@ref VertexFormat::Vector2 positions. The returned instance references +@ref Trade::DataFlag::Global data --- pass the mesh through +@ref MeshTools::owned() to get a mutable copy, if needed. @image html primitives-squarewireframe.png width=256px