From 392329b44a50eb3baf1a0be181e831648f570098 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 12 Jan 2015 13:54:45 +0100 Subject: Drop trailing vertices in GL_LINES and GL_TRIANGLES drawing modes. This results in more correct behavior if you create nodes with a number of vertices that doesn't match the drawing mode. Change-Id: Ic0f59a4019a6b4087b527b7c9b38c35a9e02ece8 Reviewed-by: Gunnar Sletta --- src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp | 35 ++++++++++++++++++----- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'src/quick/scenegraph/coreapi') diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp index fd9b2a4480..375ffac60b 100644 --- a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp +++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp @@ -1642,6 +1642,26 @@ void Renderer::prepareAlphaBatches() } +static inline int qsg_fixIndexCount(int iCount, GLenum drawMode) { + switch (drawMode) { + case GL_TRIANGLE_STRIP: + // Merged triangle strips need to contain degenerate triangles at the beginning and end. + // One could save 2 uploaded ushorts here by ditching the padding for the front of the + // first and the end of the last, but for simplicity, we simply don't care. + // Those extra triangles will be skipped while drawing to preserve the strip's parity + // anyhow. + return iCount + 2; + case GL_LINES: + // For lines we drop the last vertex if the number of vertices is uneven. + return iCount - (iCount % 2); + case GL_TRIANGLES: + // For triangles we drop trailing vertices until the result is divisible by 3. + return iCount - (iCount % 3); + default: + return iCount; + } +} + /* These parameters warrant some explanation... * * vaOffset: The byte offset into the vertex data to the location of the @@ -1695,15 +1715,21 @@ void Renderer::uploadMergedElement(Element *e, int vaOffset, char **vertexData, quint16 *indices = (quint16 *) *indexData; if (iCount == 0) { + iCount = vCount; if (g->drawingMode() == GL_TRIANGLE_STRIP) *indices++ = *iBase; - iCount = vCount; + else + iCount = qsg_fixIndexCount(iCount, g->drawingMode()); + for (int i=0; iindexDataAsUShort(); if (g->drawingMode() == GL_TRIANGLE_STRIP) *indices++ = *iBase + srcIndices[0]; + else + iCount = qsg_fixIndexCount(iCount, g->drawingMode()); + for (int i=0; imerged) { if (iCount == 0) iCount = eg->vertexCount(); - // Merged triangle strips need to contain degenerate triangles at the beginning and end. - // One could save 2 uploaded ushorts here by ditching the padding for the front of the - // first and the end of the last, but for simplicity, we simply don't care. - // Those extra triangles will be skipped while drawing to preserve the strip's parity anyhow. - if (g->drawingMode() == GL_TRIANGLE_STRIP) - iCount += 2; + iCount = qsg_fixIndexCount(iCount, g->drawingMode()); } else { unmergedIndexSize += iCount * eg->sizeOfIndex(); } -- cgit v1.2.3