28 #include <SDL_video.h> 41 m_width(0), m_height(0), m_bpp(0), m_refreshRate(0), m_SDLFlags(0),
42 m_format(0), m_display(0), m_renderDriver(
""), m_renderDriverIndex(-1) {
107 m_videoDriverName(
"dummy"),
108 m_renderDriverName(
""),
126 uint8_t driverCount = SDL_GetNumVideoDrivers();
127 for (
uint8_t i = 0; i != driverCount; i++) {
128 std::string driver(SDL_GetVideoDriver(i));
135 SDL_RendererInfo info;
136 driverCount = SDL_GetNumRenderDrivers();
137 for (
uint8_t i = 0; i != driverCount; i++) {
138 SDL_GetRenderDriverInfo(i, &info);
139 std::string name(info.name);
181 uint8_t displayCount = SDL_GetNumVideoDisplays();
182 for (
uint8_t i = 0; i != displayCount; i++) {
183 SDL_DisplayMode mode;
184 uint8_t displayModes = SDL_GetNumDisplayModes(i);
185 for (
uint8_t m = 0; m != displayModes; m++) {
186 if (SDL_GetDisplayMode(i, m, &mode) == 0) {
187 for (
uint32_t ii = 0; ii < numBPP; ++ii){
188 for (
uint32_t j = 0; j < numFlags; ++j) {
190 ScreenMode m(mode.w, mode.h, bpps[ii], mode.refresh_rate, flags[j]);
201 throw SDLException(SDL_GetError());
218 SDL_DisplayMode target, closest;
219 bool foundMode =
false;
226 }
else if (bpp == 16) {
227 target.format = SDL_PIXELFORMAT_RGB565;
229 target.format = SDL_PIXELFORMAT_RGB888;
231 target.refresh_rate = refresh;
232 target.driverdata = 0;
235 if (SDL_GetClosestDisplayMode(display, &target, &closest)) {
237 if (renderer ==
"OpenGL") {
239 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN;
241 flags = SDL_WINDOW_OPENGL;
245 flags = SDL_WINDOW_FULLSCREEN;
248 mode =
ScreenMode(closest.w, closest.h, bpp, closest.refresh_rate, flags);
259 throw NotSupported(
"Could not find a matching screen mode for the values given!");
268 for (
uint8_t i = 0; i != driverCount; i++) {
278 throw NotSupported(
"Could not find a matching render driver!");
288 uint8_t displayCount = SDL_GetNumVideoDisplays();
294 throw NotSupported(
"Could not find a matching display!");
295 return std::string(
"Invalid");
297 std::string displayName(SDL_GetDisplayName(display));
302 SDL_DisplayMode mode;
303 if (SDL_GetDesktopDisplayMode(display, &mode) != 0) {
304 throw SDLException(SDL_GetError());
310 SDL_DisplayMode mode;
311 if (SDL_GetDesktopDisplayMode(display, &mode) != 0) {
312 throw SDLException(SDL_GetError());
314 return mode.refresh_rate;
318 SDL_DisplayMode mode;
319 if (SDL_GetDesktopDisplayMode(display, &mode) != 0) {
320 throw SDLException(SDL_GetError());
326 SDL_DisplayMode mode;
327 if (SDL_GetDesktopDisplayMode(display, &mode) != 0) {
328 throw SDLException(SDL_GetError());
335 if (SDL_GetDisplayBounds(display, &srec) != 0) {
336 throw SDLException(SDL_GetError());
338 Rect rec(srec.x, srec.y, srec.w, srec.h);
uint8_t getDisplay() const
Returns the display index.
uint16_t getHeight() const
Returns the height of the screen mode.
std::vector< std::string > m_availableVideoDrivers
uint32_t getSDLFlags() const
Returns the SDL flags used when testing this mode.
int8_t getRenderDriverIndex() const
Returns the index of the render driver.
std::string m_renderDriverName
int32_t getDesktopHeight(uint8_t display=0) const
Returns the height of the desktop resolution for the given display index.
std::string m_videoDriverName
Rect getDisplayBounds(uint8_t display=0) const
Returns the bounding points for the given display index.
uint32_t getFormat() const
Returns the pixel format enum.
bool operator<(const ScreenMode &rhs) const
void setFormat(uint32_t format)
Sets the pixel format enum.
void setRenderDriverName(const std::string driver)
Sets the render driver name.
uint32_t getDesktopFormat(uint8_t display=0) const
Returns the SDL_PixelFormatEnum of the desktop for the given display index.
int32_t getDesktopWidth(uint8_t display=0) const
Returns the width of the desktop resolution for the given display index.
uint8_t getDisplayCount() const
Returns the number of displays.
void fillAvailableDrivers()
Called in the constructor.
std::string getDisplayName(uint8_t display=0) const
Returns the display name for the given display index.
static const uint32_t WINDOWED_OPENGL
ScreenMode()
Default Constructor.
static const uint32_t FULLSCREEN_SDL
void reset()
Clears all information gathered for the device.
uint16_t getBPP() const
Returns the number of bits per pixel this mode uses.
int8_t m_renderDriverIndex
ScreenMode getNearestScreenMode(uint16_t width, uint16_t height, uint16_t bpp, const std::string &renderer, bool fs) const
Gets the nearest valid screen mode based on the arguments passed.
void setRenderDriverName(const std::string &driver)
Sets the name of the render driver.
void fillDeviceCaps()
Should be called AFTER SDL_Init() has been called.
static const uint32_t FULLSCREEN_OPENGL
int8_t m_renderDriverIndex
static const uint32_t WINDOWED_SDL
const std::string & getRenderDriverName() const
Returns the render driver name.
void setDisplay(uint8_t display)
Sets the display index.
std::string m_renderDriver
void setRenderDriverIndex(int8_t index)
Sets the index of the render driver used by SDL.
uint16_t getWidth() const
Returns the width of the screen mode.
std::vector< ScreenMode > m_screenModes
uint16_t getRefreshRate() const
Returns the refresh rate in Hz of this mode.
int32_t getDesktopRefreshRate(uint8_t display=0) const
Returns the refresh rate in Hz of the desktop for the given display index.
bool isFullScreen() const
True if this is a fullscreen mode.
std::vector< std::string > m_availableRenderDrivers