changeset 639:685d250f2c2d

* Improvements for DeviceCaps. It now stores a list of valid SDL drivers. Currently in windows we are limited to the windows GDI (which is slow). This could mean that SDL users could benifit from hardware acceleration with directx (a valid SDL driver).
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 07 Oct 2010 16:44:44 +0000
parents 980c02db2f56
children 855ad500f991
files engine/core/controller/engine.i engine/core/video/devicecaps.cpp engine/core/video/devicecaps.h engine/core/video/video.i
diffstat 4 files changed, 70 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/engine/core/controller/engine.i	Thu Oct 07 16:15:09 2010 +0000
+++ b/engine/core/controller/engine.i	Thu Oct 07 16:44:44 2010 +0000
@@ -21,7 +21,6 @@
 %module fife
 %{
 #include "controller/engine.h"
-#include "video/devicecaps.h"
 %}
 
 namespace FIFE {
--- a/engine/core/video/devicecaps.cpp	Thu Oct 07 16:15:09 2010 +0000
+++ b/engine/core/video/devicecaps.cpp	Thu Oct 07 16:44:44 2010 +0000
@@ -50,6 +50,7 @@
 	}
 
 	DeviceCaps::DeviceCaps() :
+	    m_driverName("Invalid"),
 		m_hwAvailable(false),
 		m_wmAvailable(false),
 		m_hwBlitAccel(false),
@@ -60,12 +61,54 @@
 		m_swToHwAlphaBlitAccel(false),
 		m_BlitFillAccel(false),
 		m_videoMem(0) {
+
+		fillAvailableDrivers();
 	}
 
 
 	DeviceCaps::~DeviceCaps() {
 	}
 
+	void DeviceCaps::reset() {
+		m_screenModes.clear();
+		m_driverName = "Invalid";
+		m_hwAvailable = false;
+		m_wmAvailable = false;
+		m_hwBlitAccel = false;
+		m_hwCCBlitAccel = false;
+		m_hwToHwAlphaBlitAccel = false;
+		m_swToHwBlitAccel = false;
+		m_swToHwCCBlistAccel = false;
+		m_swToHwAlphaBlitAccel = false;
+		m_BlitFillAccel = false;
+		m_videoMem = 0;
+	}
+
+
+	void DeviceCaps::fillAvailableDrivers() {
+		m_availableDrivers.clear();
+#if defined( __unix__ )
+		m_availableDrivers.push_back("x11");
+		m_availableDrivers.push_back("nanox");
+		m_availableDrivers.push_back("qtopia");
+		m_availableDrivers.push_back("fbcon");
+		m_availableDrivers.push_back("directfb");
+		m_availableDrivers.push_back("svgalib");
+#endif
+
+// Win32
+#if defined( WIN32 )
+		m_availableDrivers.push_back("directx");
+		m_availableDrivers.push_back("windib");
+#endif
+
+// Macintosh
+#if defined( __APPLE_CC__ )
+		m_availableDrivers.push_back("Quartz");
+		m_availableDrivers.push_back("x11");
+#endif
+	}
+
 	void DeviceCaps::fillDeviceCaps() {
 		int bufferSize = 256;
 		char buffer[bufferSize];
@@ -75,6 +118,9 @@
 
 		SDL_Rect **modes;
 
+		//clear in case this is called twice
+		reset();
+
 		//FLAGS
 #ifdef HAVE_OPENGL
 		int numFlags = 4;
@@ -105,6 +151,11 @@
 			for (int j = 0; j < numFlags; ++j) {
 				modes = SDL_ListModes(NULL, flags[j]);
 
+				if (modes == (SDL_Rect**)0) {
+					//no modes found
+					break;
+				}
+
 				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]);
@@ -119,6 +170,7 @@
 						m_screenModes.push_back(mode);
 					}
 				}
+				modes = (SDL_Rect**)0;
 			}
 		}
 
--- a/engine/core/video/devicecaps.h	Thu Oct 07 16:15:09 2010 +0000
+++ b/engine/core/video/devicecaps.h	Thu Oct 07 16:44:44 2010 +0000
@@ -98,7 +98,20 @@
 		 */
 		~DeviceCaps();
 
+		/** Should be called AFTER SDL_Init() has been called
+		 */
 		void fillDeviceCaps();
+
+		/** Clears all information gathered for the device
+		 */
+		void reset();
+
+		/** Gets the available graphics drivers for your operating system
+		 */
+		std::vector<std::string> getAvailableDrivers() const { return m_availableDrivers; };
+
+		/** Returns a vector containing screen modes.
+		 */
 		std::vector<ScreenMode> getSupportedScreenModes() const { return m_screenModes; };
 
 		/** Returns the name of the current video driver.
@@ -148,6 +161,7 @@
 	private:
 		std::vector<ScreenMode> m_screenModes;
 		std::string m_driverName;
+		std::vector<std::string> m_availableDrivers;
 
 		bool m_hwAvailable;
 		bool m_wmAvailable;
@@ -161,6 +175,9 @@
 
 		uint32_t m_videoMem;
 
+		/** Called in the constructor.  No need for anyone to call this
+		 */
+		void fillAvailableDrivers();
 	}; //DeviceCaps
 }
 
--- a/engine/core/video/video.i	Thu Oct 07 16:15:09 2010 +0000
+++ b/engine/core/video/video.i	Thu Oct 07 16:44:44 2010 +0000
@@ -249,7 +249,7 @@
 		void fillDeviceCaps();
 		std::vector<ScreenMode> getSupportedScreenModes() const;
 		std::string getDriverName() const;
-		
+		std::vector<string> getAvailableDrivers() const;
 		bool isHwSurfaceAvail() const;
 		bool isWindowManagerAvail() const;
 		bool isHwBlitAccel() const;