[Scummvm-cvs-logs] SF.net SVN: scummvm:[51563] scummvm/branches/gsoc2010-opengl/backends/ graphics/opengl
vgvgf at users.sourceforge.net
vgvgf at users.sourceforge.net
Sun Aug 1 04:26:20 CEST 2010
Revision: 51563
http://scummvm.svn.sourceforge.net/scummvm/?rev=51563&view=rev
Author: vgvgf
Date: 2010-08-01 02:26:20 +0000 (Sun, 01 Aug 2010)
Log Message:
-----------
OPENGL: Remove use of floats for aspect ratio correction. Improved fullscreen toggling default mode selection.
Floats can lead to calculation errors because, now uints are used and aspect ratio values are handled with a x 10000 scale.
When entering fullscreen, it will be looked for the fullscreen mode with the smallest metric that mantains the game screen aspect ratio.
Modified Paths:
--------------
scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.cpp
scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.h
scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.cpp
Modified: scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.cpp
===================================================================
--- scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.cpp 2010-08-01 01:59:22 UTC (rev 51562)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.cpp 2010-08-01 02:26:20 UTC (rev 51563)
@@ -814,10 +814,10 @@
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 @@
_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 @@
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;
}
}
Modified: scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.h
===================================================================
--- scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.h 2010-08-01 01:59:22 UTC (rev 51562)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.h 2010-08-01 02:26:20 UTC (rev 51563)
@@ -195,8 +195,12 @@
virtual void refreshAspectRatio();
virtual Common::String getAspectRatioName();
- virtual float getAspectRatio();
+ /**
+ * Returns the current target aspect ratio x 10000
+ */
+ virtual uint getAspectRatio();
+
bool _formatBGR;
//
Modified: scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.cpp
===================================================================
--- scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.cpp 2010-08-01 01:59:22 UTC (rev 51562)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.cpp 2010-08-01 02:26:20 UTC (rev 51563)
@@ -199,20 +199,21 @@
_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 @@
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) {
+ if (mode->w < _videoMode.overlayWidth)
+ continue;
+ if (mode->h < _videoMode.overlayHeight)
+ continue;
+
+ uint metric = mode->w * mode->h - _videoMode.overlayWidth * _videoMode.overlayHeight;
+ if (metric < bestMetric) {
bestMode = mode;
+ bestMetric = metric;
bestModeIndex = i;
- break;
}
+ if (mode->w * 10000 / mode->h == targetAspectRatio) {
+ bestARMode = mode;
+ bestARModeIndex = i;
+ bestARMetric = metric;
+ }
+ }
- if (mode->w < _videoMode.hardwareWidth)
- continue;
- if (mode->h < _videoMode.hardwareHeight)
- continue;
+ if (bestARMode) {
+ // Prefer modes that conserves the aspect ratio
+ _videoMode.hardwareWidth = bestARMode->w;
+ _videoMode.hardwareHeight = bestARMode->h;
- uint metric = mode->w * mode->h - _videoMode.hardwareWidth * _videoMode.hardwareHeight;
- if (metric > bestMetric)
- continue;
-
- bestMode = mode;
- bestMetric = metric;
- bestModeIndex = i;
- }
-
- if (bestMode) {
+ _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 @@
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);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list