From 97c8746d2e3a889d529eb1a7349c4cce69c49f54 Mon Sep 17 00:00:00 2001 From: Le Philousophe Date: Sun, 5 Feb 2023 20:44:01 +0100 Subject: [PATCH] BACKENDS: OPENGL: Use a floating point cursor size When scaler shaders are used, cursor size is adapted to scale on the game screen texture and not on the back buffer so the size is scaled twice and is imprecise. Using a float gives more precision without any performance impact as the OpenGL code already expects floats. --- backends/graphics/opengl/opengl-graphics.cpp | 17 ++++++++++------- backends/graphics/opengl/opengl-graphics.h | 4 ++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 15c536b7fb7c..19078c46e760 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -667,9 +667,9 @@ void OpenGLGraphicsManager::updateScreen() { _backBuffer.enableBlend(Framebuffer::kBlendModePremultipliedTransparency); _pipeline->drawTexture(_cursor->getGLTexture(), - _cursorX - _cursorHotspotXScaled + _shakeOffsetScaled.x, - _cursorY - _cursorHotspotYScaled + _shakeOffsetScaled.y, - _cursorWidthScaled, _cursorHeightScaled); + _cursorX - _cursorHotspotXScaled + _shakeOffsetScaled.x, + _cursorY - _cursorHotspotYScaled + _shakeOffsetScaled.y, + _cursorWidthScaled, _cursorHeightScaled); drawCursor = false; // Everything we need to clip has been clipped @@ -1518,11 +1518,14 @@ void OpenGLGraphicsManager::recalculateCursorScaling() { return; } + uint cursorWidth = _cursor->getWidth(); + uint cursorHeight = _cursor->getHeight(); + // By default we use the unscaled versions. _cursorHotspotXScaled = _cursorHotspotX; _cursorHotspotYScaled = _cursorHotspotY; - _cursorWidthScaled = _cursor->getWidth(); - _cursorHeightScaled = _cursor->getHeight(); + _cursorWidthScaled = cursorWidth; + _cursorHeightScaled = cursorHeight; // In case scaling is actually enabled we will scale the cursor according // to the game screen. @@ -1531,10 +1534,10 @@ void OpenGLGraphicsManager::recalculateCursorScaling() { const frac_t screenScaleFactorY = intToFrac(_gameDrawRect.height()) / _gameScreen->getHeight(); _cursorHotspotXScaled = fracToInt(_cursorHotspotXScaled * screenScaleFactorX); - _cursorWidthScaled = fracToInt(_cursorWidthScaled * screenScaleFactorX); + _cursorWidthScaled = fracToDouble(cursorWidth * screenScaleFactorX); _cursorHotspotYScaled = fracToInt(_cursorHotspotYScaled * screenScaleFactorY); - _cursorHeightScaled = fracToInt(_cursorHeightScaled * screenScaleFactorY); + _cursorHeightScaled = fracToDouble(cursorHeight * screenScaleFactorY); } } diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h index 3b27c6e33cf9..4cd3c1f45f7d 100644 --- a/backends/graphics/opengl/opengl-graphics.h +++ b/backends/graphics/opengl/opengl-graphics.h @@ -405,12 +405,12 @@ class OpenGLGraphicsManager : virtual public WindowedGraphicsManager { /** * The width of the cursor in scaled game display area coordinates. */ - uint _cursorWidthScaled; + float _cursorWidthScaled; /** * The height of the cursor in scaled game display area coordinates. */ - uint _cursorHeightScaled; + float _cursorHeightScaled; /** * The key color.