diff --git a/src/Magnum/MeshTools/Compile.cpp b/src/Magnum/MeshTools/Compile.cpp index 74b434449..fa7938fa3 100644 --- a/src/Magnum/MeshTools/Compile.cpp +++ b/src/Magnum/MeshTools/Compile.cpp @@ -140,7 +140,16 @@ GL::Mesh compile(const Trade::MeshData& meshData, GL::Buffer&& indices, GL::Buff GL::Buffer verticesRef = GL::Buffer::wrap(vertices.id(), GL::Buffer::TargetHint::Array); for(UnsignedInt i = 0; i != meshData.attributeCount(); ++i) { Containers::Optional attribute; + + /* Ignore implementation-specific formats because GL needs three + separate values to describe them so there's no way to put them in a + single 32-bit value :( */ const VertexFormat format = meshData.attributeFormat(i); + if(isVertexFormatImplementationSpecific(format)) { + Warning{} << "MeshTools::compile(): ignoring attribute" << meshData.attributeName(i) << "with an implementation-specific format" << reinterpret_cast(vertexFormatUnwrap(format)); + continue; + } + switch(meshData.attributeName(i)) { case Trade::MeshAttribute::Position: /* Pick 3D position always, the type will properly reduce it to diff --git a/src/Magnum/MeshTools/Compile.h b/src/Magnum/MeshTools/Compile.h index 58e2a1fad..335349586 100644 --- a/src/Magnum/MeshTools/Compile.h +++ b/src/Magnum/MeshTools/Compile.h @@ -103,6 +103,9 @@ possibly also an index buffer, if the mesh is indexed. - If the mesh contains colors, these are bound to @ref Shaders::Generic::Color3 / @ref Shaders::Generic::Color4 based on their type. +- Custom attributes and known attributes of implementation-specific types + are ignored with a warning. See the @ref compile(const Trade::MeshData&, GL::Buffer&, GL::Buffer&) + for an example showing how to bind them manually. If normal generation is not requested, @ref Trade::MeshData::indexData() and @ref Trade::MeshData::vertexData() are uploaded as-is without any further diff --git a/src/Magnum/MeshTools/Test/CompileGLTest.cpp b/src/Magnum/MeshTools/Test/CompileGLTest.cpp index fa80cb067..7debc5f29 100644 --- a/src/Magnum/MeshTools/Test/CompileGLTest.cpp +++ b/src/Magnum/MeshTools/Test/CompileGLTest.cpp @@ -94,6 +94,7 @@ struct CompileGLTest: GL::OpenGLTester { void packedAttributes(); void unknownAttribute(); + void implementationSpecificAttributeFormat(); void generateNormalsNoPosition(); void generateNormals2DPosition(); void generateNormalsNoFloats(); @@ -205,6 +206,7 @@ CompileGLTest::CompileGLTest() { addTests({&CompileGLTest::packedAttributes, &CompileGLTest::unknownAttribute, + &CompileGLTest::implementationSpecificAttributeFormat, &CompileGLTest::generateNormalsNoPosition, &CompileGLTest::generateNormals2DPosition, &CompileGLTest::generateNormalsNoFloats}); @@ -724,6 +726,18 @@ void CompileGLTest::unknownAttribute() { "MeshTools::compile(): ignoring unknown attribute Trade::MeshAttribute::Custom(115)\n"); } +void CompileGLTest::implementationSpecificAttributeFormat() { + Trade::MeshData data{MeshPrimitive::Triangles, + nullptr, {Trade::MeshAttributeData{Trade::MeshAttribute::Position, + vertexFormatWrap(0xdead), nullptr}}}; + + std::ostringstream out; + Warning redirectError{&out}; + MeshTools::compile(data); + CORRADE_COMPARE(out.str(), + "MeshTools::compile(): ignoring attribute Trade::MeshAttribute::Position with an implementation-specific format 0xdead\n"); +} + void CompileGLTest::generateNormalsNoPosition() { Trade::MeshData data{MeshPrimitive::Triangles, 1};