Attempt to fix the retrieval of supported video resolutions

This commit is contained in:
Mark Vejvoda
2010-04-01 16:23:25 +00:00
parent 02c41f7b77
commit 05a031cc0e

View File

@@ -23,6 +23,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <direct.h> #include <direct.h>
#include <algorithm> #include <algorithm>
#include <map>
#include <SDL.h> #include <SDL.h>
#include "sdl_private.h" #include "sdl_private.h"
@@ -650,47 +651,86 @@ void getFullscreenVideoInfo(int &colorBits,int &screenWidth,int &screenHeight) {
} }
} }
void getFullscreenVideoModes(list<ModeInfo> *modeinfos) { void getFullscreenVideoModes(list<ModeInfo> *modeinfos) {
// Get the current video hardware information // Get the current video hardware information
//const SDL_VideoInfo* vidInfo = SDL_GetVideoInfo(); //const SDL_VideoInfo* vidInfo = SDL_GetVideoInfo();
//colorBits = vidInfo->vfmt->BitsPerPixel; //colorBits = vidInfo->vfmt->BitsPerPixel;
//screenWidth = vidInfo->current_w; //screenWidth = vidInfo->current_w;
//screenHeight = vidInfo->current_h; //screenHeight = vidInfo->current_h;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
/* Get available fullscreen/hardware modes */ SDL_PixelFormat format;
SDL_Rect**modes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE); SDL_Rect **modes;
int loops(0);
/* Check if there are any modes available */ int bpp(0);
if (modes == (SDL_Rect**)0) { std::map<std::string,bool> uniqueResList;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] no hardware modes available.\n",__FILE__,__FUNCTION__,__LINE__);
do
const SDL_VideoInfo* vidInfo = SDL_GetVideoInfo(); {
modeinfos->push_back(ModeInfo(vidInfo->current_w,vidInfo->current_h,vidInfo->vfmt->BitsPerPixel)); //format.BitsPerPixel seems to get zeroed out on my windows box
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] adding only current resolution: %d x %d.\n",__FILE__,__FUNCTION__,__LINE__,vidInfo->current_w,vidInfo->current_h); switch(loops)
} {
/* Check if our resolution is restricted */ case 0://32 bpp
else if (modes == (SDL_Rect**)-1) { format.BitsPerPixel = 32;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] all resolutions available.\n",__FILE__,__FUNCTION__,__LINE__); bpp = 32;
break;
const SDL_VideoInfo* vidInfo = SDL_GetVideoInfo(); case 1://24 bpp
modeinfos->push_back(ModeInfo(vidInfo->current_w,vidInfo->current_h,vidInfo->vfmt->BitsPerPixel)); format.BitsPerPixel = 24;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] adding only current resolution: %d x %d.\n",__FILE__,__FUNCTION__,__LINE__,vidInfo->current_w,vidInfo->current_h); bpp = 24;
} break;
else{ case 2://16 bpp
/* Print valid modes */ format.BitsPerPixel = 16;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] available Modes are:\n",__FILE__,__FUNCTION__,__LINE__); bpp = 16;
break;
int bestW = -1; }
int bestH = -1;
for(int i=0; modes[i]; ++i) { /* Get available fullscreen/hardware modes */
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%d x %d\n",modes[i]->w, modes[i]->h,modes[i]->x); //SDL_Rect**modes = SDL_ListModes(NULL, SDL_OPENGL|SDL_RESIZABLE);
modeinfos->push_back(ModeInfo(modes[i]->w,modes[i]->h,modes[i]->x)); SDL_Rect**modes = SDL_ListModes(&format, SDL_FULLSCREEN);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] adding resolution: %d x %d.\n",__FILE__,__FUNCTION__,__LINE__,modes[i]->w,modes[i]->h);
} /* Check if there are any modes available */
} if (modes == (SDL_Rect**)0) {
} SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] no hardware modes available.\n",__FILE__,__FUNCTION__,__LINE__);
const SDL_VideoInfo* vidInfo = SDL_GetVideoInfo();
string lookupKey = intToStr(vidInfo->current_w) + "_" + intToStr(vidInfo->current_h) + "_" + intToStr(vidInfo->vfmt->BitsPerPixel);
if(uniqueResList.find(lookupKey) == uniqueResList.end()) {
uniqueResList[lookupKey] = true;
modeinfos->push_back(ModeInfo(vidInfo->current_w,vidInfo->current_h,vidInfo->vfmt->BitsPerPixel));
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] adding only current resolution: %d x %d.\n",__FILE__,__FUNCTION__,__LINE__,vidInfo->current_w,vidInfo->current_h);
}
/* Check if our resolution is restricted */
else if (modes == (SDL_Rect**)-1) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] all resolutions available.\n",__FILE__,__FUNCTION__,__LINE__);
const SDL_VideoInfo* vidInfo = SDL_GetVideoInfo();
string lookupKey = intToStr(vidInfo->current_w) + "_" + intToStr(vidInfo->current_h) + "_" + intToStr(vidInfo->vfmt->BitsPerPixel);
if(uniqueResList.find(lookupKey) == uniqueResList.end()) {
uniqueResList[lookupKey] = true;
modeinfos->push_back(ModeInfo(vidInfo->current_w,vidInfo->current_h,vidInfo->vfmt->BitsPerPixel));
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] adding only current resolution: %d x %d.\n",__FILE__,__FUNCTION__,__LINE__,vidInfo->current_w,vidInfo->current_h);
}
else{
/* Print valid modes */
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] available Modes are:\n",__FILE__,__FUNCTION__,__LINE__);
int bestW = -1;
int bestH = -1;
for(int i=0; modes[i]; ++i) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%d x %d\n",modes[i]->w, modes[i]->h,modes[i]->x);
string lookupKey = intToStr(modes[i]->w) + "_" + intToStr(modes[i]->h) + "_" + intToStr(modes[i]->x);
if(uniqueResList.find(lookupKey) == uniqueResList.end()) {
uniqueResList[lookupKey] = true;
modeinfos->push_back(ModeInfo(modes[i]->w,modes[i]->h,modes[i]->x));
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] adding resolution: %d x %d.\n",__FILE__,__FUNCTION__,__LINE__,modes[i]->w,modes[i]->h);
}
}
}
} while(++loops != 3);
}
bool changeVideoMode(int resW, int resH, int colorBits, int ) { bool changeVideoMode(int resW, int resH, int colorBits, int ) {
Private::shouldBeFullscreen = true; Private::shouldBeFullscreen = true;