summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleix Pol <aleixpol@kde.org>2023-11-14 01:23:35 +0100
committerAleix Pol <aleixpol@kde.org>2024-01-31 01:29:40 +0100
commitba9e57d65f15c935632b0ad22db0bead9a7d5f90 (patch)
treee98c3888458859c81438c6666a898f70affbfdfe
parent23d2aaa4f8aefdc395d18162c28493e520e209fc (diff)
QOpenGLFramebufferObject: Avoid illegal call to glTexImage2D
According to the documentation: GL_INVALID_OPERATION is generated if the combination of internalFormat, format and type is not one of those in the tables above. https://registry.khronos.org/OpenGL-Refpages/es3.0/html/glTexImage2D.xhtml We were allowing the RGB values be passed as RGBA, after this change we don't do so anymore. This would result for KWin in: Mesa: User error: GL_INVALID_OPERATION in glTexImage2D(format = GL_RGBA, type = GL_UNSIGNED_BYTE, internalformat = GL_RGB8) Pick-to: 6.5 6.6 6.7 Change-Id: Ifde8a570eff01be573f780655d8cedbb96f5ba2b Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
-rw-r--r--src/opengl/qopenglframebufferobject.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/opengl/qopenglframebufferobject.cpp b/src/opengl/qopenglframebufferobject.cpp
index 379c59a827..75dc8d901e 100644
--- a/src/opengl/qopenglframebufferobject.cpp
+++ b/src/opengl/qopenglframebufferobject.cpp
@@ -550,8 +550,20 @@ void QOpenGLFramebufferObjectPrivate::initTexture(int idx)
else if (color.internalFormat == GL_RGB16F || color.internalFormat == GL_RGBA16F)
pixelType = GL_HALF_FLOAT;
+ bool isOpaque = false;
+ switch (color.internalFormat) {
+ case GL_RGB8:
+ case GL_RGB10:
+ case GL_RGB16:
+ case GL_RGB16F:
+ case GL_RGB32F:
+ isOpaque = true;
+ break;
+ }
+ const GLuint textureFormat = isOpaque ? GL_RGB : GL_RGBA;
+
funcs.glTexImage2D(target, 0, color.internalFormat, color.size.width(), color.size.height(), 0,
- GL_RGBA, pixelType, nullptr);
+ textureFormat, pixelType, nullptr);
if (format.mipmap()) {
int width = color.size.width();
int height = color.size.height();
@@ -560,8 +572,8 @@ void QOpenGLFramebufferObjectPrivate::initTexture(int idx)
width = qMax(1, width >> 1);
height = qMax(1, height >> 1);
++level;
- funcs.glTexImage2D(target, level, color.internalFormat, width, height, 0,
- GL_RGBA, pixelType, nullptr);
+ funcs.glTexImage2D(target, level, color.internalFormat, width, height, 0, textureFormat,
+ pixelType, nullptr);
}
}
funcs.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + idx,