Skip to content

Commit

Permalink
MeshTools: use only the first set of vertex attribs in compile().
Browse files Browse the repository at this point in the history
  • Loading branch information
mosra committed Jul 24, 2020
1 parent af0ab0d commit c357a44
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/changelog.dox
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ See also:
destroyed could fail with an error saying "cannot make the previous context
current" on certain system. This was due to EGL not destroying the context
if it's still made current.
- For meshes with multiple sets of vertex attributes (such as texture
coordinates), @ref MeshTools::compile() should be using only the first set
but it wasn't.

@subsection changelog-latest-compatibility Potential compatibility breakages, removed APIs

Expand Down
13 changes: 13 additions & 0 deletions src/Magnum/MeshTools/Compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ GL::Mesh compileInternal(const Trade::MeshData& meshData, GL::Buffer&& indices,

/* Vertex data */
GL::Buffer verticesRef = GL::Buffer::wrap(vertices.id(), GL::Buffer::TargetHint::Array);

/* Ensure each known attribute gets bound only once. There's 16 generic
attribs at most. */
Math::BoolVector<16> boundAttributes;

for(UnsignedInt i = 0; i != meshData.attributeCount(); ++i) {
Containers::Optional<GL::DynamicAttribute> attribute;

Expand Down Expand Up @@ -131,6 +136,14 @@ GL::Mesh compileInternal(const Trade::MeshData& meshData, GL::Buffer&& indices,
continue;
}

/* Ensure each attribute gets bound only once -- so for example when
there are two texture coordinate sets, we don't bind them both to
the same slot, effectively ignoring the first one */
/** @todo revisit when there are secondary generic texture coordinates */
if(boundAttributes[attribute->location()])
continue;
boundAttributes.set(attribute->location(), true);

/* For the first attribute move the buffer in, for all others use the
reference */
if(vertices.id()) mesh.addVertexBuffer(std::move(vertices),
Expand Down

0 comments on commit c357a44

Please sign in to comment.