SDL: Fix default graphics mode for switchable case.

The former code (incorrectly) assumed that the getDefaultGraphicsMode returns
the index in the table returned by getSupportedGraphicsModes. Now the correct
ID is searched and then used.
This commit is contained in:
Johannes Schickel 2013-10-21 01:10:09 +02:00
parent d34c9d5bcb
commit c323dedf3c
2 changed files with 18 additions and 2 deletions

View File

@ -70,6 +70,8 @@ OSystem_SDL::OSystem_SDL()
_graphicsModes(),
_graphicsMode(0),
_firstGLMode(0),
_defaultSDLMode(0),
_defaultGLMode(0),
#endif
_inited(false),
_initedSDL(false),
@ -547,9 +549,9 @@ int OSystem_SDL::getDefaultGraphicsMode() const {
} else {
// Return the default graphics mode from the current graphics manager
if (_graphicsMode < _firstGLMode)
return _graphicsManager->getDefaultGraphicsMode();
return _defaultSDLMode;
else
return _graphicsManager->getDefaultGraphicsMode() + _firstGLMode;
return _defaultGLMode;
}
}
@ -650,27 +652,39 @@ int OSystem_SDL::getGraphicsMode() const {
void OSystem_SDL::setupGraphicsModes() {
_graphicsModes.clear();
_graphicsModeIds.clear();
_defaultSDLMode = _defaultGLMode = -1;
// Count the number of graphics modes
const OSystem::GraphicsMode *srcMode;
int defaultMode;
GraphicsManager *manager = new SurfaceSdlGraphicsManager(_eventSource);
srcMode = manager->getSupportedGraphicsModes();
defaultMode = manager->getDefaultGraphicsMode();
while (srcMode->name) {
if (defaultMode == srcMode->id) {
_defaultSDLMode = _graphicsModes.size();
}
_graphicsModes.push_back(*srcMode);
srcMode++;
}
delete manager;
assert(_defaultSDLMode != -1);
_firstGLMode = _graphicsModes.size();
manager = new OpenGLSdlGraphicsManager(_desktopWidth, _desktopHeight, _eventSource);
srcMode = manager->getSupportedGraphicsModes();
defaultMode = manager->getDefaultGraphicsMode();
while (srcMode->name) {
if (defaultMode == srcMode->id) {
_defaultGLMode = _graphicsModes.size();
}
_graphicsModes.push_back(*srcMode);
srcMode++;
}
delete manager;
manager = nullptr;
assert(_defaultGLMode != -1);
// Set a null mode at the end
GraphicsMode nullMode;

View File

@ -115,6 +115,8 @@ protected:
Common::Array<int> _graphicsModeIds;
int _graphicsMode;
int _firstGLMode;
int _defaultSDLMode;
int _defaultGLMode;
/**
* Creates the merged graphics modes list