Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
elmindreda committed Jul 18, 2016
1 parent ac09592 commit 52d801b
Showing 1 changed file with 40 additions and 56 deletions.
96 changes: 40 additions & 56 deletions src/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,56 +34,6 @@
#include <stdio.h>


// Parses the client API version string and extracts the version number
//
static GLFWbool parseVersionString(int* api, int* major, int* minor, int* rev)
{
int i;
_GLFWwindow* window;
const char* version;
const char* prefixes[] =
{
"OpenGL ES-CM ",
"OpenGL ES-CL ",
"OpenGL ES ",
NULL
};

*api = GLFW_OPENGL_API;

window = _glfwPlatformGetCurrentContext();

version = (const char*) window->context.GetString(GL_VERSION);
if (!version)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Client API version string retrieval is broken");
return GLFW_FALSE;
}

for (i = 0; prefixes[i]; i++)
{
const size_t length = strlen(prefixes[i]);

if (strncmp(version, prefixes[i], length) == 0)
{
version += length;
*api = GLFW_OPENGL_ES_API;
break;
}
}

if (!sscanf(version, "%d.%d.%d", major, minor, rev))
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"No version found in client API version string");
return GLFW_FALSE;
}

return GLFW_TRUE;
}


//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -369,7 +319,21 @@ const _GLFWfbconfig* _glfwChooseFBConfig(const _GLFWfbconfig* desired,

GLFWbool _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig)
{
_GLFWwindow* window = _glfwPlatformGetCurrentContext();
int i;
_GLFWwindow* window;
const char* version;
const char* prefixes[] =
{
"OpenGL ES-CM ",
"OpenGL ES-CL ",
"OpenGL ES ",
NULL
};

window = _glfwPlatformGetCurrentContext();

window->context.source = ctxconfig->source;
window->context.client = GLFW_OPENGL_API;

window->context.GetIntegerv = (PFNGLGETINTEGERVPROC)
window->context.getProcAddress("glGetIntegerv");
Expand All @@ -381,15 +345,35 @@ GLFWbool _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig)
return GLFW_FALSE;
}

if (!parseVersionString(&window->context.client,
&window->context.major,
&window->context.minor,
&window->context.revision))
version = (const char*) window->context.GetString(GL_VERSION);
if (!version)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Client API version string retrieval is broken");
return GLFW_FALSE;
}

window->context.source = ctxconfig->source;
for (i = 0; prefixes[i]; i++)
{
const size_t length = strlen(prefixes[i]);

if (strncmp(version, prefixes[i], length) == 0)
{
version += length;
window->context.client = GLFW_OPENGL_ES_API;
break;
}
}

if (!sscanf(version, "%d.%d.%d",
&window->context.major,
&window->context.minor,
&window->context.revision))
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"No version found in client API version string");
return GLFW_FALSE;
}

if (window->context.major < ctxconfig->major ||
(window->context.major == ctxconfig->major &&
Expand Down

0 comments on commit 52d801b

Please sign in to comment.