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

Refactor user context implementation to use the standard GLFW platform / context approach

parent a9e7d51c
......@@ -771,13 +771,13 @@ GLFWAPI GLFWusercontext* glfwCreateUserContext(GLFWwindow* handle)
GLFWAPI void glfwDestroyUserContext(GLFWusercontext* handle)
{
_GLFWusercontext* context = (_GLFWusercontext*)handle;
_glfwPlatformDestroyUserContext(context);
if (context)
context->destroy(context);
}
GLFWAPI void glfwMakeUserContextCurrent(GLFWusercontext* handle)
{
_GLFWusercontext* context = (_GLFWusercontext*)handle;
_glfwPlatformMakeUserContextCurrent(context);
if (context)
context->makeCurrent(context);
}
......@@ -748,6 +748,13 @@ GLFWbool _glfwChooseVisualEGL(const _GLFWwndconfig* wndconfig,
}
#endif // _GLFW_X11
_GLFWusercontext* _glfwCreateUserContextEGL(_GLFWwindow* window)
{
// TODO
return NULL;
}
//////////////////////////////////////////////////////////////////////////
////// GLFW native API //////
......
......@@ -165,6 +165,14 @@ typedef struct _GLFWcontextEGL
} _GLFWcontextEGL;
// EGL-specific per user context data
//
typedef struct _GLFWusercontextEGL
{
EGLContext handle;
} _GLFWusercontextEGL;
// EGL-specific global data
//
typedef struct _GLFWlibraryEGL
......@@ -206,6 +214,8 @@ void _glfwTerminateEGL(void);
GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig);
_GLFWusercontext* _glfwCreateUserContextEGL(_GLFWwindow* window);
#if defined(_GLFW_X11)
GLFWbool _glfwChooseVisualEGL(const _GLFWwndconfig* wndconfig,
const _GLFWctxconfig* ctxconfig,
......
......@@ -678,11 +678,33 @@ GLFWbool _glfwChooseVisualGLX(const _GLFWwndconfig* wndconfig,
return GLFW_TRUE;
}
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
static void _glfwMakeUserContextCurrentGLX(_GLFWusercontext* context)
{
if(context)
{
if(!glXMakeCurrent(_glfw.x11.display, context->window->context.glx.window,context->glx.handle))
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"GLX: Failed to set current user context");
}
}
else
{
if (!glXMakeCurrent(_glfw.x11.display, None, NULL))
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"GLX: Failed to clear current context");
}
}
}
static void _glfwDestroyUserContextGLX(_GLFWusercontext* context)
{
glXDestroyContext(_glfw.x11.display, context->glx.handle);
free(context);
}
_GLFWusercontext* _glfwPlatformCreateUserContext(_GLFWwindow* window)
_GLFWusercontext* _glfwCreateUserContextGLX(_GLFWwindow* window)
{
_GLFWusercontext* context;
_GLFWctxconfig ctxconfig;
......@@ -693,7 +715,7 @@ _GLFWusercontext* _glfwPlatformCreateUserContext(_GLFWwindow* window)
ctxconfig = _glfw.hints.context;
ctxconfig.share = window;
if(!_glfwCreateContextForFBGLX(window,&ctxconfig,&context->handle))
if(!_glfwCreateContextForFBGLX(window,&ctxconfig,&context->glx.handle))
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"GLX: Failed to create user OpenGL context");
......@@ -701,33 +723,11 @@ _GLFWusercontext* _glfwPlatformCreateUserContext(_GLFWwindow* window)
return NULL;
}
return context;
}
context->makeCurrent = _glfwMakeUserContextCurrentGLX;
context->destroy = _glfwDestroyUserContextGLX;
void _glfwPlatformDestroyUserContext(_GLFWusercontext* context)
{
glXDestroyContext(_glfw.x11.display, context->handle);
free(context);
}
void _glfwPlatformMakeUserContextCurrent(_GLFWusercontext* context)
{
if(context)
{
if(!glXMakeCurrent(_glfw.x11.display, context->window->context.glx.window,context->handle))
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"GLX: Failed to set current user context");
}
}
else
{
if (!glXMakeCurrent(_glfw.x11.display, None, NULL))
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"GLX: Failed to clear current context");
}
}
return context;
}
//////////////////////////////////////////////////////////////////////////
......
......@@ -109,6 +109,7 @@ typedef GLXContext (*PFNGLXCREATECONTEXTATTRIBSARBPROC)(Display*,GLXFBConfig,GLX
#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextGLX glx
#define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE _GLFWlibraryGLX glx
#define _GLFW_PLATFORM_USER_CONTEXT_STATE _GLFWusercontextGLX glx
// GLX-specific per-context data
......@@ -121,6 +122,13 @@ typedef struct _GLFWcontextGLX
} _GLFWcontextGLX;
// GLX-specific per user context data
//
typedef struct _GLFWusercontextGLX
{
GLXContext handle;
} _GLFWusercontextGLX;
// GLX-specific global data
//
typedef struct _GLFWlibraryGLX
......@@ -169,13 +177,6 @@ typedef struct _GLFWlibraryGLX
} _GLFWlibraryGLX;
// GLX-specific user context data
//
typedef struct _GLFWusercontext
{
_GLFWwindow* window;
GLXContext handle;
} _GLFWusercontext;
GLFWbool _glfwInitGLX(void);
void _glfwTerminateGLX(void);
......@@ -187,4 +188,5 @@ GLFWbool _glfwChooseVisualGLX(const _GLFWwndconfig* wndconfig,
const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig,
Visual** visual, int* depth);
_GLFWusercontext* _glfwCreateUserContextGLX(_GLFWwindow* window);
......@@ -83,6 +83,8 @@ typedef void (* _GLFWswapintervalfun)(int);
typedef int (* _GLFWextensionsupportedfun)(const char*);
typedef GLFWglproc (* _GLFWgetprocaddressfun)(const char*);
typedef void (* _GLFWdestroycontextfun)(_GLFWwindow*);
typedef void (* _GLFWmakeusercontextcurrentfun)(_GLFWusercontext* context);
typedef void (* _GLFWdestroyusercontextfun)(_GLFWusercontext* context);
#define GL_VERSION 0x1f02
#define GL_NONE 0
......@@ -362,6 +364,24 @@ struct _GLFWcontext
_GLFW_OSMESA_CONTEXT_STATE;
};
// User Context structure
//
struct _GLFWusercontext
{
_GLFWwindow* window;
// This is defined in the context API's context.h
_GLFW_PLATFORM_USER_CONTEXT_STATE;
// This is defined in egl_context.h
_GLFWusercontextEGL egl;
// This is defined in osmesa_context.h
_GLFWusercontextOSMesa osmesa;
_GLFWmakeusercontextcurrentfun makeCurrent;
_GLFWdestroyusercontextfun destroy;
};
// Window and context structure
//
struct _GLFWwindow
......@@ -680,8 +700,6 @@ void _glfwPlatformWaitEventsTimeout(double timeout);
void _glfwPlatformPostEmptyEvent(void);
_GLFWusercontext* _glfwPlatformCreateUserContext(_GLFWwindow* window);
void _glfwPlatformDestroyUserContext(_GLFWusercontext* context);
void _glfwPlatformMakeUserContextCurrent(_GLFWusercontext* context);
void _glfwPlatformGetRequiredInstanceExtensions(char** extensions);
......
......@@ -287,6 +287,11 @@ GLFWbool _glfwCreateContextOSMesa(_GLFWwindow* window,
#undef setAttrib
_GLFWusercontext* _glfwCreateUserContextOSMesa(_GLFWwindow* window)
{
// TODO
return NULL;
}
//////////////////////////////////////////////////////////////////////////
////// GLFW native API //////
......
......@@ -69,6 +69,13 @@ typedef struct _GLFWcontextOSMesa
} _GLFWcontextOSMesa;
// OSMesa-specific per user context data
//
typedef struct _GLFWusercontextOSMesa
{
OSMesaContext handle;
} _GLFWusercontextOSMesa;
// OSMesa-specific global data
//
typedef struct _GLFWlibraryOSMesa
......@@ -91,4 +98,4 @@ void _glfwTerminateOSMesa(void);
GLFWbool _glfwCreateContextOSMesa(_GLFWwindow* window,
const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig);
_GLFWusercontext* _glfwCreateUserContextOSMesa(_GLFWwindow* window);
......@@ -790,12 +790,33 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window,
#undef setAttrib
static void _glfwMakeUserContextCurrentWGL(_GLFWusercontext* context)
{
if(context)
{
if(!wglMakeCurrent(context->window->context.wgl.dc,context->wgl.handle))
{
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
"WGL: Failed to set current user context");
}
}
else
{
if (!wglMakeCurrent(NULL, NULL))
{
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
"WGL: Failed to clear current context");
}
}
}
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
static void _glfwDestroyUserContextWGL(_GLFWusercontext* context)
{
wglDeleteContext(context->wgl.handle);
free(context);
}
_GLFWusercontext* _glfwPlatformCreateUserContext(_GLFWwindow* window)
_GLFWusercontext* _glfwCreateUserContextWGL(_GLFWwindow* window)
{
_GLFWusercontext* context;
_GLFWctxconfig ctxconfig;
......@@ -806,7 +827,7 @@ _GLFWusercontext* _glfwPlatformCreateUserContext(_GLFWwindow* window)
ctxconfig = _glfw.hints.context;
ctxconfig.share = window;
if (!_glfwCreateContextForDCWGL(window->context.wgl.dc, &ctxconfig, &context->handle))
if (!_glfwCreateContextForDCWGL(window->context.wgl.dc, &ctxconfig, &context->wgl.handle))
{
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
"WGL: Failed to create user OpenGL context");
......@@ -814,33 +835,10 @@ _GLFWusercontext* _glfwPlatformCreateUserContext(_GLFWwindow* window)
return NULL;
}
return context;
}
void _glfwPlatformDestroyUserContext(_GLFWusercontext* context)
{
wglDeleteContext(context->handle);
free(context);
}
context->makeCurrent = _glfwMakeUserContextCurrentWGL;
context->destroy = _glfwDestroyUserContextWGL;
void _glfwPlatformMakeUserContextCurrent(_GLFWusercontext* context)
{
if(context)
{
if(!wglMakeCurrent(context->window->context.wgl.dc,context->handle))
{
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
"WGL: Failed to set current user context");
}
}
else
{
if (!wglMakeCurrent(NULL, NULL))
{
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
"WGL: Failed to clear current context");
}
}
return context;
}
......
......@@ -110,6 +110,7 @@ typedef BOOL (WINAPI * PFN_wglShareLists)(HGLRC,HGLRC);
#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextWGL wgl
#define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE _GLFWlibraryWGL wgl
#define _GLFW_PLATFORM_USER_CONTEXT_STATE _GLFWusercontextWGL wgl
// WGL-specific per-context data
......@@ -157,15 +158,17 @@ typedef struct _GLFWlibraryWGL
// WGL-specific user context data
//
typedef struct _GLFWusercontext
typedef struct _GLFWusercontextWGL
{
_GLFWwindow* window;
HGLRC handle;
} _GLFWusercontext;
} _GLFWusercontextWGL;
GLFWbool _glfwInitWGL(void);
void _glfwTerminateWGL(void);
GLFWbool _glfwCreateContextWGL(_GLFWwindow* window,
const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig);
_GLFWusercontext* _glfwCreateUserContextWGL(_GLFWwindow* window);
......@@ -2230,6 +2230,23 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
return err;
}
_GLFWusercontext* _glfwPlatformCreateUserContext(_GLFWwindow* window)
{
if (window->context.wgl.handle)
{
return _glfwCreateUserContextWGL(window);
}
else if (window->context.egl.handle)
{
return _glfwCreateUserContextEGL(window);
}
else if (window->context.osmesa.handle)
{
return _glfwCreateUserContextOSMesa(window);
}
return GLFW_FALSE;
}
//////////////////////////////////////////////////////////////////////////
////// GLFW native API //////
......
......@@ -3120,6 +3120,24 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
}
}
_GLFWusercontext* _glfwPlatformCreateUserContext(_GLFWwindow* window)
{
if (window->context.glx.handle)
{
return _glfwCreateUserContextGLX(window);
}
else if (window->context.egl.handle)
{
return _glfwCreateUserContextEGL(window);
}
else if (window->context.osmesa.handle)
{
return _glfwCreateUserContextOSMesa(window);
}
return GLFW_FALSE;
}
//////////////////////////////////////////////////////////////////////////
////// GLFW native API //////
......
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