rhi: gl: Specify 3D textures with mipmaps correctly

When used with load/store, it is already correct due to using
glTexStorage3D. On the other code path however, individually
calling glTexImage3D for all the mip levels requires adjusting
the depth for each level, as it is done for width and height.

Pick-to: 6.8
Change-Id: I440cc10303687b686d78da4c614da4325840803a
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
(cherry picked from commit efc911aa58195d2538be7b0343154038f3a2c3b4)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Laszlo Agocs 2025-02-26 15:07:36 +01:00 committed by Qt Cherry-pick Bot
parent 982483f134
commit 8dbeacbb5c

View File

@ -5810,8 +5810,8 @@ bool QGles2Texture::create()
rhiD->glTexImage1D(target, level, GLint(glintformat), mipSize.width(), 0,
glformat, gltype, nullptr);
}
} else if (is3D || isArray) {
const int layerCount = is3D ? qMax(1, m_depth) : qMax(0, m_arraySize);
} else if (isArray) {
const int layerCount = qMax(0, m_arraySize);
if (hasMipMaps) {
for (int level = 0; level != mipLevelCount; ++level) {
const QSize mipSize = rhiD->q->sizeForMipLevel(level, size);
@ -5822,6 +5822,19 @@ bool QGles2Texture::create()
rhiD->f->glTexImage3D(target, 0, GLint(glintformat), size.width(), size.height(), layerCount,
0, glformat, gltype, nullptr);
}
} else if (is3D) {
if (hasMipMaps) {
const int depth = qMax(1, m_depth);
for (int level = 0; level != mipLevelCount; ++level) {
const QSize mipSize = rhiD->q->sizeForMipLevel(level, size);
const int mipDepth = rhiD->q->sizeForMipLevel(level, QSize(depth, depth)).width();
rhiD->f->glTexImage3D(target, level, GLint(glintformat), mipSize.width(), mipSize.height(), mipDepth,
0, glformat, gltype, nullptr);
}
} else {
rhiD->f->glTexImage3D(target, 0, GLint(glintformat), size.width(), size.height(), qMax(1, m_depth),
0, glformat, gltype, nullptr);
}
} else if (hasMipMaps || isCube) {
const GLenum faceTargetBase = isCube ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : target;
for (int layer = 0, layerCount = isCube ? 6 : 1; layer != layerCount; ++layer) {