Browse Source

MeshTools: assert in compile() if non-contiguous index buffers are used.

pull/547/head
Vladimír Vondruš 4 years ago
parent
commit
6527ec35c2
  1. 3
      src/Magnum/MeshTools/Compile.cpp
  2. 3
      src/Magnum/MeshTools/Compile.h
  3. 21
      src/Magnum/MeshTools/Test/CompileGLTest.cpp

3
src/Magnum/MeshTools/Compile.cpp

@ -160,6 +160,9 @@ GL::Mesh compileInternal(const Trade::MeshData& meshData, GL::Buffer&& indices,
}
if(meshData.isIndexed()) {
CORRADE_ASSERT(Short(meshIndexTypeSize(meshData.indexType())) == meshData.indexStride(),
"MeshTools::compile():" << meshData.indexType() << "with stride of" << meshData.indexStride() << "bytes isn't supported by OpenGL", GL::Mesh{});
mesh.setIndexBuffer(std::move(indices), meshData.indexOffset(), meshData.indexType())
.setCount(meshData.indexCount());
} else mesh.setCount(meshData.vertexCount());

3
src/Magnum/MeshTools/Compile.h

@ -120,6 +120,9 @@ possibly also an index buffer, if the mesh is indexed.
- Implementation-specific @ref Magnum::MeshPrimitive values are passed
as-is with @ref meshPrimitiveUnwrap(). It's the user responsibility to
ensure an implementation-specific value is valid in this context.
- The index buffer is expected to be contiguous (size of the index type equal
to @ref Trade::MeshData::indexStride()). OpenGL doesn't support interleaved
index buffers.
- Stride of all attributes is expected to be positive. OpenGL doesn't support
zero and negative strides.

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

@ -104,6 +104,8 @@ struct CompileGLTest: GL::OpenGLTester {
void multipleAttributes();
void packedAttributes();
void unsupportedIndexStride();
void customAttribute();
void unsupportedAttribute();
void unsupportedAttributeStride();
@ -256,6 +258,8 @@ CompileGLTest::CompileGLTest() {
&CompileGLTest::renderSetup,
&CompileGLTest::renderTeardown);
addTests({&CompileGLTest::unsupportedIndexStride});
addInstancedTests({&CompileGLTest::customAttribute,
&CompileGLTest::unsupportedAttribute},
Containers::arraySize(CustomAttributeWarningData));
@ -1153,6 +1157,23 @@ void CompileGLTest::packedAttributes() {
#endif
}
void CompileGLTest::unsupportedIndexStride() {
#ifdef CORRADE_NO_ASSERT
CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions");
#endif
UnsignedShort indices[2]{};
Trade::MeshData data{MeshPrimitive::Points,
{}, indices, Trade::MeshIndexData{Containers::stridedArrayView(indices).every(2)},
1};
std::ostringstream out;
Error redirectError{&out};
compile(data);
CORRADE_COMPARE(out.str(),
"MeshTools::compile(): MeshIndexType::UnsignedShort with stride of 4 bytes isn't supported by OpenGL\n");
}
void CompileGLTest::customAttribute() {
auto&& instanceData = CustomAttributeWarningData[testCaseInstanceId()];
setTestCaseDescription(instanceData.name);

Loading…
Cancel
Save