Removed commented-out code, added error reporting.

This commit is contained in:
Camilla Berglund 2012-07-23 18:40:31 +02:00
parent 3bb04b3a76
commit a3c4b96c91

View File

@ -39,58 +39,39 @@
// Parses the client API version string and extracts the version number // Parses the client API version string and extracts the version number
//======================================================================== //========================================================================
static void parseGLVersion(int* major, int* minor, int* rev) static GLboolean parseGLVersion(int* major, int* minor, int* rev)
{ {
GLuint _major, _minor = 0, _rev = 0; GLuint _major, _minor = 0, _rev = 0;
const GLubyte* version; const char* version;
version = glGetString(GL_VERSION); version = (const char*) glGetString(GL_VERSION);
if (!version) if (!version)
return;
#if 0
// Old version detection code. This doesn't work very well
const GLubyte* ptr;
const char* glesPrefix = "OpenGL ES ";
if (strncmp((const char*) version, glesPrefix, strlen(glesPrefix)) == 0)
{ {
// The version string on OpenGL ES has a prefix before the version _glfwSetError(GLFW_PLATFORM_ERROR,
// number, so we skip past it and then continue as normal "X11/EGL: No version string available");
return GL_FALSE;
version += strlen(glesPrefix);
} }
// Parse version from string for (;;)
ptr = version;
for (_major = 0; *ptr >= '0' && *ptr <= '9'; ptr++)
_major = 10 * _major + (*ptr - '0');
if (*ptr == '.')
{ {
ptr++; if (*version != '\0')
for (_minor = 0; *ptr >= '0' && *ptr <= '9'; ptr++)
_minor = 10 * _minor + (*ptr - '0');
if (*ptr == '.')
{ {
ptr++; _glfwSetError(GLFW_PLATFORM_ERROR,
for (_rev = 0; *ptr >= '0' && *ptr <= '9'; ptr++) "X11/EGL: No version found in version string");
_rev = 10 * _rev + (*ptr - '0'); return GL_FALSE;
} }
if (sscanf(version, "%d.%d.%d", &_major, &_minor, &_rev))
break;
version++;
} }
#endif
// Find version from OpenGL string
for (; version &&
!sscanf((char*)version, "%d.%d.%d", &_major, &_minor, &_rev);
++version);
// Store result
*major = _major; *major = _major;
*minor = _minor; *minor = _minor;
*rev = _rev; *rev = _rev;
return GL_TRUE;
} }
@ -402,7 +383,8 @@ GLboolean _glfwIsValidContext(_GLFWwindow* window, _GLFWwndconfig* wndconfig)
{ {
window->clientAPI = wndconfig->clientAPI; window->clientAPI = wndconfig->clientAPI;
parseGLVersion(&window->glMajor, &window->glMinor, &window->glRevision); if (!parseGLVersion(&window->glMajor, &window->glMinor, &window->glRevision))
return GL_FALSE;
// Read back forward-compatibility flag // Read back forward-compatibility flag
{ {