Move preservation of OpenGL context into glfw

Allows us to avoid creating an extra hidden window.
This commit is contained in:
Kovid Goyal
2025-09-05 15:17:42 +05:30
parent b241811a74
commit b7c4f42e96
2 changed files with 16 additions and 15 deletions

View File

@@ -107,12 +107,22 @@ bool _glfwInitNSGL(void)
return true;
}
// We use a globally shared context across all OS Windows so that
// if all OS Windows are closed the context does not have to be recreated
// with all associated data lost. On Apple kitty can remain running with no
// OS Windows.
static NSOpenGLContext* globally_shared_context = nil;
// Terminate OpenGL support
//
void _glfwTerminateNSGL(void)
{
void _glfwTerminateNSGL(void) {
if (globally_shared_context != nil) {
[globally_shared_context release];
globally_shared_context = nil;
}
}
// Create the OpenGL context
//
bool _glfwCreateContextNSGL(_GLFWwindow* window,
@@ -272,7 +282,7 @@ bool _glfwCreateContextNSGL(_GLFWwindow* window,
return false;
}
NSOpenGLContext* share = nil;
NSOpenGLContext* share = globally_shared_context;
if (ctxconfig->share)
share = ctxconfig->share->context.nsgl.object;
@@ -286,6 +296,9 @@ bool _glfwCreateContextNSGL(_GLFWwindow* window,
"NSGL: Failed to create OpenGL context");
return false;
}
if (globally_shared_context == nil) {
globally_shared_context = [window->context.nsgl.object retain];
}
if (fbconfig->transparent)
{