From f3c4948b2fa9d87e36758594a050f5b44ef6571d Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Tue, 18 Dec 2012 01:07:45 +0100 Subject: [PATCH] R_GetModeListForDisplay() for SDL2 --- neo/sys/sdl/sdl_glimp.cpp | 67 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 5 deletions(-) diff --git a/neo/sys/sdl/sdl_glimp.cpp b/neo/sys/sdl/sdl_glimp.cpp index b11a8818..1c6635a2 100644 --- a/neo/sys/sdl/sdl_glimp.cpp +++ b/neo/sys/sdl/sdl_glimp.cpp @@ -447,14 +447,71 @@ R_GetModeListForDisplay */ bool R_GetModeListForDisplay( const int requestedDisplayNum, idList& modeList ) { + assert( requestedDisplayNum >= 0 ); + modeList.Clear(); - #if SDL_VERSION_ATLEAST(2, 0, 0) - // RB: TODO didn't find SDL_ListModes API - FillStaticVidModes( modeList ); - return true; + // DG: SDL2 implementation + if( requestedDisplayNum >= SDL_GetNumVideoDisplays() ) + { + // requested invalid displaynum + return false; + } -#else + int numModes = SDL_GetNumDisplayModes( requestedDisplayNum ); + if( numModes > 1 ) + { + for( int i = 0; i < numModes; i++ ) + { + SDL_DisplayMode m; + int ret = SDL_GetDisplayMode( requestedDisplayNum, i, &m ); + if( ret != 0 ) + { + common->Warning( "Can't get video mode no %i, because of %s\n", i, SDL_GetError() ); + continue; + } + + vidMode_t mode; + mode.width = m.w; + mode.height = m.h; + mode.displayHz = m.refresh_rate ? m.refresh_rate : 60; // default to 60 if unknown (0) + modeList.AddUnique( mode ); + } + + if( modeList.Num() < 1 ) + { + common->Warning( "Couldn't get information for a single video mode, using default ones..!\n" ); + FillStaticVidModes( modeList ); + } + + // sort with lowest resolution first + modeList.SortWithTemplate( idSort_VidMode() ); + + return true; + } + else + { + common->Warning( "Can't get Video Info!\n" ); + if( numModes < 0 ) + { + common->Warning( "Reason was: %s\n", SDL_GetError() ); + } + FillStaticVidModes( modeList ); + return true; + } + + return true; + // DG end + +#else // SDL 1 + + // DG: SDL1 only knows of one display - some functions rely on + // R_GetModeListForDisplay() returning false for invalid displaynum to iterate all displays + if( requestedDisplayNum >= 1 ) + { + return false; + } + // DG end bool verbose = false;