Skip to content

Commit

Permalink
Handle robustness with OpenGL < 4.0
Browse files Browse the repository at this point in the history
We need to have the right idea of robustness, so check for extension.

Fixes: QTBUG-78107
Change-Id: I26987269e5c50bee20e2e3cc6d75f91a6c9af25e
Reviewed-by: Laszlo Agocs <[email protected]>
(cherry picked from commit bc34784)
Reviewed-by: Allan Sandfeld Jensen <[email protected]>
  • Loading branch information
Allan Sandfeld Jensen authored and valdmann committed Sep 13, 2019
1 parent afec593 commit c7b3c5a
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
QT_BEGIN_NAMESPACE

typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
typedef const GLubyte *(*glGetStringiProc)(GLenum, GLuint);

#ifndef GLX_CONTEXT_CORE_PROFILE_BIT_ARB
#define GLX_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
Expand Down Expand Up @@ -145,6 +146,27 @@ static inline QByteArray getGlString(GLenum param)
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)
{
// Update the version, profile, and context bit of the format
Expand All @@ -163,7 +185,7 @@ static void updateFormatFromContext(QSurfaceFormat &format)
format.setOption(QSurfaceFormat::StereoBuffers);

if (format.renderableType() == QSurfaceFormat::OpenGL) {
if (format.version() >= qMakePair(4, 0)) {
if (hasGlExtension(format, "GL_ARB_robustness")) {
GLint value = 0;
glGetIntegerv(GL_RESET_NOTIFICATION_STRATEGY_ARB, &value);
if (value == GL_LOSE_CONTEXT_ON_RESET_ARB)
Expand Down

0 comments on commit c7b3c5a

Please sign in to comment.