Cocoa and NSGL Implementation

This commit is contained in:
Doug Binks 2020-07-14 19:10:31 +01:00
parent dd854e47ba
commit f2b86a25b3
3 changed files with 76 additions and 0 deletions

View File

@ -1885,6 +1885,25 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
}
_GLFWusercontext* _glfwPlatformCreateUserContext(_GLFWwindow* window)
{
if (window->context.nsgl.object)
{
return _glfwCreateUserContextNSGL(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 //////
//////////////////////////////////////////////////////////////////////////

View File

@ -34,6 +34,7 @@
#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextNSGL nsgl
#define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE _GLFWlibraryNSGL nsgl
#define _GLFW_PLATFORM_USER_CONTEXT_STATE _GLFWusercontextNSGL nsgl
#include <stdatomic.h>
@ -47,6 +48,14 @@ typedef struct _GLFWcontextNSGL
} _GLFWcontextNSGL;
// NSGL-specific per user context data
//
typedef struct _GLFWusercontextNSGL
{
id object;
} _GLFWusercontextNSGL;
// NSGL-specific global data
//
typedef struct _GLFWlibraryNSGL
@ -63,4 +72,5 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window,
const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig);
void _glfwDestroyContextNSGL(_GLFWwindow* window);
_GLFWusercontext* _glfwCreateUserContextNSGL(_GLFWwindow* window);

View File

@ -349,6 +349,53 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window,
}
static void _glfwMakeUserContextCurrentNSGL(_GLFWusercontext* context)
{
@autoreleasepool {
if (context)
[context->nsgl.object makeCurrentContext];
else
[NSOpenGLContext clearCurrentContext];
} // autoreleasepool
}
static void _glfwDestroyUserContextNSGL(_GLFWusercontext* context)
{
@autoreleasepool {
if (context->nsgl.object)
[context->nsgl.object release];
} // autoreleasepool
free(context);
}
_GLFWusercontext* _glfwCreateUserContextNSGL(_GLFWwindow* window)
{
_GLFWusercontext* context;
context = calloc(1, sizeof(_GLFWusercontext));
context->window = window;
context->nsgl.object =
[[NSOpenGLContext alloc] initWithFormat:window->context.nsgl.pixelFormat
shareContext:window->context.nsgl.object];
if (window->context.nsgl.object == nil)
{
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
"NSGL: Failed to create OpenGL user context");
free(context);
return NULL;
}
context->makeCurrent = _glfwMakeUserContextCurrentNSGL;
context->destroy = _glfwDestroyUserContextNSGL;
return context;
}
//////////////////////////////////////////////////////////////////////////
////// GLFW native API //////
//////////////////////////////////////////////////////////////////////////