From 00470662e3ec296cd0619e1a5a71aebcb32d9a8a Mon Sep 17 00:00:00 2001 From: Berthold Krevert Date: Wed, 21 May 2014 14:23:30 +0200 Subject: Fix a crash when using QtQuickControls with core profile QOpenGLContext::versionFunctions returns 0, if a QOpenGLFunctions object for a legacy OpenGL version is requested while using the core profile. This leads to a crash QOpenGLContextPrivate::maxTextureSize() Change-Id: I32845643094336cebcc666806a411524fe3e869b Reviewed-by: Laszlo Agocs Reviewed-by: Sean Harmer --- src/gui/kernel/qopenglcontext.cpp | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'src/gui/kernel/qopenglcontext.cpp') diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp index 012e384d72..c7f4e6455c 100644 --- a/src/gui/kernel/qopenglcontext.cpp +++ b/src/gui/kernel/qopenglcontext.cpp @@ -63,6 +63,7 @@ #ifndef QT_OPENGL_ES_2 #include +#include #endif QT_BEGIN_NAMESPACE @@ -370,9 +371,25 @@ int QOpenGLContextPrivate::maxTextureSize() GLint size; GLint next = 64; funcs->glTexImage2D(proxy, 0, GL_RGBA, next, next, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); - QOpenGLFunctions_1_0 *gl1funcs = q->versionFunctions(); - gl1funcs->initializeOpenGLFunctions(); - gl1funcs->glGetTexLevelParameteriv(proxy, 0, GL_TEXTURE_WIDTH, &size); + + QOpenGLFunctions_1_0 *gl1funcs = 0; + QOpenGLFunctions_3_2_Core *gl3funcs = 0; + + if (q->format().profile() == QSurfaceFormat::CoreProfile) { + gl3funcs = q->versionFunctions(); + gl3funcs->initializeOpenGLFunctions(); + } else { + gl1funcs = q->versionFunctions(); + gl1funcs->initializeOpenGLFunctions(); + } + + Q_ASSERT(gl1funcs || gl3funcs); + + if (gl1funcs) + gl1funcs->glGetTexLevelParameteriv(proxy, 0, GL_TEXTURE_WIDTH, &size); + else + gl3funcs->glGetTexLevelParameteriv(proxy, 0, GL_TEXTURE_WIDTH, &size); + if (size == 0) { return max_texture_size; } @@ -383,7 +400,11 @@ int QOpenGLContextPrivate::maxTextureSize() if (next > max_texture_size) break; funcs->glTexImage2D(proxy, 0, GL_RGBA, next, next, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); - gl1funcs->glGetTexLevelParameteriv(proxy, 0, GL_TEXTURE_WIDTH, &next); + if (gl1funcs) + gl1funcs->glGetTexLevelParameteriv(proxy, 0, GL_TEXTURE_WIDTH, &next); + else + gl3funcs->glGetTexLevelParameteriv(proxy, 0, GL_TEXTURE_WIDTH, &next); + } while (next > size); max_texture_size = size; -- cgit v1.2.3