mirror of
https://github.com/glfw/glfw.git
synced 2024-11-15 02:34:36 +00:00
Cocoa and NSGL Implementation
This commit is contained in:
parent
dd854e47ba
commit
f2b86a25b3
@ -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 //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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 //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
Loading…
Reference in New Issue
Block a user