R_GetModeListForDisplay() for SDL2

This commit is contained in:
Daniel Gibson 2012-12-18 01:07:45 +01:00
parent dd987814f7
commit f3c4948b2f

View file

@ -447,14 +447,71 @@ R_GetModeListForDisplay
*/
bool R_GetModeListForDisplay( const int requestedDisplayNum, idList<vidMode_t>& 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;