diff options
author | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2015-01-05 18:14:56 +0100 |
---|---|---|
committer | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2015-01-06 18:26:21 +0100 |
commit | a83246146854166a54ee1f9bd4f8911d6bd49602 (patch) | |
tree | 0be3a5b584ad622cb40fb04a6c4983b22128b5b7 /src/quick | |
parent | a371bac3fba73f92aaa63a68d8ab1ae81a1d1031 (diff) |
Fix the vertex ordering of merged triangle strips
Culling and gl_FrontFacing depend on the vertex order matching the
value set through glFrontFace. To match the default counter-clockwise
order we need to preserve the parity of triangles relatively to the
start of the indices argument of glDrawElements, but we break this
parity because of the degenerate triangles between merged strips.
Fix the issue by skipping the first degenerate triangle, the parity
of following strips will be preserved since they are then separated
by two triangles.
This fixes a regression of
tests/manual/scenegraph_lancelot/data/shaders/culling/culling_1.qml
triggered by 38cab579a0c5398b7621221fd8609bc43cf1f3c5.
Change-Id: Iefa7eaab68112d31be9d8646bd288eb000528cd5
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
Diffstat (limited to 'src/quick')
-rw-r--r-- | src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp index a008552580..5d985187a4 100644 --- a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp +++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp @@ -1775,11 +1775,12 @@ 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 ushorts here by ditching the padding for the front of the + // 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 += sizeof(quint16); + iCount += 2; } else { unmergedIndexSize += iCount * eg->sizeOfIndex(); } @@ -1849,6 +1850,10 @@ void Renderer::uploadBatch(Batch *b) verticesInSet += e->node->geometry()->vertexCount(); if (verticesInSet > 0xffff) { b->drawSets.last().indexCount = indicesInSet; + if (g->drawingMode() == GL_TRIANGLE_STRIP) { + b->drawSets.last().indices += 1 * sizeof(quint16); + b->drawSets.last().indexCount -= 2; + } #ifdef QSG_SEPARATE_INDEX_BUFFER drawSetIndices = indexData - b->ibo.data; #else @@ -1865,6 +1870,12 @@ void Renderer::uploadBatch(Batch *b) e = e->nextInBatch; } b->drawSets.last().indexCount = indicesInSet; + // We skip the very first and very last degenerate triangles since they aren't needed + // and the first one would reverse the vertex ordering of the merged strips. + if (g->drawingMode() == GL_TRIANGLE_STRIP) { + b->drawSets.last().indices += 1 * sizeof(quint16); + b->drawSets.last().indexCount -= 2; + } } else { char *vboData = b->vbo.data; #ifdef QSG_SEPARATE_INDEX_BUFFER |