changeset 643:edf6dcfe8cd4

* Modified the way we detect valid resolutions because SDL_VideoModeOK() was unreliable on a Mac when passed values returned from SDL_ListModes(). It now uses a pre-canned list of common resolutions to check.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Sat, 09 Oct 2010 17:00:33 +0000
parents 6e2151325017
children b84dbc4665b0
files engine/core/controller/engine.cpp engine/core/video/devicecaps.cpp engine/core/video/devicecaps.h
diffstat 3 files changed, 47 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/engine/core/controller/engine.cpp	Fri Oct 08 21:22:02 2010 +0000
+++ b/engine/core/controller/engine.cpp	Sat Oct 09 17:00:33 2010 +0000
@@ -103,7 +103,8 @@
 		m_gui_graphics(0),
 		m_logmanager(0),
 		m_cursor(0),
-		m_settings() {
+		m_settings(),
+		m_devcaps(){
 #ifdef USE_COCOA
 		// The next lines ensure that Cocoa is initialzed correctly.
 		// This is needed for SDL to function properly on MAC OS X.
@@ -308,9 +309,11 @@
 
 		TTF_Quit();
 		SDL_Quit();
+		
 #ifdef USE_COCOA
 		objc_msgSend(m_autoreleasePool, sel_registerName("release"));
 #endif
+		
 		FL_LOG(_log, "================== Engine destructed ==================");
 		m_destroyed = true;
 		//delete m_logmanager;
--- a/engine/core/video/devicecaps.cpp	Fri Oct 08 21:22:02 2010 +0000
+++ b/engine/core/video/devicecaps.cpp	Sat Oct 09 17:00:33 2010 +0000
@@ -118,8 +118,6 @@
 		int numBPP = 1;
 		int bpps[numBPP];
 
-		SDL_Rect **modes;
-
 		//clear in case this is called twice
 		reset();
 
@@ -148,31 +146,52 @@
 		//BITS PER PIXEL
 
 		bpps[0] = 32;
+		
+		//COMMON FS RESOLUTIONS
+		int resolutions[15][2] = {
+			{640, 480},
+			{800, 600},
+			{1024, 768},
+			{1152, 864},
+			{1280, 768},
+			{1280, 800},
+			{1280, 960},
+			{1280, 1024},
+			{1366, 768},
+			{1440, 900},
+			{1600, 900},
+			{1600, 1200},
+			{1680, 1050},
+			{1920, 1080},
+			{1920, 1200}
+		};
+		int numRes = 15;
+
 
 		for (int i = 0; i < numBPP; ++i){
 			for (int j = 0; j < numFlags; ++j) {
-				modes = SDL_ListModes(NULL, flags[j]);
-
-				if (modes == (SDL_Rect**)0) {
-					//no modes found
-					break;
-				}
+				for ( int k = 0; k < numRes; ++k) {
+					int bpp;
+					if (flags[j] & SDL_FULLSCREEN) {
+						bpp = SDL_VideoModeOK(resolutions[k][0],resolutions[k][1], bpps[i], flags[j]);
+						
+						if (bpp > 0) {
+							ScreenMode mode = ScreenMode(resolutions[k][0],resolutions[k][1], bpps[i], flags[j]);
+							m_screenModes.push_back(mode);
+						}
+					}
+					else {  //windowed mode
+						//check an arbitrary value as we know all resolutions are supported in windowed mode.
+						//we are checking to make sure the bpp is supported here.
+						bpp = SDL_VideoModeOK(resolutions[k][0],resolutions[k][1], bpps[i], flags[j]);
+						if (bpp > 0) {
+							ScreenMode mode = ScreenMode(0,0, bpps[i], flags[j]);
+							m_screenModes.push_back(mode);
+							break; //insert windowed mode once as all resolutions are supported.
+						}
+					}
 
-				if (modes == (SDL_Rect**)-1) {
-					//All screen modes are available with the specified flags (a windowed mode most likely)
-					ScreenMode mode = ScreenMode(0, 0, bpps[i], flags[j]);
-					m_screenModes.push_back(mode);
-					continue;
 				}
-
-				for (int k = 0; modes[k]; ++k) {
-					int bpp = SDL_VideoModeOK(modes[k]->w, modes[k]->h, bpps[i], flags[j]);
-					if (bpp > 0) {
-						ScreenMode mode = ScreenMode(modes[k]->w, modes[k]->h, bpps[i], flags[j]);
-						m_screenModes.push_back(mode);
-					}
-				}
-				modes = (SDL_Rect**)0;
 			}
 		}
 
@@ -197,7 +216,7 @@
 		m_videoMem = vInfo->video_mem;
 	}
 
-	ScreenMode DeviceCaps::getNearestScreenMode(uint32_t width, uint32_t height, uint32_t bpp, const std::string& renderer, bool fs) const {
+	ScreenMode DeviceCaps::getNearestScreenMode(uint16_t width, uint16_t height, uint16_t bpp, const std::string& renderer, bool fs) const {
 		ScreenMode mode;
 		bool foundMode = false;
 
--- a/engine/core/video/devicecaps.h	Fri Oct 08 21:22:02 2010 +0000
+++ b/engine/core/video/devicecaps.h	Sat Oct 09 17:00:33 2010 +0000
@@ -125,7 +125,7 @@
 
 		/** Gets the nearest valid screen mode based on the arguments passed
 		 */
-		ScreenMode getNearestScreenMode(uint32_t width, uint32_t height, uint32_t bpp, const std::string& renderer, bool fs) const;
+		ScreenMode getNearestScreenMode(uint16_t width, uint16_t height, uint16_t bpp, const std::string& renderer, bool fs) const;
 
 		/** Returns the name of the current video driver.
 		 */