Fix OpenGL context caching on macOS (#737)

This commit is contained in:
Matthias Melcher 2024-01-30 15:51:37 +01:00
parent 89133cf1e1
commit 84ecb32c98
3 changed files with 16 additions and 0 deletions

View File

@ -214,6 +214,7 @@ public:
static void GLcontext_flushbuffer(NSOpenGLContext*);
static void GLcontext_release(NSOpenGLContext*);
static void GLcontext_makecurrent(NSOpenGLContext*);
static NSOpenGLContext* GLcontext_getcurrent();
static void GL_cleardrawable(void);
static void gl_start(NSOpenGLContext*);
void destroy(void);

View File

@ -409,6 +409,11 @@ static GLContext cached_context;
static Fl_Window* cached_window;
void fl_set_gl_context(Fl_Window* w, GLContext context) {
#ifdef __APPLE_QUARTZ__
// macOS may switch buffers during swapping, so we override the
// cached context with the actual current context (#737)
cached_context = Fl_X::GLcontext_getcurrent();
#endif
if (context != cached_context || w != cached_window) {
cached_context = context;
cached_window = w;
@ -439,6 +444,11 @@ void fl_no_gl_context() {
}
void fl_delete_gl_context(GLContext context) {
#ifdef __APPLE_QUARTZ__
// macOS may switch buffers during swapping, so we override the
// cached context with the actual current context (#737)
cached_context = Fl_X::GLcontext_getcurrent();
#endif
if (cached_context == context) fl_no_gl_context();
# if defined(USE_X11)
glXDestroyContext(fl_display, context);

View File

@ -3094,6 +3094,11 @@ void Fl_X::GLcontext_makecurrent(NSOpenGLContext* ctxt)
[ctxt makeCurrentContext];
}
NSOpenGLContext* Fl_X::GLcontext_getcurrent()
{
return [NSOpenGLContext currentContext];
}
void Fl_Window::fullscreen_x() {
_set_fullscreen();
if (fl_mac_os_version < 101000) {