From c40b1653532aa08412aa8232fb8a11289512283e Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Mon, 29 Jan 2024 13:41:53 +0100 Subject: [PATCH] Fix OpenGL context caching on macOS (#737) --- src/Fl_Gl_Window.cxx | 1 - src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.mm | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Fl_Gl_Window.cxx b/src/Fl_Gl_Window.cxx index 4912765c7..3e87a880a 100644 --- a/src/Fl_Gl_Window.cxx +++ b/src/Fl_Gl_Window.cxx @@ -536,7 +536,6 @@ float Fl_Gl_Window::pixels_per_unit() { */ int Fl_Gl_Window_Driver::copy = COPY; -GLContext Fl_Gl_Window_Driver::cached_context = 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 diff --git a/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.mm b/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.mm index 808a6e03a..43a1c1b9e 100644 --- a/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.mm +++ b/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.mm @@ -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) { - if (context != cached_context || w != cached_window) { - cached_context = context; + NSOpenGLContext *current_context = [NSOpenGLContext currentContext]; + if (context != current_context || w != cached_window) { cached_window = w; [(NSOpenGLContext*)context makeCurrentContext]; } } void Fl_Cocoa_Gl_Window_Driver::delete_gl_context(GLContext context) { - if (cached_context == context) { - cached_context = 0; + NSOpenGLContext *current_context = [NSOpenGLContext currentContext]; + if (current_context == context) { cached_window = 0; - [[NSOpenGLContext currentContext] clearDrawable]; + [current_context clearDrawable]; } [(NSOpenGLContext*)context release]; del_context(context);