Commit 8be7158a authored by Doug Binks's avatar Doug Binks Committed by Degrande Samuel
Browse files

Improved User Context Win32 implementation

_glfwCreateContextWGL and _glfwPlatformCreateUserContext now use  new function _glfwCreateContextForDCWGL.
parent 7fcb11f4
...@@ -538,46 +538,17 @@ void _glfwTerminateWGL(void) ...@@ -538,46 +538,17 @@ void _glfwTerminateWGL(void)
attribs[index++] = v; \ attribs[index++] = v; \
} }
// Create the OpenGL or OpenGL ES context // Create the OpenGL or OpenGL ES context for the given HDC
// //
GLFWbool _glfwCreateContextWGL(_GLFWwindow* window, GLFWbool _glfwCreateContextForDCWGL(HDC dc, const _GLFWctxconfig* ctxconfig, HGLRC* context)
const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig)
{ {
int attribs[40]; int attribs[40];
int pixelFormat;
PIXELFORMATDESCRIPTOR pfd;
HGLRC share = NULL; HGLRC share = NULL;
*context = NULL;
if (ctxconfig->share) if (ctxconfig->share)
share = ctxconfig->share->context.wgl.handle; share = ctxconfig->share->context.wgl.handle;
window->context.wgl.dc = GetDC(window->win32.handle);
if (!window->context.wgl.dc)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"WGL: Failed to retrieve DC for window");
return GLFW_FALSE;
}
pixelFormat = choosePixelFormat(window, ctxconfig, fbconfig);
if (!pixelFormat)
return GLFW_FALSE;
if (!DescribePixelFormat(window->context.wgl.dc,
pixelFormat, sizeof(pfd), &pfd))
{
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
"WGL: Failed to retrieve PFD for selected pixel format");
return GLFW_FALSE;
}
if (!SetPixelFormat(window->context.wgl.dc, pixelFormat, &pfd))
{
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
"WGL: Failed to set selected pixel format");
return GLFW_FALSE;
}
if (ctxconfig->client == GLFW_OPENGL_API) if (ctxconfig->client == GLFW_OPENGL_API)
{ {
...@@ -692,9 +663,9 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window, ...@@ -692,9 +663,9 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window,
setAttrib(0, 0); setAttrib(0, 0);
window->context.wgl.handle = *context =
wglCreateContextAttribsARB(window->context.wgl.dc, share, attribs); wglCreateContextAttribsARB(dc, share, attribs);
if (!window->context.wgl.handle) if (!(*context))
{ {
const DWORD error = GetLastError(); const DWORD error = GetLastError();
...@@ -744,8 +715,8 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window, ...@@ -744,8 +715,8 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window,
} }
else else
{ {
window->context.wgl.handle = wglCreateContext(window->context.wgl.dc); *context = wglCreateContext(dc);
if (!window->context.wgl.handle) if (!(*context) )
{ {
_glfwInputErrorWin32(GLFW_VERSION_UNAVAILABLE, _glfwInputErrorWin32(GLFW_VERSION_UNAVAILABLE,
"WGL: Failed to create OpenGL context"); "WGL: Failed to create OpenGL context");
...@@ -754,7 +725,7 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window, ...@@ -754,7 +725,7 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window,
if (share) if (share)
{ {
if (!wglShareLists(share, window->context.wgl.handle)) if (!wglShareLists(share, *context))
{ {
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR, _glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
"WGL: Failed to enable sharing with specified OpenGL context"); "WGL: Failed to enable sharing with specified OpenGL context");
...@@ -763,6 +734,50 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window, ...@@ -763,6 +734,50 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window,
} }
} }
return GLFW_TRUE;
}
// Create the OpenGL or OpenGL ES context
//
GLFWbool _glfwCreateContextWGL(_GLFWwindow* window,
const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig)
{
int pixelFormat;
PIXELFORMATDESCRIPTOR pfd;
window->context.wgl.dc = GetDC(window->win32.handle);
if (!window->context.wgl.dc)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"WGL: Failed to retrieve DC for window");
return GLFW_FALSE;
}
pixelFormat = choosePixelFormat(window, ctxconfig, fbconfig);
if (!pixelFormat)
return GLFW_FALSE;
if (!DescribePixelFormat(window->context.wgl.dc,
pixelFormat, sizeof(pfd), &pfd))
{
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
"WGL: Failed to retrieve PFD for selected pixel format");
return GLFW_FALSE;
}
if (!SetPixelFormat(window->context.wgl.dc, pixelFormat, &pfd))
{
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
"WGL: Failed to set selected pixel format");
return GLFW_FALSE;
}
if(!_glfwCreateContextForDCWGL( window->context.wgl.dc, ctxconfig, &window->context.wgl.handle ))
{
return GLFW_FALSE;
}
window->context.makeCurrent = makeContextCurrentWGL; window->context.makeCurrent = makeContextCurrentWGL;
window->context.swapBuffers = swapBuffersWGL; window->context.swapBuffers = swapBuffersWGL;
window->context.swapInterval = swapIntervalWGL; window->context.swapInterval = swapIntervalWGL;
...@@ -783,25 +798,22 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window, ...@@ -783,25 +798,22 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window,
_GLFWusercontext* _glfwPlatformCreateUserContext(_GLFWwindow* window) _GLFWusercontext* _glfwPlatformCreateUserContext(_GLFWwindow* window)
{ {
_GLFWusercontext* context; _GLFWusercontext* context;
context = calloc(1, sizeof(_GLFWusercontext)); _GLFWctxconfig ctxconfig;
context->handle = wglCreateContext(window->context.wgl.dc); context = calloc(1, sizeof(_GLFWusercontext));
context->window = window; context->window = window;
if (!context->handle)
{
_glfwInputErrorWin32(GLFW_VERSION_UNAVAILABLE,
"WGL: Failed to create user OpenGL context");
free(context);
return GLFW_FALSE;
}
if (!wglShareLists(window->context.wgl.handle,context->handle)) ctxconfig = _glfw.hints.context;
ctxconfig.share = window;
if (!_glfwCreateContextForDCWGL(window->context.wgl.dc, &ctxconfig, &context->handle))
{ {
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR, _glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
"WGL: Failed to enable sharing with window OpenGL context and user context"); "WGL: Failed to create user OpenGL context");
free(context); free(context);
return GLFW_FALSE; return NULL;
} }
return context; return context;
} }
......
...@@ -155,6 +155,8 @@ typedef struct _GLFWlibraryWGL ...@@ -155,6 +155,8 @@ typedef struct _GLFWlibraryWGL
} _GLFWlibraryWGL; } _GLFWlibraryWGL;
// WGL-specific user context data
//
typedef struct _GLFWusercontext typedef struct _GLFWusercontext
{ {
_GLFWwindow* window; _GLFWwindow* window;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment