84void QSSGRhiQuadRenderer::recordRenderQuad(QSSGRhiContext *rhiCtx,
85 QSSGRhiGraphicsPipelineState *ps, QRhiShaderResourceBindings *srb,
86 QRhiRenderPassDescriptor *rpDesc, Flags flags)
89 auto &ia = QSSGRhiInputAssemblerStatePrivate::get(*ps);
90 if (flags.testFlag(UvCoords)) {
91 ia.inputLayout.setAttributes({
92 { 0, 0, QRhiVertexInputAttribute::Float3, 0 },
93 { 0, 1, QRhiVertexInputAttribute::Float2, 3 *
sizeof(
float) }
95 ia.inputs << QSSGRhiInputAssemblerState::PositionSemantic << QSSGRhiInputAssemblerState::TexCoord0Semantic;
97 ia.inputLayout.setAttributes({ { 0, 0, QRhiVertexInputAttribute::Float3, 0 } });
98 ia.inputs << QSSGRhiInputAssemblerState::PositionSemantic;
100 ia.inputLayout.setBindings({ 5 *
sizeof(
float) });
101 ia.topology = QRhiGraphicsPipeline::Triangles;
103 ps->flags.setFlag(QSSGRhiGraphicsPipelineState::Flag::DepthTestEnabled, flags.testFlag(DepthTest));
104 ps->flags.setFlag(QSSGRhiGraphicsPipelineState::Flag::DepthWriteEnabled, flags.testFlag(DepthWrite));
105 ps->cullMode = QRhiGraphicsPipeline::None;
106 if (flags.testFlag(PremulBlend)) {
107 ps->flags |= QSSGRhiGraphicsPipelineState::Flag::BlendEnabled;
108 ps->targetBlend[0].srcColor = QRhiGraphicsPipeline::One;
109 ps->targetBlend[0].dstColor = QRhiGraphicsPipeline::OneMinusSrcAlpha;
110 ps->targetBlend[0].srcAlpha = QRhiGraphicsPipeline::One;
111 ps->targetBlend[0].dstAlpha = QRhiGraphicsPipeline::OneMinusSrcAlpha;
113 ps->targetBlend[0].srcColor = QRhiGraphicsPipeline::SrcAlpha;
114 ps->targetBlend[0].dstColor = QRhiGraphicsPipeline::OneMinusSrcAlpha;
115 ps->targetBlend[0].srcAlpha = QRhiGraphicsPipeline::One;
116 ps->targetBlend[0].dstAlpha = QRhiGraphicsPipeline::OneMinusSrcAlpha;
119 QSSGRhiContextPrivate *rhiCtxD = QSSGRhiContextPrivate::get(rhiCtx);
120 QRhiGraphicsPipeline *pipeline = rhiCtxD->pipeline(*ps, rpDesc, srb);
126 QRhiCommandBuffer *cb = rhiCtx->commandBuffer();
127 cb->setGraphicsPipeline(pipeline);
128 cb->setShaderResources(srb);
129 cb->setViewport(ps->viewport);
131 quint32 vertexOffset = flags.testAnyFlags(RenderBehind) ? 5 * 4 *
sizeof(
float) : 0;
133 QRhiCommandBuffer::VertexInput vb(m_vbuf->buffer(), vertexOffset);
134 Q_QUICK3D_PROFILE_START(QQuick3DProfiler::Quick3DRenderCall);
135 cb->setVertexInput(0, 1, &vb, m_ibuf->buffer(), m_ibuf->indexFormat());
137 QSSGRHICTX_STAT(rhiCtx, drawIndexed(6, 1));
138 Q_QUICK3D_PROFILE_END_WITH_STRING(QQuick3DProfiler::Quick3DRenderCall, 36llu | (1llu << 32), QByteArrayLiteral(
"render_quad"));
141void QSSGRhiQuadRenderer::recordRenderQuadPass(QSSGRhiContext *rhiCtx,
142 QSSGRhiGraphicsPipelineState *ps, QRhiShaderResourceBindings *srb,
143 QRhiTextureRenderTarget *rt, Flags flags)
145 QRhiCommandBuffer *cb = rhiCtx->commandBuffer();
146 cb->beginPass(rt, Qt::black, { 1.0f, 0 },
nullptr, rhiCtx->commonPassFlags());
147 QSSGRHICTX_STAT(rhiCtx, beginRenderPass(rt));
148 recordRenderQuad(rhiCtx, ps, srb, rt->renderPassDescriptor(), flags);
150 QSSGRHICTX_STAT(rhiCtx, endRenderPass());
161void QSSGRhiCubeRenderer::recordRenderCube(QSSGRhiContext *rhiCtx, QSSGRhiGraphicsPipelineState *ps, QRhiShaderResourceBindings *srb, QRhiRenderPassDescriptor *rpDesc, QSSGRhiQuadRenderer::Flags flags)
163 auto &ia = QSSGRhiInputAssemblerStatePrivate::get(*ps);
165 ia.inputLayout.setAttributes({ { 0, 0, QRhiVertexInputAttribute::Float3, 0 } });
166 ia.inputs << QSSGRhiInputAssemblerState::PositionSemantic;
167 ia.inputLayout.setBindings({ 3 *
sizeof(
float) });
168 ia.topology = QRhiGraphicsPipeline::Triangles;
170 ps->flags.setFlag(QSSGRhiGraphicsPipelineState::Flag::DepthTestEnabled, flags.testFlag(QSSGRhiQuadRenderer::DepthTest));
171 ps->flags.setFlag(QSSGRhiGraphicsPipelineState::Flag::DepthWriteEnabled, flags.testFlag(QSSGRhiQuadRenderer::DepthWrite));
172 ps->cullMode = QRhiGraphicsPipeline::None;
173 if (flags.testFlag(QSSGRhiQuadRenderer::PremulBlend)) {
174 ps->flags |= QSSGRhiGraphicsPipelineState::Flag::BlendEnabled;
175 ps->targetBlend[0].srcColor = QRhiGraphicsPipeline::One;
176 ps->targetBlend[0].dstColor = QRhiGraphicsPipeline::OneMinusSrcAlpha;
177 ps->targetBlend[0].srcAlpha = QRhiGraphicsPipeline::One;
178 ps->targetBlend[0].dstAlpha = QRhiGraphicsPipeline::OneMinusSrcAlpha;
180 ps->targetBlend[0].srcColor = QRhiGraphicsPipeline::SrcAlpha;
181 ps->targetBlend[0].dstColor = QRhiGraphicsPipeline::OneMinusSrcAlpha;
182 ps->targetBlend[0].srcAlpha = QRhiGraphicsPipeline::One;
183 ps->targetBlend[0].dstAlpha = QRhiGraphicsPipeline::OneMinusSrcAlpha;
186 QSSGRhiContextPrivate *rhiCtxD = QSSGRhiContextPrivate::get(rhiCtx);
187 QRhiGraphicsPipeline *pipeline = rhiCtxD->pipeline(*ps, rpDesc, srb);
193 QRhiCommandBuffer *cb = rhiCtx->commandBuffer();
194 cb->setGraphicsPipeline(pipeline);
195 cb->setShaderResources(srb);
196 cb->setViewport(ps->viewport);
198 QRhiCommandBuffer::VertexInput vb(m_vbuf->buffer(), 0);
199 Q_QUICK3D_PROFILE_START(QQuick3DProfiler::Quick3DRenderCall);
200 cb->setVertexInput(0, 1, &vb, m_ibuf->buffer(), m_ibuf->indexFormat());
202 QSSGRHICTX_STAT(rhiCtx, drawIndexed(36, 1));
203 Q_QUICK3D_PROFILE_END_WITH_STRING(QQuick3DProfiler::Quick3DRenderCall, 36, QByteArrayLiteral(
"render_cube"));