From 67d6a5a1fa48c52afd8c8db53eb68459bf3c7e1f Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Fri, 14 Dec 2012 00:51:22 +0100 Subject: [PATCH] Make sure SDL_Init() was called before SDL_VideoInfo() by adding GLimp_PreInit() --- neo/renderer/RenderSystem_init.cpp | 4 ++++ neo/renderer/tr_local.h | 4 ++++ neo/sys/sdl/sdl_glimp.cpp | 32 ++++++++++++++++++++++++------ neo/sys/win32/win_glimp.cpp | 4 ++++ 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/neo/renderer/RenderSystem_init.cpp b/neo/renderer/RenderSystem_init.cpp index 278dee1e..16c05b6f 100644 --- a/neo/renderer/RenderSystem_init.cpp +++ b/neo/renderer/RenderSystem_init.cpp @@ -870,6 +870,10 @@ void R_InitOpenGL() common->FatalError( "R_InitOpenGL called while active" ); } + // DG: make sure SDL has setup video so getting supported modes in R_SetNewMode() works + GLimp_PreInit(); + // DG end + R_SetNewMode( true ); diff --git a/neo/renderer/tr_local.h b/neo/renderer/tr_local.h index 49db4737..bec40039 100644 --- a/neo/renderer/tr_local.h +++ b/neo/renderer/tr_local.h @@ -1052,6 +1052,10 @@ struct glimpParms_t int multiSamples; }; +// DG: R_GetModeListForDisplay is called before GLimp_Init(), but SDL needs SDL_Init() first. +// So add PreInit for platforms that need it, others can just stub it. +void GLimp_PreInit(); + bool GLimp_Init( glimpParms_t parms ); // If the desired mode can't be set satisfactorily, false will be returned. // If succesful, sets glConfig.nativeScreenWidth, glConfig.nativeScreenHeight, and glConfig.pixelAspect diff --git a/neo/sys/sdl/sdl_glimp.cpp b/neo/sys/sdl/sdl_glimp.cpp index 0408f88f..6c79d382 100644 --- a/neo/sys/sdl/sdl_glimp.cpp +++ b/neo/sys/sdl/sdl_glimp.cpp @@ -53,6 +53,25 @@ static SDL_Surface* window = NULL; bool QGL_Init( const char* dllname ); void QGL_Shutdown(); +/* +=================== +GLimp_PreInit + + R_GetModeListForDisplay is called before GLimp_Init(), but SDL needs SDL_Init() first. + So do that in GLimp_PreInit() + Calling that function more than once doesn't make a difference +=================== +*/ +void GLimp_PreInit() // DG: added this function for SDL compatibility +{ + if( !SDL_WasInit( SDL_INIT_VIDEO ) ) + { + if( SDL_Init( SDL_INIT_VIDEO ) ) + common->Error( "Error while initializing SDL: %s", SDL_GetError() ); + } +} + + /* =================== GLimp_Init @@ -62,11 +81,7 @@ bool GLimp_Init( glimpParms_t parms ) { common->Printf( "Initializing OpenGL subsystem\n" ); - if( !SDL_WasInit( SDL_INIT_VIDEO ) ) - { - if( SDL_Init( SDL_INIT_VIDEO ) ) - common->Error( "Error while initializing SDL: %s", SDL_GetError() ); - } + GLimp_PreInit(); // DG: make sure SDL is initialized Uint32 flags = SDL_WINDOW_OPENGL; @@ -376,8 +391,13 @@ bool R_GetModeListForDisplay( const int requestedDisplayNum, idList& modeList.Clear(); bool verbose = false; - + const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo(); + if( videoInfo == NULL ) + { + // DG: yes, this can actually fail, e.g. if SDL_Init( SDL_INIT_VIDEO ) wasn't called + common->Error( "Can't get Video Info!\n" ); + } SDL_Rect** modes = SDL_ListModes( videoInfo->vfmt, SDL_OPENGL | SDL_FULLSCREEN ); diff --git a/neo/sys/win32/win_glimp.cpp b/neo/sys/win32/win_glimp.cpp index 00dd4bbe..0b5ffdec 100644 --- a/neo/sys/win32/win_glimp.cpp +++ b/neo/sys/win32/win_glimp.cpp @@ -1253,6 +1253,10 @@ static bool GLW_ChangeDislaySettingsIfNeeded( glimpParms_t parms ) return false; } +void GLimp_PreInit() { + // DG: not needed on this platform, so just do nothing +} + /* =================== GLimp_Init