Commit 52c77e47 authored by Laszlo Agocs's avatar Laszlo Agocs
Browse files

Clean up qrhi.h

parent 55b6fd85
...@@ -67,20 +67,20 @@ void QRhiResource::releaseAndDestroy() ...@@ -67,20 +67,20 @@ void QRhiResource::releaseAndDestroy()
QRhiBuffer::QRhiBuffer(QRhiImplementation *rhi, Type type_, UsageFlags usage_, int size_) QRhiBuffer::QRhiBuffer(QRhiImplementation *rhi, Type type_, UsageFlags usage_, int size_)
: QRhiResource(rhi), : QRhiResource(rhi),
type(type_), usage(usage_), size(size_) m_type(type_), m_usage(usage_), m_size(size_)
{ {
} }
QRhiRenderBuffer::QRhiRenderBuffer(QRhiImplementation *rhi, Type type_, const QSize &pixelSize_, QRhiRenderBuffer::QRhiRenderBuffer(QRhiImplementation *rhi, Type type_, const QSize &pixelSize_,
int sampleCount_, Hints hints_) int sampleCount_, Hints hints_)
: QRhiResource(rhi), : QRhiResource(rhi),
type(type_), pixelSize(pixelSize_), sampleCount(sampleCount_), hints(hints_) m_type(type_), m_pixelSize(pixelSize_), m_sampleCount(sampleCount_), m_hints(hints_)
{ {
} }
QRhiTexture::QRhiTexture(QRhiImplementation *rhi, Format format_, const QSize &pixelSize_, Flags flags_) QRhiTexture::QRhiTexture(QRhiImplementation *rhi, Format format_, const QSize &pixelSize_, Flags flags_)
: QRhiResource(rhi), : QRhiResource(rhi),
format(format_), pixelSize(pixelSize_), flags(flags_) m_format(format_), m_pixelSize(pixelSize_), m_flags(flags_)
{ {
} }
...@@ -88,8 +88,8 @@ QRhiSampler::QRhiSampler(QRhiImplementation *rhi, ...@@ -88,8 +88,8 @@ QRhiSampler::QRhiSampler(QRhiImplementation *rhi,
Filter magFilter_, Filter minFilter_, Filter mipmapMode_, Filter magFilter_, Filter minFilter_, Filter mipmapMode_,
AddressMode u_, AddressMode v_, AddressMode w_) AddressMode u_, AddressMode v_, AddressMode w_)
: QRhiResource(rhi), : QRhiResource(rhi),
magFilter(magFilter_), minFilter(minFilter_), mipmapMode(mipmapMode_), m_magFilter(magFilter_), m_minFilter(minFilter_), m_mipmapMode(mipmapMode_),
addressU(u_), addressV(v_), addressW(w_) m_addressU(u_), m_addressV(v_), m_addressW(w_)
{ {
} }
...@@ -112,8 +112,8 @@ QRhiTextureRenderTarget::QRhiTextureRenderTarget(QRhiImplementation *rhi, ...@@ -112,8 +112,8 @@ QRhiTextureRenderTarget::QRhiTextureRenderTarget(QRhiImplementation *rhi,
const QRhiTextureRenderTargetDescription &desc_, const QRhiTextureRenderTargetDescription &desc_,
Flags flags_) Flags flags_)
: QRhiRenderTarget(rhi), : QRhiRenderTarget(rhi),
desc(desc_), m_desc(desc_),
flags(flags_) m_flags(flags_)
{ {
} }
...@@ -122,10 +122,10 @@ QRhiShaderResourceBindings::QRhiShaderResourceBindings(QRhiImplementation *rhi) ...@@ -122,10 +122,10 @@ QRhiShaderResourceBindings::QRhiShaderResourceBindings(QRhiImplementation *rhi)
{ {
} }
QRhiShaderResourceBindings::Binding QRhiShaderResourceBindings::Binding::uniformBuffer( QRhiShaderResourceBinding QRhiShaderResourceBinding::uniformBuffer(
int binding_, StageFlags stage_, QRhiBuffer *buf_) int binding_, StageFlags stage_, QRhiBuffer *buf_)
{ {
Binding b; QRhiShaderResourceBinding b;
b.binding = binding_; b.binding = binding_;
b.stage = stage_; b.stage = stage_;
b.type = UniformBuffer; b.type = UniformBuffer;
...@@ -135,11 +135,11 @@ QRhiShaderResourceBindings::Binding QRhiShaderResourceBindings::Binding::uniform ...@@ -135,11 +135,11 @@ QRhiShaderResourceBindings::Binding QRhiShaderResourceBindings::Binding::uniform
return b; return b;
} }
QRhiShaderResourceBindings::Binding QRhiShaderResourceBindings::Binding::uniformBuffer( QRhiShaderResourceBinding QRhiShaderResourceBinding::uniformBuffer(
int binding_, StageFlags stage_, QRhiBuffer *buf_, int offset_, int size_) int binding_, StageFlags stage_, QRhiBuffer *buf_, int offset_, int size_)
{ {
Q_ASSERT(size_ > 0); Q_ASSERT(size_ > 0);
Binding b; QRhiShaderResourceBinding b;
b.binding = binding_; b.binding = binding_;
b.stage = stage_; b.stage = stage_;
b.type = UniformBuffer; b.type = UniformBuffer;
...@@ -149,10 +149,10 @@ QRhiShaderResourceBindings::Binding QRhiShaderResourceBindings::Binding::uniform ...@@ -149,10 +149,10 @@ QRhiShaderResourceBindings::Binding QRhiShaderResourceBindings::Binding::uniform
return b; return b;
} }
QRhiShaderResourceBindings::Binding QRhiShaderResourceBindings::Binding::sampledTexture( QRhiShaderResourceBinding QRhiShaderResourceBinding::sampledTexture(
int binding_, StageFlags stage_, QRhiTexture *tex_, QRhiSampler *sampler_) int binding_, StageFlags stage_, QRhiTexture *tex_, QRhiSampler *sampler_)
{ {
Binding b; QRhiShaderResourceBinding b;
b.binding = binding_; b.binding = binding_;
b.stage = stage_; b.stage = stage_;
b.type = SampledTexture; b.type = SampledTexture;
...@@ -265,7 +265,7 @@ void QRhiResourceUpdateBatch::uploadStaticBuffer(QRhiBuffer *buf, const void *da ...@@ -265,7 +265,7 @@ void QRhiResourceUpdateBatch::uploadStaticBuffer(QRhiBuffer *buf, const void *da
d->staticBufferUploads.append({ buf, data }); d->staticBufferUploads.append({ buf, data });
} }
void QRhiResourceUpdateBatch::uploadTexture(QRhiTexture *tex, const TextureUploadDescription &desc) void QRhiResourceUpdateBatch::uploadTexture(QRhiTexture *tex, const QRhiTextureUploadDescription &desc)
{ {
d->textureUploads.append({ tex, desc }); d->textureUploads.append({ tex, desc });
} }
......
This diff is collapsed.
...@@ -130,7 +130,7 @@ struct QRhiResourceUpdateBatchPrivate ...@@ -130,7 +130,7 @@ struct QRhiResourceUpdateBatchPrivate
struct StaticBufferUpload { struct StaticBufferUpload {
StaticBufferUpload() { } StaticBufferUpload() { }
StaticBufferUpload(QRhiBuffer *buf_, const void *data_) StaticBufferUpload(QRhiBuffer *buf_, const void *data_)
: buf(buf_), data(reinterpret_cast<const char *>(data_), buf_->size) : buf(buf_), data(reinterpret_cast<const char *>(data_), buf_->size())
{ } { }
QRhiBuffer *buf = nullptr; QRhiBuffer *buf = nullptr;
...@@ -139,12 +139,12 @@ struct QRhiResourceUpdateBatchPrivate ...@@ -139,12 +139,12 @@ struct QRhiResourceUpdateBatchPrivate
struct TextureUpload { struct TextureUpload {
TextureUpload() { } TextureUpload() { }
TextureUpload(QRhiTexture *tex_, const QRhiResourceUpdateBatch::TextureUploadDescription &desc_) TextureUpload(QRhiTexture *tex_, const QRhiTextureUploadDescription &desc_)
: tex(tex_), desc(desc_) : tex(tex_), desc(desc_)
{ } { }
QRhiTexture *tex = nullptr; QRhiTexture *tex = nullptr;
QRhiResourceUpdateBatch::TextureUploadDescription desc; QRhiTextureUploadDescription desc;
}; };
QVector<DynamicBufferUpdate> dynamicBufferUpdates; QVector<DynamicBufferUpdate> dynamicBufferUpdates;
......
This diff is collapsed.
...@@ -60,6 +60,7 @@ struct QD3D11Buffer : public QRhiBuffer ...@@ -60,6 +60,7 @@ struct QD3D11Buffer : public QRhiBuffer
QByteArray dynBuf; QByteArray dynBuf;
bool hasPendingDynamicUpdates = false; bool hasPendingDynamicUpdates = false;
uint generation = 0; uint generation = 0;
friend class QRhiD3D11;
}; };
struct QD3D11RenderBuffer : public QRhiRenderBuffer struct QD3D11RenderBuffer : public QRhiRenderBuffer
...@@ -71,6 +72,7 @@ struct QD3D11RenderBuffer : public QRhiRenderBuffer ...@@ -71,6 +72,7 @@ struct QD3D11RenderBuffer : public QRhiRenderBuffer
ID3D11Texture2D *tex = nullptr; ID3D11Texture2D *tex = nullptr;
ID3D11DepthStencilView *dsv = nullptr; ID3D11DepthStencilView *dsv = nullptr;
friend class QRhiD3D11;
}; };
struct QD3D11Texture : public QRhiTexture struct QD3D11Texture : public QRhiTexture
...@@ -83,6 +85,7 @@ struct QD3D11Texture : public QRhiTexture ...@@ -83,6 +85,7 @@ struct QD3D11Texture : public QRhiTexture
ID3D11ShaderResourceView *srv = nullptr; ID3D11ShaderResourceView *srv = nullptr;
uint mipLevelCount = 0; uint mipLevelCount = 0;
uint generation = 0; uint generation = 0;
friend class QRhiD3D11;
}; };
struct QD3D11Sampler : public QRhiSampler struct QD3D11Sampler : public QRhiSampler
...@@ -94,6 +97,7 @@ struct QD3D11Sampler : public QRhiSampler ...@@ -94,6 +97,7 @@ struct QD3D11Sampler : public QRhiSampler
ID3D11SamplerState *samplerState = nullptr; ID3D11SamplerState *samplerState = nullptr;
uint generation = 0; uint generation = 0;
friend class QRhiD3D11;
}; };
struct QD3D11RenderPass : public QRhiRenderPass struct QD3D11RenderPass : public QRhiRenderPass
...@@ -140,6 +144,7 @@ struct QD3D11TextureRenderTarget : public QRhiTextureRenderTarget ...@@ -140,6 +144,7 @@ struct QD3D11TextureRenderTarget : public QRhiTextureRenderTarget
ID3D11RenderTargetView *rtv[QD3D11RenderPass::MAX_COLOR_ATTACHMENTS]; ID3D11RenderTargetView *rtv[QD3D11RenderPass::MAX_COLOR_ATTACHMENTS];
bool ownsDsv = false; bool ownsDsv = false;
ID3D11DepthStencilView *dsv = nullptr; ID3D11DepthStencilView *dsv = nullptr;
friend class QRhiD3D11;
}; };
template<typename T> template<typename T>
...@@ -187,7 +192,7 @@ struct QD3D11ShaderResourceBindings : public QRhiShaderResourceBindings ...@@ -187,7 +192,7 @@ struct QD3D11ShaderResourceBindings : public QRhiShaderResourceBindings
void release() override; void release() override;
bool build() override; bool build() override;
QVector<Binding> sortedBindings; QVector<QRhiShaderResourceBinding> sortedBindings;
uint generation = 0; uint generation = 0;
// Keep track of the generation number of each referenced QRhi* to be able // Keep track of the generation number of each referenced QRhi* to be able
...@@ -220,6 +225,8 @@ struct QD3D11ShaderResourceBindings : public QRhiShaderResourceBindings ...@@ -220,6 +225,8 @@ struct QD3D11ShaderResourceBindings : public QRhiShaderResourceBindings
QD3D11BatchedBindings<ID3D11SamplerState *> fssamplers; QD3D11BatchedBindings<ID3D11SamplerState *> fssamplers;
QD3D11BatchedBindings<ID3D11ShaderResourceView *> fsshaderresources; QD3D11BatchedBindings<ID3D11ShaderResourceView *> fsshaderresources;
friend class QRhiD3D11;
}; };
struct QD3D11GraphicsPipeline : public QRhiGraphicsPipeline struct QD3D11GraphicsPipeline : public QRhiGraphicsPipeline
...@@ -236,6 +243,7 @@ struct QD3D11GraphicsPipeline : public QRhiGraphicsPipeline ...@@ -236,6 +243,7 @@ struct QD3D11GraphicsPipeline : public QRhiGraphicsPipeline
D3D11_PRIMITIVE_TOPOLOGY d3dTopology = D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST; D3D11_PRIMITIVE_TOPOLOGY d3dTopology = D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
ID3D11RasterizerState *rastState = nullptr; ID3D11RasterizerState *rastState = nullptr;
uint generation = 0; uint generation = 0;
friend class QRhiD3D11;
}; };
struct QD3D11SwapChain; struct QD3D11SwapChain;
......
...@@ -216,10 +216,10 @@ void QRhiGles2::setGraphicsPipeline(QRhiCommandBuffer *cb, QRhiGraphicsPipeline ...@@ -216,10 +216,10 @@ void QRhiGles2::setGraphicsPipeline(QRhiCommandBuffer *cb, QRhiGraphicsPipeline
{ {
Q_ASSERT(inPass); Q_ASSERT(inPass);
QGles2GraphicsPipeline *psD = QRHI_RES(QGles2GraphicsPipeline, ps);
if (!srb) if (!srb)
srb = ps->shaderResourceBindings; srb = psD->m_shaderResourceBindings;
QGles2GraphicsPipeline *psD = QRHI_RES(QGles2GraphicsPipeline, ps);
QGles2ShaderResourceBindings *srbD = QRHI_RES(QGles2ShaderResourceBindings, srb); QGles2ShaderResourceBindings *srbD = QRHI_RES(QGles2ShaderResourceBindings, srb);
QGles2CommandBuffer *cbD = QRHI_RES(QGles2CommandBuffer, cb); QGles2CommandBuffer *cbD = QRHI_RES(QGles2CommandBuffer, cb);
...@@ -251,7 +251,7 @@ void QRhiGles2::setVertexInput(QRhiCommandBuffer *cb, int startBinding, const QV ...@@ -251,7 +251,7 @@ void QRhiGles2::setVertexInput(QRhiCommandBuffer *cb, int startBinding, const QV
QRhiBuffer *buf = bindings[i].first; QRhiBuffer *buf = bindings[i].first;
quint32 ofs = bindings[i].second; quint32 ofs = bindings[i].second;
QGles2Buffer *bufD = QRHI_RES(QGles2Buffer, buf); QGles2Buffer *bufD = QRHI_RES(QGles2Buffer, buf);
Q_ASSERT(buf->usage.testFlag(QRhiBuffer::VertexBuffer)); Q_ASSERT(bufD->m_usage.testFlag(QRhiBuffer::VertexBuffer));
QGles2CommandBuffer::Command cmd; QGles2CommandBuffer::Command cmd;
cmd.cmd = QGles2CommandBuffer::Command::BindVertexBuffer; cmd.cmd = QGles2CommandBuffer::Command::BindVertexBuffer;
cmd.args.bindVertexBuffer.ps = cbD->currentPipeline; cmd.args.bindVertexBuffer.ps = cbD->currentPipeline;
...@@ -263,7 +263,7 @@ void QRhiGles2::setVertexInput(QRhiCommandBuffer *cb, int startBinding, const QV ...@@ -263,7 +263,7 @@ void QRhiGles2::setVertexInput(QRhiCommandBuffer *cb, int startBinding, const QV
if (indexBuf) { if (indexBuf) {
QGles2Buffer *ibufD = QRHI_RES(QGles2Buffer, indexBuf); QGles2Buffer *ibufD = QRHI_RES(QGles2Buffer, indexBuf);
Q_ASSERT(indexBuf->usage.testFlag(QRhiBuffer::IndexBuffer)); Q_ASSERT(ibufD->m_usage.testFlag(QRhiBuffer::IndexBuffer));
QGles2CommandBuffer::Command cmd; QGles2CommandBuffer::Command cmd;
cmd.cmd = QGles2CommandBuffer::Command::BindIndexBuffer; cmd.cmd = QGles2CommandBuffer::Command::BindIndexBuffer;
cmd.args.bindIndexBuffer.buffer = ibufD->buffer; cmd.args.bindIndexBuffer.buffer = ibufD->buffer;
...@@ -394,9 +394,9 @@ void QRhiGles2::commitResourceUpdates(QRhiResourceUpdateBatch *resourceUpdates) ...@@ -394,9 +394,9 @@ void QRhiGles2::commitResourceUpdates(QRhiResourceUpdateBatch *resourceUpdates)
QRhiResourceUpdateBatchPrivate *ud = QRhiResourceUpdateBatchPrivate::get(resourceUpdates); QRhiResourceUpdateBatchPrivate *ud = QRhiResourceUpdateBatchPrivate::get(resourceUpdates);
for (const QRhiResourceUpdateBatchPrivate::DynamicBufferUpdate &u : ud->dynamicBufferUpdates) { for (const QRhiResourceUpdateBatchPrivate::DynamicBufferUpdate &u : ud->dynamicBufferUpdates) {
Q_ASSERT(u.buf->type == QRhiBuffer::Dynamic);
QGles2Buffer *bufD = QRHI_RES(QGles2Buffer, u.buf); QGles2Buffer *bufD = QRHI_RES(QGles2Buffer, u.buf);
if (u.buf->usage.testFlag(QRhiBuffer::UniformBuffer)) { Q_ASSERT(bufD->m_type == QRhiBuffer::Dynamic);
if (bufD->m_usage.testFlag(QRhiBuffer::UniformBuffer)) {
memcpy(bufD->ubuf.data() + u.offset, u.data.constData(), u.data.size()); memcpy(bufD->ubuf.data() + u.offset, u.data.constData(), u.data.size());
QGles2Buffer::ChangeRange &r(bufD->ubufChangeRange); QGles2Buffer::ChangeRange &r(bufD->ubufChangeRange);
if (r.changeBegin == -1 || u.offset < r.changeBegin) if (r.changeBegin == -1 || u.offset < r.changeBegin)
...@@ -410,10 +410,10 @@ void QRhiGles2::commitResourceUpdates(QRhiResourceUpdateBatch *resourceUpdates) ...@@ -410,10 +410,10 @@ void QRhiGles2::commitResourceUpdates(QRhiResourceUpdateBatch *resourceUpdates)
} }
for (const QRhiResourceUpdateBatchPrivate::StaticBufferUpload &u : ud->staticBufferUploads) { for (const QRhiResourceUpdateBatchPrivate::StaticBufferUpload &u : ud->staticBufferUploads) {
Q_ASSERT(u.buf->type != QRhiBuffer::Dynamic);
Q_ASSERT(u.data.size() == u.buf->size);
QGles2Buffer *bufD = QRHI_RES(QGles2Buffer, u.buf); QGles2Buffer *bufD = QRHI_RES(QGles2Buffer, u.buf);
if (u.buf->usage.testFlag(QRhiBuffer::UniformBuffer)) { Q_ASSERT(bufD->m_type != QRhiBuffer::Dynamic);
Q_ASSERT(u.data.size() == bufD->m_size);
if (bufD->m_usage.testFlag(QRhiBuffer::UniformBuffer)) {
memcpy(bufD->ubuf.data(), u.data.constData(), u.data.size()); memcpy(bufD->ubuf.data(), u.data.constData(), u.data.size());
bufD->ubufChangeRange = { 0, u.data.size() }; bufD->ubufChangeRange = { 0, u.data.size() };
} else { } else {
...@@ -424,13 +424,13 @@ void QRhiGles2::commitResourceUpdates(QRhiResourceUpdateBatch *resourceUpdates) ...@@ -424,13 +424,13 @@ void QRhiGles2::commitResourceUpdates(QRhiResourceUpdateBatch *resourceUpdates)
for (const QRhiResourceUpdateBatchPrivate::TextureUpload &u : ud->textureUploads) { for (const QRhiResourceUpdateBatchPrivate::TextureUpload &u : ud->textureUploads) {
QGles2Texture *texD = QRHI_RES(QGles2Texture, u.tex); QGles2Texture *texD = QRHI_RES(QGles2Texture, u.tex);
const bool isCubeMap = texD->flags.testFlag(QRhiTexture::CubeMap); const bool isCubeMap = texD->m_flags.testFlag(QRhiTexture::CubeMap);
const GLenum targetBase = isCubeMap ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : texD->target; const GLenum targetBase = isCubeMap ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : texD->target;
for (int layer = 0, layerCount = u.desc.layers.count(); layer != layerCount; ++layer) { for (int layer = 0, layerCount = u.desc.layers.count(); layer != layerCount; ++layer) {
const QRhiResourceUpdateBatch::TextureUploadDescription::Layer &layerDesc(u.desc.layers[layer]); const QRhiTextureUploadDescription::Layer &layerDesc(u.desc.layers[layer]);
f->glBindTexture(targetBase + layer, texD->texture); f->glBindTexture(targetBase + layer, texD->texture);
for (int level = 0, levelCount = layerDesc.mipImages.count(); level != levelCount; ++level) { for (int level = 0, levelCount = layerDesc.mipImages.count(); level != levelCount; ++level) {
const QRhiResourceUpdateBatch::TextureUploadDescription::Layer::MipLevel mipDesc(layerDesc.mipImages[level]); const QRhiTextureUploadDescription::Layer::MipLevel mipDesc(layerDesc.mipImages[level]);
f->glTexSubImage2D(targetBase + layer, level, f->glTexSubImage2D(targetBase + layer, level,
0, 0, mipDesc.image.width(), mipDesc.image.height(), 0, 0, mipDesc.image.width(), mipDesc.image.height(),
texD->glformat, texD->gltype, mipDesc.image.constBits()); texD->glformat, texD->gltype, mipDesc.image.constBits());
...@@ -676,10 +676,10 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb) ...@@ -676,10 +676,10 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb)
break; break;
case QGles2CommandBuffer::Command::StencilRef: case QGles2CommandBuffer::Command::StencilRef:
{ {
QGles2GraphicsPipeline *ps = QRHI_RES(QGles2GraphicsPipeline, cmd.args.stencilRef.ps); QGles2GraphicsPipeline *psD = QRHI_RES(QGles2GraphicsPipeline, cmd.args.stencilRef.ps);
if (ps) { if (psD) {
f->glStencilFuncSeparate(GL_FRONT, toGlCompareOp(ps->stencilFront.compareOp), cmd.args.stencilRef.ref, ps->stencilReadMask); f->glStencilFuncSeparate(GL_FRONT, toGlCompareOp(psD->m_stencilFront.compareOp), cmd.args.stencilRef.ref, psD->m_stencilReadMask);
f->glStencilFuncSeparate(GL_BACK, toGlCompareOp(ps->stencilBack.compareOp), cmd.args.stencilRef.ref, ps->stencilReadMask); f->glStencilFuncSeparate(GL_BACK, toGlCompareOp(psD->m_stencilBack.compareOp), cmd.args.stencilRef.ref, psD->m_stencilReadMask);
} else { } else {
qWarning("No graphics pipeline active for setStencilRef; ignored"); qWarning("No graphics pipeline active for setStencilRef; ignored");
} }
...@@ -687,16 +687,16 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb) ...@@ -687,16 +687,16 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb)
break; break;
case QGles2CommandBuffer::Command::BindVertexBuffer: case QGles2CommandBuffer::Command::BindVertexBuffer:
{ {
QGles2GraphicsPipeline *ps = QRHI_RES(QGles2GraphicsPipeline, cmd.args.bindVertexBuffer.ps); QGles2GraphicsPipeline *psD = QRHI_RES(QGles2GraphicsPipeline, cmd.args.bindVertexBuffer.ps);
if (ps) { if (psD) {
for (const QRhiVertexInputLayout::Attribute &a : ps->vertexInputLayout.attributes) { for (const QRhiVertexInputLayout::Attribute &a : psD->m_vertexInputLayout.attributes) {
if (a.binding != cmd.args.bindVertexBuffer.binding) if (a.binding != cmd.args.bindVertexBuffer.binding)
continue; continue;
// we do not support more than one vertex buffer // we do not support more than one vertex buffer
f->glBindBuffer(GL_ARRAY_BUFFER, cmd.args.bindVertexBuffer.buffer); f->glBindBuffer(GL_ARRAY_BUFFER, cmd.args.bindVertexBuffer.buffer);
const int stride = ps->vertexInputLayout.bindings[a.binding].stride; const int stride = psD->m_vertexInputLayout.bindings[a.binding].stride;
int size = 1; int size = 1;
GLenum type = GL_FLOAT; GLenum type = GL_FLOAT;
switch (a.format) { switch (a.format) {
...@@ -749,19 +749,19 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb) ...@@ -749,19 +749,19 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb)
break; break;
case QGles2CommandBuffer::Command::Draw: case QGles2CommandBuffer::Command::Draw:
{ {
QGles2GraphicsPipeline *ps = QRHI_RES(QGles2GraphicsPipeline, cmd.args.draw.ps); QGles2GraphicsPipeline *psD = QRHI_RES(QGles2GraphicsPipeline, cmd.args.draw.ps);
if (ps) if (psD)
f->glDrawArrays(ps->drawMode, cmd.args.draw.firstVertex, cmd.args.draw.vertexCount); f->glDrawArrays(psD->drawMode, cmd.args.draw.firstVertex, cmd.args.draw.vertexCount);
else else
qWarning("No graphics pipeline active for draw; ignored"); qWarning("No graphics pipeline active for draw; ignored");
} }
break; break;
case QGles2CommandBuffer::Command::DrawIndexed: case QGles2CommandBuffer::Command::DrawIndexed:
{ {
QGles2GraphicsPipeline *ps = QRHI_RES(QGles2GraphicsPipeline, cmd.args.drawIndexed.ps); QGles2GraphicsPipeline *psD = QRHI_RES(QGles2GraphicsPipeline, cmd.args.drawIndexed.ps);
if (ps) { if (psD) {
quint32 ofs = cmd.args.drawIndexed.firstIndex * indexStride + indexOffset; quint32 ofs = cmd.args.drawIndexed.firstIndex * indexStride + indexOffset;
f->glDrawElements(ps->drawMode, f->glDrawElements(psD->drawMode,
cmd.args.drawIndexed.indexCount, cmd.args.drawIndexed.indexCount,
indexType, indexType,
reinterpret_cast<const GLvoid *>(quintptr(ofs))); reinterpret_cast<const GLvoid *>(quintptr(ofs)));
...@@ -814,19 +814,19 @@ void QRhiGles2::executeBindGraphicsPipeline(QRhiGraphicsPipeline *ps, QRhiShader ...@@ -814,19 +814,19 @@ void QRhiGles2::executeBindGraphicsPipeline(QRhiGraphicsPipeline *ps, QRhiShader
// ### this needs some proper caching later on to minimize state changes // ### this needs some proper caching later on to minimize state changes
if (ps->flags.testFlag(QRhiGraphicsPipeline::UsesScissor)) if (psD->m_flags.testFlag(QRhiGraphicsPipeline::UsesScissor))
f->glEnable(GL_SCISSOR_TEST); f->glEnable(GL_SCISSOR_TEST);
else else
f->glDisable(GL_SCISSOR_TEST); f->glDisable(GL_SCISSOR_TEST);
if (ps->cullMode == QRhiGraphicsPipeline::None) { if (psD->m_cullMode == QRhiGraphicsPipeline::None) {
f->glDisable(GL_CULL_FACE); f->glDisable(GL_CULL_FACE);
} else { } else {
f->glEnable(GL_CULL_FACE); f->glEnable(GL_CULL_FACE);
f->glCullFace(toGlCullMode(ps->cullMode)); f->glCullFace(toGlCullMode(psD->m_cullMode));
} }
f->glFrontFace(toGlFrontFace(ps->frontFace)); f->glFrontFace(toGlFrontFace(psD->m_frontFace));
if (!ps->targetBlends.isEmpty()) { if (!psD->m_targetBlends.isEmpty()) {
const QRhiGraphicsPipeline::TargetBlend &blend(ps->targetBlends.first()); // no MRT const QRhiGraphicsPipeline::TargetBlend &blend(psD->m_targetBlends.first()); // no MRT
GLboolean wr = blend.colorWrite.testFlag(QRhiGraphicsPipeline::R); GLboolean wr = blend.colorWrite.testFlag(QRhiGraphicsPipeline::R);
GLboolean wg = blend.colorWrite.testFlag(QRhiGraphicsPipeline::G); GLboolean wg = blend.colorWrite.testFlag(QRhiGraphicsPipeline::G);
GLboolean wb = blend.colorWrite.testFlag(QRhiGraphicsPipeline::B); GLboolean wb = blend.colorWrite.testFlag(QRhiGraphicsPipeline::B);
...@@ -845,29 +845,29 @@ void QRhiGles2::executeBindGraphicsPipeline(QRhiGraphicsPipeline *ps, QRhiShader ...@@ -845,29 +845,29 @@ void QRhiGles2::executeBindGraphicsPipeline(QRhiGraphicsPipeline *ps, QRhiShader
} else { } else {
f->glDisable(GL_BLEND); f->glDisable(GL_BLEND);
} }
if (ps->depthTest) if (psD->m_depthTest)
f->glEnable(GL_DEPTH_TEST); f->glEnable(GL_DEPTH_TEST);
else else
f->glDisable(GL_DEPTH_TEST); f->glDisable(GL_DEPTH_TEST);
if (ps->depthWrite) if (psD->m_depthWrite)
f->glDepthMask(GL_TRUE); f->glDepthMask(GL_TRUE);
else else
f->glDepthMask(GL_FALSE); f->glDepthMask(GL_FALSE);
f->glDepthFunc(toGlCompareOp(ps->depthOp)); f->glDepthFunc(toGlCompareOp(psD->m_depthOp));
if (ps->stencilTest) { if (psD->m_stencilTest) {
f->glEnable(GL_STENCIL_TEST); f->glEnable(GL_STENCIL_TEST);
f->glStencilFuncSeparate(GL_FRONT, toGlCompareOp(ps->stencilFront.compareOp), 0, ps->stencilReadMask); f->glStencilFuncSeparate(GL_FRONT, toGlCompareOp(psD->m_stencilFront.compareOp), 0, psD->m_stencilReadMask);
f->glStencilOpSeparate(GL_FRONT, f->glStencilOpSeparate(GL_FRONT,
toGlStencilOp(ps->stencilFront.failOp), toGlStencilOp(psD->m_stencilFront.failOp),
toGlStencilOp(ps->stencilFront.depthFailOp), toGlStencilOp(psD->m_stencilFront.depthFailOp),
toGlStencilOp(ps->stencilFront.passOp)); toGlStencilOp(psD->m_stencilFront.passOp));
f->glStencilMaskSeparate(GL_FRONT, ps->stencilWriteMask); f->glStencilMaskSeparate(GL_FRONT, psD->m_stencilWriteMask);
f->glStencilFuncSeparate(GL_BACK, toGlCompareOp(ps->stencilBack.compareOp), 0, ps->stencilReadMask); f->glStencilFuncSeparate(GL_BACK, toGlCompareOp(psD->m_stencilBack.compareOp), 0, psD->m_stencilReadMask);
f->glStencilOpSeparate(GL_BACK, f->glStencilOpSeparate(GL_BACK,
toGlStencilOp(ps->stencilBack.failOp), toGlStencilOp(psD->m_stencilBack.failOp),
toGlStencilOp(ps->stencilBack.depthFailOp), toGlStencilOp(psD->m_stencilBack.depthFailOp),
toGlStencilOp(ps->stencilBack.passOp)); toGlStencilOp(psD->m_stencilBack.passOp));
f->glStencilMaskSeparate(GL_BACK, ps->stencilWriteMask); f->glStencilMaskSeparate(GL_BACK, psD->m_stencilWriteMask);
} else { } else {
f->glDisable(GL_STENCIL_TEST); f->glDisable(GL_STENCIL_TEST);
} }
...@@ -879,16 +879,17 @@ void QRhiGles2::executeBindGraphicsPipeline(QRhiGraphicsPipeline *ps, QRhiShader ...@@ -879,16 +879,17 @@ void QRhiGles2::executeBindGraphicsPipeline(QRhiGraphicsPipeline *ps, QRhiShader
void QRhiGles2::setChangedUniforms(QGles2GraphicsPipeline *psD, QRhiShaderResourceBindings *srb, bool changedOnly) void QRhiGles2::setChangedUniforms(QGles2GraphicsPipeline *psD, QRhiShaderResourceBindings *srb, bool changedOnly)
{ {
for (int i = 0, ie = srb->bindings.count(); i != ie; ++i) { QGles2ShaderResourceBindings *srbD = QRHI_RES(QGles2ShaderResourceBindings, srb);
const QRhiShaderResourceBindings::Binding &b(srb->bindings[i]); for (int i = 0, ie = srbD->m_bindings.count(); i != ie; ++i) {
const QRhiShaderResourceBinding &b(srbD->m_bindings[i]);
switch (b.type) { switch (b.type) {
case QRhiShaderResourceBindings::Binding::UniformBuffer: case QRhiShaderResourceBinding::UniformBuffer:
{ {
QGles2Buffer *bufD = QRHI_RES(QGles2Buffer, b.ubuf.buf); QGles2Buffer *bufD = QRHI_RES(QGles2Buffer, b.ubuf.buf);
if (changedOnly && bufD->ubufChangeRange.isNull()) // do not set again when nothing changed if (changedOnly && bufD->ubufChangeRange.isNull()) // do not set again when nothing changed
break; break;
const QByteArray bufView = QByteArray::fromRawData(bufD->ubuf.constData() + b.ubuf.offset, const QByteArray bufView = QByteArray::fromRawData(bufD->ubuf.constData() + b.ubuf.offset,
b.ubuf.maybeSize ? b.ubuf.maybeSize : bufD->size); b.ubuf.maybeSize ? b.ubuf.maybeSize : bufD->m_size);
for (QGles2GraphicsPipeline::Uniform &uniform : psD->uniforms) { for (QGles2GraphicsPipeline::Uniform &uniform : psD->uniforms) {
if (uniform.binding == b.binding if (uniform.binding == b.binding
&& (!changedOnly || && (!changedOnly ||
...@@ -941,7 +942,7 @@ void QRhiGles2::setChangedUniforms(QGles2GraphicsPipeline *psD, QRhiShaderResour ...@@ -941,7 +942,7 @@ void QRhiGles2::setChangedUniforms(QGles2GraphicsPipeline *psD, QRhiShaderResour
bufD->ubufChangeRange = QGles2Buffer::ChangeRange(); bufD->ubufChangeRange = QGles2Buffer::ChangeRange();
} }
break; break;
case QRhiShaderResourceBindings::Binding::SampledTexture: case QRhiShaderResourceBinding::SampledTexture: