aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaszlo Agocs <lagocs83@gmail.com>2025-06-23 10:00:37 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2025-06-26 17:21:52 +0000
commit3efd8c0333e991c3b0e82cdd4bc51f43b3163592 (patch)
tree66a44bb3fbaa80e178c8b53f97862a90628a54ff
parent2c4f2c9e975b3c3594eb6a47998efdf2f8928442 (diff)
Allow triangle fan in QSGGeometry when the underlying API supports it
Will not work with D3D and Metal. With those we will continue to reject QSGGeometries having a drawing mode of DrawTrangineFan with a warning. Relevant mainly for OpenGL and applications ported from Qt 5. For a cross-platform, portable solution they would need to move away from triangle fans, but in the meantime, if the intent is to function just with OpenGL on Qt 6, it is good for compatibility if we enable this. Change-Id: Iaa9376234ef854557458e5b6020e39c60666ad91 Reviewed-by: Andy Nichols <andy.nichols@qt.io> (cherry picked from commit 630e6db35d390b277d91f9cc7d392c8f50aef6c8) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit 66ec7e688e67b8fb5879f56465bf8d5f4391318e) (cherry picked from commit 27369d89c42cb1661ae104721d0048f6fbe2b82b)
-rw-r--r--src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp22
-rw-r--r--src/quick/scenegraph/coreapi/qsgrhivisualizer.cpp16
2 files changed, 26 insertions, 12 deletions
diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp
index d776f705e4..591d5d4df0 100644
--- a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp
+++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp
@@ -174,7 +174,7 @@ QRhiCommandBuffer::IndexFormat qsg_indexFormat(const QSGGeometry *geometry)
}
}
-QRhiGraphicsPipeline::Topology qsg_topology(int geomDrawMode)
+QRhiGraphicsPipeline::Topology qsg_topology(int geomDrawMode, QRhi *rhi)
{
QRhiGraphicsPipeline::Topology topology = QRhiGraphicsPipeline::Triangles;
switch (geomDrawMode) {
@@ -193,6 +193,20 @@ QRhiGraphicsPipeline::Topology qsg_topology(int geomDrawMode)
case QSGGeometry::DrawTriangleStrip:
topology = QRhiGraphicsPipeline::TriangleStrip;
break;
+ case QSGGeometry::DrawTriangleFan:
+ {
+ static bool triangleFanSupported = false;
+ static bool triangleFanSupportChecked = false;
+ if (!triangleFanSupportChecked) {
+ triangleFanSupportChecked = true;
+ triangleFanSupported = rhi->isFeatureSupported(QRhi::TriangleFanTopology);
+ }
+ if (triangleFanSupported) {
+ topology = QRhiGraphicsPipeline::TriangleFan;
+ break;
+ }
+ Q_FALLTHROUGH();
+ }
default:
qWarning("Primitive topology 0x%x not supported", geomDrawMode);
break;
@@ -2544,11 +2558,11 @@ void Renderer::updateClipState(const QSGClipNode *clipList, Batch *batch)
if (firstStencilClipInBatch) {
m_stencilClipCommon.inputLayout.setBindings({ QRhiVertexInputBinding(g->sizeOfVertex()) });
m_stencilClipCommon.inputLayout.setAttributes({ QRhiVertexInputAttribute(0, 0, qsg_vertexInputFormat(*a), 0) });
- m_stencilClipCommon.topology = qsg_topology(g->drawingMode());
+ m_stencilClipCommon.topology = qsg_topology(g->drawingMode(), m_rhi);
}
#ifndef QT_NO_DEBUG
else {
- if (qsg_topology(g->drawingMode()) != m_stencilClipCommon.topology)
+ if (qsg_topology(g->drawingMode(), m_rhi) != m_stencilClipCommon.topology)
qWarning("updateClipState: Clip list entries have different primitive topologies, this is not currently supported.");
if (qsg_vertexInputFormat(*a) != m_stencilClipCommon.inputLayout.cbeginAttributes()->format())
qWarning("updateClipState: Clip list entries have different vertex input layouts, this is must not happen.");
@@ -2740,7 +2754,7 @@ bool Renderer::ensurePipelineState(Element *e, const ShaderManager::Shader *sms,
flags |= QRhiGraphicsPipeline::UsesStencilRef;
ps->setFlags(flags);
- ps->setTopology(qsg_topology(m_gstate.drawMode));
+ ps->setTopology(qsg_topology(m_gstate.drawMode, m_rhi));
ps->setCullMode(m_gstate.cullMode);
ps->setPolygonMode(m_gstate.polygonMode);
ps->setMultiViewCount(m_gstate.multiViewCount);
diff --git a/src/quick/scenegraph/coreapi/qsgrhivisualizer.cpp b/src/quick/scenegraph/coreapi/qsgrhivisualizer.cpp
index d1f4e46ed0..a60d3a1984 100644
--- a/src/quick/scenegraph/coreapi/qsgrhivisualizer.cpp
+++ b/src/quick/scenegraph/coreapi/qsgrhivisualizer.cpp
@@ -22,7 +22,7 @@ namespace QSGBatchRenderer
QMatrix4x4 qsg_matrixForRoot(Node *node);
QRhiVertexInputAttribute::Format qsg_vertexInputFormat(const QSGGeometry::Attribute &a);
QRhiCommandBuffer::IndexFormat qsg_indexFormat(const QSGGeometry *geometry);
-QRhiGraphicsPipeline::Topology qsg_topology(int geomDrawMode);
+QRhiGraphicsPipeline::Topology qsg_topology(int geomDrawMode, QRhi *rhi);
RhiVisualizer::RhiVisualizer(Renderer *renderer)
: Visualizer(renderer)
@@ -231,9 +231,9 @@ void RhiVisualizer::Fade::render(QRhiCommandBuffer *cb)
cb->draw(4);
}
-static void fillVertexIndex(RhiVisualizer::DrawCall *dc, QSGGeometry *g, bool withData, bool forceUintIndex)
+static void fillVertexIndex(RhiVisualizer::DrawCall *dc, QSGGeometry *g, bool withData, bool forceUintIndex, QRhi *rhi)
{
- dc->vertex.topology = qsg_topology(g->drawingMode());
+ dc->vertex.topology = qsg_topology(g->drawingMode(), rhi);
dc->vertex.format = qsg_vertexInputFormat(g->attributes()[0]);
dc->vertex.count = g->vertexCount();
dc->vertex.stride = g->sizeOfVertex();
@@ -355,7 +355,7 @@ void RhiVisualizer::ChangeVis::gather(Node *n)
qint32 projection = 0;
memcpy(dc.uniforms.data + 148, &projection, 4);
- fillVertexIndex(&dc, g, true, false);
+ fillVertexIndex(&dc, g, true, false, visualizer->m_renderer->m_rhi);
drawCalls.append(dc);
}
@@ -476,7 +476,7 @@ void RhiVisualizer::BatchVis::gather(Batch *b)
QSGGeometryNode *gn = b->first->node;
QSGGeometry *g = gn->geometry();
- fillVertexIndex(&dc, g, false, forceUintIndex);
+ fillVertexIndex(&dc, g, false, forceUintIndex, visualizer->m_renderer->m_rhi);
for (int ds = 0; ds < b->drawSets.size(); ++ds) {
const DrawSet &set = b->drawSets.at(ds);
@@ -499,7 +499,7 @@ void RhiVisualizer::BatchVis::gather(Batch *b)
QMatrix4x4 m = matrix * *gn->matrix();
memcpy(dc.uniforms.data, m.constData(), 64);
- fillVertexIndex(&dc, g, false, forceUintIndex);
+ fillVertexIndex(&dc, g, false, forceUintIndex, visualizer->m_renderer->m_rhi);
dc.buf.vbuf = b->vbo.buf;
dc.buf.vbufOffset = vOffset;
@@ -591,7 +591,7 @@ void RhiVisualizer::ClipVis::gather(QSGNode *node)
memcpy(dc.uniforms.data + 144, &pattern, 4);
qint32 projection = 0;
memcpy(dc.uniforms.data + 148, &projection, 4);
- fillVertexIndex(&dc, g, true, false);
+ fillVertexIndex(&dc, g, true, false, visualizer->m_renderer->m_rhi);
drawCalls.append(dc);
}
}
@@ -703,7 +703,7 @@ void RhiVisualizer::OverdrawVis::gather(Node *n)
qint32 projection = 1;
memcpy(dc.uniforms.data + 148, &projection, 4);
- fillVertexIndex(&dc, g, true, false);
+ fillVertexIndex(&dc, g, true, false, visualizer->m_renderer->m_rhi);
drawCalls.append(dc);
}
}