mirror of
https://github.com/gwm17/glfw.git
synced 2024-11-23 10:48:51 -05:00
Imported version parsing from EGL branch.
This commit is contained in:
parent
59896c327a
commit
208377d08e
50
src/opengl.c
50
src/opengl.c
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
|
@ -40,47 +41,38 @@
|
||||||
|
|
||||||
static GLboolean parseGLVersion(int* major, int* minor, int* rev)
|
static GLboolean parseGLVersion(int* major, int* minor, int* rev)
|
||||||
{
|
{
|
||||||
GLuint _major, _minor = 0, _rev = 0;
|
int i, _major, _minor = 0, _rev = 0;
|
||||||
const GLubyte* version;
|
const char* version;
|
||||||
const GLubyte* ptr;
|
const char* prefixes[] =
|
||||||
const char* glesPrefix = "OpenGL ES ";
|
{
|
||||||
|
"OpenGL ES ",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
version = glGetString(GL_VERSION);
|
version = (const char*) glGetString(GL_VERSION);
|
||||||
if (!version)
|
if (!version)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR, "Failed to retrieve version string");
|
_glfwSetError(GLFW_PLATFORM_ERROR, "Failed to retrieve version string");
|
||||||
return;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strncmp((const char*) version, glesPrefix, strlen(glesPrefix)) == 0)
|
for (i = 0; prefixes[i]; i++)
|
||||||
{
|
{
|
||||||
// The version string on OpenGL ES has a prefix before the version
|
const size_t length = strlen(prefixes[i]);
|
||||||
// number, so we skip past it and then continue as normal
|
|
||||||
|
|
||||||
version += strlen(glesPrefix);
|
if (strncmp(version, prefixes[i], length) == 0)
|
||||||
}
|
|
||||||
|
|
||||||
// Parse version from string
|
|
||||||
|
|
||||||
ptr = version;
|
|
||||||
for (_major = 0; *ptr >= '0' && *ptr <= '9'; ptr++)
|
|
||||||
_major = 10 * _major + (*ptr - '0');
|
|
||||||
|
|
||||||
if (*ptr == '.')
|
|
||||||
{
|
|
||||||
ptr++;
|
|
||||||
for (_minor = 0; *ptr >= '0' && *ptr <= '9'; ptr++)
|
|
||||||
_minor = 10 * _minor + (*ptr - '0');
|
|
||||||
|
|
||||||
if (*ptr == '.')
|
|
||||||
{
|
{
|
||||||
ptr++;
|
version += length;
|
||||||
for (_rev = 0; *ptr >= '0' && *ptr <= '9'; ptr++)
|
break;
|
||||||
_rev = 10 * _rev + (*ptr - '0');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store result
|
if (!sscanf(version, "%d.%d.%d", &_major, &_minor, &_rev))
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_PLATFORM_ERROR, "No version found in version string");
|
||||||
|
return GL_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
*major = _major;
|
*major = _major;
|
||||||
*minor = _minor;
|
*minor = _minor;
|
||||||
*rev = _rev;
|
*rev = _rev;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user