[Scummvm-git-logs] scummvm branch-2-8 -> 0e7aefa351afa028d44b6070616de1ad889f589a
sev-
noreply at scummvm.org
Thu Dec 14 17:37:47 UTC 2023
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
0e7aefa351 OPENGL: Use GLAD version when available and check functions before use
Commit: 0e7aefa351afa028d44b6070616de1ad889f589a
https://github.com/scummvm/scummvm/commit/0e7aefa351afa028d44b6070616de1ad889f589a
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2023-12-14T18:37:42+01:00
Commit Message:
OPENGL: Use GLAD version when available and check functions before use
When GLAD fails to parse version, glGetError is null and raises a
SIGSEGV.
Current version of GLAD has a bug while parsing extensions so there is a
workaround here which should disappear when it's fixed.
Changed paths:
graphics/opengl/context.cpp
diff --git a/graphics/opengl/context.cpp b/graphics/opengl/context.cpp
index cde9011a241..ae8105129c4 100644
--- a/graphics/opengl/context.cpp
+++ b/graphics/opengl/context.cpp
@@ -84,56 +84,77 @@ void Context::initialize(ContextType contextType) {
type = contextType;
#ifdef USE_GLAD
+ int gladVersion;
switch (type) {
case kContextGL:
- gladLoadGL(loadFunc);
+ gladVersion = gladLoadGL(loadFunc);
break;
case kContextGLES:
- gladLoadGLES1(loadFunc);
+ gladVersion = gladLoadGLES1(loadFunc);
break;
case kContextGLES2:
- gladLoadGLES2(loadFunc);
+ gladVersion = gladLoadGLES2(loadFunc);
break;
default:
+ gladVersion = 0;
break;
}
-#endif
- const char *verString = (const char *)glGetString(GL_VERSION);
+ majorVersion = GLAD_VERSION_MAJOR(gladVersion);
+ minorVersion = GLAD_VERSION_MINOR(gladVersion);
- if (!verString) {
- majorVersion = minorVersion = 0;
- warning("Could not parse fetch GL_VERSION: %d", glGetError());
- } else if (type == kContextGL) {
- // OpenGL version number is either of the form major.minor or major.minor.release,
- // where the numbers all have one or more digits
- if (sscanf(verString, "%d.%d", &majorVersion, &minorVersion) != 2) {
- majorVersion = minorVersion = 0;
- warning("Could not parse GL version '%s'", verString);
+ if (!gladVersion)
+ // If gladVersion is 0 it either means:
+ // - loading failed and glad didn't even set up core functions
+ // - we are hit by GLAD bug #446 which fails to parse some extensions
+ // In this case just try to do the parsing by ourselves
+#endif
+ {
+ if (!glGetString) {
+ error("Couldn't initialize OpenGL");
}
- } else if (type == kContextGLES) {
- // The form of the string is "OpenGL ES-<profile> <major>.<minor>",
- // where <profile> is either "CM" (Common) or "CL" (Common-Lite),
- // and <major> and <minor> are integers.
- char profile[3];
- if (sscanf(verString, "OpenGL ES-%2s %d.%d", profile,
- &majorVersion, &minorVersion) != 3) {
+
+ const char *verString = (const char *)glGetString(GL_VERSION);
+
+ if (!verString) {
majorVersion = minorVersion = 0;
- warning("Could not parse GL ES version '%s'", verString);
- }
- } else if (type == kContextGLES2) {
- // The version is of the form
- // OpenGL<space>ES<space><version number><space><vendor-specific information>
- // version number format is not defined
- // There is only OpenGL ES 2.0 anyway
- if (sscanf(verString, "OpenGL ES %d.%d", &majorVersion, &minorVersion) != 2) {
- minorVersion = 0;
- if (sscanf(verString, "OpenGL ES %d ", &majorVersion) != 1) {
- majorVersion = 0;
- warning("Could not parse GL ES 2 version '%s'", verString);
+ int errorCode = 0;
+ if (glGetError) {
+ errorCode = glGetError();
+ }
+ warning("Could not fetch GL_VERSION: %d", errorCode);
+ return;
+ } else if (type == kContextGL) {
+ // OpenGL version number is either of the form major.minor or major.minor.release,
+ // where the numbers all have one or more digits
+ if (sscanf(verString, "%d.%d", &majorVersion, &minorVersion) != 2) {
+ majorVersion = minorVersion = 0;
+ warning("Could not parse GL version '%s'", verString);
+ }
+ } else if (type == kContextGLES) {
+ // The form of the string is "OpenGL ES-<profile> <major>.<minor>",
+ // where <profile> is either "CM" (Common) or "CL" (Common-Lite),
+ // and <major> and <minor> are integers.
+ char profile[3];
+ if (sscanf(verString, "OpenGL ES-%2s %d.%d", profile,
+ &majorVersion, &minorVersion) != 3) {
+ majorVersion = minorVersion = 0;
+ warning("Could not parse GL ES version '%s'", verString);
+ }
+ } else if (type == kContextGLES2) {
+ // The version is of the form
+ // OpenGL<space>ES<space><version number><space><vendor-specific information>
+ // version number format is not defined
+ // There is only OpenGL ES 2.0 anyway
+ if (sscanf(verString, "OpenGL ES %d.%d", &majorVersion, &minorVersion) != 2) {
+ minorVersion = 0;
+ if (sscanf(verString, "OpenGL ES %d ", &majorVersion) != 1) {
+ majorVersion = 0;
+ warning("Could not parse GL ES 2 version '%s'", verString);
+ }
}
}
}
@@ -294,7 +315,7 @@ void Context::initialize(ContextType contextType) {
const char *glslVersionString = (const char *)glGetString(GL_SHADING_LANGUAGE_VERSION);
// Log features supported by GL context.
- debug(5, "OpenGL version: %s", verString);
+ debug(5, "OpenGL version: %s", glGetString(GL_VERSION));
debug(5, "OpenGL vendor: %s", glGetString(GL_VENDOR));
debug(5, "OpenGL renderer: %s", glGetString(GL_RENDERER));
debug(5, "OpenGL: version %d.%d", majorVersion, minorVersion);
More information about the Scummvm-git-logs
mailing list