Handle robustness with OpenGL < 4.0

We need to have the right idea of robustness, so check for extension.

Fixes: QTBUG-78107
Change-Id: I26987269e5c50bee20e2e3cc6d75f91a6c9af25e
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
(cherry picked from commit bc34784d053ebf9b0d167e9398052fcc80d8af87)
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
This commit is contained in:
Allan Sandfeld Jensen 2019-09-08 10:27:47 +02:00 committed by Jüri Valdmann
parent afec5935ea
commit c7b3c5a082

View File

@ -63,6 +63,7 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*); typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
typedef const GLubyte *(*glGetStringiProc)(GLenum, GLuint);
#ifndef GLX_CONTEXT_CORE_PROFILE_BIT_ARB #ifndef GLX_CONTEXT_CORE_PROFILE_BIT_ARB
#define GLX_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 #define GLX_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
@ -145,6 +146,27 @@ static inline QByteArray getGlString(GLenum param)
return QByteArray(); return QByteArray();
} }
static bool hasGlExtension(const QSurfaceFormat &format, const char *ext)
{
if (format.majorVersion() < 3) {
auto exts = reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS));
return exts && strstr(exts, ext);
} else {
auto glGetStringi = reinterpret_cast<glGetStringiProc>(
glXGetProcAddress(reinterpret_cast<const GLubyte*>("glGetStringi")));
if (glGetStringi) {
GLint n = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &n);
for (GLint i = 0; i < n; ++i) {
const char *p = reinterpret_cast<const char *>(glGetStringi(GL_EXTENSIONS, i));
if (p && !strcmp(p, ext))
return true;
}
}
return false;
}
}
static void updateFormatFromContext(QSurfaceFormat &format) static void updateFormatFromContext(QSurfaceFormat &format)
{ {
// Update the version, profile, and context bit of the format // Update the version, profile, and context bit of the format
@ -163,7 +185,7 @@ static void updateFormatFromContext(QSurfaceFormat &format)
format.setOption(QSurfaceFormat::StereoBuffers); format.setOption(QSurfaceFormat::StereoBuffers);
if (format.renderableType() == QSurfaceFormat::OpenGL) { if (format.renderableType() == QSurfaceFormat::OpenGL) {
if (format.version() >= qMakePair(4, 0)) { if (hasGlExtension(format, "GL_ARB_robustness")) {
GLint value = 0; GLint value = 0;
glGetIntegerv(GL_RESET_NOTIFICATION_STRATEGY_ARB, &value); glGetIntegerv(GL_RESET_NOTIFICATION_STRATEGY_ARB, &value);
if (value == GL_LOSE_CONTEXT_ON_RESET_ARB) if (value == GL_LOSE_CONTEXT_ON_RESET_ARB)