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

View File

@ -919,6 +919,8 @@ GLFWbool _glfwChooseVisualEGL(const _GLFWwndconfig* wndconfig,
static void _glfwMakeUserContextCurrentEGL(_GLFWusercontext* context)
{
if (context)
{
if (!eglMakeCurrent(_glfw.egl.display,
context->egl.surface,
context->egl.surface,
@ -930,6 +932,20 @@ static void _glfwMakeUserContextCurrentEGL(_GLFWusercontext* context)
_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);
}

View File

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

View File

@ -357,7 +357,10 @@ static void _glfwMakeUserContextCurrentNSGL(_GLFWusercontext* context)
{
@autoreleasepool {
if (context)
[context->nsgl.object makeCurrentContext];
else
[NSOpenGLContext clearCurrentContext];
_glfwPlatformSetTls(&_glfw.usercontextSlot, context);

View File

@ -300,6 +300,8 @@ GLFWbool _glfwCreateContextOSMesa(_GLFWwindow* window,
static void _glfwMakeUserContextCurrentOSMesa(_GLFWusercontext* context)
{
if (context)
{
if (!OSMesaMakeCurrent(context->osmesa.handle,
context->window->context.osmesa.buffer,
GL_UNSIGNED_BYTE,
@ -310,6 +312,7 @@ static void _glfwMakeUserContextCurrentOSMesa(_GLFWusercontext* context)
_glfwPlatformSetTls(&_glfw.usercontextSlot, NULL);
return;
}
}
_glfwPlatformSetTls(&_glfw.usercontextSlot, context);
}

View File

@ -787,13 +787,25 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window,
static void _glfwMakeUserContextCurrentWGL(_GLFWusercontext* context)
{
if(!wglMakeCurrent(context->window->context.wgl.dc,context->wgl.handle))
if (context)
{
if (!wglMakeCurrent(context->window->context.wgl.dc,context->wgl.handle))
{
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
"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);
}