From 94064e9015dcd28738e2aa5fb48420fd9406e8ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9=20Vissers?= Date: Thu, 10 Feb 2022 16:28:56 +0100 Subject: [PATCH] Check if deprecated function works Some systems when using an OpenGL 3.0 or higher context, do not support pre-3.0 functionality, even though a compatibility profile is selected (for OpenGL >= 3.2), the ARB_compatibility extension is supported (for OpenGL 3.1), or OpenGL 3.0 is used which deprecated this functionality but should not remove it. Do a quick test to see if a deprecated function (glGetString(GL_EXTENSIONS)) can be used, and if that does not work, choose a lower version context. --- gl_init.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/gl_init.c b/gl_init.c index 77b0c9b9c..3a8fd20aa 100644 --- a/gl_init.c +++ b/gl_init.c @@ -321,7 +321,19 @@ void init_video(void) SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, versions_to_try[i][2]); el_gl_context = SDL_GL_CreateContext(el_gl_window); if (el_gl_context) - break; + { + // OpenGL deprecated a lot of features we use in OpenGL 3.0, and removed them in + // 3.1. OpenGL. OpenGL 3.2 introduced compatibility profiles, and 3.1 has the + // ARB_compativility extension, but some systems fail with an OpenGL context >= 3.0 + // even when they report compatibility, or when the context is OpenGL 3.0 which should + // still support the old functionality, Therefore, try a deprecated function here, + // and if it fails, downgrade to a lower version context. + const GLubyte* extensions_str = glGetString(GL_EXTENSIONS); + DO_CHECK_GL_ERRORS(); + if (extensions_str) + // That seemd to work, hopefully we're good + break; + } } if (el_gl_context == NULL) {