Skip to content

Commit

Permalink
BACKENDS: OPENGL: Use a floating point cursor size
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lephilousophe committed Feb 5, 2023
1 parent 2dca8d8 commit 97c8746
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
17 changes: 10 additions & 7 deletions backends/graphics/opengl/opengl-graphics.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions backends/graphics/opengl/opengl-graphics.h
Expand Up @@ -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.
Expand Down

0 comments on commit 97c8746

Please sign in to comment.