Fix OpenGL context caching on macOS (#737)

This commit is contained in:
Matthias Melcher 2024-01-29 13:41:53 +01:00
parent d9612e3cc7
commit c40b165353
2 changed files with 5 additions and 6 deletions

View File

@ -536,7 +536,6 @@ float Fl_Gl_Window::pixels_per_unit() {
*/ */
int Fl_Gl_Window_Driver::copy = COPY; int Fl_Gl_Window_Driver::copy = COPY;
GLContext Fl_Gl_Window_Driver::cached_context = NULL;
Fl_Window* Fl_Gl_Window_Driver::cached_window = NULL; Fl_Window* Fl_Gl_Window_Driver::cached_window = NULL;
float Fl_Gl_Window_Driver::gl_scale = 1; // scaling factor between FLTK and GL drawing units: GL = FLTK * gl_scale float Fl_Gl_Window_Driver::gl_scale = 1; // scaling factor between FLTK and GL drawing units: GL = FLTK * gl_scale

View File

@ -217,18 +217,18 @@ GLContext Fl_Cocoa_Gl_Window_Driver::create_gl_context(Fl_Window* window, const
} }
void Fl_Cocoa_Gl_Window_Driver::set_gl_context(Fl_Window* w, GLContext context) { void Fl_Cocoa_Gl_Window_Driver::set_gl_context(Fl_Window* w, GLContext context) {
if (context != cached_context || w != cached_window) { NSOpenGLContext *current_context = [NSOpenGLContext currentContext];
cached_context = context; if (context != current_context || w != cached_window) {
cached_window = w; cached_window = w;
[(NSOpenGLContext*)context makeCurrentContext]; [(NSOpenGLContext*)context makeCurrentContext];
} }
} }
void Fl_Cocoa_Gl_Window_Driver::delete_gl_context(GLContext context) { void Fl_Cocoa_Gl_Window_Driver::delete_gl_context(GLContext context) {
if (cached_context == context) { NSOpenGLContext *current_context = [NSOpenGLContext currentContext];
cached_context = 0; if (current_context == context) {
cached_window = 0; cached_window = 0;
[[NSOpenGLContext currentContext] clearDrawable]; [current_context clearDrawable];
} }
[(NSOpenGLContext*)context release]; [(NSOpenGLContext*)context release];
del_context(context); del_context(context);