diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index 45ca74507..cd3fa2717 100644 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -25,6 +25,7 @@ #include "SDL_messagebox.h" #include "SDL_shape.h" +#include "SDL_thread.h" /* The SDL video driver */ @@ -301,6 +302,7 @@ struct SDL_VideoDevice /* Cache current GL context; don't call the OS when it hasn't changed. */ SDL_Window *current_glwin; SDL_GLContext current_glctx; + SDL_threadID current_glthread; /* * * */ /* Data private to this driver */ diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index d5d0a7556..801fa5e3e 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -2730,6 +2730,7 @@ SDL_GL_CreateContext(SDL_Window * window) /* Creating a context is assumed to make it current in the SDL driver. */ _this->current_glwin = window; _this->current_glctx = ctx; + _this->current_glthread = SDL_ThreadID(); return ctx; } @@ -2738,6 +2739,7 @@ int SDL_GL_MakeCurrent(SDL_Window * window, SDL_GLContext ctx) { int retval; + SDL_threadID thread = SDL_ThreadID(); if (!ctx) { window = NULL; @@ -2749,13 +2751,14 @@ SDL_GL_MakeCurrent(SDL_Window * window, SDL_GLContext ctx) } } - if ((window == _this->current_glwin) && (ctx == _this->current_glctx)) { + if ((window == _this->current_glwin) && (ctx == _this->current_glctx) && (thread == _this->current_glthread)) { retval = 0; /* we're already current. */ } else { retval = _this->GL_MakeCurrent(_this, window, ctx); if (retval == 0) { _this->current_glwin = window; _this->current_glctx = ctx; + _this->current_glthread = thread; } }