Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Turn SDL_GL_MakeCurrent() into a no-op if setting the same context tw…
Browse files Browse the repository at this point in the history
…ice.
  • Loading branch information
icculus committed Jul 16, 2011
1 parent d4dc53c commit 0c68fac
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/video/SDL_sysvideo.h
Expand Up @@ -276,6 +276,11 @@ struct SDL_VideoDevice
void *dll_handle;
} gl_config;

/* * * */
/* Cache current GL context; don't call the OS when it hasn't changed. */
SDL_Window *current_glwin;
SDL_GLContext current_glctx;

/* * * */
/* Data private to this driver */
void *driverdata;
Expand Down
26 changes: 23 additions & 3 deletions src/video/SDL_video.c
Expand Up @@ -1931,6 +1931,13 @@ SDL_DestroyWindow(SDL_Window * window)

CHECK_WINDOW_MAGIC(window, );

/* make no context current if this is the current context window. */
if (window->flags & SDL_WINDOW_OPENGL) {
if (_this->current_glwin == window) {
SDL_GL_MakeCurrent(NULL, NULL);
}
}

/* Restore video mode, etc. */
SDL_HideWindow(window);

Expand Down Expand Up @@ -2462,18 +2469,31 @@ SDL_GL_CreateContext(SDL_Window * window)
}

int
SDL_GL_MakeCurrent(SDL_Window * window, SDL_GLContext context)
SDL_GL_MakeCurrent(SDL_Window * window, SDL_GLContext ctx)
{
int retval;

CHECK_WINDOW_MAGIC(window, -1);

if (!(window->flags & SDL_WINDOW_OPENGL)) {
SDL_SetError("The specified window isn't an OpenGL window");
return -1;
}
if (!context) {
if (!ctx) {
window = NULL;
}
return _this->GL_MakeCurrent(_this, window, context);

if ((window == _this->current_glwin) && (ctx == _this->current_glctx)) {
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;
}
}

return retval;
}

int
Expand Down

0 comments on commit 0c68fac

Please sign in to comment.