1
0
Fork 0

Fix support for Uint32 indices.

This commit is contained in:
James Turner 2017-02-18 08:14:50 -08:00
parent 905d8ae734
commit 66543f1588

View file

@ -75,12 +75,20 @@ public:
QTransform transform; QTransform transform;
QTriangleSet triangles = qTriangulate(m_path, transform); QTriangleSet triangles = qTriangulate(m_path, transform);
// TODO, handle > 2^16 indices int indexType = QSGGeometry::UnsignedShortType;
Q_ASSERT(triangles.indices.type() == QVertexIndexVector::UnsignedShort); if (triangles.indices.type() == QVertexIndexVector::UnsignedShort) {
// default is fine
} else if (triangles.indices.type() == QVertexIndexVector::UnsignedInt) {
indexType = QSGGeometry::UnsignedIntType;
} else {
qFatal("Unsupported triangle index type");
}
QSGGeometry* sgGeom = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), QSGGeometry* sgGeom = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(),
triangles.vertices.size() >> 1, triangles.vertices.size() >> 1,
triangles.indices.size()); triangles.indices.size(),
indexType);
sgGeom->setIndexDataPattern(QSGGeometry::StaticPattern); sgGeom->setIndexDataPattern(QSGGeometry::StaticPattern);
sgGeom->setDrawingMode(GL_TRIANGLES); sgGeom->setDrawingMode(GL_TRIANGLES);
@ -92,8 +100,13 @@ public:
(points++)->set(vx, vy); (points++)->set(vx, vy);
} }
if (triangles.indices.type() == QVertexIndexVector::UnsignedShort) {
quint16* indices = sgGeom->indexDataAsUShort(); quint16* indices = sgGeom->indexDataAsUShort();
::memcpy(indices, triangles.indices.data(), sizeof(unsigned short) * triangles.indices.size()); ::memcpy(indices, triangles.indices.data(), sizeof(unsigned short) * triangles.indices.size());
} else {
quint32* indices = sgGeom->indexDataAsUInt();
::memcpy(indices, triangles.indices.data(), sizeof(quint32) * triangles.indices.size());
}
// create the node now, pretty trivial // create the node now, pretty trivial
fillGeom = new QSGGeometryNode; fillGeom = new QSGGeometryNode;