51 #include "../shared/examplefw.h"
57 static float vertexData[] =
59 -0.5f, 0.5f, 0.0f, 0.0f,
60 -0.5f, -0.5f, 0.0f, 1.0f,
61 0.5f, -0.5f, 1.0f, 1.0f,
62 0.5f, 0.5f, 1.0f, 0.0f
70 static float triangleData[] =
72 0.0f, 0.5f, 1.0f, 0.0f, 0.0f,
73 -0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
74 0.5f, -0.5f, 0.0f, 0.0f, 1.0f,
112 qFatal(
"Multisample textures not supported by this backend");
115 d.releasePool <<
d.vbuf;
119 d.releasePool <<
d.ibuf;
124 d.releasePool <<
d.ubuf;
128 d.releasePool <<
d.tex;
135 d.releasePool <<
d.msaaTex;
139 d.initialUpdates->uploadStaticBuffer(
d.vbuf, 0,
sizeof(vertexData), vertexData);
140 d.initialUpdates->uploadStaticBuffer(
d.vbuf,
sizeof(vertexData),
sizeof(triangleData), triangleData);
141 d.initialUpdates->uploadStaticBuffer(
d.ibuf, indexData);
145 d.releasePool <<
d.sampler;
149 d.releasePool <<
d.srbLeft;
150 d.srbLeft->setBindings({
157 d.releasePool <<
d.srbRight;
158 d.srbRight->setBindings({
162 d.srbRight->create();
165 d.releasePool <<
d.psLeft;
166 d.psLeft->setShaderStages({
171 inputLayout.
setBindings({ { 4 *
sizeof(float) } });
176 d.psLeft->setVertexInputLayout(inputLayout);
177 d.psLeft->setShaderResourceBindings(
d.srbLeft);
178 d.psLeft->setRenderPassDescriptor(
m_rp);
182 d.releasePool <<
d.psRight;
183 d.psRight->setShaderStages({
191 d.psRight->setVertexInputLayout(
d.psLeft->vertexInputLayout());
192 d.psRight->setShaderResourceBindings(
d.srbRight);
193 d.psRight->setRenderPassDescriptor(
m_rp);
198 d.releasePool <<
d.triUbuf;
201 d.releasePool <<
d.triSrb;
202 d.triSrb->setBindings({
207 d.releasePool <<
d.rt;
208 d.rtRp =
d.rt->newCompatibleRenderPassDescriptor();
209 d.releasePool <<
d.rtRp;
210 d.rt->setRenderPassDescriptor(
d.rtRp);
213 d.releasePool <<
d.msaaRt;
214 d.msaaRtRp =
d.msaaRt->newCompatibleRenderPassDescriptor();
215 d.releasePool <<
d.msaaRtRp;
216 d.msaaRt->setRenderPassDescriptor(
d.msaaRtRp);
219 d.releasePool <<
d.triPs;
220 d.triPs->setSampleCount(1);
221 d.triPs->setShaderStages({
226 { 5 *
sizeof(float) }
232 d.triPs->setVertexInputLayout(inputLayout);
233 d.triPs->setShaderResourceBindings(
d.triSrb);
234 d.triPs->setRenderPassDescriptor(
d.rtRp);
237 d.releasePool <<
d.msaaTriPs;
239 d.msaaTriPs->setSampleCount(4);
241 d.msaaTriPs->setSampleCount(1);
243 d.msaaTriPs->setShaderStages(
d.triPs->cbeginShaderStages(),
d.triPs->cendShaderStages());
244 d.msaaTriPs->setVertexInputLayout(
d.triPs->vertexInputLayout());
245 d.msaaTriPs->setShaderResourceBindings(
d.triSrb);
246 d.msaaTriPs->setRenderPassDescriptor(
d.msaaRtRp);
247 d.msaaTriPs->create();
253 d.releasePool.clear();
260 if (
d.initialUpdates) {
261 u->merge(
d.initialUpdates);
262 d.initialUpdates->release();
263 d.initialUpdates =
nullptr;
267 u->updateDynamicBuffer(
d.ubuf, 64, 4, &flip);
268 u->updateDynamicBuffer(
d.ubuf,
d.rightOfs + 64, 4, &flip);
272 d.triBaseMvp.perspective(45.0f,
d.msaaTex->pixelSize().width() /
float(
d.msaaTex->pixelSize().height()), 0.01f, 1000.0f);
273 d.triBaseMvp.translate(0, 0, -2);
275 u->updateDynamicBuffer(
d.triUbuf, 64, 4, &
opacity);
284 u->updateDynamicBuffer(
d.ubuf, 0, 64, mvp.
constData());
286 u->updateDynamicBuffer(
d.ubuf,
d.rightOfs, 64, mvp.
constData());
291 triMvp.
rotate(
d.triRot, 0, 1, 0);
293 u->updateDynamicBuffer(
d.triUbuf, 0, 64, triMvp.
constData());
295 cb->resourceUpdate(
u);
299 cb->setGraphicsPipeline(
d.triPs);
300 cb->setViewport({ 0, 0, float(
d.msaaTex->pixelSize().width()), float(
d.msaaTex->pixelSize().height()) });
301 cb->setShaderResources();
303 cb->setVertexInput(0, 1, &vbufBinding);
309 cb->setGraphicsPipeline(
d.msaaTriPs);
310 cb->setViewport({ 0, 0, float(
d.msaaTex->pixelSize().width()), float(
d.msaaTex->pixelSize().height()) });
311 cb->setShaderResources();
312 cb->setVertexInput(0, 1, &vbufBinding);
317 const QSize outputSizeInPixels =
m_sc->currentPixelSize();
319 cb->setGraphicsPipeline(
d.psLeft);
320 cb->setViewport({ 0, 0, float(outputSizeInPixels.
width()), float(outputSizeInPixels.
height()) });
321 cb->setShaderResources();
322 vbufBinding.second = 0;
325 cb->setGraphicsPipeline(
d.psRight);
326 cb->setShaderResources();
small capitals from c petite p scientific f u
static QColor fromRgbF(float r, float g, float b, float a=1.0)
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)
const float * constData() const
void translate(const QVector3D &vector)
QPair< QRhiBuffer *, quint32 > VertexInput
int ubufAligned(int v) const
QMatrix4x4 clipSpaceCorrMatrix() const
bool isYUpInFramebuffer() const
bool isFeatureSupported(QRhi::Feature feature) 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 sampledTexture(int binding, StageFlags stage, QRhiTexture *tex, QRhiSampler *sampler)
static QRhiShaderResourceBinding uniformBuffer(int binding, StageFlags stage, QRhiBuffer *buf)
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
qreal opacity
The opacity of the window in the windowing system.
std::unique_ptr< QRhiSwapChain > m_sc
std::unique_ptr< QRhiRenderPassDescriptor > m_rp
virtual void customRender()
virtual void customInit()
qDeleteAll(list.begin(), list.end())
QShader getShader(const QString &name)
QRhiShaderResourceBindings * srbLeft
QRhiRenderPassDescriptor * msaaRtRp
QRhiGraphicsPipeline * psRight
QRhiShaderResourceBindings * triSrb
QList< QRhiResource * > releasePool
QRhiGraphicsPipeline * msaaTriPs
QRhiShaderResourceBindings * srbRight
QRhiTextureRenderTarget * rt
QRhiRenderPassDescriptor * rtRp
QRhiGraphicsPipeline * triPs
QRhiTextureRenderTarget * msaaRt
QRhiResourceUpdateBatch * initialUpdates
QRhiGraphicsPipeline * psLeft
SSL_CTX int(* cb)(SSL *ssl, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)