From e3d7c44a8e42a1c44e1d75bd159fdba825af210e Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Sun, 24 Aug 2008 14:47:19 +0000 Subject: [PATCH] For the SDL version of this driver, set the video mode in the CPU thread, otherwise GL calls will crash. There is a big comment block with all the details. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@291 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Plugins/Plugin_VideoOGL/Src/GLInit.cpp | 68 +++++++++---------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/GLInit.cpp b/Source/Plugins/Plugin_VideoOGL/Src/GLInit.cpp index 38728ba357..35e5f1f33f 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/GLInit.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/GLInit.cpp @@ -407,10 +407,7 @@ bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight XMapRaised(GLWin.dpy, GLWin.win); } #else - //SDL for other OS (osx, bsd, ...) - int videoFlags = SDL_OPENGL; - SDL_Surface *screen; - const SDL_VideoInfo *videoInfo; + //SDL for other OS (osx, bsd, ...) //init sdl video if (SDL_Init(SDL_INIT_VIDEO) < 0) { @@ -418,39 +415,14 @@ bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight SDL_Quit(); return false; } - //fetch video info - videoInfo = SDL_GetVideoInfo(); - if (!videoInfo) { - //TODO : Display an error message - SDL_Quit(); - return false; - } - //hw or sw ogl ? - if (videoInfo->hw_available) - videoFlags |= SDL_HWSURFACE; - else - videoFlags |= SDL_SWSURFACE; - - //fullscreen or not - if(g_Config.bFullscreen) - videoFlags |= SDL_FULLSCREEN; - //setup ogl to use double buffering SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - - screen = SDL_SetVideoMode(_twidth, _theight, 0, videoFlags); - if (!screen) { - //TODO : Display an error message - SDL_Quit(); - return false; - } - - + #endif return true; } - + bool OpenGL_MakeCurrent() { #if defined(_WIN32) @@ -475,10 +447,36 @@ bool OpenGL_MakeCurrent() XSelectInput(GLWin.dpy, GLWin.win, ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | StructureNotifyMask | EnterWindowMask | LeaveWindowMask | FocusChangeMask ); -#else - - //TODO - +#else + // Note: The reason for having the call to SDL_SetVideoMode in here instead + // of in OpenGL_Create() is that "make current" is part of the video + // mode setting and is not available as a separate call in SDL. We + // have to do "make current" here because this method runs in the CPU + // thread while OpenGL_Create() runs in a diferent thread and "make + // current" has to be done in the same thread that will be making + // calls to OpenGL. + + // Fetch video info. + const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo(); + if (!videoInfo) { + // TODO: Display an error message. + SDL_Quit(); + return false; + } + // Compute video mode flags. + const int videoFlags = SDL_OPENGL + | ( videoInfo->hw_available ? SDL_HWSURFACE : SDL_SWSURFACE ) + | ( g_Config.bFullscreen ? SDL_FULLSCREEN : 0); + // Set vide mode. + // TODO: Can we use this field or is a separate field needed? + int _twidth = nBackbufferWidth; + int _theight = nBackbufferHeight; + SDL_Surface *screen = SDL_SetVideoMode(_twidth, _theight, 0, videoFlags); + if (!screen) { + //TODO : Display an error message + SDL_Quit(); + return false; + } #endif return true; }