From 66d7b9fb0282a48e91224c28a457458132ca19a2 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Mon, 11 Nov 2013 09:27:07 -0800 Subject: [PATCH] Fix the version detection for GL < 3. Those nice enums came late in the GL spec. This code is copied from piglit, by Matt Turner in 2012. --- src/dispatch_common.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/dispatch_common.c b/src/dispatch_common.c index 49d1b47..8268a93 100644 --- a/src/dispatch_common.c +++ b/src/dispatch_common.c @@ -91,6 +91,7 @@ #include #include #include +#include #include #include "epoxy/gl.h" #include "epoxy/glx.h" @@ -113,12 +114,22 @@ epoxy_is_desktop_gl(void) PUBLIC int epoxy_gl_version(void) { + const char *version = (const char *)glGetString(GL_VERSION); GLint major, minor; + int scanf_count; - glGetIntegerv(GL_MAJOR_VERSION, &major); - glGetIntegerv(GL_MINOR_VERSION, &minor); + /* skip to version number */ + while (!isdigit(*version) && *version != '\0') + version++; - return major * 10 + minor; + /* Interpret version number */ + scanf_count = sscanf(version, "%i.%i", &major, &minor); + if (scanf_count != 2) { + fprintf(stderr, "Unable to interpret GL_VERSION string: %s\n", + version); + exit(1); + } + return 10 * major + minor; } bool