comparison engine/core/video/devicecaps.cpp @ 642:6e2151325017

* Added the ability to query the current running screen mode * Added a method to detect the closest supported screen mode (not complete yet). If no matching screen modes are detected an exception is thrown. * Small change to the way the screen is initialized. The screen mode now MUST be in the supported screen mode list before the screen will initialize.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Fri, 08 Oct 2010 21:22:02 +0000
parents 685d250f2c2d
children edf6dcfe8cd4
comparison
equal deleted inserted replaced
641:52708806f35c 642:6e2151325017
28 28
29 // FIFE includes 29 // FIFE includes
30 // These includes are split up in two parts, separated by one empty line 30 // These includes are split up in two parts, separated by one empty line
31 // First block: files included from the FIFE root src directory 31 // First block: files included from the FIFE root src directory
32 // Second block: files included from the same folder 32 // Second block: files included from the same folder
33 #include "util/base/exception.h"
34
33 #include "devicecaps.h" 35 #include "devicecaps.h"
34 36
35 namespace FIFE { 37 namespace FIFE {
36 38
37 ScreenMode::ScreenMode() : 39 ScreenMode::ScreenMode() :
125 #ifdef HAVE_OPENGL 127 #ifdef HAVE_OPENGL
126 int numFlags = 4; 128 int numFlags = 4;
127 Uint32 flags[numFlags]; 129 Uint32 flags[numFlags];
128 130
129 //OpenGL, windowed, hw accel 131 //OpenGL, windowed, hw accel
130 flags[0] = SDL_OPENGL | SDL_HWPALETTE | SDL_HWACCEL; 132 flags[0] = ScreenMode::HW_WINDOWED_OPENGL;
131 //OpenGL, fullscree, hw accel 133 //OpenGL, fullscree, hw accel
132 flags[1] = SDL_OPENGL | SDL_HWPALETTE | SDL_HWACCEL | SDL_FULLSCREEN; 134 flags[1] = ScreenMode::HW_FULLSCREEN_OPENGL;
133 //SDL, windowed 135 //SDL, windowed
134 flags[2] = 0; 136 flags[2] = ScreenMode::WINDOWED_SDL;
135 //SDL, fullscreen 137 //SDL, fullscreen
136 flags[3] = SDL_FULLSCREEN; 138 flags[3] = ScreenMode::FULLSCREEN_SDL;
137 #else 139 #else
138 int numFlags = 2; 140 int numFlags = 2;
139 Uint32 flags[numFlags]; 141 Uint32 flags[numFlags];
140 142
141 //SDL, windowed 143 //SDL, windowed
142 flags[0] = 0; 144 flags[0] = ScreenMode::WINDOWED_SDL;
143 //SDL, fullscreen 145 //SDL, fullscreen
144 flags[1] = SDL_FULLSCREEN; 146 flags[1] = ScreenMode::FULLSCREEN_SDL;
145 #endif 147 #endif
146 //BITS PER PIXEL 148 //BITS PER PIXEL
147 149
148 bpps[0] = 32; 150 bpps[0] = 32;
149 151
193 m_swToHwAlphaBlitAccel = vInfo->blit_sw_A; 195 m_swToHwAlphaBlitAccel = vInfo->blit_sw_A;
194 m_BlitFillAccel = vInfo->blit_fill; 196 m_BlitFillAccel = vInfo->blit_fill;
195 m_videoMem = vInfo->video_mem; 197 m_videoMem = vInfo->video_mem;
196 } 198 }
197 199
200 ScreenMode DeviceCaps::getNearestScreenMode(uint32_t width, uint32_t height, uint32_t bpp, const std::string& renderer, bool fs) const {
201 ScreenMode mode;
202 bool foundMode = false;
203
204 bool widthCheck = false;
205 bool heightCheck = false;
206 bool bppCheck = false;
207 bool rendCheck = false;
208 bool fsCheck = false;
209
210
211 for (uint32_t i = 0; i < m_screenModes.size(); i++) {
212 if (m_screenModes[i].getWidth() == width) {
213 widthCheck = true;
214 }
215 if (m_screenModes[i].getHeight() == height) {
216 heightCheck = true;
217 }
218 if (m_screenModes[i].getBPP() == bpp) {
219 bppCheck = true;
220 }
221 if (m_screenModes[i].isFullScreen() == fs) {
222 fsCheck = true;
223 }
224
225 if ((m_screenModes[i].isOpenGL() && renderer == "OpenGL") || (!m_screenModes[i].isOpenGL() && renderer == "SDL")){
226 rendCheck = true;
227 }
228
229 //check for exact match
230 if (widthCheck && heightCheck && bppCheck && fsCheck && rendCheck) {
231 mode = m_screenModes[i];
232 foundMode = true;
233 break;
234 }
235
236 //@note When the width and height to 0 that means that all
237 //resolutions are supported
238 if (m_screenModes[i].getWidth() == 0 && m_screenModes[i].getHeight() == 0 && bppCheck && fsCheck && rendCheck) {
239 mode = ScreenMode(width, height, bpp, m_screenModes[i].getSDLFlags());
240 foundMode = true;
241 break;
242 }
243
244 widthCheck = false;
245 heightCheck = false;
246 bppCheck = false;
247 rendCheck = false;
248 fsCheck = false;
249 }
250
251 if (!foundMode) {
252 throw NotSupported("Could not find a maching screen mode for the values given!");
253 }
254
255 return mode;
256 }
257
198 } //FIFE 258 } //FIFE