diff options
author | Tarja Sundqvist <tarja.sundqvist@qt.io> | 2023-03-23 16:00:07 +0200 |
---|---|---|
committer | Tarja Sundqvist <tarja.sundqvist@qt.io> | 2023-03-23 16:00:07 +0200 |
commit | 19ed7973a311a8d42d3a558bb551230e902ce9b9 (patch) | |
tree | 9832c0cc796722f85579e25fd50cc38b65e6ef6c /src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp | |
parent | f5701f0def37fcc0c2b38ae9552eb3a896a34687 (diff) | |
parent | a5635345175e667601c8b6a344508c4d4ebb0f9d (diff) |
Merge remote-tracking branch 'origin/tqtc/lts-5.15.9' into tqtc/lts-5.15-opensourcev5.15.9-lts-lgpl
Change-Id: I91d2b178e7111d0802ea973bccf230b264c30c96
Diffstat (limited to 'src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp')
-rw-r--r-- | src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp index 77bac7c8a5..ea1a1a9b93 100644 --- a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp +++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp @@ -2215,6 +2215,15 @@ void Renderer::uploadBatch(Batch *b) */ int bufferSize = b->vertexCount * g->sizeOfVertex(); int ibufferSize = 0; + // At this point, we need to check if the vertices byte size is 4 byte aligned or not. + // If an unaligned value is used in a shared buffer with indices, it causes problems with + // glDrawElements. We need to do a 4 byte alignment so that it can work with both + // QSGGeometry::UnsignedShortType and QSGGeometry::UnsignedIntType + int paddingBytes = 0; + if (!m_context->separateIndexBuffer()) { + paddingBytes = aligned(bufferSize, 4) - bufferSize; + bufferSize += paddingBytes; + } if (b->merged) { ibufferSize = b->indexCount * mergedIndexElemSize(); if (m_useDepthBuffer) @@ -2239,7 +2248,7 @@ void Renderer::uploadBatch(Batch *b) char *zData = vertexData + b->vertexCount * g->sizeOfVertex(); char *indexData = separateIndexBuffer ? b->ibo.data - : zData + (int(m_useDepthBuffer) * b->vertexCount * sizeof(float)); + : zData + (int(m_useDepthBuffer) * b->vertexCount * sizeof(float)) + paddingBytes; quint16 iOffset16 = 0; quint32 iOffset32 = 0; @@ -2287,7 +2296,7 @@ void Renderer::uploadBatch(Batch *b) } else { char *vboData = b->vbo.data; char *iboData = separateIndexBuffer ? b->ibo.data - : vboData + b->vertexCount * g->sizeOfVertex(); + : vboData + b->vertexCount * g->sizeOfVertex() + paddingBytes; Element *e = b->first; while (e) { QSGGeometry *g = e->node->geometry(); @@ -3176,8 +3185,14 @@ void Renderer::renderUnmergedBatch(const Batch *batch) // legacy (GL-only) int vOffset = 0; char *iOffset = indexBase; + // If a shared buffer is used, 4 byte alignment was done to avoid issues + // while using glDrawElements with both QSGGeometry::UnsignedShortType and + // QSGGeometry::UnsignedIntType. Here, we need to take this into account + // while calculating iOffset value to end up with the correct offset for drawing. + int vertexDataByteSize = batch->vertexCount * gn->geometry()->sizeOfVertex(); + vertexDataByteSize = aligned(vertexDataByteSize, 4); if (!separateIndexBuffer) - iOffset += batch->vertexCount * gn->geometry()->sizeOfVertex(); + iOffset += vertexDataByteSize; QMatrix4x4 rootMatrix = batch->root ? qsg_matrixForRoot(batch->root) : QMatrix4x4(); |