SDL: Prevent unnecessary gfx manager hotswap

This commit is contained in:
dhewg 2011-02-24 19:47:08 +01:00
parent 2e1497d835
commit 273a324a71

View file

@ -125,10 +125,11 @@ void OSystem_SDL::init() {
if (_timerManager == 0) if (_timerManager == 0)
_timerManager = new SdlTimerManager(); _timerManager = new SdlTimerManager();
#ifdef USE_OPENGL #ifdef USE_OPENGL
// Setup a list with both SDL and OpenGL graphics modes // Setup a list with both SDL and OpenGL graphics modes
setupGraphicsModes(); setupGraphicsModes();
#endif _graphicsMode = _sdlModesCount;
#endif
} }
void OSystem_SDL::initBackend() { void OSystem_SDL::initBackend() {
@ -464,6 +465,7 @@ int OSystem_SDL::getDefaultGraphicsMode() const {
bool OSystem_SDL::setGraphicsMode(int mode) { bool OSystem_SDL::setGraphicsMode(int mode) {
const OSystem::GraphicsMode *srcMode; const OSystem::GraphicsMode *srcMode;
int i; int i;
// Check if mode is from SDL or OpenGL // Check if mode is from SDL or OpenGL
if (mode < _sdlModesCount) { if (mode < _sdlModesCount) {
srcMode = SdlGraphicsManager::supportedGraphicsModes(); srcMode = SdlGraphicsManager::supportedGraphicsModes();
@ -472,28 +474,34 @@ bool OSystem_SDL::setGraphicsMode(int mode) {
srcMode = OpenGLSdlGraphicsManager::supportedGraphicsModes(); srcMode = OpenGLSdlGraphicsManager::supportedGraphicsModes();
i = _sdlModesCount; i = _sdlModesCount;
} }
// Loop through modes // Loop through modes
while (srcMode->name) { while (srcMode->name) {
if (i == mode) { if (i == mode) {
// If the new mode and the current mode are not from the same graphics // If the new mode and the current mode are not from the same graphics
// manager, delete and create the new mode graphics manager // manager, delete and create the new mode graphics manager
if (_graphicsMode >= _sdlModesCount && mode < _sdlModesCount) { if (_graphicsMode >= _sdlModesCount && mode < _sdlModesCount) {
debug(1, "switching to plain SDL graphics");
delete _graphicsManager; delete _graphicsManager;
_graphicsManager = new SdlGraphicsManager(_eventSource); _graphicsManager = new SdlGraphicsManager(_eventSource);
((SdlGraphicsManager *)_graphicsManager)->initEventObserver(); ((SdlGraphicsManager *)_graphicsManager)->initEventObserver();
_graphicsManager->beginGFXTransaction(); _graphicsManager->beginGFXTransaction();
} else if (_graphicsMode < _sdlModesCount && mode >= _sdlModesCount) { } else if (_graphicsMode < _sdlModesCount && mode >= _sdlModesCount) {
debug(1, "switching to OpenGL graphics");
delete _graphicsManager; delete _graphicsManager;
_graphicsManager = new OpenGLSdlGraphicsManager(); _graphicsManager = new OpenGLSdlGraphicsManager();
((OpenGLSdlGraphicsManager *)_graphicsManager)->initEventObserver(); ((OpenGLSdlGraphicsManager *)_graphicsManager)->initEventObserver();
_graphicsManager->beginGFXTransaction(); _graphicsManager->beginGFXTransaction();
} }
_graphicsMode = mode; _graphicsMode = mode;
return _graphicsManager->setGraphicsMode(srcMode->id); return _graphicsManager->setGraphicsMode(srcMode->id);
} }
i++; i++;
srcMode++; srcMode++;
} }
return false; return false;
} }