src/video/SDL_video.c
changeset 5563 2a152e7e82f2
parent 5535 96594ac5fd1a
child 5570 70b6f92e4539
     1.1 --- a/src/video/SDL_video.c	Wed Jul 13 17:38:09 2011 -0700
     1.2 +++ b/src/video/SDL_video.c	Fri Jul 15 17:05:32 2011 -0700
     1.3 @@ -1931,6 +1931,13 @@
     1.4  
     1.5      CHECK_WINDOW_MAGIC(window, );
     1.6  
     1.7 +    /* make no context current if this is the current context window. */
     1.8 +    if (window->flags & SDL_WINDOW_OPENGL) {
     1.9 +        if (_this->current_glwin == window) {
    1.10 +            SDL_GL_MakeCurrent(NULL, NULL);
    1.11 +        }
    1.12 +    }
    1.13 +
    1.14      /* Restore video mode, etc. */
    1.15      SDL_HideWindow(window);
    1.16  
    1.17 @@ -2462,18 +2469,31 @@
    1.18  }
    1.19  
    1.20  int
    1.21 -SDL_GL_MakeCurrent(SDL_Window * window, SDL_GLContext context)
    1.22 +SDL_GL_MakeCurrent(SDL_Window * window, SDL_GLContext ctx)
    1.23  {
    1.24 +    int retval;
    1.25 +
    1.26      CHECK_WINDOW_MAGIC(window, -1);
    1.27  
    1.28      if (!(window->flags & SDL_WINDOW_OPENGL)) {
    1.29          SDL_SetError("The specified window isn't an OpenGL window");
    1.30          return -1;
    1.31      }
    1.32 -    if (!context) {
    1.33 +    if (!ctx) {
    1.34          window = NULL;
    1.35      }
    1.36 -    return _this->GL_MakeCurrent(_this, window, context);
    1.37 +
    1.38 +    if ((window == _this->current_glwin) && (ctx == _this->current_glctx)) {
    1.39 +        retval = 0;  /* we're already current. */
    1.40 +    } else {
    1.41 +        retval = _this->GL_MakeCurrent(_this, window, ctx);
    1.42 +        if (retval == 0) {
    1.43 +            _this->current_glwin = window;
    1.44 +            _this->current_glctx = ctx;
    1.45 +        }
    1.46 +    }
    1.47 +
    1.48 +    return retval;
    1.49  }
    1.50  
    1.51  int