Browse Source

MeshTools: explicitly handle unavailable attribute types in compile().

pull/371/head
Vladimír Vondruš 6 years ago
parent
commit
a3bb6ba4c5
  1. 9
      src/Magnum/MeshTools/Compile.cpp
  2. 3
      src/Magnum/MeshTools/Compile.h
  3. 14
      src/Magnum/MeshTools/Test/CompileGLTest.cpp

9
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); GL::Buffer verticesRef = GL::Buffer::wrap(vertices.id(), GL::Buffer::TargetHint::Array);
for(UnsignedInt i = 0; i != meshData.attributeCount(); ++i) { for(UnsignedInt i = 0; i != meshData.attributeCount(); ++i) {
Containers::Optional<GL::DynamicAttribute> attribute; Containers::Optional<GL::DynamicAttribute> 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); const VertexFormat format = meshData.attributeFormat(i);
if(isVertexFormatImplementationSpecific(format)) {
Warning{} << "MeshTools::compile(): ignoring attribute" << meshData.attributeName(i) << "with an implementation-specific format" << reinterpret_cast<void*>(vertexFormatUnwrap(format));
continue;
}
switch(meshData.attributeName(i)) { switch(meshData.attributeName(i)) {
case Trade::MeshAttribute::Position: case Trade::MeshAttribute::Position:
/* Pick 3D position always, the type will properly reduce it to /* Pick 3D position always, the type will properly reduce it to

3
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 - If the mesh contains colors, these are bound to
@ref Shaders::Generic::Color3 / @ref Shaders::Generic::Color4 based on @ref Shaders::Generic::Color3 / @ref Shaders::Generic::Color4 based on
their type. 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 If normal generation is not requested, @ref Trade::MeshData::indexData() and
@ref Trade::MeshData::vertexData() are uploaded as-is without any further @ref Trade::MeshData::vertexData() are uploaded as-is without any further

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

@ -94,6 +94,7 @@ struct CompileGLTest: GL::OpenGLTester {
void packedAttributes(); void packedAttributes();
void unknownAttribute(); void unknownAttribute();
void implementationSpecificAttributeFormat();
void generateNormalsNoPosition(); void generateNormalsNoPosition();
void generateNormals2DPosition(); void generateNormals2DPosition();
void generateNormalsNoFloats(); void generateNormalsNoFloats();
@ -205,6 +206,7 @@ CompileGLTest::CompileGLTest() {
addTests({&CompileGLTest::packedAttributes, addTests({&CompileGLTest::packedAttributes,
&CompileGLTest::unknownAttribute, &CompileGLTest::unknownAttribute,
&CompileGLTest::implementationSpecificAttributeFormat,
&CompileGLTest::generateNormalsNoPosition, &CompileGLTest::generateNormalsNoPosition,
&CompileGLTest::generateNormals2DPosition, &CompileGLTest::generateNormals2DPosition,
&CompileGLTest::generateNormalsNoFloats}); &CompileGLTest::generateNormalsNoFloats});
@ -724,6 +726,18 @@ void CompileGLTest::unknownAttribute() {
"MeshTools::compile(): ignoring unknown attribute Trade::MeshAttribute::Custom(115)\n"); "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() { void CompileGLTest::generateNormalsNoPosition() {
Trade::MeshData data{MeshPrimitive::Triangles, 1}; Trade::MeshData data{MeshPrimitive::Triangles, 1};

Loading…
Cancel
Save