aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backends/graphics/opengl/opengl-graphics.cpp46
-rw-r--r--backends/graphics/opengl/opengl-graphics.h6
-rw-r--r--backends/graphics/openglsdl/openglsdl-graphics.cpp56
3 files changed, 62 insertions, 46 deletions
diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp
index 32dd14580e..60eae8b7ea 100644
--- a/backends/graphics/opengl/opengl-graphics.cpp
+++ b/backends/graphics/opengl/opengl-graphics.cpp
@@ -814,10 +814,10 @@ void OpenGLGraphicsManager::refreshCursor() {
void OpenGLGraphicsManager::refreshCursorScale() {
// Get the window minimum scale factor. The cursor will mantain its original aspect
// ratio, and we do not want it to get too big if only one dimension is resized
- float screenScaleFactor = MIN((float)_videoMode.hardwareWidth / _videoMode.screenWidth,
- (float)_videoMode.hardwareHeight / _videoMode.screenHeight);
+ uint screenScaleFactor = MIN(_videoMode.hardwareWidth * 10000 / _videoMode.screenWidth,
+ _videoMode.hardwareHeight * 10000 / _videoMode.screenHeight);
- if (_cursorTargetScale >= screenScaleFactor && _videoMode.scaleFactor >= screenScaleFactor) {
+ if (_cursorTargetScale * 10000 >= screenScaleFactor && _videoMode.scaleFactor * 10000 >= screenScaleFactor) {
// If the cursor target scale and the video mode scale factor are bigger than
// the current window scale, do not scale the cursor for the overlay
_cursorState.rW = _cursorState.w;
@@ -826,33 +826,33 @@ void OpenGLGraphicsManager::refreshCursorScale() {
_cursorState.rHotY = _cursorState.hotY;
} else {
// Otherwise, scale the cursor for the overlay
- float targetScaleFactor = MIN(_cursorTargetScale, _videoMode.scaleFactor);
- float actualFactor = (screenScaleFactor - targetScaleFactor + 1);
- _cursorState.rW = (int16)(_cursorState.w * actualFactor);
- _cursorState.rH = (int16)(_cursorState.h * actualFactor);
- _cursorState.rHotX = (int16)(_cursorState.hotX * actualFactor);
- _cursorState.rHotY = (int16)(_cursorState.hotY * actualFactor);
+ int targetScaleFactor = MIN(_cursorTargetScale, _videoMode.scaleFactor);
+ int actualFactor = screenScaleFactor - (targetScaleFactor - 1) * 10000;
+ _cursorState.rW = (int16)(_cursorState.w * actualFactor / 10000);
+ _cursorState.rH = (int16)(_cursorState.h * actualFactor / 10000);
+ _cursorState.rHotX = (int16)(_cursorState.hotX * actualFactor / 10000);
+ _cursorState.rHotY = (int16)(_cursorState.hotY * actualFactor / 10000);
}
// Always scale the cursor for the game
- _cursorState.vW = (int16)(_cursorState.w * screenScaleFactor);
- _cursorState.vH = (int16)(_cursorState.h * screenScaleFactor);
- _cursorState.vHotX = (int16)(_cursorState.hotX * screenScaleFactor);
- _cursorState.vHotY = (int16)(_cursorState.hotY * screenScaleFactor);
+ _cursorState.vW = (int16)(_cursorState.w * screenScaleFactor / 10000);
+ _cursorState.vH = (int16)(_cursorState.h * screenScaleFactor / 10000);
+ _cursorState.vHotX = (int16)(_cursorState.hotX * screenScaleFactor / 10000);
+ _cursorState.vHotY = (int16)(_cursorState.hotY * screenScaleFactor / 10000);
}
void OpenGLGraphicsManager::refreshAspectRatio() {
_aspectWidth = _videoMode.hardwareWidth;
_aspectHeight = _videoMode.hardwareHeight;
- float aspectRatio = (float)_videoMode.hardwareWidth / _videoMode.hardwareHeight;
- float desiredAspectRatio = getAspectRatio();
+ uint aspectRatio = _videoMode.hardwareWidth * 10000 / _videoMode.hardwareHeight;
+ uint desiredAspectRatio = getAspectRatio();
// Adjust one screen dimension for mantaining the aspect ratio
if (aspectRatio < desiredAspectRatio)
- _aspectHeight = (int)(_aspectWidth / desiredAspectRatio + 0.5f);
+ _aspectHeight = _aspectWidth * 10000 / desiredAspectRatio;
else if (aspectRatio > desiredAspectRatio)
- _aspectWidth = (int)(_aspectHeight * desiredAspectRatio + 0.5f);
+ _aspectWidth = _aspectHeight * desiredAspectRatio / 10000;
// Adjust x and y for centering the screen
_aspectX = (_videoMode.hardwareWidth - _aspectWidth) / 2;
@@ -1202,18 +1202,18 @@ Common::String OpenGLGraphicsManager::getAspectRatioName() {
return "";
}
-float OpenGLGraphicsManager::getAspectRatio() {
+uint OpenGLGraphicsManager::getAspectRatio() {
switch (_videoMode.aspectRatioCorrection) {
case kAspectRatioConserve:
- return (float)_videoMode.screenWidth / _videoMode.screenHeight;
+ return _videoMode.screenWidth * 10000 / _videoMode.screenHeight;
case kAspectRatio4_3:
- return 4.0f / 3.0f;
+ return 13333;
case kAspectRatio16_9:
- return 16.0f / 9.0f;
+ return 17777;
case kAspectRatio16_10:
- return 16.0f / 10.0f;
+ return 16000;
default:
- return (float)_videoMode.hardwareWidth / _videoMode.hardwareHeight;
+ return _videoMode.hardwareWidth * 10000 / _videoMode.hardwareHeight;
}
}
diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h
index 52262fe31f..02930a4756 100644
--- a/backends/graphics/opengl/opengl-graphics.h
+++ b/backends/graphics/opengl/opengl-graphics.h
@@ -195,7 +195,11 @@ protected:
virtual void refreshAspectRatio();
virtual Common::String getAspectRatioName();
- virtual float getAspectRatio();
+
+ /**
+ * Returns the current target aspect ratio x 10000
+ */
+ virtual uint getAspectRatio();
bool _formatBGR;
diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp
index 1ac892b5b1..5b71df68af 100644
--- a/backends/graphics/openglsdl/openglsdl-graphics.cpp
+++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp
@@ -199,20 +199,21 @@ bool OpenGLSdlGraphicsManager::loadGFXMode() {
_videoMode.hardwareWidth = _videoMode.overlayWidth;
_videoMode.hardwareHeight = _videoMode.overlayHeight;
- float screenAspectRatio = (float)_videoMode.screenWidth / _videoMode.screenHeight;
- float desiredAspectRatio = getAspectRatio();
+ int screenAspectRatio = _videoMode.screenWidth * 10000 / _videoMode.screenHeight;
+ int desiredAspectRatio = getAspectRatio();
// Do not downscale dimensions, only enlarge them if needed
if (screenAspectRatio > desiredAspectRatio)
- _videoMode.hardwareHeight = (int)(_videoMode.overlayWidth / desiredAspectRatio + 0.5f);
+ _videoMode.hardwareHeight = _videoMode.overlayWidth * 10000 / desiredAspectRatio;
else if (screenAspectRatio < desiredAspectRatio)
- _videoMode.hardwareWidth = (int)(_videoMode.overlayHeight * desiredAspectRatio + 0.5f);
+ _videoMode.hardwareWidth = _videoMode.overlayHeight * desiredAspectRatio / 10000;
// Only adjust the overlay height if it is bigger than original one. If
// the width is modified it can break the overlay.
if (_videoMode.hardwareHeight > _videoMode.overlayHeight)
_videoMode.overlayHeight = _videoMode.hardwareHeight;
}
+
_screenResized = false;
@@ -232,30 +233,40 @@ bool OpenGLSdlGraphicsManager::loadGFXMode() {
int bestModeIndex = 0;
uint bestMetric = (uint)-1;
+ // Best Aspect Ratio mode
+ const SDL_Rect *bestARMode = NULL;
+ int bestARModeIndex = 0;
+ uint bestARMetric = (uint)-1;
+
+ int targetAspectRatio = _videoMode.overlayWidth * 10000 / _videoMode.overlayHeight;
+
// Iterate over all available fullscreen modes
for (int i = 0; const SDL_Rect *mode = availableModes[i]; i++) {
- // Prefer the native resolution over other modes
- if(mode->w == _desktopWidth && mode->h == _desktopHeight) {
- bestMode = mode;
- bestModeIndex = i;
- break;
- }
-
- if (mode->w < _videoMode.hardwareWidth)
+ if (mode->w < _videoMode.overlayWidth)
continue;
- if (mode->h < _videoMode.hardwareHeight)
+ if (mode->h < _videoMode.overlayHeight)
continue;
- uint metric = mode->w * mode->h - _videoMode.hardwareWidth * _videoMode.hardwareHeight;
- if (metric > bestMetric)
- continue;
-
- bestMode = mode;
- bestMetric = metric;
- bestModeIndex = i;
+ uint metric = mode->w * mode->h - _videoMode.overlayWidth * _videoMode.overlayHeight;
+ if (metric < bestMetric) {
+ bestMode = mode;
+ bestMetric = metric;
+ bestModeIndex = i;
+ }
+ if (mode->w * 10000 / mode->h == targetAspectRatio) {
+ bestARMode = mode;
+ bestARModeIndex = i;
+ bestARMetric = metric;
+ }
}
- if (bestMode) {
+ if (bestARMode) {
+ // Prefer modes that conserves the aspect ratio
+ _videoMode.hardwareWidth = bestARMode->w;
+ _videoMode.hardwareHeight = bestARMode->h;
+
+ _videoMode.activeFullscreenMode = bestARModeIndex;
+ } else if (bestMode) {
// If there is a suiting mode, use it
_videoMode.hardwareWidth = bestMode->w;
_videoMode.hardwareHeight = bestMode->h;
@@ -333,7 +344,8 @@ bool OpenGLSdlGraphicsManager::handleScalerHotkeys(Common::KeyCode key) {
char buffer[128];
sprintf(buffer, "Current aspect ratio mode: %s\n%d x %d -> %d x %d",
getAspectRatioName().c_str(),
- _videoMode.screenWidth, _videoMode.screenHeight,
+ _videoMode.screenWidth * _videoMode.scaleFactor,
+ _videoMode.screenHeight * _videoMode.scaleFactor,
_hwscreen->w, _hwscreen->h
);
displayMessageOnOSD(buffer);