From aaba67eea940e933f97fc6232d2d7d637575b095 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 22 Feb 2024 17:26:55 +0100 Subject: [PATCH] rhi: gl: Fix multisample texture specification ...so that MSAA is actually effective. Pick-to: 6.6 Change-Id: I4bf85df1312773ec29154a51c9c8464912e6ef8a Reviewed-by: Andy Nichols (cherry picked from commit 46366a14a41ec6db5ab4ab72c473a4a4e187d484) Reviewed-by: Qt Cherry-pick Bot --- src/gui/rhi/qrhigles2.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index 32b1ad97521..09bbbcf0443 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -5462,8 +5462,16 @@ bool QGles2Texture::create() } } } else { - rhiD->f->glTexImage2D(target, 0, GLint(glintformat), size.width(), size.height(), - 0, glformat, gltype, nullptr); + // 2D texture. For multisample textures the GLES 3.1 + // glStorage2DMultisample must be used for portability. + if (m_sampleCount > 1 && rhiD->caps.multisampledTexture) { + // internal format must be sized + rhiD->f->glTexStorage2DMultisample(target, m_sampleCount, glsizedintformat, + size.width(), size.height(), GL_TRUE); + } else { + rhiD->f->glTexImage2D(target, 0, GLint(glintformat), size.width(), size.height(), + 0, glformat, gltype, nullptr); + } } } else { // Must be specified with immutable storage functions otherwise @@ -5474,6 +5482,9 @@ bool QGles2Texture::create() else if (!is1D && (is3D || isArray)) rhiD->f->glTexStorage3D(target, mipLevelCount, glsizedintformat, size.width(), size.height(), is3D ? qMax(1, m_depth) : qMax(0, m_arraySize)); + else if (m_sampleCount > 1) + rhiD->f->glTexStorage2DMultisample(target, m_sampleCount, glsizedintformat, + size.width(), size.height(), GL_TRUE); else rhiD->f->glTexStorage2D(target, mipLevelCount, glsizedintformat, size.width(), is1D ? qMax(0, m_arraySize) : size.height());