diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2023-05-24 14:26:49 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2023-05-30 10:29:55 +0200 |
commit | 09597d05f7cb966c9bdc659caa2a8a0a2f6f29b5 (patch) | |
tree | 329b6b2304d7cad138723c540f43b446f1978745 /src/gui/rhi/qrhigles2.cpp | |
parent | afe0bf0914362ff6f8e83ebd17f6cc346805a072 (diff) |
rhi: avoid backends modifying the frontend depth and arraySize
Buffer and texture sizes (size, pixelSize) may get increased, if needed,
but those actual sizes calculated by the QRhi backends are not written
back to the QRhiBuffer m_size or QRhiTexture m_pixelSize.
In contrast, both m_depth and m_arraySize are clamped in QRhiTexture
by most backends (to ensure a lower bound of 1 and 0, respectively).
This is not great since it means the getters for depth() and arraySize()
may return values different from what the user has provided. To avoid
confusion, do not modify the m_* variables.
Change-Id: I2cc5b9abf41ea108549ffd7f2403306e6e8ebba2
Reviewed-by: Jonas Karlsson <jonas.karlsson@qt.io>
Diffstat (limited to 'src/gui/rhi/qrhigles2.cpp')
-rw-r--r-- | src/gui/rhi/qrhigles2.cpp | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index 806e17c1a6..37e3373c21 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -2239,6 +2239,8 @@ void QRhiGles2::enqueueSubresUpload(QGles2Texture *texD, QGles2CommandBuffer *cb cmd.args.subImage.rowLength = 0; cmd.args.subImage.data = cbD->retainImage(img); } else if (!rawData.isEmpty() && isCompressed) { + const int depth = qMax(1, texD->m_depth); + const int arraySize = qMax(0, texD->m_arraySize); if ((texD->flags().testFlag(QRhiTexture::UsedAsCompressedAtlas) || is3D || isArray) && !texD->zeroInitialized) { @@ -2250,9 +2252,9 @@ void QRhiGles2::enqueueSubresUpload(QGles2Texture *texD, QGles2CommandBuffer *cb quint32 byteSize = 0; compressedFormatInfo(texD->m_format, texD->m_pixelSize, nullptr, &byteSize, nullptr); if (is3D) - byteSize *= texD->m_depth; + byteSize *= depth; if (isArray) - byteSize *= texD->m_arraySize; + byteSize *= arraySize; QByteArray zeroBuf(byteSize, 0); QGles2CommandBuffer::Command &cmd(cbD->commands.get()); cmd.cmd = QGles2CommandBuffer::Command::CompressedImage; @@ -2262,9 +2264,8 @@ void QRhiGles2::enqueueSubresUpload(QGles2Texture *texD, QGles2CommandBuffer *cb cmd.args.compressedImage.level = level; cmd.args.compressedImage.glintformat = texD->glintformat; cmd.args.compressedImage.w = texD->m_pixelSize.width(); - cmd.args.compressedImage.h = - is1D && isArray ? texD->m_arraySize : texD->m_pixelSize.height(); - cmd.args.compressedImage.depth = is3D ? texD->m_depth : (isArray ? texD->m_arraySize : 0); + cmd.args.compressedImage.h = is1D && isArray ? arraySize : texD->m_pixelSize.height(); + cmd.args.compressedImage.depth = is3D ? depth : (isArray ? arraySize : 0); cmd.args.compressedImage.size = byteSize; cmd.args.compressedImage.data = cbD->retainData(zeroBuf); texD->zeroInitialized = true; @@ -2296,8 +2297,8 @@ void QRhiGles2::enqueueSubresUpload(QGles2Texture *texD, QGles2CommandBuffer *cb cmd.args.compressedImage.level = level; cmd.args.compressedImage.glintformat = texD->glintformat; cmd.args.compressedImage.w = size.width(); - cmd.args.compressedImage.h = is1D && isArray ? texD->m_arraySize : size.height(); - cmd.args.compressedImage.depth = is3D ? texD->m_depth : (isArray ? texD->m_arraySize : 0); + cmd.args.compressedImage.h = is1D && isArray ? arraySize : size.height(); + cmd.args.compressedImage.depth = is3D ? depth : (isArray ? arraySize : 0); cmd.args.compressedImage.size = rawData.size(); cmd.args.compressedImage.data = cbD->retainData(rawData); } @@ -5209,12 +5210,10 @@ bool QGles2Texture::prepareCreate(QSize *adjustedSize) return false; } - m_depth = qMax(1, m_depth); if (m_depth > 1 && !is3D) { qWarning("Texture cannot have a depth of %d when it is not 3D", m_depth); return false; } - m_arraySize = qMax(0, m_arraySize); if (m_arraySize > 0 && !isArray) { qWarning("Texture cannot have an array size of %d when it is not an array", m_arraySize); return false; @@ -5289,13 +5288,13 @@ bool QGles2Texture::create() const QSize mipSize = rhiD->q->sizeForMipLevel(level, size); if (isArray) rhiD->f->glTexImage2D(target, level, GLint(glintformat), mipSize.width(), - m_arraySize, 0, glformat, gltype, nullptr); + qMax(0, m_arraySize), 0, glformat, gltype, nullptr); else rhiD->glTexImage1D(target, level, GLint(glintformat), mipSize.width(), 0, glformat, gltype, nullptr); } } else if (is3D || isArray) { - const int layerCount = is3D ? m_depth : m_arraySize; + const int layerCount = is3D ? qMax(1, m_depth) : qMax(0, m_arraySize); if (hasMipMaps) { for (int level = 0; level != mipLevelCount; ++level) { const QSize mipSize = rhiD->q->sizeForMipLevel(level, size); @@ -5327,10 +5326,11 @@ bool QGles2Texture::create() if (is1D && !isArray) rhiD->glTexStorage1D(target, mipLevelCount, glsizedintformat, size.width()); else if (!is1D && (is3D || isArray)) - rhiD->f->glTexStorage3D(target, mipLevelCount, glsizedintformat, size.width(), size.height(), is3D ? m_depth : m_arraySize); + rhiD->f->glTexStorage3D(target, mipLevelCount, glsizedintformat, size.width(), size.height(), + is3D ? qMax(1, m_depth) : qMax(0, m_arraySize)); else rhiD->f->glTexStorage2D(target, mipLevelCount, glsizedintformat, size.width(), - is1D ? m_arraySize : size.height()); + is1D ? qMax(0, m_arraySize) : size.height()); } specified = true; } else { |