gl: Correctly extract GL version from OpenGL ES version strings

The GL version string returned by glGetString() for GLES doesn't have the
version number at the beginning of the string.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
This commit is contained in:
Alexandros Frantzis 2011-02-14 14:45:52 +02:00 committed by Chris Wilson
parent b1c96f1852
commit f1eef40c2a

View file

@ -38,13 +38,17 @@ _cairo_gl_get_version (void)
int major, minor;
const char *version = (const char *) glGetString (GL_VERSION);
const char *dot = version == NULL ? NULL : strchr (version, '.');
const char *major_start = dot;
/* Sanity check */
if (dot == NULL || dot == version || *(dot + 1) == '\0') {
major = 0;
minor = 0;
} else {
major = strtol (version, NULL, 10);
/* Find the start of the major version in the string */
while (major_start > version && *major_start != ' ')
--major_start;
major = strtol (major_start, NULL, 10);
minor = strtol (dot + 1, NULL, 10);
}