Fix for not being able to clear the user context

This commit is contained in:
Doug Binks 2025-02-10 18:36:01 +00:00
parent e4e46b4cc5
commit 58aad6c136
6 changed files with 83 additions and 30 deletions

View File

@ -619,8 +619,9 @@ GLFWAPI void glfwMakeContextCurrent(GLFWwindow* handle)
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFWwindow* previous; _GLFWwindow* previous;
_GLFWusercontext* previousUserContext;
_glfwPlatformSetTls(&_glfw.usercontextSlot, NULL); previousUserContext = _glfwPlatformGetTls(&_glfw.usercontextSlot);
previous = _glfwPlatformGetTls(&_glfw.contextSlot); previous = _glfwPlatformGetTls(&_glfw.contextSlot);
if (window && window->context.client == GLFW_NO_API) if (window && window->context.client == GLFW_NO_API)
@ -630,6 +631,12 @@ GLFWAPI void glfwMakeContextCurrent(GLFWwindow* handle)
return; return;
} }
if (previousUserContext)
{
assert(previous==NULL);
previousUserContext->makeCurrent(NULL);
}
if (previous) if (previous)
{ {
if (!window || window->context.source != previous->context.source) if (!window || window->context.source != previous->context.source)

View File

@ -919,16 +919,32 @@ GLFWbool _glfwChooseVisualEGL(const _GLFWwndconfig* wndconfig,
static void _glfwMakeUserContextCurrentEGL(_GLFWusercontext* context) static void _glfwMakeUserContextCurrentEGL(_GLFWusercontext* context)
{ {
if (!eglMakeCurrent(_glfw.egl.display, if (context)
context->egl.surface,
context->egl.surface,
context->egl.handle))
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, if (!eglMakeCurrent(_glfw.egl.display,
"EGL: Failed to make user context current: %s", context->egl.surface,
getEGLErrorString(eglGetError())); context->egl.surface,
_glfwPlatformSetTls(&_glfw.usercontextSlot, NULL); context->egl.handle))
return; {
_glfwInputError(GLFW_PLATFORM_ERROR,
"EGL: Failed to make user context current: %s",
getEGLErrorString(eglGetError()));
_glfwPlatformSetTls(&_glfw.usercontextSlot, NULL);
return;
}
}
else
{
if (!eglMakeCurrent(_glfw.egl.display,
EGL_NO_SURFACE,
EGL_NO_SURFACE,
EGL_NO_CONTEXT))
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"EGL: Failed to clear current user context: %s",
getEGLErrorString(eglGetError()));
return;
}
} }
_glfwPlatformSetTls(&_glfw.usercontextSlot, context); _glfwPlatformSetTls(&_glfw.usercontextSlot, context);
} }

View File

@ -687,12 +687,24 @@ GLFWbool _glfwChooseVisualGLX(const _GLFWwndconfig* wndconfig,
static void _glfwMakeUserContextCurrentGLX(_GLFWusercontext* context) static void _glfwMakeUserContextCurrentGLX(_GLFWusercontext* context)
{ {
if(!glXMakeCurrent(_glfw.x11.display, context->window->context.glx.window,context->glx.handle)) if (context)
{
if(!glXMakeCurrent(_glfw.x11.display, context->window->context.glx.window,context->glx.handle))
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"GLX: Failed to make user context current");
_glfwPlatformSetTls(&_glfw.usercontextSlot, NULL);
return;
}
}
else
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, if (!glXMakeCurrent(_glfw.x11.display, None, NULL))
"GLX: Failed to make user context current"); {
_glfwPlatformSetTls(&_glfw.usercontextSlot, NULL); _glfwInputError(GLFW_PLATFORM_ERROR,
return; "GLX: Failed to clear current user context");
return;
}
} }
_glfwPlatformSetTls(&_glfw.usercontextSlot, context); _glfwPlatformSetTls(&_glfw.usercontextSlot, context);
} }

View File

@ -357,9 +357,12 @@ static void _glfwMakeUserContextCurrentNSGL(_GLFWusercontext* context)
{ {
@autoreleasepool { @autoreleasepool {
if (context)
[context->nsgl.object makeCurrentContext]; [context->nsgl.object makeCurrentContext];
else
[NSOpenGLContext clearCurrentContext];
_glfwPlatformSetTls(&_glfw.usercontextSlot, context); _glfwPlatformSetTls(&_glfw.usercontextSlot, context);
} // autoreleasepool } // autoreleasepool
} }
@ -368,7 +371,7 @@ static void _glfwDestroyUserContextNSGL(_GLFWusercontext* context)
{ {
@autoreleasepool { @autoreleasepool {
[context->nsgl.object release]; [context->nsgl.object release];
} // autoreleasepool } // autoreleasepool
free(context); free(context);

View File

@ -300,15 +300,18 @@ GLFWbool _glfwCreateContextOSMesa(_GLFWwindow* window,
static void _glfwMakeUserContextCurrentOSMesa(_GLFWusercontext* context) static void _glfwMakeUserContextCurrentOSMesa(_GLFWusercontext* context)
{ {
if (!OSMesaMakeCurrent(context->osmesa.handle, if (context)
context->window->context.osmesa.buffer,
GL_UNSIGNED_BYTE,
context->window->context.osmesa.width, context->window->context.osmesa.height))
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, if (!OSMesaMakeCurrent(context->osmesa.handle,
"OSMesa: Failed to make user context current"); context->window->context.osmesa.buffer,
_glfwPlatformSetTls(&_glfw.usercontextSlot, NULL); GL_UNSIGNED_BYTE,
return; context->window->context.osmesa.width, context->window->context.osmesa.height))
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"OSMesa: Failed to make user context current");
_glfwPlatformSetTls(&_glfw.usercontextSlot, NULL);
return;
}
} }
_glfwPlatformSetTls(&_glfw.usercontextSlot, context); _glfwPlatformSetTls(&_glfw.usercontextSlot, context);
} }

View File

@ -787,13 +787,25 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window,
static void _glfwMakeUserContextCurrentWGL(_GLFWusercontext* context) static void _glfwMakeUserContextCurrentWGL(_GLFWusercontext* context)
{ {
if(!wglMakeCurrent(context->window->context.wgl.dc,context->wgl.handle)) if (context)
{ {
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR, if (!wglMakeCurrent(context->window->context.wgl.dc,context->wgl.handle))
"WGL: Failed to make user context current"); {
_glfwPlatformSetTls(&_glfw.usercontextSlot, NULL); _glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
return; "WGL: Failed to make user context current");
_glfwPlatformSetTls(&_glfw.usercontextSlot, NULL);
return;
}
} }
else
{
if (!wglMakeCurrent(NULL, NULL))
{
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
"WGL: Failed to clear current user context");
}
}
_glfwPlatformSetTls(&_glfw.usercontextSlot, context); _glfwPlatformSetTls(&_glfw.usercontextSlot, context);
} }