Browse Source

compile()

Signed-off-by: Squareys <squareys@googlemail.com>
pull/444/head
Squareys 6 years ago
parent
commit
385ecc94b2
  1. 24
      src/Magnum/MeshTools/Compile.cpp
  2. 55
      src/Magnum/MeshTools/Test/CompileGLTest.cpp

24
src/Magnum/MeshTools/Compile.cpp

@ -79,6 +79,8 @@ GL::Mesh compileInternal(const Trade::MeshData& meshData, GL::Buffer&& indices,
continue; continue;
} }
UnsignedInt jointIdsAttributesCount = 0;
UnsignedInt weightsAttributesCount = 0;
switch(meshData.attributeName(i)) { switch(meshData.attributeName(i)) {
case Trade::MeshAttribute::Position: case Trade::MeshAttribute::Position:
/* Pick 3D position always, the format will properly reduce it /* Pick 3D position always, the format will properly reduce it
@ -113,6 +115,28 @@ GL::Mesh compileInternal(const Trade::MeshData& meshData, GL::Buffer&& indices,
attribute.emplace(Shaders::Generic3D::ObjectId{}, format); attribute.emplace(Shaders::Generic3D::ObjectId{}, format);
break; break;
#endif #endif
case Trade::MeshAttribute::Weights:
if(weightsAttributesCount == 0) {
attribute.emplace(Shaders::Generic3D::Weights{}, format);
} else if(weightsAttributesCount == 1) {
attribute.emplace(Shaders::Generic3D::SecondaryWeights{}, format);
} else {
Warning{} << "MeshTools::compile(): ignoring" << meshData.attributeName(i)
<< weightsAttributesCount << ", more than two are unsupported";
}
++weightsAttributesCount;
break;
case Trade::MeshAttribute::JointIds:
if(jointIdsAttributesCount == 0) {
attribute.emplace(Shaders::Generic3D::JointIds{}, format);
} else if(jointIdsAttributesCount == 1) {
attribute.emplace(Shaders::Generic3D::SecondaryJointIds{}, format);
} else {
Warning{} << "MeshTools::compile(): ignoring" << meshData.attributeName(i)
<< jointIdsAttributesCount << ", more than two are unsupported";
}
++jointIdsAttributesCount;
break;
/* To avoid the compiler warning that we didn't handle an enum /* To avoid the compiler warning that we didn't handle an enum
value. For these a runtime warning is printed below. */ value. For these a runtime warning is printed below. */

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

@ -76,7 +76,8 @@ enum class Flag {
GeneratedSmoothNormals = 1 << 6, GeneratedSmoothNormals = 1 << 6,
TextureCoordinates2D = 1 << 7, TextureCoordinates2D = 1 << 7,
Colors = 1 << 8, Colors = 1 << 8,
ObjectId = 1 << 9 ObjectId = 1 << 9,
Skinning = 1 << 10
}; };
typedef Containers::EnumSet<Flag> Flags; typedef Containers::EnumSet<Flag> Flags;
@ -152,7 +153,8 @@ constexpr struct {
{"positions + colors", Flag::Colors}, {"positions + colors", Flag::Colors},
{"positions + texture coordinates", Flag::TextureCoordinates2D}, {"positions + texture coordinates", Flag::TextureCoordinates2D},
{"positions + texture coordinates + colors", Flag::TextureCoordinates2D|Flag::Colors}, {"positions + texture coordinates + colors", Flag::TextureCoordinates2D|Flag::Colors},
{"positions, object id, nonindexed", Flag::ObjectId|Flag::NonIndexed} {"positions, object id, nonindexed", Flag::ObjectId|Flag::NonIndexed},
{"positions + skinning", Flag::Skinning},
}; };
constexpr struct { constexpr struct {
@ -888,6 +890,8 @@ struct PackedVertex {
Vector2us textureCoordinates; Vector2us textureCoordinates;
Color4ub color; Color4ub color;
UnsignedShort objectId; UnsignedShort objectId;
Vector4 weights;
Vector4us jointIds;
UnsignedShort:16; UnsignedShort:16;
}; };
@ -913,43 +917,55 @@ void CompileGLTest::packedAttributes() {
const PackedVertex vertexData[]{ const PackedVertex vertexData[]{
{Math::pack<Vector3s>(Vector3{-0.75f, -0.75f, -0.35f}), {Math::pack<Vector3s>(Vector3{-0.75f, -0.75f, -0.35f}),
Math::pack<Vector3s>(Vector3{-0.5f, -0.5f, 1.0f}.normalized()), Math::pack<Vector3s>(Vector3{-0.5f, -0.5f, 1.0f}.normalized()),
Math::pack<Vector2us>(Vector2{0.0f, 0.0f}), 0x00ff00_rgb, 13562}, Math::pack<Vector2us>(Vector2{0.0f, 0.0f}), 0x00ff00_rgb, 13562,
Vector4{0.4f, 0.3f, 0.2f, 0.1f}, Vector4us{0, 1, 2, 3}},
{Math::pack<Vector3s>(Vector3{ 0.00f, -0.75f, -0.25f}), {Math::pack<Vector3s>(Vector3{ 0.00f, -0.75f, -0.25f}),
Math::pack<Vector3s>(Vector3{ 0.0f, -0.5f, 1.0f}.normalized()), Math::pack<Vector3s>(Vector3{ 0.0f, -0.5f, 1.0f}.normalized()),
Math::pack<Vector2us>(Vector2{0.5f, 0.0f}), 0x808000_rgb, 13562}, Math::pack<Vector2us>(Vector2{0.5f, 0.0f}), 0x808000_rgb, 13562,
Vector4{0.4f, 0.3f, 0.2f, 0.1f}, Vector4us{0, 1, 2, 3}},
{Math::pack<Vector3s>(Vector3{ 0.75f, -0.75f, -0.35f}), {Math::pack<Vector3s>(Vector3{ 0.75f, -0.75f, -0.35f}),
Math::pack<Vector3s>(Vector3{ 0.5f, -0.5f, 1.0f}.normalized()), Math::pack<Vector3s>(Vector3{ 0.5f, -0.5f, 1.0f}.normalized()),
Math::pack<Vector2us>(Vector2{1.0f, 0.0f}), 0xff0000_rgb, 13562}, Math::pack<Vector2us>(Vector2{1.0f, 0.0f}), 0xff0000_rgb, 13562,
Vector4{0.4f, 0.3f, 0.2f, 0.1f}, Vector4us{0, 1, 2, 3}},
{Math::pack<Vector3s>(Vector3{-0.75f, 0.00f, -0.25f}), {Math::pack<Vector3s>(Vector3{-0.75f, 0.00f, -0.25f}),
Math::pack<Vector3s>(Vector3{-0.5f, 0.0f, 1.0f}.normalized()), Math::pack<Vector3s>(Vector3{-0.5f, 0.0f, 1.0f}.normalized()),
Math::pack<Vector2us>(Vector2{0.0f, 0.5f}), 0x00ff80_rgb, 13562}, Math::pack<Vector2us>(Vector2{0.0f, 0.5f}), 0x00ff80_rgb, 13562,
Vector4{0.4f, 0.3f, 0.2f, 0.1f}, Vector4us{0, 1, 2, 3}},
{Math::pack<Vector3s>(Vector3{ 0.00f, 0.00f, 0.00f}), {Math::pack<Vector3s>(Vector3{ 0.00f, 0.00f, 0.00f}),
Math::pack<Vector3s>(Vector3{ 0.0f, 0.0f, 1.0f}.normalized()), Math::pack<Vector3s>(Vector3{ 0.0f, 0.0f, 1.0f}.normalized()),
Math::pack<Vector2us>(Vector2{0.5f, 0.5f}), 0x808080_rgb, 13562}, Math::pack<Vector2us>(Vector2{0.5f, 0.5f}), 0x808080_rgb, 13562,
Vector4{0.4f, 0.3f, 0.2f, 0.1f}, Vector4us{0, 1, 2, 3}},
{Math::pack<Vector3s>(Vector3{ 0.75f, 0.00f, -0.25f}), {Math::pack<Vector3s>(Vector3{ 0.75f, 0.00f, -0.25f}),
Math::pack<Vector3s>(Vector3{ 0.5f, 0.0f, 1.0f}.normalized()), Math::pack<Vector3s>(Vector3{ 0.5f, 0.0f, 1.0f}.normalized()),
Math::pack<Vector2us>(Vector2{1.0f, 0.5f}), 0xff0080_rgb, 13562}, Math::pack<Vector2us>(Vector2{1.0f, 0.5f}), 0xff0080_rgb, 13562,
Vector4{0.4f, 0.3f, 0.2f, 0.1f}, Vector4us{0, 1, 2, 3}},
{Math::pack<Vector3s>(Vector3{-0.75f, 0.00f, -0.25f}), {Math::pack<Vector3s>(Vector3{-0.75f, 0.00f, -0.25f}),
Math::pack<Vector3s>(Vector3{-0.5f, 0.0f, 1.0f}.normalized()), Math::pack<Vector3s>(Vector3{-0.5f, 0.0f, 1.0f}.normalized()),
Math::pack<Vector2us>(Vector2{0.0f, 0.5f}), 0x00ff80_rgb, 26234}, Math::pack<Vector2us>(Vector2{0.0f, 0.5f}), 0x00ff80_rgb, 26234,
Vector4{0.4f, 0.3f, 0.2f, 0.1f}, Vector4us{0, 1, 2, 3}},
{Math::pack<Vector3s>(Vector3{ 0.00f, 0.00f, 0.00f}), {Math::pack<Vector3s>(Vector3{ 0.00f, 0.00f, 0.00f}),
Math::pack<Vector3s>(Vector3{ 0.0f, 0.0f, 1.0f}.normalized()), Math::pack<Vector3s>(Vector3{ 0.0f, 0.0f, 1.0f}.normalized()),
Math::pack<Vector2us>(Vector2{0.5f, 0.5f}), 0x808080_rgb, 26234}, Math::pack<Vector2us>(Vector2{0.5f, 0.5f}), 0x808080_rgb, 26234,
Vector4{0.4f, 0.3f, 0.2f, 0.1f}, Vector4us{0, 1, 2, 3}},
{Math::pack<Vector3s>(Vector3{ 0.75f, 0.00f, -0.25f}), {Math::pack<Vector3s>(Vector3{ 0.75f, 0.00f, -0.25f}),
Math::pack<Vector3s>(Vector3{ 0.5f, 0.0f, 1.0f}.normalized()), Math::pack<Vector3s>(Vector3{ 0.5f, 0.0f, 1.0f}.normalized()),
Math::pack<Vector2us>(Vector2{1.0f, 0.5f}), 0xff0080_rgb, 26234}, Math::pack<Vector2us>(Vector2{1.0f, 0.5f}), 0xff0080_rgb, 26234,
Vector4{0.4f, 0.3f, 0.2f, 0.1f}, Vector4us{0, 1, 2, 3}},
{Math::pack<Vector3s>(Vector3{-0.75f, 0.75f, -0.35f}), {Math::pack<Vector3s>(Vector3{-0.75f, 0.75f, -0.35f}),
Math::pack<Vector3s>(Vector3{-0.5f, 0.5f, 1.0f}.normalized()), Math::pack<Vector3s>(Vector3{-0.5f, 0.5f, 1.0f}.normalized()),
Math::pack<Vector2us>(Vector2{0.0f, 1.0f}), 0x00ffff_rgb, 26234}, Math::pack<Vector2us>(Vector2{0.0f, 1.0f}), 0x00ffff_rgb, 26234,
Vector4{0.4f, 0.3f, 0.2f, 0.1f}, Vector4us{0, 1, 2, 3}},
{Math::pack<Vector3s>(Vector3{ 0.0f, 0.75f, -0.25f}), {Math::pack<Vector3s>(Vector3{ 0.0f, 0.75f, -0.25f}),
Math::pack<Vector3s>(Vector3{ 0.0f, 0.5f, 1.0f}.normalized()), Math::pack<Vector3s>(Vector3{ 0.0f, 0.5f, 1.0f}.normalized()),
Math::pack<Vector2us>(Vector2{0.5f, 1.0f}), 0x8080ff_rgb, 26234}, Math::pack<Vector2us>(Vector2{0.5f, 1.0f}), 0x8080ff_rgb, 26234,
Vector4{0.4f, 0.3f, 0.2f, 0.1f}, Vector4us{0, 1, 2, 3}},
{Math::pack<Vector3s>(Vector3{ 0.75f, 0.75f, -0.35f}), {Math::pack<Vector3s>(Vector3{ 0.75f, 0.75f, -0.35f}),
Math::pack<Vector3s>(Vector3{ 0.5f, 0.5f, 1.0f}.normalized()), Math::pack<Vector3s>(Vector3{ 0.5f, 0.5f, 1.0f}.normalized()),
Math::pack<Vector2us>(Vector2{1.0f, 1.0f}), 0xff00ff_rgb, 26234} Math::pack<Vector2us>(Vector2{1.0f, 1.0f}), 0xff00ff_rgb, 26234,
Vector4{0.4f, 0.3f, 0.2f, 0.1f}, Vector4us{0, 1, 2, 3}},
}; };
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");
@ -987,8 +1003,16 @@ void CompileGLTest::packedAttributes() {
Trade::MeshAttributeData{ Trade::MeshAttributeData{
Trade::MeshAttribute::ObjectId, Trade::MeshAttribute::ObjectId,
Containers::stridedArrayView(vertexData, &vertexData[0].objectId, Containers::stridedArrayView(vertexData, &vertexData[0].objectId,
Containers::arraySize(vertexData), sizeof(PackedVertex))} Containers::arraySize(vertexData), sizeof(PackedVertex))},
#endif #endif
Trade::MeshAttributeData{
Trade::MeshAttribute::Weights,
Containers::stridedArrayView(vertexData, &vertexData[0].weights,
Containers::arraySize(vertexData), sizeof(PackedVertex))},
Trade::MeshAttributeData{
Trade::MeshAttribute::JointIds,
Containers::stridedArrayView(vertexData, &vertexData[0].jointIds,
Containers::arraySize(vertexData), sizeof(PackedVertex))}
}}; }};
GL::Mesh mesh = compile(meshData); GL::Mesh mesh = compile(meshData);
@ -1012,6 +1036,7 @@ void CompileGLTest::packedAttributes() {
.setTransformationMatrix(transformation) .setTransformationMatrix(transformation)
.setNormalMatrix(transformation.normalMatrix()) .setNormalMatrix(transformation.normalMatrix())
.setProjectionMatrix(projection) .setProjectionMatrix(projection)
.setJointMatrices({Matrix4{}, Matrix4{}, Matrix4{}, Matrix4{}})
.draw(mesh); .draw(mesh);
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE_WITH( CORRADE_COMPARE_WITH(

Loading…
Cancel
Save