Browse Source

Primitives: mark primitive data as global where appropriate.

pull/617/head
Vladimír Vondruš 3 years ago
parent
commit
0b66b85c20
  1. 2
      doc/changelog.dox
  2. 10
      src/Magnum/MeshTools/Test/ReferenceTest.cpp
  3. 8
      src/Magnum/Primitives/Axis.cpp
  4. 8
      src/Magnum/Primitives/Axis.h
  5. 6
      src/Magnum/Primitives/Crosshair.cpp
  6. 8
      src/Magnum/Primitives/Crosshair.h
  7. 10
      src/Magnum/Primitives/Cube.cpp
  8. 13
      src/Magnum/Primitives/Cube.h
  9. 4
      src/Magnum/Primitives/Plane.cpp
  10. 11
      src/Magnum/Primitives/Plane.h
  11. 6
      src/Magnum/Primitives/Square.cpp
  12. 8
      src/Magnum/Primitives/Square.h

2
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

10
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());

8
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)};
}
}}

8
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

6
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)};
}

8
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

10
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)};
}
}}

13
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

4
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)};
}

11
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

6
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)};
}

8
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

Loading…
Cancel
Save