aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/scenegraph/coreapi
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@theqtcompany.com>2015-01-12 13:54:45 +0100
committerUlf Hermann <ulf.hermann@theqtcompany.com>2015-01-16 16:12:54 +0100
commit392329b44a50eb3baf1a0be181e831648f570098 (patch)
tree271dd412981da78f92f52cddeb590ae50f6b3827 /src/quick/scenegraph/coreapi
parentb0afb913e6e3440a61c2a692b1d15ee017fb3c40 (diff)
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 <gunnar@sletta.org>
Diffstat (limited to 'src/quick/scenegraph/coreapi')
-rw-r--r--src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp35
1 files changed, 28 insertions, 7 deletions
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; i<iCount; ++i)
indices[i] = *iBase + i;
} else {
const quint16 *srcIndices = g->indexDataAsUShort();
if (g->drawingMode() == GL_TRIANGLE_STRIP)
*indices++ = *iBase + srcIndices[0];
+ else
+ iCount = qsg_fixIndexCount(iCount, g->drawingMode());
+
for (int i=0; i<iCount; ++i)
indices[i] = *iBase + srcIndices[i];
}
@@ -1775,12 +1801,7 @@ void Renderer::uploadBatch(Batch *b)
if (b->merged) {
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();
}