diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2019-06-24 16:53:46 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2019-07-04 19:48:40 +0200 |
commit | fc40f0738e55725d4449059578510802dbf596ec (patch) | |
tree | d046049be94b417bc72f6e01dbd9e75034ff93b6 /src | |
parent | ae4765265b2ed9458b6ba9983284d850cc8e2d6d (diff) |
Enable line width on the rhi code path
So examples like customgeometry show up as they should now, at least
with OpenGL and Vulkan (when wide lines are supported).
This way applications drawing lines on Qt Quick on OpenGL can continue
functioning on Qt Quick on RHI on OpenGL as well.
Those relying on drawing points with a size set from C++ and not from
the vertex shader will need to migrate, but this has not been supported
on OpenGL ES in Qt 5 either.
Those wishing full cross-platform, cross-graphics-API compatibility should
avoid relying on wide lines and points completely.
The unsupported cases get a helpful warning now.
Change-Id: If4255ccc46ad5d91a3a10d69d1c90260055037cc
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp | 54 | ||||
-rw-r--r-- | src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h | 2 |
2 files changed, 40 insertions, 16 deletions
diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp index b6ea4ed560..eab40bb253 100644 --- a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp +++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp @@ -3282,6 +3282,8 @@ bool Renderer::ensurePipelineState(Element *e, const ShaderManager::Shader *sms) ps->setSampleCount(m_gstate.sampleCount); + ps->setLineWidth(m_gstate.lineWidth); + //qDebug("building new ps %p", ps); if (!ps->build()) { qWarning("Failed to build graphics pipeline state"); @@ -3634,7 +3636,10 @@ bool Renderer::prepareRenderMergedBatch(Batch *batch, PreparedRenderBatch *rende e->srb = m_shaderManager->srb(bindings); m_gstate.drawMode = QSGGeometry::DrawingMode(g->drawingMode()); + m_gstate.lineWidth = g->lineWidth(); + const bool hasPipeline = ensurePipelineState(e, sms); + if (pendingGStatePop) m_gstate = m_gstateStack.pop(); @@ -3651,19 +3656,38 @@ bool Renderer::prepareRenderMergedBatch(Batch *batch, PreparedRenderBatch *rende return true; } +void Renderer::checkLineWidth(QSGGeometry *g) +{ + if (g->drawingMode() == QSGGeometry::DrawLines || g->drawingMode() == QSGGeometry::DrawLineLoop + || g->drawingMode() == QSGGeometry::DrawLineStrip) + { + if (g->lineWidth() != 1.0f) { + static bool checkedWideLineSupport = false; + if (!checkedWideLineSupport) { + checkedWideLineSupport = true; + if (!m_rhi->isFeatureSupported(QRhi::WideLines)) + qWarning("Line widths other than 1 are not supported by the graphics API"); + } + } + } else if (g->drawingMode() == QSGGeometry::DrawPoints) { + if (g->lineWidth() != 1.0f) { + static bool warnedPointSize = false; + if (!warnedPointSize) { + warnedPointSize = true; + qWarning("Point size is not controllable by QSGGeometry. " + "Set gl_PointSize from the vertex shader instead."); + } + } + } +} + void Renderer::renderMergedBatch(PreparedRenderBatch *renderBatch) // split prepare-render (RHI only) { const Batch *batch = renderBatch->batch; Element *e = batch->first; QSGGeometryNode *gn = e->node; QSGGeometry *g = gn->geometry(); - - if (g->drawingMode() == QSGGeometry::DrawLineStrip || g->drawingMode() == QSGGeometry::DrawLineLoop - || g->drawingMode() == QSGGeometry::DrawLines || g->drawingMode() == QSGGeometry::DrawPoints) - { - if (g->lineWidth() != 1.0f) - qWarning("Line width and point size other than 1 not supported"); - } + checkLineWidth(g); if (batch->clipState.type & ClipState::StencilClip) enqueueStencilDraw(batch); @@ -3804,11 +3828,14 @@ bool Renderer::prepareRenderUnmergedBatch(Batch *batch, PreparedRenderBatch *ren ubufOffset += aligned(ubufSize, m_ubufAlignment); const QSGGeometry::DrawingMode prevDrawMode = m_gstate.drawMode; + const float prevLineWidth = m_gstate.lineWidth; m_gstate.drawMode = QSGGeometry::DrawingMode(g->drawingMode()); + m_gstate.lineWidth = g->lineWidth(); + // Do not bother even looking up the ps if the topology has not changed // since everything else is the same for all elements in the batch. // (except if the material modified blend state) - if (!ps || m_gstate.drawMode != prevDrawMode || pendingGStatePop) { + if (!ps || m_gstate.drawMode != prevDrawMode || m_gstate.lineWidth != prevLineWidth || pendingGStatePop) { if (!ensurePipelineState(e, sms)) { if (pendingGStatePop) m_gstate = m_gstateStack.pop(); @@ -3856,15 +3883,9 @@ void Renderer::renderUnmergedBatch(PreparedRenderBatch *renderBatch) // split pr while (e) { gn = e->node; QSGGeometry *g = gn->geometry(); + checkLineWidth(g); const int effectiveIndexSize = m_uint32IndexForRhi ? sizeof(quint32) : g->sizeOfIndex(); - if (g->drawingMode() == QSGGeometry::DrawLineStrip || g->drawingMode() == QSGGeometry::DrawLineLoop - || g->drawingMode() == QSGGeometry::DrawLines || g->drawingMode() == QSGGeometry::DrawPoints) - { - if (g->lineWidth() != 1.0f) - qWarning("Line width and point size other than 1 not supported"); - } - setGraphicsPipeline(cb, batch, e); const QRhiCommandBuffer::VertexInput vbufBinding(batch->vbo.buf, vOffset); @@ -4753,7 +4774,8 @@ bool operator==(const GraphicsState &a, const GraphicsState &b) Q_DECL_NOTHROW && a.usesScissor == b.usesScissor && a.stencilTest == b.stencilTest && a.sampleCount == b.sampleCount - && a.drawMode == b.drawMode; + && a.drawMode == b.drawMode + && a.lineWidth == b.lineWidth; } bool operator!=(const GraphicsState &a, const GraphicsState &b) Q_DECL_NOTHROW diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h index 8564492b76..9dec203e73 100644 --- a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h +++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h @@ -691,6 +691,7 @@ struct GraphicsState bool stencilTest = false; int sampleCount = 1; QSGGeometry::DrawingMode drawMode = QSGGeometry::DrawTriangles; + float lineWidth = 1.0f; }; bool operator==(const GraphicsState &a, const GraphicsState &b) Q_DECL_NOTHROW; @@ -779,6 +780,7 @@ private: const Batch *batch, int ubufOffset, int ubufRegionSize); void updateMaterialStaticData(ShaderManager::Shader *sms, const QSGMaterialRhiShader::RenderState &renderState, QSGMaterial *material, Batch *batch, bool *gstateChanged); + void checkLineWidth(QSGGeometry *g); bool prepareRenderMergedBatch(Batch *batch, PreparedRenderBatch *renderBatch); void renderMergedBatch(PreparedRenderBatch *renderBatch); bool prepareRenderUnmergedBatch(Batch *batch, PreparedRenderBatch *renderBatch); |