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);
132 if (ps->flags.testFlag(QSSGRhiGraphicsPipelineState::Flag::UsesScissor))
133 cb->setScissor(ps->scissor);
135 quint32 vertexOffset = flags.testAnyFlags(RenderBehind) ? 5 * 4 *
sizeof(
float) : 0;
137 QRhiCommandBuffer::VertexInput vb(m_vbuf->buffer(), vertexOffset);
138 Q_QUICK3D_PROFILE_START(QQuick3DProfiler::Quick3DRenderCall);
139 cb->setVertexInput(0, 1, &vb, m_ibuf->buffer(), m_ibuf->indexFormat());
141 QSSGRHICTX_STAT(rhiCtx, drawIndexed(6, 1));
142 Q_QUICK3D_PROFILE_END_WITH_STRING(QQuick3DProfiler::Quick3DRenderCall, 36llu | (1llu << 32), QByteArrayLiteral(
"render_quad"));
145void QSSGRhiQuadRenderer::recordRenderQuadPass(QSSGRhiContext *rhiCtx,
146 QSSGRhiGraphicsPipelineState *ps, QRhiShaderResourceBindings *srb,
147 QRhiTextureRenderTarget *rt, Flags flags)
149 QRhiCommandBuffer *cb = rhiCtx->commandBuffer();
150 cb->beginPass(rt, Qt::black, { 1.0f, 0 },
nullptr, rhiCtx->commonPassFlags());
151 QSSGRHICTX_STAT(rhiCtx, beginRenderPass(rt));
152 recordRenderQuad(rhiCtx, ps, srb, rt->renderPassDescriptor(), flags);
154 QSSGRHICTX_STAT(rhiCtx, endRenderPass());
165void QSSGRhiCubeRenderer::recordRenderCube(QSSGRhiContext *rhiCtx, QSSGRhiGraphicsPipelineState *ps, QRhiShaderResourceBindings *srb, QRhiRenderPassDescriptor *rpDesc, QSSGRhiQuadRenderer::Flags flags)
167 auto &ia = QSSGRhiInputAssemblerStatePrivate::get(*ps);
169 ia.inputLayout.setAttributes({ { 0, 0, QRhiVertexInputAttribute::Float3, 0 } });
170 ia.inputs << QSSGRhiInputAssemblerState::PositionSemantic;
171 ia.inputLayout.setBindings({ 3 *
sizeof(
float) });
172 ia.topology = QRhiGraphicsPipeline::Triangles;
174 ps->flags.setFlag(QSSGRhiGraphicsPipelineState::Flag::DepthTestEnabled, flags.testFlag(QSSGRhiQuadRenderer::DepthTest));
175 ps->flags.setFlag(QSSGRhiGraphicsPipelineState::Flag::DepthWriteEnabled, flags.testFlag(QSSGRhiQuadRenderer::DepthWrite));
176 ps->cullMode = QRhiGraphicsPipeline::None;
177 if (flags.testFlag(QSSGRhiQuadRenderer::PremulBlend)) {
178 ps->flags |= QSSGRhiGraphicsPipelineState::Flag::BlendEnabled;
179 ps->targetBlend[0].srcColor = QRhiGraphicsPipeline::One;
180 ps->targetBlend[0].dstColor = QRhiGraphicsPipeline::OneMinusSrcAlpha;
181 ps->targetBlend[0].srcAlpha = QRhiGraphicsPipeline::One;
182 ps->targetBlend[0].dstAlpha = QRhiGraphicsPipeline::OneMinusSrcAlpha;
184 ps->targetBlend[0].srcColor = QRhiGraphicsPipeline::SrcAlpha;
185 ps->targetBlend[0].dstColor = QRhiGraphicsPipeline::OneMinusSrcAlpha;
186 ps->targetBlend[0].srcAlpha = QRhiGraphicsPipeline::One;
187 ps->targetBlend[0].dstAlpha = QRhiGraphicsPipeline::OneMinusSrcAlpha;
190 QSSGRhiContextPrivate *rhiCtxD = QSSGRhiContextPrivate::get(rhiCtx);
191 QRhiGraphicsPipeline *pipeline = rhiCtxD->pipeline(*ps, rpDesc, srb);
197 QRhiCommandBuffer *cb = rhiCtx->commandBuffer();
198 cb->setGraphicsPipeline(pipeline);
199 cb->setShaderResources(srb);
200 cb->setViewport(ps->viewport);
201 if (ps->flags.testFlag(QSSGRhiGraphicsPipelineState::Flag::UsesScissor))
202 cb->setScissor(ps->scissor);
204 QRhiCommandBuffer::VertexInput vb(m_vbuf->buffer(), 0);
205 Q_QUICK3D_PROFILE_START(QQuick3DProfiler::Quick3DRenderCall);
206 cb->setVertexInput(0, 1, &vb, m_ibuf->buffer(), m_ibuf->indexFormat());
208 QSSGRHICTX_STAT(rhiCtx, drawIndexed(36, 1));
209 Q_QUICK3D_PROFILE_END_WITH_STRING(QQuick3DProfiler::Quick3DRenderCall, 36, QByteArrayLiteral(
"render_cube"));