SDL_GL_MakeCurrent: Only no-op redundant calls on *same* thread.
authorJørgen P. Tjernø <jorgen@valvesoftware.com>
Tue, 09 Jul 2013 12:58:54 -0700
changeset 7390e4b98404baa4
parent 7389 361d1a0c90f6
child 7391 a29895dc5e9a
SDL_GL_MakeCurrent: Only no-op redundant calls on *same* thread.

This ensures that we only no-op redundant calls if they're made on the
same thread as the last MakeCurrent with those arguments. This should
maek SDL behave better with multithreaded environments.
src/video/SDL_sysvideo.h
src/video/SDL_video.c
     1.1 --- a/src/video/SDL_sysvideo.h	Tue Jul 09 12:57:12 2013 -0700
     1.2 +++ b/src/video/SDL_sysvideo.h	Tue Jul 09 12:58:54 2013 -0700
     1.3 @@ -25,6 +25,7 @@
     1.4  
     1.5  #include "SDL_messagebox.h"
     1.6  #include "SDL_shape.h"
     1.7 +#include "SDL_thread.h"
     1.8  
     1.9  /* The SDL video driver */
    1.10  
    1.11 @@ -301,6 +302,7 @@
    1.12      /* Cache current GL context; don't call the OS when it hasn't changed. */
    1.13      SDL_Window *current_glwin;
    1.14      SDL_GLContext current_glctx;
    1.15 +    SDL_threadID current_glthread;
    1.16  
    1.17      /* * * */
    1.18      /* Data private to this driver */
     2.1 --- a/src/video/SDL_video.c	Tue Jul 09 12:57:12 2013 -0700
     2.2 +++ b/src/video/SDL_video.c	Tue Jul 09 12:58:54 2013 -0700
     2.3 @@ -2730,6 +2730,7 @@
     2.4      /* Creating a context is assumed to make it current in the SDL driver. */
     2.5      _this->current_glwin = window;
     2.6      _this->current_glctx = ctx;
     2.7 +    _this->current_glthread = SDL_ThreadID();
     2.8  
     2.9      return ctx;
    2.10  }
    2.11 @@ -2738,6 +2739,7 @@
    2.12  SDL_GL_MakeCurrent(SDL_Window * window, SDL_GLContext ctx)
    2.13  {
    2.14      int retval;
    2.15 +    SDL_threadID thread = SDL_ThreadID();
    2.16  
    2.17      if (!ctx) {
    2.18          window = NULL;
    2.19 @@ -2749,13 +2751,14 @@
    2.20          }
    2.21      }
    2.22  
    2.23 -    if ((window == _this->current_glwin) && (ctx == _this->current_glctx)) {
    2.24 +    if ((window == _this->current_glwin) && (ctx == _this->current_glctx) && (thread == _this->current_glthread)) {
    2.25          retval = 0;  /* we're already current. */
    2.26      } else {
    2.27          retval = _this->GL_MakeCurrent(_this, window, ctx);
    2.28          if (retval == 0) {
    2.29              _this->current_glwin = window;
    2.30              _this->current_glctx = ctx;
    2.31 +            _this->current_glthread = thread;
    2.32          }
    2.33      }
    2.34