5#include <QGuiApplication>
10int main(
int argc,
char **argv)
14 std::unique_ptr<QRhi> rhi;
16 QRhiD3D12InitParams
params;
18#elif defined(Q_OS_MACOS) || defined(Q_OS_IOS)
21#elif QT_CONFIG(vulkan)
23 inst.setExtensions(QRhiVulkanInitParams::preferredInstanceExtensions());
29 qFatal(
"Failed to create Vulkan instance");
33 qDebug() << rhi->backendName() << rhi->driverInfo();
35 qFatal(
"Failed to initialize RHI");
37 float rotation = 0.0f;
46 std::unique_ptr<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget({ tex.get() }));
47 std::unique_ptr<QRhiRenderPassDescriptor> rp(rt->newCompatibleRenderPassDescriptor());
48 rt->setRenderPassDescriptor(rp.get());
51 QMatrix4x4 viewProjection = rhi->clipSpaceCorrMatrix();
52 viewProjection.
perspective(45.0f, 1280 / 720.f, 0.01f, 1000.0f);
55 static float vertexData[] = {
56 0.0f, 0.5f, 1.0f, 0.0f, 0.0f,
57 -0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
58 0.5f, -0.5f, 0.0f, 0.0f, 1.0f,
71 std::unique_ptr<QRhiShaderResourceBindings> srb(rhi->newShaderResourceBindings());
79 std::unique_ptr<QRhiGraphicsPipeline> ps(rhi->newGraphicsPipeline());
81 premulAlphaBlend.
enable =
true;
82 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();
144 if (rhi->isYUpInFramebuffer())
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
@ Format_RGBA8888_Premultiplied
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
void rotate(float angle, const QVector3D &vector)
Multiples this matrix by another that rotates coordinates through angle degrees about vector.
void perspective(float verticalAngle, float aspectRatio, float nearPlane, float farPlane)
Multiplies this matrix by another that applies a perspective projection.
const float * constData() const
Returns a constant pointer to the raw data of this matrix.
void translate(const QVector3D &vector)
Multiplies this matrix by another that translates coordinates by the components of vector.
QPair< QRhiBuffer *, quint32 > VertexInput
Synonym for QPair<QRhiBuffer *, quint32>.
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...
void readBackTexture(const QRhiReadbackDescription &rb, QRhiReadbackResult *result)
Enqueues a texture-to-host copy operation as described by rb.
static QRhiShaderResourceBinding uniformBuffer(int binding, StageFlags stage, QRhiBuffer *buf)
static QRhi * create(Implementation impl, QRhiInitParams *params, Flags flags={}, QRhiNativeHandles *importDevice=nullptr)
static QShader fromSerialized(const QByteArray &data)
Creates a new QShader instance from the given data.
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString static QString asprintf(const char *format,...) Q_ATTRIBUTE_FORMAT_PRINTF(1
The QVulkanInstance class represents a native Vulkan instance, enabling Vulkan rendering onto a QSurf...
static QShader getShader(const QString &name)
constexpr const T & qBound(const T &min, const T &val, const T &max)
SSL_CTX int(* cb)(SSL *ssl, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)
QLatin1StringView QLatin1String
QApplication app(argc, argv)
[0]