60 #define EXAMPLEFW_KEYPRESS_EVENTS
61 #include "../shared/examplefw.h"
62 #include "../shared/cube.h"
65 static const QSize cubemapSize(512, 512);
68 static float halfQuadVertexData[] =
76 static quint16 halfQuadIndexData[] =
118 d.cubemap1->create();
119 d.releasePool <<
d.cubemap1;
123 d.oneface_ubuf->create();
124 d.releasePool <<
d.oneface_ubuf;
132 d.oneface_rp =
d.oneface_rt[0]->newCompatibleRenderPassDescriptor();
133 d.releasePool <<
d.oneface_rp;
135 d.oneface_rt[
face]->setRenderPassDescriptor(
d.oneface_rp);
136 d.oneface_rt[
face]->create();
137 d.releasePool <<
d.oneface_rt[
face];
141 const QRhiShaderResourceBinding::StageFlags visibility =
143 d.oneface_srb->setBindings({
146 d.oneface_srb->create();
147 d.releasePool <<
d.oneface_srb;
150 d.oneface_ps->setShaderStages({
156 { 2 *
sizeof(float) }
161 d.oneface_ps->setVertexInputLayout(inputLayout);
162 d.oneface_ps->setShaderResourceBindings(
d.oneface_srb);
163 d.oneface_ps->setRenderPassDescriptor(
d.oneface_rp);
164 d.oneface_ps->create();
165 d.releasePool <<
d.oneface_ps;
171 d.initialUpdates->updateDynamicBuffer(
d.oneface_ubuf,
offset, 64, identity.
constData());
194 float color[] = { float(
c.redF()), float(
c.greenF()), float(
c.blueF()) };
195 d.initialUpdates->updateDynamicBuffer(
d.oneface_ubuf,
offset + 64, 12,
color);
204 cb->setGraphicsPipeline(
d.oneface_ps);
205 cb->setViewport({ 0, 0,
206 float(
d.oneface_rt[
face]->pixelSize().width()),
207 float(
d.oneface_rt[
face]->pixelSize().height()) });
209 cb->setShaderResources(
nullptr, 1, &dynamicOffset);
220 d.cubemap2->create();
221 d.releasePool <<
d.cubemap2;
224 d.mrt_ubuf->create();
225 d.releasePool <<
d.mrt_ubuf;
236 d.mrt_rp =
d.mrt_rt->newCompatibleRenderPassDescriptor();
237 d.releasePool <<
d.mrt_rp;
238 d.mrt_rt->setRenderPassDescriptor(
d.mrt_rp);
240 d.releasePool <<
d.mrt_rt;
243 const QRhiShaderResourceBinding::StageFlags visibility =
245 d.mrt_srb->setBindings({
249 d.releasePool <<
d.mrt_srb;
252 d.mrt_ps->setShaderStages({
259 d.mrt_ps->setTargetBlends(targetBlends.cbegin(), targetBlends.cend());
262 { 2 *
sizeof(float) }
267 d.mrt_ps->setVertexInputLayout(inputLayout);
268 d.mrt_ps->setShaderResourceBindings(
d.mrt_srb);
269 d.mrt_ps->setRenderPassDescriptor(
d.mrt_rp);
271 d.releasePool <<
d.mrt_ps;
274 d.initialUpdates->updateDynamicBuffer(
d.mrt_ubuf, 0, 64, identity.
constData());
299 float color[] = { float(
c.redF()), float(
c.greenF()), float(
c.blueF()) };
300 d.initialUpdates->updateDynamicBuffer(
d.mrt_ubuf,
offset, 12,
color);
310 cb->setGraphicsPipeline(
d.mrt_ps);
311 cb->setViewport({ 0, 0,
312 float(
d.mrt_rt->pixelSize().width()),
313 float(
d.mrt_rt->pixelSize().height()) });
314 cb->setShaderResources();
324 d.half_quad_vbuf->create();
325 d.releasePool <<
d.half_quad_vbuf;
328 d.half_quad_ibuf->create();
329 d.releasePool <<
d.half_quad_ibuf;
332 d.initialUpdates->uploadStaticBuffer(
d.half_quad_vbuf, 0,
sizeof(halfQuadVertexData), halfQuadVertexData);
333 d.initialUpdates->uploadStaticBuffer(
d.half_quad_ibuf, halfQuadIndexData);
347 d.releasePool <<
d.vbuf;
348 d.initialUpdates->uploadStaticBuffer(
d.vbuf, cube);
352 d.releasePool <<
d.ubuf;
357 d.releasePool <<
d.sampler;
365 d.releasePool <<
d.srb;
368 d.ps->setDepthTest(
true);
369 d.ps->setDepthWrite(
true);
377 d.ps->setShaderStages({
383 { 3 *
sizeof(float) }
388 d.ps->setVertexInputLayout(inputLayout);
389 d.ps->setShaderResourceBindings(
d.srb);
390 d.ps->setRenderPassDescriptor(
m_rp);
392 d.releasePool <<
d.ps;
395 qDebug(
"Use the arrow keys to switch between the two generated cubemaps");
401 d.releasePool.clear();
406 const QSize outputSizeInPixels =
m_sc->currentPixelSize();
409 if (
d.initialUpdates) {
410 u->merge(
d.initialUpdates);
411 d.initialUpdates->release();
412 d.initialUpdates =
nullptr;
420 u->updateDynamicBuffer(
d.ubuf, 0, 64, mvp.
constData());
422 cb->resourceUpdate(
u);
430 cb->setGraphicsPipeline(
d.ps);
432 cb->setShaderResources();
434 cb->setVertexInput(0, 1, &vbufBinding);
444 qDebug(
"Showing first cubemap (generated by rendering to the faces one by one; black background)");
454 qDebug(
"Showing second cubemap (generated with multiple render targets; magenta background)");
small capitals from c petite p scientific f u
The QColor class provides colors based on RGB, HSV or CMYK values.
The QKeyEvent class describes a key event.
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
void rotate(float angle, const QVector3D &vector)
void scale(const QVector3D &vector)
void perspective(float verticalAngle, float aspectRatio, float nearPlane, float farPlane)
const float * constData() const
QPair< QRhiBuffer *, quint32 > VertexInput
QPair< int, quint32 > DynamicOffset
int ubufAligned(int v) const
int resourceLimit(ResourceLimit limit) const
QMatrix4x4 clipSpaceCorrMatrix() const
QRhiShaderResourceBindings * newShaderResourceBindings()
QRhiBuffer * newBuffer(QRhiBuffer::Type type, QRhiBuffer::UsageFlags usage, int size)
QRhiSampler * newSampler(QRhiSampler::Filter magFilter, QRhiSampler::Filter minFilter, QRhiSampler::Filter mipmapMode, QRhiSampler::AddressMode addressU, QRhiSampler::AddressMode addressV, QRhiSampler::AddressMode addressW=QRhiSampler::Repeat)
QRhiTextureRenderTarget * newTextureRenderTarget(const QRhiTextureRenderTargetDescription &desc, QRhiTextureRenderTarget::Flags flags={})
QRhiGraphicsPipeline * newGraphicsPipeline()
QRhiTexture * newTexture(QRhiTexture::Format format, const QSize &pixelSize, int sampleCount=1, QRhiTexture::Flags flags={})
QRhiResourceUpdateBatch * nextResourceUpdateBatch()
static QRhiShaderResourceBinding uniformBufferWithDynamicOffset(int binding, StageFlags stage, QRhiBuffer *buf, int size)
static QRhiShaderResourceBinding sampledTexture(int binding, StageFlags stage, QRhiTexture *tex, QRhiSampler *sampler)
static QRhiShaderResourceBinding uniformBuffer(int binding, StageFlags stage, QRhiBuffer *buf)
void setColorAttachments(std::initializer_list< QRhiColorAttachment > list)
The QSize class defines the size of a two-dimensional object using integer point precision.
constexpr int height() const noexcept
constexpr int width() const noexcept
std::unique_ptr< QRhiSwapChain > m_sc
std::unique_ptr< QRhiRenderPassDescriptor > m_rp
void keyPressEvent(QKeyEvent *event) override
virtual void customRender()
virtual void customInit()
void initializePerFaceRendering(QRhi *rhi)
QRhiRenderPassDescriptor * oneface_rp
void renderPerFace(QRhiCommandBuffer *cb)
QRhiBuffer * half_quad_vbuf
QRhiGraphicsPipeline * mrt_ps
QRhiShaderResourceBindings * mrt_srb
QList< QRhiResource * > releasePool
QRhiBuffer * half_quad_ibuf
QRhiTextureRenderTarget * mrt_rt
QRhiTextureRenderTarget * oneface_rt[6]
QRhiRenderPassDescriptor * mrt_rp
QRhiGraphicsPipeline * oneface_ps
void initializeMrtRendering(QRhi *rhi)
void renderWithMrt(QRhiCommandBuffer *cb)
QRhiShaderResourceBindings * srb
QRhiShaderResourceBindings * oneface_srb
QRhiBuffer * oneface_ubuf
QRhiGraphicsPipeline * ps
QRhiResourceUpdateBatch * initialUpdates
qDeleteAll(list.begin(), list.end())
QShader getShader(const QString &name)
GLsizei const GLenum * attachments
GLenum GLuint GLintptr offset
SSL_CTX int(* cb)(SSL *ssl, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)