Browse Source

MeshTools: clean up compile() tests.

Wow, the times before slicing to struct members was invented were
*dark*.
pull/499/head
Vladimír Vondruš 3 years ago
parent
commit
ecbe70bb40
  1. 109
      src/Magnum/MeshTools/Test/CompileGLTest.cpp

109
src/Magnum/MeshTools/Test/CompileGLTest.cpp

@ -442,27 +442,20 @@ template<class T> void CompileGLTest::twoDimensions() {
{{ 0.0f, 0.75f}, {0.5f, 1.0f}, 0x8080ff_rgbf, 26234}, {{ 0.0f, 0.75f}, {0.5f, 1.0f}, 0x8080ff_rgbf, 26234},
{{ 0.75f, 0.75f}, {1.0f, 1.0f}, 0xff00ff_rgbf, 26234} {{ 0.75f, 0.75f}, {1.0f, 1.0f}, 0xff00ff_rgbf, 26234}
}; };
auto vertices = Containers::stridedArrayView(vertexData);
Containers::Array<Trade::MeshAttributeData> attributeData; Containers::Array<Trade::MeshAttributeData> attributeData;
arrayAppend(attributeData, Trade::MeshAttributeData{ arrayAppend(attributeData, InPlaceInit, Trade::MeshAttribute::Position,
Trade::MeshAttribute::Position, vertices.slice(&Vertex::position));
Containers::stridedArrayView(vertexData, &vertexData[0].position,
Containers::arraySize(vertexData), sizeof(Vertex))});
if(data.flags & Flag::TextureCoordinates2D) if(data.flags & Flag::TextureCoordinates2D)
arrayAppend(attributeData, Trade::MeshAttributeData{ arrayAppend(attributeData, InPlaceInit, Trade::MeshAttribute::TextureCoordinates,
Trade::MeshAttribute::TextureCoordinates, vertices.slice(&Vertex::textureCoordinates));
Containers::stridedArrayView(vertexData, &vertexData[0].textureCoordinates,
Containers::arraySize(vertexData), sizeof(Vertex))});
if(data.flags & Flag::Colors) if(data.flags & Flag::Colors)
arrayAppend(attributeData, Trade::MeshAttributeData{ arrayAppend(attributeData, InPlaceInit, Trade::MeshAttribute::Color,
Trade::MeshAttribute::Color, vertices.slice(&Vertex::color));
Containers::stridedArrayView(vertexData, &vertexData[0].color,
Containers::arraySize(vertexData), sizeof(Vertex))});
if(data.flags & Flag::ObjectId) if(data.flags & Flag::ObjectId)
arrayAppend(attributeData, Trade::MeshAttributeData{ arrayAppend(attributeData, InPlaceInit, Trade::MeshAttribute::ObjectId,
Trade::MeshAttribute::ObjectId, vertices.slice(&Vertex::objectId));
Containers::stridedArrayView(vertexData, &vertexData[0].objectId,
Containers::arraySize(vertexData), sizeof(Vertex))});
const UnsignedInt indexData[]{ const UnsignedInt indexData[]{
66, 78, 23, /* offset */ 66, 78, 23, /* offset */
@ -657,46 +650,33 @@ template<class T> void CompileGLTest::threeDimensions() {
Vector3{ 0.5f, 0.5f, 1.0f}.normalized(), Vector3{ 0.5f, 0.5f, 1.0f}.normalized(),
{1.0f, 1.0f}, 0xff00ff_rgbf, 26234} {1.0f, 1.0f}, 0xff00ff_rgbf, 26234}
}; };
auto vertices = Containers::stridedArrayView(vertexData);
/* Calculate bitangents from normal+tangent */ /* Calculate bitangents from normal+tangent */
for(Vertex& i: vertexData) for(Vertex& i: vertexData)
i.bitangent = Math::cross(i.normal, i.tangent.xyz())*i.tangent.w(); i.bitangent = Math::cross(i.normal, i.tangent.xyz())*i.tangent.w();
Containers::Array<Trade::MeshAttributeData> attributeData; Containers::Array<Trade::MeshAttributeData> attributeData;
arrayAppend(attributeData, Trade::MeshAttributeData{ arrayAppend(attributeData, InPlaceInit, Trade::MeshAttribute::Position,
Trade::MeshAttribute::Position, vertices.slice(&Vertex::position));
Containers::stridedArrayView(vertexData, &vertexData[0].position,
Containers::arraySize(vertexData), sizeof(Vertex))});
if(data.flags & Flag::Tangents || data.flags & Flag::BitangentsFromTangents) if(data.flags & Flag::Tangents || data.flags & Flag::BitangentsFromTangents)
arrayAppend(attributeData, Trade::MeshAttributeData{ arrayAppend(attributeData, InPlaceInit, Trade::MeshAttribute::Tangent,
Trade::MeshAttribute::Tangent, vertices.slice(&Vertex::tangent));
Containers::stridedArrayView(vertexData, &vertexData[0].tangent,
Containers::arraySize(vertexData), sizeof(Vertex))});
if(data.flags & Flag::Bitangents) if(data.flags & Flag::Bitangents)
arrayAppend(attributeData, Trade::MeshAttributeData{ arrayAppend(attributeData, InPlaceInit, Trade::MeshAttribute::Bitangent,
Trade::MeshAttribute::Bitangent, vertices.slice(&Vertex::bitangent));
Containers::stridedArrayView(vertexData, &vertexData[0].bitangent,
Containers::arraySize(vertexData), sizeof(Vertex))});
if(data.flags & Flag::Normals) if(data.flags & Flag::Normals)
arrayAppend(attributeData, Trade::MeshAttributeData{ arrayAppend(attributeData, InPlaceInit, Trade::MeshAttribute::Normal,
Trade::MeshAttribute::Normal, vertices.slice(&Vertex::normal));
Containers::stridedArrayView(vertexData, &vertexData[0].normal,
Containers::arraySize(vertexData), sizeof(Vertex))});
if(data.flags & Flag::TextureCoordinates2D) if(data.flags & Flag::TextureCoordinates2D)
arrayAppend(attributeData, Trade::MeshAttributeData{ arrayAppend(attributeData, InPlaceInit, Trade::MeshAttribute::TextureCoordinates,
Trade::MeshAttribute::TextureCoordinates, vertices.slice(&Vertex::textureCoordinates));
Containers::stridedArrayView(vertexData, &vertexData[0].textureCoordinates,
Containers::arraySize(vertexData), sizeof(Vertex))});
if(data.flags & Flag::Colors) if(data.flags & Flag::Colors)
arrayAppend(attributeData, Trade::MeshAttributeData{ arrayAppend(attributeData, InPlaceInit, Trade::MeshAttribute::Color,
Trade::MeshAttribute::Color, vertices.slice(&Vertex::color));
Containers::stridedArrayView(vertexData, &vertexData[0].color,
Containers::arraySize(vertexData), sizeof(Vertex))});
if(data.flags & Flag::ObjectId) if(data.flags & Flag::ObjectId)
arrayAppend(attributeData, Trade::MeshAttributeData{ arrayAppend(attributeData, InPlaceInit, Trade::MeshAttribute::ObjectId,
Trade::MeshAttribute::ObjectId, vertices.slice(&Vertex::objectId));
Containers::stridedArrayView(vertexData, &vertexData[0].objectId,
Containers::arraySize(vertexData), sizeof(Vertex))});
const UnsignedByte indexData[]{ const UnsignedByte indexData[]{
66, 78, 23, /* offset */ 66, 78, 23, /* offset */
@ -939,6 +919,7 @@ void CompileGLTest::multipleAttributes() {
{{ 0.0f, 0.75f}, {0.5f, 1.0f}, {5.0f, 10.0f}}, {{ 0.0f, 0.75f}, {0.5f, 1.0f}, {5.0f, 10.0f}},
{{ 0.75f, 0.75f}, {1.0f, 1.0f}, {10.0f, 10.0f}} {{ 0.75f, 0.75f}, {1.0f, 1.0f}, {10.0f, 10.0f}}
}; };
auto vertices = Containers::stridedArrayView(vertexData);
const UnsignedInt indexData[]{ const UnsignedInt indexData[]{
0, 1, 4, 0, 4, 3, 0, 1, 4, 0, 4, 3,
@ -951,14 +932,11 @@ void CompileGLTest::multipleAttributes() {
{}, indexData, Trade::MeshIndexData{indexData}, {}, indexData, Trade::MeshIndexData{indexData},
{}, vertexData, { {}, vertexData, {
Trade::MeshAttributeData{Trade::MeshAttribute::Position, Trade::MeshAttributeData{Trade::MeshAttribute::Position,
Containers::stridedArrayView(vertexData, vertices.slice(&Vertex::position)},
&vertexData[0].position, Containers::arraySize(vertexData), sizeof(Vertex))},
Trade::MeshAttributeData{Trade::MeshAttribute::TextureCoordinates, Trade::MeshAttributeData{Trade::MeshAttribute::TextureCoordinates,
Containers::stridedArrayView(vertexData, vertices.slice(&Vertex::textureCoordinates1)},
&vertexData[0].textureCoordinates1, Containers::arraySize(vertexData), sizeof(Vertex))},
Trade::MeshAttributeData{Trade::MeshAttribute::TextureCoordinates, Trade::MeshAttributeData{Trade::MeshAttribute::TextureCoordinates,
Containers::stridedArrayView(vertexData, vertices.slice(&Vertex::textureCoordinates2)},
&vertexData[0].textureCoordinates2, Containers::arraySize(vertexData), sizeof(Vertex))},
}}; }};
GL::Mesh mesh = compile(meshData); GL::Mesh mesh = compile(meshData);
@ -1057,6 +1035,7 @@ void CompileGLTest::packedAttributes() {
}; };
static_assert(sizeof(PackedVertex) % 4 == 0, static_assert(sizeof(PackedVertex) % 4 == 0,
"the vertex is not 4-byte aligned and that's bad"); "the vertex is not 4-byte aligned and that's bad");
auto vertices = Containers::stridedArrayView(vertexData);
const UnsignedByte indexData[]{ const UnsignedByte indexData[]{
0, 1, 4, 0, 4, 3, 0, 1, 4, 0, 4, 3,
@ -1067,31 +1046,21 @@ void CompileGLTest::packedAttributes() {
Trade::MeshData meshData{MeshPrimitive::Triangles, {}, indexData, Trade::MeshData meshData{MeshPrimitive::Triangles, {}, indexData,
Trade::MeshIndexData{indexData}, {}, vertexData, { Trade::MeshIndexData{indexData}, {}, vertexData, {
Trade::MeshAttributeData{ Trade::MeshAttributeData{Trade::MeshAttribute::Position,
Trade::MeshAttribute::Position,
VertexFormat::Vector3sNormalized, VertexFormat::Vector3sNormalized,
Containers::stridedArrayView(vertexData, &vertexData[0].position, vertices.slice(&PackedVertex::position)},
Containers::arraySize(vertexData), sizeof(PackedVertex))}, Trade::MeshAttributeData{Trade::MeshAttribute::Normal,
Trade::MeshAttributeData{
Trade::MeshAttribute::Normal,
VertexFormat::Vector3sNormalized, VertexFormat::Vector3sNormalized,
Containers::stridedArrayView(vertexData, &vertexData[0].normal, vertices.slice(&PackedVertex::normal)},
Containers::arraySize(vertexData), sizeof(PackedVertex))}, Trade::MeshAttributeData{Trade::MeshAttribute::TextureCoordinates,
Trade::MeshAttributeData{
Trade::MeshAttribute::TextureCoordinates,
VertexFormat::Vector2usNormalized, VertexFormat::Vector2usNormalized,
Containers::stridedArrayView(vertexData, &vertexData[0].textureCoordinates, vertices.slice(&PackedVertex::textureCoordinates)},
Containers::arraySize(vertexData), sizeof(PackedVertex))}, Trade::MeshAttributeData{Trade::MeshAttribute::Color,
Trade::MeshAttributeData{
Trade::MeshAttribute::Color,
/* It should figure out the type itself here */ /* It should figure out the type itself here */
Containers::stridedArrayView(vertexData, &vertexData[0].color, vertices.slice(&PackedVertex::color)},
Containers::arraySize(vertexData), sizeof(PackedVertex))},
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
Trade::MeshAttributeData{ Trade::MeshAttributeData{Trade::MeshAttribute::ObjectId,
Trade::MeshAttribute::ObjectId, vertices.slice(&PackedVertex::objectId)}
Containers::stridedArrayView(vertexData, &vertexData[0].objectId,
Containers::arraySize(vertexData), sizeof(PackedVertex))}
#endif #endif
}}; }};

Loading…
Cancel
Save