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

Commit

Permalink
SDL_GL_MakeCurrent: Only no-op redundant calls on *same* thread.
Browse files Browse the repository at this point in the history
This ensures that we only no-op redundant calls if they're made on the
same thread as the last MakeCurrent with those arguments. This should
maek SDL behave better with multithreaded environments.
  • Loading branch information
jorgenpt committed Jul 9, 2013
1 parent 5ea198f commit f728a26
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/video/SDL_sysvideo.h
Expand Up @@ -25,6 +25,7 @@

#include "SDL_messagebox.h"
#include "SDL_shape.h"
#include "SDL_thread.h"

/* The SDL video driver */

Expand Down Expand Up @@ -301,6 +302,7 @@ struct SDL_VideoDevice
/* Cache current GL context; don't call the OS when it hasn't changed. */
SDL_Window *current_glwin;
SDL_GLContext current_glctx;
SDL_threadID current_glthread;

/* * * */
/* Data private to this driver */
Expand Down
5 changes: 4 additions & 1 deletion src/video/SDL_video.c
Expand Up @@ -2730,6 +2730,7 @@ SDL_GL_CreateContext(SDL_Window * window)
/* Creating a context is assumed to make it current in the SDL driver. */
_this->current_glwin = window;
_this->current_glctx = ctx;
_this->current_glthread = SDL_ThreadID();

return ctx;
}
Expand All @@ -2738,6 +2739,7 @@ int
SDL_GL_MakeCurrent(SDL_Window * window, SDL_GLContext ctx)
{
int retval;
SDL_threadID thread = SDL_ThreadID();

if (!ctx) {
window = NULL;
Expand All @@ -2749,13 +2751,14 @@ SDL_GL_MakeCurrent(SDL_Window * window, SDL_GLContext ctx)
}
}

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

Expand Down

0 comments on commit f728a26

Please sign in to comment.