Fix cached GL context on all platforms (#737)

This commit is contained in:
Matthias Melcher 2024-01-29 14:01:41 +01:00
parent c40b165353
commit faff63130c
4 changed files with 13 additions and 14 deletions

View File

@ -38,7 +38,6 @@ protected:
GLint current_prog;
Fl_Gl_Window *pWindow;
public:
static GLContext cached_context;
static Fl_Window* cached_window;
static int nContext;
static GLContext *context_list;

View File

@ -228,8 +228,8 @@ void Fl_Wayland_Gl_Window_Driver::set_gl_context(Fl_Window* w, GLContext context
target_egl_surface = dr->gl_start_support_->egl_surface = eglCreateWindowSurface(
egl_display, wld_egl_conf, dr->gl_start_support_->egl_window, NULL);
}
if (context != cached_context || w != cached_window) {
cached_context = context;
GLContext current_context = eglGetCurrentContext();
if (context != current_context || w != cached_window) {
cached_window = w;
if (eglMakeCurrent(egl_display, target_egl_surface, target_egl_surface,
(EGLContext)context)) {
@ -259,11 +259,11 @@ void Fl_Wayland_Gl_Window_Driver::apply_scissor() {
void Fl_Wayland_Gl_Window_Driver::delete_gl_context(GLContext context) {
if (cached_context == context) {
cached_context = 0;
GLContext current_context = eglGetCurrentContext();
if (current_context == context) {
cached_window = 0;
}
if (eglGetCurrentContext() == (EGLContext)context) {
if (current_context == (EGLContext)context) {
eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
}
eglDestroyContext(egl_display, (EGLContext)context);

View File

@ -163,16 +163,16 @@ GLContext Fl_WinAPI_Gl_Window_Driver::create_gl_context(Fl_Window* window, const
}
void Fl_WinAPI_Gl_Window_Driver::set_gl_context(Fl_Window* w, GLContext context) {
if (context != cached_context || w != cached_window) {
cached_context = context;
GLContext current_context = wglGetCurrentContext();
if (context != current_context || w != cached_window) {
cached_window = w;
wglMakeCurrent(Fl_WinAPI_Window_Driver::driver(w)->private_dc, (HGLRC)context);
}
}
void Fl_WinAPI_Gl_Window_Driver::delete_gl_context(GLContext context) {
if (cached_context == context) {
cached_context = 0;
GLContext current_context = wglGetCurrentContext();
if (current_context == context) {
cached_window = 0;
wglMakeCurrent(0, 0);
}

View File

@ -321,16 +321,16 @@ GLContext Fl_X11_Gl_Window_Driver::create_gl_context(XVisualInfo *vis) {
}*/
void Fl_X11_Gl_Window_Driver::set_gl_context(Fl_Window* w, GLContext context) {
if (context != cached_context || w != cached_window) {
cached_context = context;
GLContext current_context = glXGetCurrentContext();
if (context != current_context || w != cached_window) {
cached_window = w;
glXMakeCurrent(fl_display, fl_xid(w), (GLXContext)context);
}
}
void Fl_X11_Gl_Window_Driver::delete_gl_context(GLContext context) {
if (cached_context == context) {
cached_context = 0;
GLContext current_context = glXGetCurrentContext();
if (current_context == context) {
cached_window = 0;
glXMakeCurrent(fl_display, 0, 0);
}