Commit 34edc624 authored by Ryan C. Gordon's avatar Ryan C. Gordon

Turn SDL_GL_MakeCurrent() into a no-op if setting the same context twice.

parent c4348f44
...@@ -276,6 +276,11 @@ struct SDL_VideoDevice ...@@ -276,6 +276,11 @@ struct SDL_VideoDevice
void *dll_handle; void *dll_handle;
} gl_config; } 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 */ /* Data private to this driver */
void *driverdata; void *driverdata;
......
...@@ -1931,6 +1931,13 @@ SDL_DestroyWindow(SDL_Window * window) ...@@ -1931,6 +1931,13 @@ SDL_DestroyWindow(SDL_Window * window)
CHECK_WINDOW_MAGIC(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. */ /* Restore video mode, etc. */
SDL_HideWindow(window); SDL_HideWindow(window);
...@@ -2462,18 +2469,31 @@ SDL_GL_CreateContext(SDL_Window * window) ...@@ -2462,18 +2469,31 @@ SDL_GL_CreateContext(SDL_Window * window)
} }
int 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); CHECK_WINDOW_MAGIC(window, -1);
if (!(window->flags & SDL_WINDOW_OPENGL)) { if (!(window->flags & SDL_WINDOW_OPENGL)) {
SDL_SetError("The specified window isn't an OpenGL window"); SDL_SetError("The specified window isn't an OpenGL window");
return -1; return -1;
} }
if (!context) { if (!ctx) {
window = NULL; 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 int
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment