86void QSSGRhiQuadRenderer::recordRenderQuad(QSSGRhiContext *rhiCtx,
87 QSSGRhiGraphicsPipelineState *ps, QRhiShaderResourceBindings *srb,
88 QRhiRenderPassDescriptor *rpDesc, Flags flags)
91 auto &ia = QSSGRhiInputAssemblerStatePrivate::get(*ps);
92 if (flags.testFlag(UvCoords)) {
93 ia.inputLayout.setAttributes({
94 { 0, 0, QRhiVertexInputAttribute::Float3, 0 },
95 { 0, 1, QRhiVertexInputAttribute::Float2, 3 *
sizeof(
float) }
97 ia.inputs << QSSGRhiInputAssemblerState::PositionSemantic << QSSGRhiInputAssemblerState::TexCoord0Semantic;
99 ia.inputLayout.setAttributes({ { 0, 0, QRhiVertexInputAttribute::Float3, 0 } });
100 ia.inputs << QSSGRhiInputAssemblerState::PositionSemantic;
102 ia.inputLayout.setBindings({ 5 *
sizeof(
float) });
103 ia.topology = QRhiGraphicsPipeline::Triangles;
105 ps->flags.setFlag(QSSGRhiGraphicsPipelineState::Flag::DepthTestEnabled, flags.testFlag(DepthTest));
106 ps->flags.setFlag(QSSGRhiGraphicsPipelineState::Flag::DepthWriteEnabled, flags.testFlag(DepthWrite));
107 ps->cullMode = QRhiGraphicsPipeline::None;
108 if (flags.testFlag(PremulBlend)) {
109 ps->flags |= QSSGRhiGraphicsPipelineState::Flag::BlendEnabled;
110 ps->targetBlend[0].srcColor = QRhiGraphicsPipeline::One;
111 ps->targetBlend[0].dstColor = QRhiGraphicsPipeline::OneMinusSrcAlpha;
112 ps->targetBlend[0].srcAlpha = QRhiGraphicsPipeline::One;
113 ps->targetBlend[0].dstAlpha = QRhiGraphicsPipeline::OneMinusSrcAlpha;
115 ps->targetBlend[0].srcColor = QRhiGraphicsPipeline::SrcAlpha;
116 ps->targetBlend[0].dstColor = QRhiGraphicsPipeline::OneMinusSrcAlpha;
117 ps->targetBlend[0].srcAlpha = QRhiGraphicsPipeline::One;
118 ps->targetBlend[0].dstAlpha = QRhiGraphicsPipeline::OneMinusSrcAlpha;
121 QSSGRhiContextPrivate *rhiCtxD = QSSGRhiContextPrivate::get(rhiCtx);
122 QRhiGraphicsPipeline *pipeline = rhiCtxD->pipeline(*ps, rpDesc, srb);
128 QRhiCommandBuffer *cb = rhiCtx->commandBuffer();
129 cb->setGraphicsPipeline(pipeline);
130 cb->setShaderResources(srb);
131 cb->setViewport(ps->viewport);
133 quint32 vertexOffset = flags.testAnyFlags(RenderBehind) ? 5 * 4 *
sizeof(
float) : 0;
135 QRhiCommandBuffer::VertexInput vb(m_vbuf->buffer(), vertexOffset);
136 Q_QUICK3D_PROFILE_START(QQuick3DProfiler::Quick3DRenderCall);
137 cb->setVertexInput(0, 1, &vb, m_ibuf->buffer(), m_ibuf->indexFormat());
139 QSSGRHICTX_STAT(rhiCtx, drawIndexed(6, 1));
140 Q_QUICK3D_PROFILE_END_WITH_STRING(QQuick3DProfiler::Quick3DRenderCall, 36llu | (1llu << 32), QByteArrayLiteral(
"render_quad"));
143void QSSGRhiQuadRenderer::recordRenderQuadPass(QSSGRhiContext *rhiCtx,
144 QSSGRhiGraphicsPipelineState *ps, QRhiShaderResourceBindings *srb,
145 QRhiTextureRenderTarget *rt, Flags flags)
147 QRhiCommandBuffer *cb = rhiCtx->commandBuffer();
148 cb->beginPass(rt, Qt::black, { 1.0f, 0 },
nullptr, rhiCtx->commonPassFlags());
149 QSSGRHICTX_STAT(rhiCtx, beginRenderPass(rt));
150 recordRenderQuad(rhiCtx, ps, srb, rt->renderPassDescriptor(), flags);
152 QSSGRHICTX_STAT(rhiCtx, endRenderPass());
163void QSSGRhiCubeRenderer::recordRenderCube(QSSGRhiContext *rhiCtx, QSSGRhiGraphicsPipelineState *ps, QRhiShaderResourceBindings *srb, QRhiRenderPassDescriptor *rpDesc, QSSGRhiQuadRenderer::Flags flags)
165 auto &ia = QSSGRhiInputAssemblerStatePrivate::get(*ps);
167 ia.inputLayout.setAttributes({ { 0, 0, QRhiVertexInputAttribute::Float3, 0 } });
168 ia.inputs << QSSGRhiInputAssemblerState::PositionSemantic;
169 ia.inputLayout.setBindings({ 3 *
sizeof(
float) });
170 ia.topology = QRhiGraphicsPipeline::Triangles;
172 ps->flags.setFlag(QSSGRhiGraphicsPipelineState::Flag::DepthTestEnabled, flags.testFlag(QSSGRhiQuadRenderer::DepthTest));
173 ps->flags.setFlag(QSSGRhiGraphicsPipelineState::Flag::DepthWriteEnabled, flags.testFlag(QSSGRhiQuadRenderer::DepthWrite));
174 ps->cullMode = QRhiGraphicsPipeline::None;
175 if (flags.testFlag(QSSGRhiQuadRenderer::PremulBlend)) {
176 ps->flags |= QSSGRhiGraphicsPipelineState::Flag::BlendEnabled;
177 ps->targetBlend[0].srcColor = QRhiGraphicsPipeline::One;
178 ps->targetBlend[0].dstColor = QRhiGraphicsPipeline::OneMinusSrcAlpha;
179 ps->targetBlend[0].srcAlpha = QRhiGraphicsPipeline::One;
180 ps->targetBlend[0].dstAlpha = QRhiGraphicsPipeline::OneMinusSrcAlpha;
182 ps->targetBlend[0].srcColor = QRhiGraphicsPipeline::SrcAlpha;
183 ps->targetBlend[0].dstColor = QRhiGraphicsPipeline::OneMinusSrcAlpha;
184 ps->targetBlend[0].srcAlpha = QRhiGraphicsPipeline::One;
185 ps->targetBlend[0].dstAlpha = QRhiGraphicsPipeline::OneMinusSrcAlpha;
188 QSSGRhiContextPrivate *rhiCtxD = QSSGRhiContextPrivate::get(rhiCtx);
189 QRhiGraphicsPipeline *pipeline = rhiCtxD->pipeline(*ps, rpDesc, srb);
195 QRhiCommandBuffer *cb = rhiCtx->commandBuffer();
196 cb->setGraphicsPipeline(pipeline);
197 cb->setShaderResources(srb);
198 cb->setViewport(ps->viewport);
200 QRhiCommandBuffer::VertexInput vb(m_vbuf->buffer(), 0);
201 Q_QUICK3D_PROFILE_START(QQuick3DProfiler::Quick3DRenderCall);
202 cb->setVertexInput(0, 1, &vb, m_ibuf->buffer(), m_ibuf->indexFormat());
204 QSSGRHICTX_STAT(rhiCtx, drawIndexed(36, 1));
205 Q_QUICK3D_PROFILE_END_WITH_STRING(QQuick3DProfiler::Quick3DRenderCall, 36, QByteArrayLiteral(
"render_cube"));