Browse Source

Primitives: MSVC 2015 is this what makes you throw up?

pull/371/head
Vladimír Vondruš 6 years ago
parent
commit
0657d6073d
  1. 40
      src/Magnum/Primitives/Crosshair.cpp
  2. 64
      src/Magnum/Primitives/Cube.cpp
  3. 17
      src/Magnum/Primitives/Plane.cpp
  4. 34
      src/Magnum/Primitives/Square.cpp

40
src/Magnum/Primitives/Crosshair.cpp

@ -33,32 +33,50 @@ namespace Magnum { namespace Primitives {
namespace {
constexpr Vector2 Positions2D[]{
{-1.0f, 0.0f}, {1.0f, 0.0f},
{ 0.0f, -1.0f}, {0.0f, 1.0f}
/* Can't be just an array of Vector2 but has to be a struct, because then MSVC
2015 fails with an assertion like
Trade::MeshData: attribute 0 [0x7ffd6c4fb290:0x7ffd6c4fb338] is not contained in passed vertexData array [0x7ffd6c4fb170:0x7ffd6c4fb218]
which leads me to believe that it will make two copies of the data, one for
the MeshAttributeData constructor and one for the MeshData constructor. Same
for the Cube, Square and Plane primitives. Interestingly enough, this isn't
a problem for index arrays (maybe because those are integers and not
constexpr classes?). Also not a problem for MSVC 2017 and up. */
constexpr struct Vertex2D {
Vector2 position;
} Vertices2D[]{
{{-1.0f, 0.0f}}, {{1.0f, 0.0f}},
{{ 0.0f, -1.0f}}, {{0.0f, 1.0f}}
};
constexpr Vector3 Positions3D[]{
{-1.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f},
{ 0.0f, -1.0f, 0.0f}, {0.0f, 1.0f, 0.0f},
{ 0.0f, 0.0f, -1.0f}, {0.0f, 0.0f, 1.0f}
constexpr struct Vertex3D {
Vector3 position;
} Vertices3D[]{
{{-1.0f, 0.0f, 0.0f}}, {{1.0f, 0.0f, 0.0f}},
{{ 0.0f, -1.0f, 0.0f}}, {{0.0f, 1.0f, 0.0f}},
{{ 0.0f, 0.0f, -1.0f}}, {{0.0f, 0.0f, 1.0f}}
};
constexpr Trade::MeshAttributeData Attributes2D[]{
Trade::MeshAttributeData{Trade::MeshAttribute::Position, Containers::arrayView(Positions2D)}
Trade::MeshAttributeData{Trade::MeshAttribute::Position,
Containers::stridedArrayView(Vertices2D, &Vertices2D[0].position,
Containers::arraySize(Vertices2D), sizeof(Vertex2D))}
};
constexpr Trade::MeshAttributeData Attributes3D[]{
Trade::MeshAttributeData{Trade::MeshAttribute::Position, Containers::arrayView(Positions3D)}
Trade::MeshAttributeData{Trade::MeshAttribute::Position,
Containers::stridedArrayView(Vertices3D, &Vertices3D[0].position,
Containers::arraySize(Vertices3D), sizeof(Vertex3D))}
};
}
Trade::MeshData crosshair2D() {
return Trade::MeshData{MeshPrimitive::Lines, {}, Positions2D,
return Trade::MeshData{MeshPrimitive::Lines, {}, Vertices2D,
Trade::meshAttributeDataNonOwningArray(Attributes2D)};
}
Trade::MeshData crosshair3D() {
return Trade::MeshData{MeshPrimitive::Lines, {}, Positions3D,
return Trade::MeshData{MeshPrimitive::Lines, {}, Vertices3D,
Trade::meshAttributeDataNonOwningArray(Attributes3D)};
}

64
src/Magnum/Primitives/Cube.cpp

@ -95,7 +95,11 @@ Trade::MeshData cubeSolid() {
namespace {
constexpr Vector3 VerticesSolidStrip[]{
/* Can't be just an array of Vector3 because MSVC 2015 is special. See
Crosshair.cpp for details. */
constexpr struct VertexSolidStrip {
Vector3 position;
} VerticesSolidStrip[]{
/* Sources:
https://twitter.com/Donzanoid/status/436843034966507520
http://www.asmcommunity.net/forums/topic/?id=6284#post-45209
@ -119,24 +123,25 @@ constexpr Vector3 VerticesSolidStrip[]{
|F \|
2---3
*/
{ 1.0f, 1.0f, 1.0f}, /* 3 */
{-1.0f, 1.0f, 1.0f}, /* 2 */
{ 1.0f, -1.0f, 1.0f}, /* 6 */
{-1.0f, -1.0f, 1.0f}, /* 7 */
{-1.0f, -1.0f, -1.0f}, /* 4 */
{-1.0f, 1.0f, 1.0f}, /* 2 */
{-1.0f, 1.0f, -1.0f}, /* 0 */
{ 1.0f, 1.0f, 1.0f}, /* 3 */
{ 1.0f, 1.0f, -1.0f}, /* 1 */
{ 1.0f, -1.0f, 1.0f}, /* 6 */
{ 1.0f, -1.0f, -1.0f}, /* 5 */
{-1.0f, -1.0f, -1.0f}, /* 4 */
{ 1.0f, 1.0f, -1.0f}, /* 1 */
{-1.0f, 1.0f, -1.0f} /* 0 */
{{ 1.0f, 1.0f, 1.0f}}, /* 3 */
{{-1.0f, 1.0f, 1.0f}}, /* 2 */
{{ 1.0f, -1.0f, 1.0f}}, /* 6 */
{{-1.0f, -1.0f, 1.0f}}, /* 7 */
{{-1.0f, -1.0f, -1.0f}}, /* 4 */
{{-1.0f, 1.0f, 1.0f}}, /* 2 */
{{-1.0f, 1.0f, -1.0f}}, /* 0 */
{{ 1.0f, 1.0f, 1.0f}}, /* 3 */
{{ 1.0f, 1.0f, -1.0f}}, /* 1 */
{{ 1.0f, -1.0f, 1.0f}}, /* 6 */
{{ 1.0f, -1.0f, -1.0f}}, /* 5 */
{{-1.0f, -1.0f, -1.0f}}, /* 4 */
{{ 1.0f, 1.0f, -1.0f}}, /* 1 */
{{-1.0f, 1.0f, -1.0f}} /* 0 */
};
constexpr Trade::MeshAttributeData AttributesSolidStrip[]{
Trade::MeshAttributeData{Trade::MeshAttribute::Position,
Containers::stridedArrayView(VerticesSolidStrip)}
Containers::stridedArrayView(VerticesSolidStrip, &VerticesSolidStrip[0].position,
Containers::arraySize(VerticesSolidStrip), sizeof(VertexSolidStrip))}
};
}
@ -155,20 +160,25 @@ constexpr UnsignedShort IndicesWireframe[]{
1, 5, 2, 6, /* +X */
0, 4, 3, 7 /* -X */
};
constexpr Vector3 VerticesWireframe[]{
{-1.0f, -1.0f, 1.0f},
{ 1.0f, -1.0f, 1.0f},
{ 1.0f, 1.0f, 1.0f},
{-1.0f, 1.0f, 1.0f},
{-1.0f, -1.0f, -1.0f},
{ 1.0f, -1.0f, -1.0f},
{ 1.0f, 1.0f, -1.0f},
{-1.0f, 1.0f, -1.0f}
/* Can't be just an array of Vector3 because MSVC 2015 is special. See
Crosshair.cpp for details. */
constexpr struct VertexWireframe {
Vector3 position;
} VerticesWireframe[]{
{{-1.0f, -1.0f, 1.0f}},
{{ 1.0f, -1.0f, 1.0f}},
{{ 1.0f, 1.0f, 1.0f}},
{{-1.0f, 1.0f, 1.0f}},
{{-1.0f, -1.0f, -1.0f}},
{{ 1.0f, -1.0f, -1.0f}},
{{ 1.0f, 1.0f, -1.0f}},
{{-1.0f, 1.0f, -1.0f}}
};
constexpr Trade::MeshAttributeData AttributesWireframe[]{
Trade::MeshAttributeData{Trade::MeshAttribute::Position,
Containers::stridedArrayView(VerticesWireframe)}
Containers::stridedArrayView(VerticesWireframe, &VerticesWireframe[0].position,
Containers::arraySize(VerticesWireframe), sizeof(VertexWireframe))}
};
}

17
src/Magnum/Primitives/Plane.cpp

@ -90,15 +90,20 @@ Trade::MeshData planeSolid(const PlaneTextureCoords textureCoords) {
namespace {
constexpr Vector3 VerticesWireframe[]{
{-1.0f, -1.0f, 0.0f},
{ 1.0f, -1.0f, 0.0f},
{ 1.0f, 1.0f, 0.0f},
{-1.0f, 1.0f, 0.0f}
/* Can't be just an array of Vector3 because MSVC 2015 is special. See
Crosshair.cpp for details. */
constexpr struct VertexWireframe {
Vector3 position;
} VerticesWireframe[]{
{{-1.0f, -1.0f, 0.0f}},
{{ 1.0f, -1.0f, 0.0f}},
{{ 1.0f, 1.0f, 0.0f}},
{{-1.0f, 1.0f, 0.0f}}
};
constexpr Trade::MeshAttributeData AttributesWireframe[]{
Trade::MeshAttributeData{Trade::MeshAttribute::Position,
Containers::arrayView(VerticesWireframe)}
Containers::stridedArrayView(VerticesWireframe, &VerticesWireframe[0].position,
Containers::arraySize(VerticesWireframe), sizeof(VertexWireframe))}
};
}

34
src/Magnum/Primitives/Square.cpp

@ -33,11 +33,15 @@ namespace Magnum { namespace Primitives {
namespace {
constexpr Vector2 VerticesSolid[] {
{ 1.0f, -1.0f},
{ 1.0f, 1.0f},
{-1.0f, -1.0f},
{-1.0f, 1.0f}
/* Can't be just an array of Vector2 because MSVC 2015 is special. See
Crosshair.cpp for details. */
constexpr struct VertexSolid {
Vector2 position;
} VerticesSolid[] {
{{ 1.0f, -1.0f}},
{{ 1.0f, 1.0f}},
{{-1.0f, -1.0f}},
{{-1.0f, 1.0f}}
};
constexpr struct VertexSolidTextureCoords {
Vector2 position;
@ -50,7 +54,8 @@ constexpr struct VertexSolidTextureCoords {
};
constexpr Trade::MeshAttributeData AttributesSolid[]{
Trade::MeshAttributeData{Trade::MeshAttribute::Position,
Containers::stridedArrayView(VerticesSolid)}
Containers::stridedArrayView(VerticesSolid, &VerticesSolid[0].position,
Containers::arraySize(VerticesSolid), sizeof(VertexSolid))},
};
constexpr Trade::MeshAttributeData AttributesSolidTextureCoords[]{
Trade::MeshAttributeData{Trade::MeshAttribute::Position,
@ -78,15 +83,20 @@ Trade::MeshData squareSolid(const SquareTextureCoords textureCoords) {
namespace {
constexpr Vector2 VerticesWireframe[]{
{-1.0f, -1.0f},
{ 1.0f, -1.0f},
{ 1.0f, 1.0f},
{-1.0f, 1.0f}
/* Can't be just an array of Vector2 because MSVC 2015 is special. See
Crosshair.cpp for details. */
constexpr struct VertexWireframe {
Vector2 position;
} VerticesWireframe[]{
{{-1.0f, -1.0f}},
{{ 1.0f, -1.0f}},
{{ 1.0f, 1.0f}},
{{-1.0f, 1.0f}}
};
constexpr Trade::MeshAttributeData AttributesWireframe[]{
Trade::MeshAttributeData{Trade::MeshAttribute::Position,
Containers::stridedArrayView(VerticesWireframe)}
Containers::stridedArrayView(VerticesWireframe, &VerticesWireframe[0].position,
Containers::arraySize(VerticesWireframe), sizeof(VertexWireframe))}
};
}

Loading…
Cancel
Save