void GraphicsManager::setFullScreen(bool fullScreen) { if (_fullScreen == fullScreen) // Nothing to do return; // Force calling it from the main thread if (!Common::isMainThread()) { Events::MainThreadFunctor<void> functor(boost::bind(&GraphicsManager::setFullScreen, this, fullScreen)); return RequestMan.callInMainThread(functor); } destroyContext(); // uint32 flags = SDL_GetWindowFlags(_screen); // Now try to change modes SDL_SetWindowFullscreen(_screen, SDL_WINDOW_FULLSCREEN); // If we could not go full screen, revert back. if (!_screen) SDL_SetWindowFullscreen(_screen, 0); else _fullScreen = fullScreen; // There's no reason how this could possibly fail, but ok... if (!_screen) throw Common::Exception("Failed going to fullscreen and then failed reverting."); rebuildContext(); }
void GraphicsManager::setFullScreen(bool fullScreen) { if (_fullScreen == fullScreen) // Nothing to do return; if (!Common::isMainThread()) { // Not the main thread, send a request instead RequestMan.dispatchAndWait(RequestMan.fullscreen(fullScreen)); return; } destroyContext(); // Save the flags uint32 flags = _screen->flags; // Now try to change modes _screen = SDL_SetVideoMode(0, 0, 0, flags ^ SDL_FULLSCREEN); // If we could not go full screen, revert back. if (!_screen) _screen = SDL_SetVideoMode(0, 0, 0, flags); else _fullScreen = fullScreen; // There's no reason how this could possibly fail, but ok... if (!_screen) throw Common::Exception("Failed going to fullscreen and then failed reverting."); rebuildContext(); }
void GraphicsManager::setScreenSize(int width, int height) { // Force calling it from the main thread if (!Common::isMainThread()) { Events::MainThreadFunctor<void> functor(boost::bind(&GraphicsManager::setScreenSize, this, width, height)); return RequestMan.callInMainThread(functor); } // Save properties // uint32 flags = SDL_GetWindowFlags(_screen); destroyContext(); SDL_DisplayMode displayMode; // Now try to change modes if (!_fullScreen) { SDL_SetWindowSize(_screen, width, height); } else { SDL_SetWindowFullscreen(_screen, 0); displayMode.w = width; displayMode.h = height; displayMode.driverdata = 0; displayMode.refresh_rate = 0; displayMode.format = 0; SDL_SetWindowDisplayMode(_screen, &displayMode); SDL_SetWindowFullscreen(_screen, SDL_WINDOW_FULLSCREEN); } if (!_screen) { // Could not change mode, revert back. if (!_fullScreen) SDL_SetWindowSize(_screen, _width, _height); else { displayMode.w = _width; displayMode.h = _height; SDL_SetWindowDisplayMode(_screen, &displayMode); } // There's no reason how this could possibly fail, but ok... if (!_screen) throw Common::Exception("Failed changing the resolution and then failed reverting."); return; } _width = width; _height = height; rebuildContext(); // Let the NotificationManager notify the Notifyables that the resolution changed NotificationMan.resized(_width, _height, width, height); }
bool GraphicsManager::setFSAA(int level) { // Force calling it from the main thread if (!Common::isMainThread()) { Events::MainThreadFunctor<bool> functor(boost::bind(&GraphicsManager::setFSAA, this, level)); return RequestMan.callInMainThread(functor); } if (_fsaa == level) // Nothing to do return true; // Check if we have the support for that level if (level > _fsaaMax) return false; // Backup the old level and set the new level int oldFSAA = _fsaa; _fsaa = level; destroyContext(); // Set the multisample level SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, (_fsaa > 0) ? 1 : 0); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, _fsaa); uint32 flags = _screen->flags; // Now try to change the screen _screen = SDL_SetVideoMode(0, 0, 0, flags); if (!_screen) { // Failed changing, back up _fsaa = oldFSAA; // Set the multisample level SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, (_fsaa > 0) ? 1 : 0); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, _fsaa); _screen = SDL_SetVideoMode(0, 0, 0, flags); // There's no reason how this could possibly fail, but ok... if (!_screen) throw Common::Exception("Failed reverting to the old FSAA settings"); } rebuildContext(); return _fsaa == level; }
void GraphicsManager::setScreenSize(int width, int height) { if ((width == _screen->w) && (height == _screen->h)) // No changes, nothing to do return; // Force calling it from the main thread if (!Common::isMainThread()) { Events::MainThreadFunctor<void> functor(boost::bind(&GraphicsManager::setScreenSize, this, width, height)); return RequestMan.callInMainThread(functor); } // Save properties uint32 flags = _screen->flags; int bpp = _screen->format->BitsPerPixel; int oldWidth = _screen->w; int oldHeight = _screen->h; destroyContext(); // Now try to change modes _screen = SDL_SetVideoMode(width, height, bpp, flags); if (!_screen) { // Could not change mode, revert back. _screen = SDL_SetVideoMode(oldWidth, oldHeight, bpp, flags); } // There's no reason how this could possibly fail, but ok... if (!_screen) throw Common::Exception("Failed changing the resolution and then failed reverting."); rebuildContext(); // Let the NotificationManager notify the Notifyables that the resolution changed if ((oldWidth != _screen->w) || (oldHeight != _screen->h)) NotificationMan.resized(oldWidth, oldHeight, _screen->w, _screen->h); }
bool GraphicsManager::setFSAA(int level) { // Force calling it from the main thread if (!Common::isMainThread()) { Events::MainThreadFunctor<bool> functor(boost::bind(&GraphicsManager::setFSAA, this, level)); return RequestMan.callInMainThread(functor); } if (_fsaa == level) // Nothing to do return true; // Check if we have the support for that level if (level > _fsaaMax) return false; // Backup the old level and set the new level int oldFSAA = _fsaa; _fsaa = level; destroyContext(); uint32 flags = SDL_GetWindowFlags(_screen); int displayIndex = SDL_GetWindowDisplayIndex(_screen); SDL_GL_DeleteContext(_glContext); SDL_DestroyWindow(_screen); // Set the multisample level SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, (_fsaa > 0) ? 1 : 0); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, _fsaa); // Now try to change the screen _screen = SDL_CreateWindow(_windowTitle.c_str(), SDL_WINDOWPOS_UNDEFINED_DISPLAY(displayIndex), SDL_WINDOWPOS_UNDEFINED_DISPLAY(displayIndex), _width, _height, flags); if (!_screen) { // Failed changing, back up _fsaa = oldFSAA; // Set the multisample level SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, (_fsaa > 0) ? 1 : 0); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, _fsaa); _screen = SDL_CreateWindow(_windowTitle.c_str(), SDL_WINDOWPOS_UNDEFINED_DISPLAY(displayIndex), SDL_WINDOWPOS_UNDEFINED_DISPLAY(displayIndex), _width, _height, flags); // There's no reason how this could possibly fail, but ok... if (!_screen) throw Common::Exception("Failed reverting to the old FSAA settings"); } setWindowIcon(*_screen); // Initial call to setupSDLGL has already identified which GL context we can use. if (_gl3) { SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); } else { SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); } _glContext = SDL_GL_CreateContext(_screen); rebuildContext(); return _fsaa == level; }