src/video/SDL_video.c
changeset 7412 50211a1fd557
parent 7399 f35ff854121a
child 7429 ff7edbf76a73
     1.1 --- a/src/video/SDL_video.c	Fri Jul 12 01:26:43 2013 -0400
     1.2 +++ b/src/video/SDL_video.c	Thu Jul 11 22:59:20 2013 -0700
     1.3 @@ -500,6 +500,9 @@
     1.4      _this->gl_config.profile_mask = 0;
     1.5      _this->gl_config.share_with_current_context = 0;
     1.6  
     1.7 +    _this->current_glwin_tls = SDL_TLSCreate();
     1.8 +    _this->current_glctx_tls = SDL_TLSCreate();
     1.9 +
    1.10      /* Initialize the video subsystem */
    1.11      if (_this->VideoInit(_this) < 0) {
    1.12          SDL_VideoQuit();
    1.13 @@ -2738,7 +2741,8 @@
    1.14      /* Creating a context is assumed to make it current in the SDL driver. */
    1.15      _this->current_glwin = window;
    1.16      _this->current_glctx = ctx;
    1.17 -    _this->current_glthread = SDL_ThreadID();
    1.18 +    SDL_TLSSet(_this->current_glwin_tls, window, NULL);
    1.19 +    SDL_TLSSet(_this->current_glctx_tls, ctx, NULL);
    1.20  
    1.21      return ctx;
    1.22  }
    1.23 @@ -2747,7 +2751,12 @@
    1.24  SDL_GL_MakeCurrent(SDL_Window * window, SDL_GLContext ctx)
    1.25  {
    1.26      int retval;
    1.27 -    SDL_threadID thread = SDL_ThreadID();
    1.28 +
    1.29 +    if (window == SDL_GL_GetCurrentWindow() &&
    1.30 +        ctx == SDL_GL_GetCurrentContext()) {
    1.31 +        /* We're already current. */
    1.32 +        return 0;
    1.33 +    }
    1.34  
    1.35      if (!ctx) {
    1.36          window = NULL;
    1.37 @@ -2759,26 +2768,42 @@
    1.38          }
    1.39      }
    1.40  
    1.41 -    if ((window == _this->current_glwin) && (ctx == _this->current_glctx) && (thread == _this->current_glthread)) {
    1.42 -        retval = 0;  /* we're already current. */
    1.43 -    } else {
    1.44 -        retval = _this->GL_MakeCurrent(_this, window, ctx);
    1.45 -        if (retval == 0) {
    1.46 -            _this->current_glwin = window;
    1.47 -            _this->current_glctx = ctx;
    1.48 -            _this->current_glthread = thread;
    1.49 -        }
    1.50 +    retval = _this->GL_MakeCurrent(_this, window, ctx);
    1.51 +    if (retval == 0) {
    1.52 +        _this->current_glwin = window;
    1.53 +        _this->current_glctx = ctx;
    1.54 +        SDL_TLSSet(_this->current_glwin_tls, window, NULL);
    1.55 +        SDL_TLSSet(_this->current_glctx_tls, ctx, NULL);
    1.56      }
    1.57 -
    1.58      return retval;
    1.59  }
    1.60  
    1.61 +SDL_Window *
    1.62 +SDL_GL_GetCurrentWindow(void)
    1.63 +{
    1.64 +    if (!_this) {
    1.65 +        SDL_UninitializedVideo();
    1.66 +        return NULL;
    1.67 +    }
    1.68 +    return (SDL_Window *)SDL_TLSGet(_this->current_glwin_tls);
    1.69 +}
    1.70 +
    1.71 +SDL_GLContext
    1.72 +SDL_GL_GetCurrentContext(void)
    1.73 +{
    1.74 +    if (!_this) {
    1.75 +        SDL_UninitializedVideo();
    1.76 +        return NULL;
    1.77 +    }
    1.78 +    return (SDL_GLContext)SDL_TLSGet(_this->current_glctx_tls);
    1.79 +}
    1.80 +
    1.81  int
    1.82  SDL_GL_SetSwapInterval(int interval)
    1.83  {
    1.84      if (!_this) {
    1.85          return SDL_UninitializedVideo();
    1.86 -    } else if (_this->current_glctx == NULL) {
    1.87 +    } else if (SDL_GL_GetCurrentContext() == NULL) {
    1.88          return SDL_SetError("No OpenGL context has been made current");
    1.89      } else if (_this->GL_SetSwapInterval) {
    1.90          return _this->GL_SetSwapInterval(_this, interval);
    1.91 @@ -2792,7 +2817,7 @@
    1.92  {
    1.93      if (!_this) {
    1.94          return 0;
    1.95 -    } else if (_this->current_glctx == NULL) {
    1.96 +    } else if (SDL_GL_GetCurrentContext() == NULL) {
    1.97          return 0;
    1.98      } else if (_this->GL_GetSwapInterval) {
    1.99          return _this->GL_GetSwapInterval(_this);
   1.100 @@ -2820,7 +2845,7 @@
   1.101          return;
   1.102      }
   1.103  
   1.104 -    if (_this->current_glctx == context) {
   1.105 +    if (SDL_GL_GetCurrentContext() == context) {
   1.106          SDL_GL_MakeCurrent(NULL, NULL);
   1.107      }
   1.108