10int main(
int argc,
char **argv)
17 std::unique_ptr<QRhi> rhi;
19 QRhiD3D12InitParams
params;
24#elif QT_CONFIG(vulkan)
25 inst.setExtensions(QRhiVulkanInitParams::preferredInstanceExtensions());
31 qFatal(
"Failed to create Vulkan instance");
35 qDebug() << rhi->backendName() << rhi->driverInfo();
37 qFatal(
"Failed to initialize RHI");
39 float rotation = 0.0f;
48 std::unique_ptr<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget({ tex.get() }));
49 std::unique_ptr<QRhiRenderPassDescriptor> rp(rt->newCompatibleRenderPassDescriptor());
50 rt->setRenderPassDescriptor(rp.get());
53 QMatrix4x4 viewProjection = rhi->clipSpaceCorrMatrix();
54 viewProjection.
perspective(45.0f, 1280 / 720.f, 0.01f, 1000.0f);
58 0.0f, 0.5f, 1.0f, 0.0f, 0.0f,
59 -0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
60 0.5f, -0.5f, 0.0f, 0.0f, 1.0f,
73 std::unique_ptr<QRhiShaderResourceBindings> srb(rhi->newShaderResourceBindings());
81 std::unique_ptr<QRhiGraphicsPipeline> ps(rhi->newGraphicsPipeline());
83 premulAlphaBlend.
enable =
true;
84 ps->setTargetBlends({ premulAlphaBlend });
101 ps->setVertexInputLayout(inputLayout);
102 ps->setShaderResourceBindings(srb.get());
103 ps->setRenderPassDescriptor(rp.get());
108 rhi->beginOffscreenFrame(&
cb);
115 mvp.
rotate(rotation, 0, 1, 0);
120 opacity += opacityDir * 0.2f;
121 if (opacity < 0.0f || opacity > 1.0f) {
123 opacity =
qBound(0.0f, opacity, 1.0f);
126 cb->beginPass(rt.get(),
Qt::green, { 1.0f, 0 }, u);
127 cb->setGraphicsPipeline(ps.get());
128 cb->setViewport({ 0, 0, 1280, 720 });
129 cb->setShaderResources();
131 cb->setVertexInput(0, 1, &vbufBinding);
134 u = rhi->nextResourceUpdateBatch();
138 rhi->endOffscreenFrame();
140 QImage image(
reinterpret_cast<const uchar *
>(readbackResult.data.constData()),
141 readbackResult.pixelSize.width(),
142 readbackResult.pixelSize.height(),
144 if (rhi->isYUpInFramebuffer())
void perspective(float verticalAngle, float aspectRatio, float nearPlane, float farPlane)
Multiplies this matrix by another that applies a perspective projection.
void updateDynamicBuffer(QRhiBuffer *buf, quint32 offset, quint32 size, const void *data)
Enqueues updating a region of a QRhiBuffer buf created with the type QRhiBuffer::Dynamic.
void uploadStaticBuffer(QRhiBuffer *buf, quint32 offset, quint32 size, const void *data)
Enqueues updating a region of a QRhiBuffer buf created with the type QRhiBuffer::Immutable or QRhiBuf...
SSL_CTX int(* cb)(SSL *ssl, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)