Add run-time context creation API selection

Fixes #145.
This commit is contained in:
Camilla Berglund
2016-03-28 13:19:31 +02:00
parent 9d50a346f0
commit ef80beab81
32 changed files with 806 additions and 804 deletions
+48 -19
View File
@@ -90,17 +90,26 @@ static GLFWbool parseVersionString(int* api, int* major, int* minor, int* rev)
GLFWbool _glfwIsValidContextConfig(const _GLFWctxconfig* ctxconfig)
{
if (ctxconfig->api != GLFW_NO_API &&
ctxconfig->api != GLFW_OPENGL_API &&
ctxconfig->api != GLFW_OPENGL_ES_API)
if (ctxconfig->source != GLFW_NATIVE_CONTEXT_API &&
ctxconfig->source != GLFW_EGL_CONTEXT_API)
{
_glfwInputError(GLFW_INVALID_ENUM,
"Invalid client API %i",
ctxconfig->api);
"Invalid context creation API %i",
ctxconfig->source);
return GLFW_FALSE;
}
if (ctxconfig->api == GLFW_OPENGL_API)
if (ctxconfig->client != GLFW_NO_API &&
ctxconfig->client != GLFW_OPENGL_API &&
ctxconfig->client != GLFW_OPENGL_ES_API)
{
_glfwInputError(GLFW_INVALID_ENUM,
"Invalid client API %i",
ctxconfig->client);
return GLFW_FALSE;
}
if (ctxconfig->client == GLFW_OPENGL_API)
{
if ((ctxconfig->major < 1 || ctxconfig->minor < 0) ||
(ctxconfig->major == 1 && ctxconfig->minor > 5) ||
@@ -150,7 +159,7 @@ GLFWbool _glfwIsValidContextConfig(const _GLFWctxconfig* ctxconfig)
return GLFW_FALSE;
}
}
else if (ctxconfig->api == GLFW_OPENGL_ES_API)
else if (ctxconfig->client == GLFW_OPENGL_ES_API)
{
if (ctxconfig->major < 1 || ctxconfig->minor < 0 ||
(ctxconfig->major == 1 && ctxconfig->minor > 1) ||
@@ -366,8 +375,13 @@ GLFWbool _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig)
glfwGetProcAddress("glGetIntegerv");
window->context.GetString = (PFNGLGETSTRINGPROC)
glfwGetProcAddress("glGetString");
if (!window->context.GetIntegerv || !window->context.GetString)
{
_glfwInputError(GLFW_PLATFORM_ERROR, "Entry point retrieval is broken");
return GLFW_FALSE;
}
if (!parseVersionString(&window->context.api,
if (!parseVersionString(&window->context.client,
&window->context.major,
&window->context.minor,
&window->context.revision))
@@ -375,6 +389,8 @@ GLFWbool _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig)
return GLFW_FALSE;
}
window->context.source = ctxconfig->source;
if (window->context.major < ctxconfig->major ||
(window->context.major == ctxconfig->major &&
window->context.minor < ctxconfig->minor))
@@ -409,7 +425,7 @@ GLFWbool _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig)
}
}
if (window->context.api == GLFW_OPENGL_API)
if (window->context.client == GLFW_OPENGL_API)
{
// Read back context flags (OpenGL 3.0 and above)
if (window->context.major >= 3)
@@ -507,7 +523,7 @@ GLFWbool _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig)
{
PFNGLCLEARPROC glClear = (PFNGLCLEARPROC) glfwGetProcAddress("glClear");
glClear(GL_COLOR_BUFFER_BIT);
_glfwPlatformSwapBuffers(window);
window->context.swapBuffers(window);
}
return GLFW_TRUE;
@@ -547,16 +563,24 @@ GLFWbool _glfwStringInExtensionString(const char* string, const char* extensions
GLFWAPI void glfwMakeContextCurrent(GLFWwindow* handle)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
_GLFWwindow* previous = _glfwPlatformGetCurrentContext();
_GLFW_REQUIRE_INIT();
if (window && window->context.api == GLFW_NO_API)
if (window && window->context.client == GLFW_NO_API)
{
_glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
return;
}
_glfwPlatformMakeContextCurrent(window);
if (previous)
{
if (!window || window->context.source != previous->context.source)
previous->context.makeContextCurrent(NULL);
}
if (window)
window->context.makeContextCurrent(window);
}
GLFWAPI GLFWwindow* glfwGetCurrentContext(void)
@@ -572,26 +596,29 @@ GLFWAPI void glfwSwapBuffers(GLFWwindow* handle)
_GLFW_REQUIRE_INIT();
if (window->context.api == GLFW_NO_API)
if (window->context.client == GLFW_NO_API)
{
_glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
return;
}
_glfwPlatformSwapBuffers(window);
window->context.swapBuffers(window);
}
GLFWAPI void glfwSwapInterval(int interval)
{
_GLFWwindow* window;
_GLFW_REQUIRE_INIT();
if (!_glfwPlatformGetCurrentContext())
window = _glfwPlatformGetCurrentContext();
if (!window)
{
_glfwInputError(GLFW_NO_CURRENT_CONTEXT, NULL);
return;
}
_glfwPlatformSwapInterval(interval);
window->context.swapInterval(interval);
}
GLFWAPI int glfwExtensionSupported(const char* extension)
@@ -657,21 +684,23 @@ GLFWAPI int glfwExtensionSupported(const char* extension)
}
// Check if extension is in the platform-specific string
return _glfwPlatformExtensionSupported(extension);
return window->context.extensionSupported(extension);
}
GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname)
{
_GLFWwindow* window;
assert(procname != NULL);
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
if (!_glfwPlatformGetCurrentContext())
window = _glfwPlatformGetCurrentContext();
if (!window)
{
_glfwInputError(GLFW_NO_CURRENT_CONTEXT, NULL);
return NULL;
}
return _glfwPlatformGetProcAddress(procname);
return window->context.getProcAddress(procname);
}