diff options
author | Ben Fletcher <ben.fletcher@me.com> | 2022-01-31 21:22:26 -0800 |
---|---|---|
committer | Ben Fletcher <ben.fletcher@me.com> | 2022-02-16 00:57:05 -0800 |
commit | 160190968df4a2b5163700a2aebd88842d0c784e (patch) | |
tree | cd1b461e5238c91b2ec6b10fc113cec99baf6edf | |
parent | 5ed8eb091fb4d4c7d26640ab1db4aa79f15893de (diff) |
scenegraph: Add support for polygon fill mode
The qtbase RHI graphics pipeline recently gained support for Polygon
Mode (Triangle Fill Mode in Metal, Fill Mode in D3D). This patch
extends support to the scenegraph.
Note - glPolygonMode not supported on OpenGL ES
[ChangeLog][QtQuick][QSGMaterialShader] Added support for polygon
rasterization mode to graphics pipeline state.
Change-Id: I6fc05bc4d38446e573687ca651d6d13a76b3e667
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
4 files changed, 31 insertions, 2 deletions
diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp index c848b681e6..bda0085818 100644 --- a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp +++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp @@ -2654,6 +2654,7 @@ bool Renderer::ensurePipelineState(Element *e, const ShaderManager::Shader *sms, ps->setFlags(flags); ps->setTopology(qsg_topology(m_gstate.drawMode)); ps->setCullMode(m_gstate.cullMode); + ps->setPolygonMode(m_gstate.polygonMode); QRhiGraphicsPipeline::TargetBlend blend; blend.colorWrite = m_gstate.colorWrite; @@ -2793,13 +2794,14 @@ static void rendererToMaterialGraphicsState(QSGMaterialShader::GraphicsPipelineS Q_ASSERT(int(QSGMaterialShader::GraphicsPipelineState::OneMinusSrc1Alpha) == int(QRhiGraphicsPipeline::OneMinusSrc1Alpha)); Q_ASSERT(int(QSGMaterialShader::GraphicsPipelineState::A) == int(QRhiGraphicsPipeline::A)); Q_ASSERT(int(QSGMaterialShader::GraphicsPipelineState::CullBack) == int(QRhiGraphicsPipeline::Back)); - + Q_ASSERT(int(QSGMaterialShader::GraphicsPipelineState::Line) == int(QRhiGraphicsPipeline::Line)); dst->srcColor = QSGMaterialShader::GraphicsPipelineState::BlendFactor(src->srcColor); dst->dstColor = QSGMaterialShader::GraphicsPipelineState::BlendFactor(src->dstColor); dst->colorWrite = QSGMaterialShader::GraphicsPipelineState::ColorMask(int(src->colorWrite)); dst->cullMode = QSGMaterialShader::GraphicsPipelineState::CullMode(src->cullMode); + dst->polygonMode = QSGMaterialShader::GraphicsPipelineState::PolygonMode(src->polygonMode); } static void materialToRendererGraphicsState(GraphicsState *dst, @@ -2810,6 +2812,7 @@ static void materialToRendererGraphicsState(GraphicsState *dst, dst->dstColor = QRhiGraphicsPipeline::BlendFactor(src->dstColor); dst->colorWrite = QRhiGraphicsPipeline::ColorMask(int(src->colorWrite)); dst->cullMode = QRhiGraphicsPipeline::CullMode(src->cullMode); + dst->polygonMode = QRhiGraphicsPipeline::PolygonMode(src->polygonMode); } void Renderer::updateMaterialDynamicData(ShaderManager::Shader *sms, @@ -3712,6 +3715,7 @@ void Renderer::prepareRenderPass(RenderPassContext *ctx) m_gstate.blending = false; m_gstate.cullMode = QRhiGraphicsPipeline::None; + m_gstate.polygonMode = QRhiGraphicsPipeline::Fill; m_gstate.colorWrite = QRhiGraphicsPipeline::R | QRhiGraphicsPipeline::G | QRhiGraphicsPipeline::B @@ -4027,7 +4031,8 @@ bool operator==(const GraphicsState &a, const GraphicsState &b) noexcept && a.stencilTest == b.stencilTest && a.sampleCount == b.sampleCount && a.drawMode == b.drawMode - && a.lineWidth == b.lineWidth; + && a.lineWidth == b.lineWidth + && a.polygonMode == b.polygonMode; } bool operator!=(const GraphicsState &a, const GraphicsState &b) noexcept diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h index 241f5748b6..5cfc6c54c6 100644 --- a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h +++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h @@ -640,6 +640,7 @@ struct GraphicsState int sampleCount = 1; QSGGeometry::DrawingMode drawMode = QSGGeometry::DrawTriangles; float lineWidth = 1.0f; + QRhiGraphicsPipeline::PolygonMode polygonMode = QRhiGraphicsPipeline::Fill; }; bool operator==(const GraphicsState &a, const GraphicsState &b) noexcept; diff --git a/src/quick/scenegraph/coreapi/qsgmaterialshader.cpp b/src/quick/scenegraph/coreapi/qsgmaterialshader.cpp index bd17fd365a..3eb544f94d 100644 --- a/src/quick/scenegraph/coreapi/qsgmaterialshader.cpp +++ b/src/quick/scenegraph/coreapi/qsgmaterialshader.cpp @@ -684,6 +684,23 @@ bool QSGMaterialShader::updateGraphicsPipelineState(RenderState &state, Graphics */ /*! + \enum QSGMaterialShader::GraphicsPipelineState::PolygonMode + \since 6.4 + \brief Specifies the polygon rasterization mode + + Polygon Mode (Triangle Fill Mode in Metal, Fill Mode in D3D) specifies + the fill mode used when rasterizing polygons. Polygons may be drawn as + solids (Fill), or as a wire mesh (Line). + + \warning OpenGL ES does not support the \c{Line} polygon mode. OpenGL ES + will rasterize all polygons as filled no matter what polygon mode is set. + Using \c{Line} will make your application non-portable. + + \value Fill The interior of the polygon is filled (default) + \value Line Boundary edges of the polygon are drawn as line segments. + */ + +/*! Returns the accumulated opacity to be used for rendering. */ float QSGMaterialShader::RenderState::opacity() const diff --git a/src/quick/scenegraph/coreapi/qsgmaterialshader.h b/src/quick/scenegraph/coreapi/qsgmaterialshader.h index 566f954b06..a3c8afb875 100644 --- a/src/quick/scenegraph/coreapi/qsgmaterialshader.h +++ b/src/quick/scenegraph/coreapi/qsgmaterialshader.h @@ -130,12 +130,18 @@ public: CullBack }; + enum PolygonMode { + Fill, + Line, + }; + bool blendEnable; BlendFactor srcColor; BlendFactor dstColor; ColorMask colorWrite; QColor blendConstant; CullMode cullMode; + PolygonMode polygonMode; // This struct is extensible while keeping BC since apps only ever get // a ptr to the struct, it is not created by them. }; |