From 344dd3fc17e732c717e639f075f415c7260e855b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 21 Jan 2022 09:34:30 +0100 Subject: [PATCH] MeshTools: fix compile() with a non-trivial index offset. Haha, what the heck, how did nobody hit this yet. --- doc/changelog.dox | 2 ++ src/Magnum/MeshTools/Compile.cpp | 2 +- src/Magnum/MeshTools/Test/CompileGLTest.cpp | 6 ++++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/doc/changelog.dox b/doc/changelog.dox index b4b22f3fe..9de79b7be 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -530,6 +530,8 @@ See also: - Fixed an assertion when using @ref MeshTools::removeDuplicates() on an interleaved @ref Trade::MeshData that included padding at the beginning or end of each vertex +- Fixed @ref MeshTools::compile() to properly take into account index buffer + offsets - Fixed @ref MeshTools::removeDuplicates() to not take into account random padding bytes and filtered-out attributes in interleaved source @ref Trade::MeshData. This was a particularly glaring issue when using diff --git a/src/Magnum/MeshTools/Compile.cpp b/src/Magnum/MeshTools/Compile.cpp index 7dec471a3..b6cc272fa 100644 --- a/src/Magnum/MeshTools/Compile.cpp +++ b/src/Magnum/MeshTools/Compile.cpp @@ -154,7 +154,7 @@ GL::Mesh compileInternal(const Trade::MeshData& meshData, GL::Buffer&& indices, } if(meshData.isIndexed()) { - mesh.setIndexBuffer(std::move(indices), 0, meshData.indexType()) + mesh.setIndexBuffer(std::move(indices), meshData.indexOffset(), meshData.indexType()) .setCount(meshData.indexCount()); } else mesh.setCount(meshData.vertexCount()); diff --git a/src/Magnum/MeshTools/Test/CompileGLTest.cpp b/src/Magnum/MeshTools/Test/CompileGLTest.cpp index c5838c51c..2c8e04de4 100644 --- a/src/Magnum/MeshTools/Test/CompileGLTest.cpp +++ b/src/Magnum/MeshTools/Test/CompileGLTest.cpp @@ -445,6 +445,7 @@ template void CompileGLTest::twoDimensions() { Containers::arraySize(vertexData), sizeof(Vertex))}); const UnsignedInt indexData[]{ + 66, 78, 23, /* offset */ 0, 1, 4, 0, 4, 3, 1, 2, 5, 1, 5, 4, 3, 4, 7, 3, 7, 6, @@ -452,7 +453,7 @@ template void CompileGLTest::twoDimensions() { }; Trade::MeshData meshData{MeshPrimitive::Triangles, - {}, indexData, Trade::MeshIndexData{indexData}, + {}, indexData, Trade::MeshIndexData{Containers::arrayView(indexData).suffix(3)}, {}, vertexData, std::move(attributeData)}; /* Duplicate everything if data is non-indexed */ @@ -672,6 +673,7 @@ template void CompileGLTest::threeDimensions() { Containers::arraySize(vertexData), sizeof(Vertex))}); const UnsignedByte indexData[]{ + 66, 78, 23, /* offset */ 0, 1, 4, 0, 4, 3, 1, 2, 5, 1, 5, 4, 3, 4, 7, 3, 7, 6, @@ -679,7 +681,7 @@ template void CompileGLTest::threeDimensions() { }; Trade::MeshData meshData{MeshPrimitive::Triangles, - {}, indexData, Trade::MeshIndexData{indexData}, + {}, indexData, Trade::MeshIndexData{Containers::arrayView(indexData).suffix(3)}, {}, vertexData, std::move(attributeData)}; /* Duplicate everything if data is non-indexed */