[Commits] SDL: Turn SDL_GL_MakeCurrent() into a no-op if setting the same ...
libsdl.org revision control
commits-owner at libsdl.org
Fri Jul 15 17:06:00 PDT 2011
details: http://hg.libsdl.org/SDL/rev/2a152e7e82f2
changeset: 5563:2a152e7e82f2
user: Ryan C. Gordon <icculus at icculus.org>
date: Fri Jul 15 17:05:32 2011 -0700
description:
Turn SDL_GL_MakeCurrent() into a no-op if setting the same context twice.
diffstat:
src/video/SDL_sysvideo.h | 5 +++++
src/video/SDL_video.c | 26 +++++++++++++++++++++++---
2 files changed, 28 insertions(+), 3 deletions(-)
diffs (67 lines):
diff -r aa0e501baca0 -r 2a152e7e82f2 src/video/SDL_sysvideo.h
--- a/src/video/SDL_sysvideo.h Wed Jul 13 17:38:09 2011 -0700
+++ b/src/video/SDL_sysvideo.h Fri Jul 15 17:05:32 2011 -0700
@@ -277,6 +277,11 @@
} 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;
struct SDL_GLDriverData *gl_data;
diff -r aa0e501baca0 -r 2a152e7e82f2 src/video/SDL_video.c
--- a/src/video/SDL_video.c Wed Jul 13 17:38:09 2011 -0700
+++ b/src/video/SDL_video.c Fri Jul 15 17:05:32 2011 -0700
@@ -1931,6 +1931,13 @@
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);
@@ -2462,18 +2469,31 @@
}
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
More information about the commits
mailing list