From efc911aa58195d2538be7b0343154038f3a2c3b4 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 26 Feb 2025 15:07:36 +0100 Subject: [PATCH] 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.9 6.8 Change-Id: I440cc10303687b686d78da4c614da4325840803a Reviewed-by: Andy Nichols --- src/gui/rhi/qrhigles2.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index 73e0bc8ee87..5d7f910219d 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -5866,8 +5866,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); @@ -5878,6 +5878,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) {