aboutsummaryrefslogtreecommitdiff
path: root/backends/graphics/openglsdl
diff options
context:
space:
mode:
authorColin Snover2017-07-19 19:15:12 -0500
committerColin Snover2017-10-15 13:24:20 -0500
commitde2bbe3b9738ef95b2529db989570770ef434f9d (patch)
treeb1a2994225ca92ec454bd4108673f27a6222145b /backends/graphics/openglsdl
parent0ad03e492ac030193536e3167e8bf428e88cafb3 (diff)
downloadscummvm-rg350-de2bbe3b9738ef95b2529db989570770ef434f9d.tar.gz
scummvm-rg350-de2bbe3b9738ef95b2529db989570770ef434f9d.tar.bz2
scummvm-rg350-de2bbe3b9738ef95b2529db989570770ef434f9d.zip
BACKENDS: Refactor OpenGL & SDL graphics backends
This patch refactors the OpenGL and SDL graphics backends, primarily to unify window scaling and mouse handling, and to fix coordinate mapping between the ScummVM window and the virtual game screen when they have different aspect ratios. Unified code for these two backends has been moved to a new header-only WindowedGraphicsManager class, so named because it contains code for managing graphics managers that interact with a windowing system and render virtual screens within a larger physical content window. The biggest behavioral change here is with the coordinate system mapping: Previously, mouse offsets were converted by mapping the whole space within the window as input to the virtual game screen without maintaining aspect ratio. This was done to prevent 'stickiness' when the mouse cursor was within the window but outside of the virtual game screen, but it caused noticeable distortion of mouse movement speed on the axis with blank space. Instead of introducing mouse speed distortion to prevent stickiness, this patch changes coordinate transformation to show the system cursor when the mouse moves outside of the virtual game screen when mouse grab is off, or by holding the mouse inside the virtual game screen (instead of the entire window) when mouse grab is on. This patch also improves some other properties of the GraphicsManager/PaletteManager interfaces: * Nullipotent operations (getWidth, getHeight, etc.) of the PaletteManager/GraphicsManager interfaces are now const * Methods marked `virtual` but not inherited by any subclass have been de-virtualized * Extra unnecessary calculations of hardware height in SurfaceSdlGraphicsManager have been removed * Methods have been renamed where appropriate for clarity (setWindowSize -> handleResize, etc.) * C++11 support improved with `override` specifier added on overridden virtual methods in subclasses (primarily to avoid myself accidentally creating new methods in the subclasses by changing types/names during refactoring) Additional refactoring can and should be done at some point to continue to deduplicate code between the OpenGL and SDL backends. Since the primary goal here was to improve the coordinate mapping, full refactoring of these backends was not completed here.
Diffstat (limited to 'backends/graphics/openglsdl')
-rw-r--r--backends/graphics/openglsdl/openglsdl-graphics.cpp82
-rw-r--r--backends/graphics/openglsdl/openglsdl-graphics.h36
2 files changed, 44 insertions, 74 deletions
diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp
index 46940d74f2..c77e9dafc5 100644
--- a/backends/graphics/openglsdl/openglsdl-graphics.cpp
+++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp
@@ -21,8 +21,10 @@
*/
#include "backends/graphics/openglsdl/openglsdl-graphics.h"
+#include "backends/graphics/opengl/texture.h"
#include "backends/events/sdl/sdl-events.h"
#include "backends/platform/sdl/sdl.h"
+#include "graphics/scaler/aspect.h"
#include "common/textconsole.h"
#include "common/config-manager.h"
@@ -35,7 +37,7 @@ OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(uint desktopWidth, uint deskt
#if SDL_VERSION_ATLEAST(2, 0, 0)
_glContext(),
#else
- _lastVideoModeLoad(0), _hwScreen(nullptr),
+ _lastVideoModeLoad(0),
#endif
_graphicsScale(2), _ignoreLoadVideoMode(false), _gotResize(false), _wantsFullScreen(false), _ignoreResizeEvents(0),
_desiredFullscreenWidth(0), _desiredFullscreenHeight(0) {
@@ -52,14 +54,16 @@ OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(uint desktopWidth, uint deskt
// Context version 1.4 is choosen arbitrarily based on what most shader
// extensions were written against.
-#define DEFAULT_GL_MAJOR 1
-#define DEFAULT_GL_MINOR 4
+ enum {
+ DEFAULT_GL_MAJOR = 1,
+ DEFAULT_GL_MINOR = 4,
-#define DEFAULT_GLES_MAJOR 1
-#define DEFAULT_GLES_MINOR 1
+ DEFAULT_GLES_MAJOR = 1,
+ DEFAULT_GLES_MINOR = 1,
-#define DEFAULT_GLES2_MAJOR 2
-#define DEFAULT_GLES2_MINOR 0
+ DEFAULT_GLES2_MAJOR = 2,
+ DEFAULT_GLES2_MINOR = 0
+ };
#if USE_FORCED_GL
glContextType = OpenGL::kContextGL;
@@ -127,12 +131,6 @@ OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(uint desktopWidth, uint deskt
} else {
glContextType = OpenGL::kContextGL;
}
-#undef DEFAULT_GL_MAJOR
-#undef DEFAULT_GL_MINOR
-#undef DEFAULT_GLES_MAJOR
-#undef DEFAULT_GLES_MINOR
-#undef DEFAULT_GLES2_MAJOR
-#undef DEFAULT_GLES2_MINOR
#endif
setContextType(glContextType);
@@ -217,7 +215,7 @@ void OpenGLSdlGraphicsManager::deactivateManager() {
SdlGraphicsManager::deactivateManager();
}
-bool OpenGLSdlGraphicsManager::hasFeature(OSystem::Feature f) {
+bool OpenGLSdlGraphicsManager::hasFeature(OSystem::Feature f) const {
switch (f) {
case OSystem::kFeatureFullscreenMode:
case OSystem::kFeatureIconifyWindow:
@@ -246,7 +244,7 @@ void OpenGLSdlGraphicsManager::setFeatureState(OSystem::Feature f, bool enable)
}
}
-bool OpenGLSdlGraphicsManager::getFeatureState(OSystem::Feature f) {
+bool OpenGLSdlGraphicsManager::getFeatureState(OSystem::Feature f) const {
switch (f) {
case OSystem::kFeatureFullscreenMode:
#if SDL_VERSION_ATLEAST(2, 0, 0)
@@ -344,7 +342,7 @@ void OpenGLSdlGraphicsManager::updateScreen() {
void OpenGLSdlGraphicsManager::notifyVideoExpose() {
}
-void OpenGLSdlGraphicsManager::notifyResize(const uint width, const uint height) {
+void OpenGLSdlGraphicsManager::notifyResize(const int width, const int height) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
// We sometime get outdated resize events from SDL2. So check that the size we get
// is the actual current window size. If not ignore the resize.
@@ -354,11 +352,10 @@ void OpenGLSdlGraphicsManager::notifyResize(const uint width, const uint height)
// causes a SDL_WINDOWEVENT_RESIZED event with the old resolution to be sent, and this
// event is processed after recreating the window at the new resolution.
int currentWidth, currentHeight;
- getWindowDimensions(&currentWidth, &currentHeight);
- if (width != (uint)currentWidth || height != (uint)currentHeight)
+ getWindowSizeFromSdl(&currentWidth, &currentHeight);
+ if (width != currentWidth || height != currentHeight)
return;
- setActualScreenSize(width, height);
- _eventSource->resetKeyboardEmulation(width - 1, height - 1);
+ handleResize(width, height);
#else
if (!_ignoreResizeEvents && _hwScreen && !(_hwScreen->flags & SDL_FULLSCREEN)) {
// We save that we handled a resize event here. We need to know this
@@ -373,18 +370,6 @@ void OpenGLSdlGraphicsManager::notifyResize(const uint width, const uint height)
#endif
}
-void OpenGLSdlGraphicsManager::transformMouseCoordinates(Common::Point &point) {
- adjustMousePosition(point.x, point.y);
-}
-
-void OpenGLSdlGraphicsManager::notifyMousePos(Common::Point mouse) {
- setMousePosition(mouse.x, mouse.y);
-}
-
-void OpenGLSdlGraphicsManager::setInternalMousePosition(int x, int y) {
- _window->warpMouseInWindow(x, y);
-}
-
bool OpenGLSdlGraphicsManager::loadVideoMode(uint requestedWidth, uint requestedHeight, const Graphics::PixelFormat &format) {
// In some cases we might not want to load the requested video mode. This
// will assure that the window size is not altered.
@@ -422,6 +407,11 @@ void *OpenGLSdlGraphicsManager::getProcAddress(const char *name) const {
return SDL_GL_GetProcAddress(name);
}
+void OpenGLSdlGraphicsManager::handleResizeImpl(const int width, const int height) {
+ OpenGLGraphicsManager::handleResizeImpl(width, height);
+ SdlGraphicsManager::handleResizeImpl(width, height);
+}
+
bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) {
// In case we request a fullscreen mode we will use the mode the user
// has chosen last time or the biggest mode available.
@@ -517,9 +507,8 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) {
notifyContextCreate(rgba8888, rgba8888);
int actualWidth, actualHeight;
- getWindowDimensions(&actualWidth, &actualHeight);
- setActualScreenSize(actualWidth, actualHeight);
- _eventSource->resetKeyboardEmulation(actualWidth - 1, actualHeight - 1);
+ getWindowSizeFromSdl(&actualWidth, &actualHeight);
+ handleResize(actualWidth, actualHeight);
return true;
#else
// WORKAROUND: Working around infamous SDL bugs when switching
@@ -566,8 +555,7 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) {
if (_hwScreen) {
notifyContextCreate(rgba8888, rgba8888);
- setActualScreenSize(_hwScreen->w, _hwScreen->h);
- _eventSource->resetKeyboardEmulation(_hwScreen->w - 1, _hwScreen->h - 1);
+ handleResize(_hwScreen->w, _hwScreen->h);
}
// Ignore resize events (from SDL) for a few frames, if this isn't
@@ -580,20 +568,6 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) {
#endif
}
-void OpenGLSdlGraphicsManager::getWindowDimensions(int *width, int *height) {
-#if SDL_VERSION_ATLEAST(2, 0, 0)
- SDL_GetWindowSize(_window->getSDLWindow(), width, height);
-#else
- if (width) {
- *width = _hwScreen->w;
- }
-
- if (height) {
- *height = _hwScreen->h;
- }
-#endif
-}
-
bool OpenGLSdlGraphicsManager::notifyEvent(const Common::Event &event) {
switch (event.type) {
case Common::EVENT_KEYUP:
@@ -707,7 +681,7 @@ bool OpenGLSdlGraphicsManager::notifyEvent(const Common::Event &event) {
// current scale setting in case the user resized the
// window. Then we apply the direction change.
int windowWidth = 0, windowHeight = 0;
- getWindowDimensions(&windowWidth, &windowHeight);
+ getWindowSizeFromSdl(&windowWidth, &windowHeight);
_graphicsScale = MAX<int>(windowWidth / _lastRequestedWidth, windowHeight / _lastRequestedHeight);
_graphicsScale = MAX<int>(_graphicsScale + direction, 1);
@@ -725,7 +699,7 @@ bool OpenGLSdlGraphicsManager::notifyEvent(const Common::Event &event) {
#ifdef USE_OSD
int windowWidth = 0, windowHeight = 0;
- getWindowDimensions(&windowWidth, &windowHeight);
+ getWindowSizeFromSdl(&windowWidth, &windowHeight);
const Common::String osdMsg = Common::String::format(_("Resolution: %dx%d"), windowWidth, windowHeight);
displayMessageOnOSD(osdMsg.c_str());
#endif
@@ -785,7 +759,7 @@ bool OpenGLSdlGraphicsManager::notifyEvent(const Common::Event &event) {
}
}
-bool OpenGLSdlGraphicsManager::isHotkey(const Common::Event &event) {
+bool OpenGLSdlGraphicsManager::isHotkey(const Common::Event &event) const {
if (event.kbd.hasFlags(Common::KBD_ALT)) {
return event.kbd.keycode == Common::KEYCODE_RETURN
|| event.kbd.keycode == (Common::KeyCode)SDLK_KP_ENTER
diff --git a/backends/graphics/openglsdl/openglsdl-graphics.h b/backends/graphics/openglsdl/openglsdl-graphics.h
index c5003d867b..954c7215a4 100644
--- a/backends/graphics/openglsdl/openglsdl-graphics.h
+++ b/backends/graphics/openglsdl/openglsdl-graphics.h
@@ -36,38 +36,37 @@ public:
virtual ~OpenGLSdlGraphicsManager();
// GraphicsManager API
- virtual void activateManager();
- virtual void deactivateManager();
+ virtual void activateManager() override;
+ virtual void deactivateManager() override;
- virtual bool hasFeature(OSystem::Feature f);
- virtual void setFeatureState(OSystem::Feature f, bool enable);
- virtual bool getFeatureState(OSystem::Feature f);
+ virtual bool hasFeature(OSystem::Feature f) const override;
+ virtual void setFeatureState(OSystem::Feature f, bool enable) override;
+ virtual bool getFeatureState(OSystem::Feature f) const override;
virtual void initSize(uint w, uint h, const Graphics::PixelFormat *format) override;
#ifdef USE_RGB_COLOR
- virtual Common::List<Graphics::PixelFormat> getSupportedFormats() const;
+ virtual Common::List<Graphics::PixelFormat> getSupportedFormats() const override;
#endif
- virtual void updateScreen();
+ virtual void updateScreen() override;
// EventObserver API
- virtual bool notifyEvent(const Common::Event &event);
+ virtual bool notifyEvent(const Common::Event &event) override;
// SdlGraphicsManager API
- virtual void notifyVideoExpose();
- virtual void notifyResize(const uint width, const uint height);
- virtual void transformMouseCoordinates(Common::Point &point);
- virtual void notifyMousePos(Common::Point mouse);
+ virtual void notifyVideoExpose() override;
+ virtual void notifyResize(const int width, const int height) override;
protected:
- virtual void setInternalMousePosition(int x, int y);
+ virtual bool loadVideoMode(uint requestedWidth, uint requestedHeight, const Graphics::PixelFormat &format) override;
- virtual bool loadVideoMode(uint requestedWidth, uint requestedHeight, const Graphics::PixelFormat &format);
+ virtual void refreshScreen() override;
- virtual void refreshScreen();
+ virtual void *getProcAddress(const char *name) const override;
+
+ virtual void handleResizeImpl(const int width, const int height) override;
- virtual void *getProcAddress(const char *name) const;
virtual int getGraphicsModeScale(int mode) const override { return 1; }
private:
@@ -78,11 +77,8 @@ private:
SDL_GLContext _glContext;
#else
uint32 _lastVideoModeLoad;
- SDL_Surface *_hwScreen;
#endif
- void getWindowDimensions(int *width, int *height);
-
uint _lastRequestedWidth;
uint _lastRequestedHeight;
uint _graphicsScale;
@@ -122,7 +118,7 @@ private:
uint _desiredFullscreenWidth;
uint _desiredFullscreenHeight;
- virtual bool isHotkey(const Common::Event &event);
+ bool isHotkey(const Common::Event &event) const;
};
#endif