2013-08-18 16:56:34 +02:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
2021-12-26 18:47:58 +01:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2013-08-18 16:56:34 +02:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-12-26 18:47:58 +01:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2013-08-18 16:56:34 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "backends/graphics/openglsdl/openglsdl-graphics.h"
|
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.
2017-07-19 19:15:12 -05:00
|
|
|
#include "backends/graphics/opengl/texture.h"
|
2015-12-13 23:47:52 +01:00
|
|
|
#include "backends/events/sdl/sdl-events.h"
|
2017-03-24 22:25:46 +01:00
|
|
|
#include "backends/platform/sdl/sdl.h"
|
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.
2017-07-19 19:15:12 -05:00
|
|
|
#include "graphics/scaler/aspect.h"
|
2013-08-18 16:56:34 +02:00
|
|
|
|
|
|
|
#include "common/textconsole.h"
|
|
|
|
#include "common/config-manager.h"
|
2013-08-19 00:54:41 +02:00
|
|
|
#ifdef USE_OSD
|
|
|
|
#include "common/translation.h"
|
|
|
|
#endif
|
2013-08-18 16:56:34 +02:00
|
|
|
|
2020-04-16 12:28:55 +01:00
|
|
|
OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(SdlEventSource *eventSource, SdlWindow *window)
|
2021-04-15 21:20:04 +02:00
|
|
|
: SdlGraphicsManager(eventSource, window), _lastRequestedHeight(0),
|
2015-01-25 01:34:57 +01:00
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
2021-04-15 21:20:04 +02:00
|
|
|
_glContext(),
|
2015-01-25 01:34:57 +01:00
|
|
|
#else
|
2021-04-15 21:20:04 +02:00
|
|
|
_lastVideoModeLoad(0),
|
2015-01-25 01:34:57 +01:00
|
|
|
#endif
|
2021-04-15 21:20:04 +02:00
|
|
|
_graphicsScale(2), _ignoreLoadVideoMode(false), _gotResize(false), _wantsFullScreen(false), _ignoreResizeEvents(0),
|
|
|
|
_desiredFullscreenWidth(0), _desiredFullscreenHeight(0) {
|
2013-08-18 16:56:34 +02:00
|
|
|
// Setup OpenGL attributes for SDL
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
|
2022-08-03 19:40:13 +02:00
|
|
|
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
|
2013-08-18 16:56:34 +02:00
|
|
|
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
|
|
|
|
2017-09-03 16:31:16 -05:00
|
|
|
// Set up proper SDL OpenGL context creation.
|
2015-12-18 20:50:31 +01:00
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
2015-12-18 21:14:48 +01:00
|
|
|
OpenGL::ContextType glContextType;
|
|
|
|
|
2015-12-18 21:50:44 +01:00
|
|
|
// Context version 1.4 is choosen arbitrarily based on what most shader
|
|
|
|
// extensions were written against.
|
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.
2017-07-19 19:15:12 -05:00
|
|
|
enum {
|
|
|
|
DEFAULT_GL_MAJOR = 1,
|
|
|
|
DEFAULT_GL_MINOR = 4,
|
2015-12-18 21:50:44 +01:00
|
|
|
|
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.
2017-07-19 19:15:12 -05:00
|
|
|
DEFAULT_GLES_MAJOR = 1,
|
|
|
|
DEFAULT_GLES_MINOR = 1,
|
2015-12-18 21:50:44 +01:00
|
|
|
|
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.
2017-07-19 19:15:12 -05:00
|
|
|
DEFAULT_GLES2_MAJOR = 2,
|
|
|
|
DEFAULT_GLES2_MINOR = 0
|
|
|
|
};
|
2015-12-20 05:42:54 +01:00
|
|
|
|
2015-12-18 20:50:31 +01:00
|
|
|
#if USE_FORCED_GL
|
2015-12-18 21:14:48 +01:00
|
|
|
glContextType = OpenGL::kContextGL;
|
2015-12-22 06:51:14 +01:00
|
|
|
_glContextProfileMask = 0;
|
2015-12-18 21:50:44 +01:00
|
|
|
_glContextMajor = DEFAULT_GL_MAJOR;
|
|
|
|
_glContextMinor = DEFAULT_GL_MINOR;
|
2015-12-18 20:50:31 +01:00
|
|
|
#elif USE_FORCED_GLES
|
2015-12-18 21:14:48 +01:00
|
|
|
glContextType = OpenGL::kContextGLES;
|
2015-12-18 20:50:31 +01:00
|
|
|
_glContextProfileMask = SDL_GL_CONTEXT_PROFILE_ES;
|
2015-12-18 21:50:44 +01:00
|
|
|
_glContextMajor = DEFAULT_GLES_MAJOR;
|
|
|
|
_glContextMinor = DEFAULT_GLES_MINOR;
|
2015-12-20 05:42:54 +01:00
|
|
|
#elif USE_FORCED_GLES2
|
|
|
|
glContextType = OpenGL::kContextGLES2;
|
|
|
|
_glContextProfileMask = SDL_GL_CONTEXT_PROFILE_ES;
|
|
|
|
_glContextMajor = DEFAULT_GLES2_MAJOR;
|
|
|
|
_glContextMinor = DEFAULT_GLES2_MINOR;
|
2015-12-18 20:50:31 +01:00
|
|
|
#else
|
2015-12-18 21:50:44 +01:00
|
|
|
bool noDefaults = false;
|
2015-12-18 20:50:31 +01:00
|
|
|
|
|
|
|
// Obtain the default GL(ES) context SDL2 tries to setup.
|
|
|
|
//
|
|
|
|
// Please note this might not actually be SDL2's defaults when multiple
|
|
|
|
// instances of this object have been created. But that is no issue
|
|
|
|
// because then we already set up what we want to use.
|
|
|
|
//
|
|
|
|
// In case no defaults are given we prefer OpenGL over OpenGL ES.
|
|
|
|
if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &_glContextProfileMask) != 0) {
|
2015-12-22 06:51:14 +01:00
|
|
|
_glContextProfileMask = 0;
|
2015-12-18 21:50:44 +01:00
|
|
|
noDefaults = true;
|
2015-12-18 20:50:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &_glContextMajor) != 0) {
|
2015-12-18 21:50:44 +01:00
|
|
|
noDefaults = true;
|
2015-12-18 20:50:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &_glContextMinor) != 0) {
|
2015-12-18 21:50:44 +01:00
|
|
|
noDefaults = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (noDefaults) {
|
2015-12-18 20:50:31 +01:00
|
|
|
if (_glContextProfileMask == SDL_GL_CONTEXT_PROFILE_ES) {
|
2015-12-18 21:50:44 +01:00
|
|
|
_glContextMajor = DEFAULT_GLES_MAJOR;
|
|
|
|
_glContextMinor = DEFAULT_GLES_MINOR;
|
2015-12-18 20:50:31 +01:00
|
|
|
} else {
|
2015-12-22 06:51:14 +01:00
|
|
|
_glContextProfileMask = 0;
|
2015-12-18 21:50:44 +01:00
|
|
|
_glContextMajor = DEFAULT_GL_MAJOR;
|
|
|
|
_glContextMinor = DEFAULT_GL_MINOR;
|
2015-12-18 20:50:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_glContextProfileMask == SDL_GL_CONTEXT_PROFILE_ES) {
|
|
|
|
if (_glContextMajor >= 2) {
|
2015-12-20 05:42:54 +01:00
|
|
|
glContextType = OpenGL::kContextGLES2;
|
|
|
|
} else {
|
|
|
|
glContextType = OpenGL::kContextGLES;
|
2015-12-18 20:50:31 +01:00
|
|
|
}
|
|
|
|
} else if (_glContextProfileMask == SDL_GL_CONTEXT_PROFILE_CORE) {
|
2015-12-18 21:14:48 +01:00
|
|
|
glContextType = OpenGL::kContextGL;
|
2015-12-18 20:50:31 +01:00
|
|
|
|
|
|
|
// Core profile does not allow legacy functionality, which we use.
|
2015-12-22 06:51:14 +01:00
|
|
|
// Thus we request a standard OpenGL context.
|
|
|
|
_glContextProfileMask = 0;
|
2015-12-18 21:50:44 +01:00
|
|
|
_glContextMajor = DEFAULT_GL_MAJOR;
|
|
|
|
_glContextMinor = DEFAULT_GL_MINOR;
|
2015-12-18 20:50:31 +01:00
|
|
|
} else {
|
2015-12-18 21:14:48 +01:00
|
|
|
glContextType = OpenGL::kContextGL;
|
2015-12-18 20:50:31 +01:00
|
|
|
}
|
|
|
|
#endif
|
2015-12-18 21:50:44 +01:00
|
|
|
|
2015-12-18 21:14:48 +01:00
|
|
|
setContextType(glContextType);
|
|
|
|
#else
|
|
|
|
setContextType(OpenGL::kContextGL);
|
2015-12-18 20:50:31 +01:00
|
|
|
#endif
|
|
|
|
|
2013-08-18 16:56:34 +02:00
|
|
|
// Retrieve a list of working fullscreen modes
|
2021-07-16 13:08:26 +01:00
|
|
|
Common::Rect desktopRes = _window->getDesktopResolution();
|
2015-01-25 01:34:57 +01:00
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
2021-07-16 13:08:26 +01:00
|
|
|
// With SDL2 we use the SDL_WINDOW_FULLSCREEN_DESKTOP flag.
|
|
|
|
// Thus SDL always use the desktop resolution and it is useless to try to use something else.
|
|
|
|
// Do nothing here as adding the desktop resolution to _fullscreenVideoModes is done as a fallback.
|
|
|
|
_fullscreenVideoModes.push_back(VideoMode(desktopRes.width(), desktopRes.height()));
|
2015-01-25 01:34:57 +01:00
|
|
|
#else
|
2013-08-18 16:56:34 +02:00
|
|
|
const SDL_Rect *const *availableModes = SDL_ListModes(NULL, SDL_OPENGL | SDL_FULLSCREEN);
|
2015-05-16 16:57:44 +02:00
|
|
|
// TODO: NULL means that there are no fullscreen modes supported. We
|
|
|
|
// should probably use this information and disable any fullscreen support
|
|
|
|
// in this case.
|
2015-05-15 23:30:02 -04:00
|
|
|
if (availableModes != NULL && availableModes != (void *)-1) {
|
2013-08-18 16:56:34 +02:00
|
|
|
for (;*availableModes; ++availableModes) {
|
|
|
|
const SDL_Rect *mode = *availableModes;
|
|
|
|
|
|
|
|
_fullscreenVideoModes.push_back(VideoMode(mode->w, mode->h));
|
|
|
|
}
|
2015-01-25 01:34:57 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Sort the modes in ascending order.
|
|
|
|
Common::sort(_fullscreenVideoModes.begin(), _fullscreenVideoModes.end());
|
2013-08-18 16:56:34 +02:00
|
|
|
|
2015-01-25 01:34:57 +01:00
|
|
|
// Strip duplicates in video modes.
|
|
|
|
for (uint i = 0; i + 1 < _fullscreenVideoModes.size();) {
|
|
|
|
if (_fullscreenVideoModes[i] == _fullscreenVideoModes[i + 1]) {
|
|
|
|
_fullscreenVideoModes.remove_at(i);
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
2013-08-18 16:56:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// In case SDL is fine with every mode we will force the desktop mode.
|
|
|
|
// TODO? We could also try to add some default resolutions here.
|
2020-04-16 12:28:55 +01:00
|
|
|
if (_fullscreenVideoModes.empty() && !desktopRes.isEmpty()) {
|
|
|
|
_fullscreenVideoModes.push_back(VideoMode(desktopRes.width(), desktopRes.height()));
|
2013-08-18 16:56:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get information about display sizes from the previous runs.
|
|
|
|
if (ConfMan.hasKey("last_fullscreen_mode_width", Common::ConfigManager::kApplicationDomain) && ConfMan.hasKey("last_fullscreen_mode_height", Common::ConfigManager::kApplicationDomain)) {
|
|
|
|
_desiredFullscreenWidth = ConfMan.getInt("last_fullscreen_mode_width", Common::ConfigManager::kApplicationDomain);
|
|
|
|
_desiredFullscreenHeight = ConfMan.getInt("last_fullscreen_mode_height", Common::ConfigManager::kApplicationDomain);
|
|
|
|
} else {
|
|
|
|
// Use the desktop resolutions when no previous default has been setup.
|
2020-04-16 12:28:55 +01:00
|
|
|
_desiredFullscreenWidth = desktopRes.width();
|
|
|
|
_desiredFullscreenHeight = desktopRes.height();
|
2013-08-18 16:56:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OpenGLSdlGraphicsManager::~OpenGLSdlGraphicsManager() {
|
2015-12-20 09:58:35 +01:00
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
|
|
|
notifyContextDestroy();
|
|
|
|
SDL_GL_DeleteContext(_glContext);
|
|
|
|
#endif
|
2013-10-20 22:27:50 +02:00
|
|
|
}
|
|
|
|
|
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.
2017-07-19 19:15:12 -05:00
|
|
|
bool OpenGLSdlGraphicsManager::hasFeature(OSystem::Feature f) const {
|
2013-08-18 16:56:34 +02:00
|
|
|
switch (f) {
|
|
|
|
case OSystem::kFeatureFullscreenMode:
|
|
|
|
case OSystem::kFeatureIconifyWindow:
|
2020-10-13 20:27:58 +02:00
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
|
|
|
case OSystem::kFeatureFullscreenToggleKeepsContext:
|
2021-10-21 08:17:24 +02:00
|
|
|
case OSystem::kFeatureVSync:
|
2020-10-13 20:27:58 +02:00
|
|
|
#endif
|
2013-08-18 16:56:34 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return OpenGLGraphicsManager::hasFeature(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLSdlGraphicsManager::setFeatureState(OSystem::Feature f, bool enable) {
|
|
|
|
switch (f) {
|
|
|
|
case OSystem::kFeatureFullscreenMode:
|
|
|
|
assert(getTransactionMode() != kTransactionNone);
|
|
|
|
_wantsFullScreen = enable;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OSystem::kFeatureIconifyWindow:
|
|
|
|
if (enable) {
|
2015-02-16 00:49:42 +01:00
|
|
|
_window->iconifyWindow();
|
2013-08-18 16:56:34 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
OpenGLGraphicsManager::setFeatureState(f, enable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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.
2017-07-19 19:15:12 -05:00
|
|
|
bool OpenGLSdlGraphicsManager::getFeatureState(OSystem::Feature f) const {
|
2013-08-18 16:56:34 +02:00
|
|
|
switch (f) {
|
|
|
|
case OSystem::kFeatureFullscreenMode:
|
2015-01-25 01:34:57 +01:00
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
2020-11-01 20:10:15 +00:00
|
|
|
if (_window && _window->getSDLWindow()) {
|
2021-10-02 18:59:44 +01:00
|
|
|
return (SDL_GetWindowFlags(_window->getSDLWindow()) & SDL_WINDOW_FULLSCREEN_DESKTOP) != 0;
|
2015-01-25 01:34:57 +01:00
|
|
|
} else {
|
|
|
|
return _wantsFullScreen;
|
|
|
|
}
|
|
|
|
#else
|
2013-08-18 16:56:34 +02:00
|
|
|
if (_hwScreen) {
|
|
|
|
return (_hwScreen->flags & SDL_FULLSCREEN) != 0;
|
|
|
|
} else {
|
|
|
|
return _wantsFullScreen;
|
|
|
|
}
|
2015-01-25 01:34:57 +01:00
|
|
|
#endif
|
2021-10-21 08:39:08 +02:00
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
|
|
|
case OSystem::kFeatureVSync:
|
|
|
|
return SDL_GL_GetSwapInterval() != 0;
|
|
|
|
#endif
|
2013-08-18 16:56:34 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
return OpenGLGraphicsManager::getFeatureState(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-10 22:29:31 +01:00
|
|
|
float OpenGLSdlGraphicsManager::getHiDPIScreenFactor() const {
|
2021-08-14 14:33:05 +01:00
|
|
|
return _window->getDpiScalingFactor();
|
2021-08-10 22:29:31 +01:00
|
|
|
}
|
|
|
|
|
2017-10-01 16:23:22 -05:00
|
|
|
void OpenGLSdlGraphicsManager::initSize(uint w, uint h, const Graphics::PixelFormat *format) {
|
2013-08-18 16:56:34 +02:00
|
|
|
// HACK: This is stupid but the SurfaceSDL backend defaults to 2x. This
|
|
|
|
// assures that the launcher (which requests 320x200) has a reasonable
|
|
|
|
// size. It also makes small games have a reasonable size (i.e. at least
|
|
|
|
// 640x400). We follow the same logic here until we have a better way to
|
|
|
|
// give hints to our backend for that.
|
2017-10-01 16:23:22 -05:00
|
|
|
if (w > 320) {
|
|
|
|
_graphicsScale = 1;
|
|
|
|
} else {
|
|
|
|
_graphicsScale = 2;
|
|
|
|
}
|
2013-08-18 16:56:34 +02:00
|
|
|
|
2017-10-01 16:23:22 -05:00
|
|
|
return OpenGLGraphicsManager::initSize(w, h, format);
|
2013-08-18 16:56:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLSdlGraphicsManager::updateScreen() {
|
|
|
|
if (_ignoreResizeEvents) {
|
|
|
|
--_ignoreResizeEvents;
|
|
|
|
}
|
|
|
|
|
|
|
|
OpenGLGraphicsManager::updateScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLSdlGraphicsManager::notifyVideoExpose() {
|
|
|
|
}
|
|
|
|
|
2021-04-12 08:43:04 +01:00
|
|
|
void OpenGLSdlGraphicsManager::notifyResize(const int width, const int height) {
|
2015-01-25 01:34:57 +01:00
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
2021-04-12 08:43:04 +01:00
|
|
|
// We sometime get inaccurate resize events from SDL2. So use the real drawable size
|
|
|
|
// we get from SDL2 and ignore the event data.
|
2016-09-18 04:23:17 +01:00
|
|
|
// The issue for example occurs when switching from fullscreen to windowed mode or
|
|
|
|
// when switching between different fullscreen resolutions because SDL_DestroyWindow
|
|
|
|
// for a fullscreen window that doesn't have the SDL_WINDOW_FULLSCREEN_DESKTOP flag
|
|
|
|
// 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;
|
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.
2017-07-19 19:15:12 -05:00
|
|
|
getWindowSizeFromSdl(¤tWidth, ¤tHeight);
|
2021-08-20 00:26:36 +01:00
|
|
|
float dpiScale = _window->getSdlDpiScalingFactor();
|
|
|
|
debug(3, "req: %d x %d cur: %d x %d, scale: %f", width, height, currentWidth, currentHeight, dpiScale);
|
2020-10-29 19:12:24 +01:00
|
|
|
|
2021-04-12 08:43:04 +01:00
|
|
|
handleResize(currentWidth, currentHeight);
|
2021-04-18 12:46:56 +02:00
|
|
|
|
|
|
|
// Remember window size in windowed mode
|
|
|
|
if (!_wantsFullScreen) {
|
2021-08-20 00:26:36 +01:00
|
|
|
currentWidth = (int)(currentWidth / dpiScale + 0.5f);
|
|
|
|
currentHeight = (int)(currentHeight / dpiScale + 0.5f);
|
2021-04-25 14:45:51 +02:00
|
|
|
|
|
|
|
// Check if the ScummVM window is maximized and store the current
|
|
|
|
// window dimensions.
|
2021-08-10 22:26:02 +02:00
|
|
|
if (SDL_GetWindowFlags(_window->getSDLWindow()) & SDL_WINDOW_MAXIMIZED) {
|
2021-04-25 14:45:51 +02:00
|
|
|
ConfMan.setInt("window_maximized_width", currentWidth, Common::ConfigManager::kApplicationDomain);
|
|
|
|
ConfMan.setInt("window_maximized_height", currentHeight, Common::ConfigManager::kApplicationDomain);
|
2021-08-20 18:43:26 +02:00
|
|
|
ConfMan.setBool("window_maximized", true, Common::ConfigManager::kApplicationDomain);
|
2021-04-25 14:45:51 +02:00
|
|
|
} else {
|
|
|
|
ConfMan.setInt("last_window_width", currentWidth, Common::ConfigManager::kApplicationDomain);
|
|
|
|
ConfMan.setInt("last_window_height", currentHeight, Common::ConfigManager::kApplicationDomain);
|
2021-08-20 18:43:26 +02:00
|
|
|
ConfMan.setBool("window_maximized", false, Common::ConfigManager::kApplicationDomain);
|
2021-04-25 14:45:51 +02:00
|
|
|
}
|
2021-04-18 15:16:52 +02:00
|
|
|
ConfMan.flushToDisk();
|
2021-04-18 12:46:56 +02:00
|
|
|
}
|
|
|
|
|
2015-01-25 01:34:57 +01:00
|
|
|
#else
|
2013-08-18 16:56:34 +02:00
|
|
|
if (!_ignoreResizeEvents && _hwScreen && !(_hwScreen->flags & SDL_FULLSCREEN)) {
|
|
|
|
// We save that we handled a resize event here. We need to know this
|
|
|
|
// so we do not overwrite the users requested window size whenever we
|
|
|
|
// switch aspect ratio or similar.
|
|
|
|
_gotResize = true;
|
2021-04-12 08:43:04 +01:00
|
|
|
if (!setupMode(width, height)) {
|
2013-08-18 16:56:34 +02:00
|
|
|
warning("OpenGLSdlGraphicsManager::notifyResize: Resize failed ('%s')", SDL_GetError());
|
|
|
|
g_system->quit();
|
|
|
|
}
|
|
|
|
}
|
2015-01-25 01:34:57 +01:00
|
|
|
#endif
|
2013-08-18 16:56:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
|
|
|
if (_ignoreLoadVideoMode) {
|
|
|
|
_ignoreLoadVideoMode = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This function should never be called from notifyResize thus we know
|
|
|
|
// that the requested size came from somewhere else.
|
|
|
|
_gotResize = false;
|
|
|
|
|
|
|
|
// Save the requested dimensions.
|
|
|
|
_lastRequestedWidth = requestedWidth;
|
|
|
|
_lastRequestedHeight = requestedHeight;
|
|
|
|
|
2021-06-13 07:50:27 +02:00
|
|
|
// Fetch current desktop resolution and determining max. width and height
|
|
|
|
Common::Rect desktopRes = _window->getDesktopResolution();
|
|
|
|
|
2021-08-11 14:04:12 +02:00
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
2021-10-02 22:01:02 +01:00
|
|
|
bool isMaximized = ConfMan.getBool("window_maximized", Common::ConfigManager::kApplicationDomain);
|
2021-10-02 22:52:43 +01:00
|
|
|
if (!_wantsFullScreen) {
|
|
|
|
if (isMaximized && ConfMan.hasKey("window_maximized_width", Common::ConfigManager::kApplicationDomain) && ConfMan.hasKey("window_maximized_height", Common::ConfigManager::kApplicationDomain)) {
|
|
|
|
// Set the window size to the values stored when the window was maximized
|
|
|
|
// for the last time.
|
|
|
|
requestedWidth = ConfMan.getInt("window_maximized_width", Common::ConfigManager::kApplicationDomain);
|
|
|
|
requestedHeight = ConfMan.getInt("window_maximized_height", Common::ConfigManager::kApplicationDomain);
|
2021-04-25 14:45:51 +02:00
|
|
|
|
2021-10-02 22:52:43 +01:00
|
|
|
} else if (!isMaximized && ConfMan.hasKey("last_window_width", Common::ConfigManager::kApplicationDomain) && ConfMan.hasKey("last_window_height", Common::ConfigManager::kApplicationDomain)) {
|
|
|
|
// Load previously stored window dimensions.
|
|
|
|
requestedWidth = ConfMan.getInt("last_window_width", Common::ConfigManager::kApplicationDomain);
|
|
|
|
requestedHeight = ConfMan.getInt("last_window_height", Common::ConfigManager::kApplicationDomain);
|
2021-07-30 20:35:03 +02:00
|
|
|
|
2021-10-02 22:52:43 +01:00
|
|
|
} else {
|
|
|
|
// Set the basic window size based on the desktop resolution
|
|
|
|
// since we have no values stored, e.g. on first launch.
|
|
|
|
requestedWidth = MAX<uint>(desktopRes.width() / 2, 640);
|
|
|
|
requestedHeight = requestedWidth * 3 / 4;
|
|
|
|
|
|
|
|
// Save current window dimensions
|
|
|
|
ConfMan.setInt("last_window_width", requestedWidth, Common::ConfigManager::kApplicationDomain);
|
|
|
|
ConfMan.setInt("last_window_height", requestedHeight, Common::ConfigManager::kApplicationDomain);
|
|
|
|
ConfMan.flushToDisk();
|
|
|
|
}
|
2021-04-18 12:46:56 +02:00
|
|
|
}
|
2013-08-18 16:56:34 +02:00
|
|
|
|
2021-08-11 14:04:12 +02:00
|
|
|
#else
|
|
|
|
// Set the basic window size based on the desktop resolution
|
|
|
|
// since we cannot reliably determine the current window state
|
|
|
|
// on SDL1.
|
2021-08-12 13:57:31 +02:00
|
|
|
requestedWidth = MAX<uint>(desktopRes.width() / 2, 640);
|
|
|
|
requestedHeight = requestedWidth * 3 / 4;
|
2021-08-11 14:04:12 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2021-08-13 22:19:16 +02:00
|
|
|
// In order to prevent any unnecessary downscaling (e.g. when launching
|
|
|
|
// a game in 800x600 while having a smaller screen size stored in the configuration file),
|
|
|
|
// we override the window dimensions with the "real" resolution request made by the engine.
|
|
|
|
if ((requestedWidth < _lastRequestedWidth * _graphicsScale || requestedHeight < _lastRequestedHeight * _graphicsScale) && ConfMan.getActiveDomain()) {
|
|
|
|
requestedWidth = _lastRequestedWidth * _graphicsScale;
|
|
|
|
requestedHeight = _lastRequestedHeight * _graphicsScale;
|
|
|
|
}
|
|
|
|
|
2021-08-12 13:57:31 +02:00
|
|
|
// Set allowed dimensions
|
2021-06-13 07:50:27 +02:00
|
|
|
uint maxAllowedWidth = desktopRes.width();
|
|
|
|
uint maxAllowedHeight = desktopRes.height();
|
2021-08-12 13:57:31 +02:00
|
|
|
float ratio = (float)requestedWidth / (float)requestedHeight;
|
2021-06-13 07:50:27 +02:00
|
|
|
|
|
|
|
// Check if we request a larger window than physically possible,
|
|
|
|
// e.g. by starting with additional launcher parameters forcing
|
|
|
|
// specific (openGL) scaler modes that could exceed the desktop/screen size
|
|
|
|
if (requestedWidth > maxAllowedWidth) {
|
|
|
|
requestedWidth = maxAllowedWidth;
|
|
|
|
requestedHeight = requestedWidth / ratio;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (requestedHeight > maxAllowedHeight) {
|
|
|
|
requestedHeight = maxAllowedHeight;
|
|
|
|
requestedWidth = requestedHeight * ratio;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set up the mode
|
2013-08-18 16:56:34 +02:00
|
|
|
return setupMode(requestedWidth, requestedHeight);
|
|
|
|
}
|
|
|
|
|
2015-12-11 19:23:41 +01:00
|
|
|
void OpenGLSdlGraphicsManager::refreshScreen() {
|
|
|
|
// Swap OpenGL buffers
|
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
|
|
|
SDL_GL_SwapWindow(_window->getSDLWindow());
|
|
|
|
#else
|
|
|
|
SDL_GL_SwapBuffers();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-12-11 23:51:21 +01:00
|
|
|
void *OpenGLSdlGraphicsManager::getProcAddress(const char *name) const {
|
|
|
|
return SDL_GL_GetProcAddress(name);
|
|
|
|
}
|
|
|
|
|
2020-10-29 17:30:05 +00:00
|
|
|
void OpenGLSdlGraphicsManager::handleResizeImpl(const int width, const int height) {
|
|
|
|
OpenGLGraphicsManager::handleResizeImpl(width, height);
|
|
|
|
SdlGraphicsManager::handleResizeImpl(width, height);
|
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.
2017-07-19 19:15:12 -05:00
|
|
|
}
|
|
|
|
|
2019-03-10 16:25:25 +00:00
|
|
|
bool OpenGLSdlGraphicsManager::saveScreenshot(const Common::String &filename) const {
|
|
|
|
return OpenGLGraphicsManager::saveScreenshot(filename);
|
|
|
|
}
|
|
|
|
|
2013-08-18 16:56:34 +02:00
|
|
|
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.
|
|
|
|
if (_wantsFullScreen) {
|
|
|
|
if (_desiredFullscreenWidth && _desiredFullscreenHeight) {
|
|
|
|
// In case only a distinct set of modes is available we check
|
|
|
|
// whether the requested mode is actually available.
|
|
|
|
if (!_fullscreenVideoModes.empty()) {
|
|
|
|
VideoModeArray::const_iterator i = Common::find(_fullscreenVideoModes.begin(),
|
|
|
|
_fullscreenVideoModes.end(),
|
|
|
|
VideoMode(_desiredFullscreenWidth, _desiredFullscreenHeight));
|
|
|
|
// It's not available fall back to default.
|
|
|
|
if (i == _fullscreenVideoModes.end()) {
|
|
|
|
_desiredFullscreenWidth = 0;
|
|
|
|
_desiredFullscreenHeight = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// In case no desired mode has been set we default to the biggest mode
|
|
|
|
// available or the requested mode in case we don't know any
|
|
|
|
// any fullscreen modes.
|
|
|
|
if (!_desiredFullscreenWidth || !_desiredFullscreenHeight) {
|
|
|
|
if (!_fullscreenVideoModes.empty()) {
|
|
|
|
VideoModeArray::const_iterator i = _fullscreenVideoModes.end();
|
|
|
|
--i;
|
2014-10-28 15:36:22 +02:00
|
|
|
|
2013-08-18 16:56:34 +02:00
|
|
|
_desiredFullscreenWidth = i->width;
|
|
|
|
_desiredFullscreenHeight = i->height;
|
|
|
|
} else {
|
|
|
|
_desiredFullscreenWidth = width;
|
|
|
|
_desiredFullscreenHeight = height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remember our choice.
|
|
|
|
ConfMan.setInt("last_fullscreen_mode_width", _desiredFullscreenWidth, Common::ConfigManager::kApplicationDomain);
|
|
|
|
ConfMan.setInt("last_fullscreen_mode_height", _desiredFullscreenHeight, Common::ConfigManager::kApplicationDomain);
|
|
|
|
}
|
|
|
|
|
2015-01-25 01:34:57 +01:00
|
|
|
// This is pretty confusing since RGBA8888 talks about the memory
|
|
|
|
// layout here. This is a different logical layout depending on
|
|
|
|
// whether we run on little endian or big endian. However, we can
|
|
|
|
// only safely assume that RGBA8888 in memory layout is supported.
|
|
|
|
// Thus, we chose this one.
|
|
|
|
const Graphics::PixelFormat rgba8888 =
|
|
|
|
#ifdef SCUMM_LITTLE_ENDIAN
|
|
|
|
Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24);
|
|
|
|
#else
|
|
|
|
Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
|
|
|
if (_glContext) {
|
|
|
|
notifyContextDestroy();
|
|
|
|
|
|
|
|
SDL_GL_DeleteContext(_glContext);
|
|
|
|
_glContext = nullptr;
|
|
|
|
}
|
|
|
|
|
2020-10-29 19:12:24 +01:00
|
|
|
uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI;
|
|
|
|
|
2015-01-25 01:34:57 +01:00
|
|
|
if (_wantsFullScreen) {
|
2017-02-12 19:17:33 -06:00
|
|
|
// On Linux/X11, when toggling to fullscreen, the window manager saves
|
|
|
|
// the window size to be able to restore it when going back to windowed mode.
|
|
|
|
// If the user configured ScummVM to start in fullscreen mode, we first
|
|
|
|
// create a window and then toggle it to fullscreen to give the window manager
|
|
|
|
// a chance to save the window size. That way if the user switches back
|
|
|
|
// to windowed mode, the window manager has a window size to apply instead
|
|
|
|
// of leaving the window at the fullscreen resolution size.
|
2017-12-10 15:18:42 +01:00
|
|
|
const char *driver = SDL_GetCurrentVideoDriver();
|
|
|
|
if (!_window->getSDLWindow() && driver && strcmp(driver, "x11") == 0) {
|
2017-02-12 19:17:33 -06:00
|
|
|
_window->createOrUpdateWindow(width, height, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
width = _desiredFullscreenWidth;
|
|
|
|
height = _desiredFullscreenHeight;
|
|
|
|
|
2020-10-31 21:53:15 +01:00
|
|
|
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
|
2015-01-25 01:34:57 +01:00
|
|
|
}
|
|
|
|
|
2021-08-21 21:02:12 +02:00
|
|
|
if (!_wantsFullScreen && ConfMan.getBool("window_maximized", Common::ConfigManager::kApplicationDomain)) {
|
2021-08-20 18:43:26 +02:00
|
|
|
flags |= SDL_WINDOW_MAXIMIZED;
|
|
|
|
}
|
|
|
|
|
2015-12-18 20:50:31 +01:00
|
|
|
// Request a OpenGL (ES) context we can use.
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, _glContextProfileMask);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, _glContextMajor);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, _glContextMinor);
|
|
|
|
|
2021-04-13 14:43:15 -05:00
|
|
|
#ifdef NINTENDO_SWITCH
|
|
|
|
// Switch quirk: Switch seems to need this flag, otherwise the screen
|
|
|
|
// is zoomed when switching from Normal graphics mode to OpenGL
|
|
|
|
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
|
|
|
|
#endif
|
2017-08-27 22:21:05 -05:00
|
|
|
if (!createOrUpdateWindow(width, height, flags)) {
|
|
|
|
return false;
|
2015-01-25 01:34:57 +01:00
|
|
|
}
|
|
|
|
|
2015-02-16 00:49:42 +01:00
|
|
|
_glContext = SDL_GL_CreateContext(_window->getSDLWindow());
|
2015-01-25 01:34:57 +01:00
|
|
|
if (!_glContext) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-10-21 08:02:00 +02:00
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
|
|
|
_vsync = ConfMan.getBool("vsync");
|
|
|
|
if (SDL_GL_SetSwapInterval(_vsync ? 1 : 0)) {
|
|
|
|
warning("Unable to %s VSync: %s", _vsync ? "enable" : "disable", SDL_GetError());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-12-18 21:14:48 +01:00
|
|
|
notifyContextCreate(rgba8888, rgba8888);
|
2015-01-25 01:34:57 +01:00
|
|
|
int actualWidth, actualHeight;
|
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.
2017-07-19 19:15:12 -05:00
|
|
|
getWindowSizeFromSdl(&actualWidth, &actualHeight);
|
2020-10-29 19:12:24 +01:00
|
|
|
|
2020-10-29 17:30:05 +00:00
|
|
|
handleResize(actualWidth, actualHeight);
|
2021-08-21 21:39:30 +02:00
|
|
|
|
2021-08-22 10:30:34 +02:00
|
|
|
#ifdef WIN32
|
2021-08-21 21:39:30 +02:00
|
|
|
// WORKAROUND: Prevent (nearly) offscreen positioning of the ScummVM window by forcefully
|
|
|
|
// trigger a re-positioning event to center the window.
|
2021-08-21 21:59:51 +02:00
|
|
|
if (!_wantsFullScreen && !(SDL_GetWindowFlags(_window->getSDLWindow()) & SDL_WINDOW_MAXIMIZED)) {
|
2021-08-24 19:46:00 +02:00
|
|
|
|
|
|
|
// Read the current window position
|
|
|
|
int _xWindowPos;
|
2021-11-13 23:33:13 +02:00
|
|
|
SDL_GetWindowPosition(_window->getSDLWindow(), &_xWindowPos, nullptr);
|
2021-08-24 19:46:00 +02:00
|
|
|
|
|
|
|
// Relocate the window to the center of the screen in case we try to draw
|
|
|
|
// outside the window area. In this case, _xWindowPos always returns 0.
|
|
|
|
if (_xWindowPos == 0) {
|
|
|
|
SDL_SetWindowPosition(_window->getSDLWindow(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
|
|
|
}
|
2021-08-21 21:59:51 +02:00
|
|
|
}
|
2021-08-22 10:30:34 +02:00
|
|
|
#endif
|
2015-01-25 01:34:57 +01:00
|
|
|
return true;
|
|
|
|
#else
|
2013-08-18 16:56:34 +02:00
|
|
|
// WORKAROUND: Working around infamous SDL bugs when switching
|
|
|
|
// resolutions too fast. This might cause the event system to supply
|
|
|
|
// incorrect mouse position events otherwise.
|
|
|
|
// Reference: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=665779
|
|
|
|
const uint32 curTime = SDL_GetTicks();
|
|
|
|
if (_hwScreen && (curTime < _lastVideoModeLoad || curTime - _lastVideoModeLoad < 100)) {
|
|
|
|
for (int i = 10; i > 0; --i) {
|
|
|
|
SDL_PumpEvents();
|
|
|
|
SDL_Delay(10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 flags = SDL_OPENGL;
|
|
|
|
if (_wantsFullScreen) {
|
2017-02-12 19:17:33 -06:00
|
|
|
width = _desiredFullscreenWidth;
|
|
|
|
height = _desiredFullscreenHeight;
|
2013-08-18 16:56:34 +02:00
|
|
|
flags |= SDL_FULLSCREEN;
|
|
|
|
} else {
|
|
|
|
flags |= SDL_RESIZABLE;
|
|
|
|
}
|
|
|
|
|
2014-02-11 11:07:37 +01:00
|
|
|
if (_hwScreen) {
|
|
|
|
// When a video mode has been setup already we notify the manager that
|
|
|
|
// the context is about to be destroyed.
|
|
|
|
// We do this because on Windows SDL_SetVideoMode can destroy and
|
|
|
|
// recreate the OpenGL context.
|
|
|
|
notifyContextDestroy();
|
|
|
|
}
|
|
|
|
|
2013-08-18 16:56:34 +02:00
|
|
|
_hwScreen = SDL_SetVideoMode(width, height, 32, flags);
|
|
|
|
|
|
|
|
if (!_hwScreen) {
|
|
|
|
// We treat fullscreen requests as a "hint" for now. This means in
|
|
|
|
// case it is not available we simply ignore it.
|
|
|
|
if (_wantsFullScreen) {
|
|
|
|
_hwScreen = SDL_SetVideoMode(width, height, 32, SDL_OPENGL | SDL_RESIZABLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-17 23:31:16 +02:00
|
|
|
// Part of the WORKAROUND mentioned above.
|
|
|
|
_lastVideoModeLoad = SDL_GetTicks();
|
|
|
|
|
2013-08-18 16:56:34 +02:00
|
|
|
if (_hwScreen) {
|
2015-12-18 21:14:48 +01:00
|
|
|
notifyContextCreate(rgba8888, rgba8888);
|
2020-10-29 17:30:05 +00:00
|
|
|
handleResize(_hwScreen->w, _hwScreen->h);
|
2013-08-18 16:56:34 +02:00
|
|
|
}
|
|
|
|
|
2014-07-04 22:37:43 +02:00
|
|
|
// Ignore resize events (from SDL) for a few frames, if this isn't
|
|
|
|
// caused by a notification from SDL. This avoids bad resizes to a
|
|
|
|
// (former) resolution for which we haven't processed an event yet.
|
|
|
|
if (!_gotResize)
|
|
|
|
_ignoreResizeEvents = 10;
|
2014-06-10 22:01:38 +02:00
|
|
|
|
2013-08-18 16:56:34 +02:00
|
|
|
return _hwScreen != nullptr;
|
2015-01-25 01:34:57 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-08-18 16:56:34 +02:00
|
|
|
bool OpenGLSdlGraphicsManager::notifyEvent(const Common::Event &event) {
|
2017-08-15 15:48:40 +02:00
|
|
|
if (event.type != Common::EVENT_CUSTOM_BACKEND_ACTION_START) {
|
|
|
|
return SdlGraphicsManager::notifyEvent(event);
|
|
|
|
}
|
2013-10-19 20:39:01 +02:00
|
|
|
|
2017-08-15 15:48:40 +02:00
|
|
|
switch ((CustomEventAction) event.customType) {
|
|
|
|
case kActionIncreaseScaleFactor:
|
|
|
|
case kActionDecreaseScaleFactor: {
|
|
|
|
const int direction = event.customType == kActionIncreaseScaleFactor ? +1 : -1;
|
|
|
|
|
|
|
|
if (getFeatureState(OSystem::kFeatureFullscreenMode)) {
|
|
|
|
// In case we are in fullscreen we will choose the previous
|
|
|
|
// or next mode.
|
|
|
|
|
2021-07-16 13:08:26 +01:00
|
|
|
// In case no modes are available or we only have one mode we do nothing.
|
|
|
|
if (_fullscreenVideoModes.size() < 2) {
|
2017-08-15 15:48:40 +02:00
|
|
|
return true;
|
|
|
|
}
|
2017-03-24 22:25:46 +01:00
|
|
|
|
2017-08-15 15:48:40 +02:00
|
|
|
// Look for the current mode.
|
|
|
|
VideoModeArray::const_iterator i = Common::find(_fullscreenVideoModes.begin(),
|
|
|
|
_fullscreenVideoModes.end(),
|
|
|
|
VideoMode(_desiredFullscreenWidth, _desiredFullscreenHeight));
|
|
|
|
if (i == _fullscreenVideoModes.end()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cycle through the modes in the specified direction.
|
|
|
|
if (direction > 0) {
|
|
|
|
++i;
|
|
|
|
if (i == _fullscreenVideoModes.end()) {
|
|
|
|
i = _fullscreenVideoModes.begin();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (i == _fullscreenVideoModes.begin()) {
|
|
|
|
i = _fullscreenVideoModes.end();
|
2013-08-18 16:56:34 +02:00
|
|
|
}
|
2017-08-15 15:48:40 +02:00
|
|
|
--i;
|
|
|
|
}
|
|
|
|
|
|
|
|
_desiredFullscreenWidth = i->width;
|
|
|
|
_desiredFullscreenHeight = i->height;
|
|
|
|
|
|
|
|
// Try to setup the mode.
|
|
|
|
if (!setupMode(_lastRequestedWidth, _lastRequestedHeight)) {
|
|
|
|
warning("OpenGLSdlGraphicsManager::notifyEvent: Fullscreen resize failed ('%s')", SDL_GetError());
|
|
|
|
g_system->quit();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Calculate the next scaling setting. We approximate the
|
|
|
|
// current scale setting in case the user resized the
|
|
|
|
// window. Then we apply the direction change.
|
|
|
|
int windowWidth = 0, windowHeight = 0;
|
|
|
|
getWindowSizeFromSdl(&windowWidth, &windowHeight);
|
2021-08-20 00:26:36 +01:00
|
|
|
|
|
|
|
float dpiScale = _window->getSdlDpiScalingFactor();
|
|
|
|
windowWidth = (int)(windowWidth / dpiScale + 0.5f);
|
|
|
|
windowHeight = (int)(windowHeight / dpiScale + 0.5f);
|
|
|
|
|
2021-08-13 23:58:34 +01:00
|
|
|
if (direction > 0)
|
|
|
|
_graphicsScale = MAX<int>(windowWidth / _lastRequestedWidth, windowHeight / _lastRequestedHeight);
|
|
|
|
else
|
|
|
|
_graphicsScale = 1 + MIN<int>((windowWidth - 1) / _lastRequestedWidth, (windowHeight - 1) / _lastRequestedHeight);
|
2017-08-15 15:48:40 +02:00
|
|
|
_graphicsScale = MAX<int>(_graphicsScale + direction, 1);
|
|
|
|
|
|
|
|
// Since we overwrite a user resize here we reset its
|
|
|
|
// flag here. This makes enabling AR smoother because it
|
|
|
|
// will change the window size like in surface SDL.
|
|
|
|
_gotResize = false;
|
|
|
|
|
|
|
|
// Try to setup the mode.
|
2021-08-14 03:25:13 +01:00
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
2021-08-13 23:58:34 +01:00
|
|
|
unlockWindowSize();
|
2021-08-14 03:25:13 +01:00
|
|
|
#endif
|
2017-08-15 15:48:40 +02:00
|
|
|
if (!setupMode(_lastRequestedWidth * _graphicsScale, _lastRequestedHeight * _graphicsScale)) {
|
|
|
|
warning("OpenGLSdlGraphicsManager::notifyEvent: Window resize failed ('%s')", SDL_GetError());
|
|
|
|
g_system->quit();
|
|
|
|
}
|
|
|
|
}
|
2013-08-18 16:56:34 +02:00
|
|
|
|
2013-08-19 00:54:41 +02:00
|
|
|
#ifdef USE_OSD
|
2017-08-15 15:48:40 +02:00
|
|
|
int windowWidth = 0, windowHeight = 0;
|
|
|
|
getWindowSizeFromSdl(&windowWidth, &windowHeight);
|
2020-06-20 23:34:23 +05:30
|
|
|
const Common::U32String osdMsg = Common::U32String::format(_("Resolution: %dx%d"), windowWidth, windowHeight);
|
2020-06-13 22:12:25 +05:30
|
|
|
displayMessageOnOSD(osdMsg);
|
2013-08-19 00:54:41 +02:00
|
|
|
#endif
|
|
|
|
|
2017-08-15 15:48:40 +02:00
|
|
|
return true;
|
|
|
|
}
|
2013-08-18 16:56:34 +02:00
|
|
|
|
2017-08-15 15:48:40 +02:00
|
|
|
case kActionToggleAspectRatioCorrection:
|
|
|
|
// In case the user changed the window size manually we will
|
|
|
|
// not change the window size again here.
|
|
|
|
_ignoreLoadVideoMode = _gotResize;
|
2013-08-18 16:56:34 +02:00
|
|
|
|
2017-08-15 15:48:40 +02:00
|
|
|
// Toggles the aspect ratio correction state.
|
|
|
|
beginGFXTransaction();
|
|
|
|
setFeatureState(OSystem::kFeatureAspectRatioCorrection, !getFeatureState(OSystem::kFeatureAspectRatioCorrection));
|
|
|
|
endGFXTransaction();
|
|
|
|
|
|
|
|
// Make sure we do not ignore the next resize. This
|
|
|
|
// effectively checks whether loadVideoMode has been called.
|
|
|
|
assert(!_ignoreLoadVideoMode);
|
2013-08-18 16:56:34 +02:00
|
|
|
|
2013-08-19 00:54:41 +02:00
|
|
|
#ifdef USE_OSD
|
2017-08-15 15:48:40 +02:00
|
|
|
if (getFeatureState(OSystem::kFeatureAspectRatioCorrection))
|
|
|
|
displayMessageOnOSD(_("Enabled aspect ratio correction"));
|
|
|
|
else
|
|
|
|
displayMessageOnOSD(_("Disabled aspect ratio correction"));
|
2013-08-19 00:54:41 +02:00
|
|
|
#endif
|
|
|
|
|
2017-08-15 15:48:40 +02:00
|
|
|
return true;
|
2013-08-18 16:56:34 +02:00
|
|
|
|
2017-08-15 15:48:40 +02:00
|
|
|
case kActionToggleFilteredScaling:
|
|
|
|
// Never ever try to resize the window when we simply want to enable or disable filtering.
|
|
|
|
// This assures that the window size does not change.
|
|
|
|
_ignoreLoadVideoMode = true;
|
2013-08-18 16:56:34 +02:00
|
|
|
|
2017-08-15 15:48:40 +02:00
|
|
|
// Ctrl+Alt+f toggles filtering on/off
|
|
|
|
beginGFXTransaction();
|
|
|
|
setFeatureState(OSystem::kFeatureFilteringMode, !getFeatureState(OSystem::kFeatureFilteringMode));
|
|
|
|
endGFXTransaction();
|
|
|
|
|
|
|
|
// Make sure we do not ignore the next resize. This
|
|
|
|
// effectively checks whether loadVideoMode has been called.
|
|
|
|
assert(!_ignoreLoadVideoMode);
|
2013-08-18 16:56:34 +02:00
|
|
|
|
2013-08-19 00:54:41 +02:00
|
|
|
#ifdef USE_OSD
|
2017-08-15 15:48:40 +02:00
|
|
|
if (getFeatureState(OSystem::kFeatureFilteringMode)) {
|
|
|
|
displayMessageOnOSD(_("Filtering enabled"));
|
|
|
|
} else {
|
|
|
|
displayMessageOnOSD(_("Filtering disabled"));
|
|
|
|
}
|
2013-08-19 00:54:41 +02:00
|
|
|
#endif
|
|
|
|
|
2017-08-15 15:48:40 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
case kActionCycleStretchMode: {
|
|
|
|
// Never try to resize the window when changing the scaling mode.
|
|
|
|
_ignoreLoadVideoMode = true;
|
|
|
|
|
|
|
|
// Ctrl+Alt+s cycles through stretch mode
|
|
|
|
int index = 0;
|
|
|
|
const OSystem::GraphicsMode *stretchModes = getSupportedStretchModes();
|
|
|
|
const OSystem::GraphicsMode *sm = stretchModes;
|
|
|
|
while (sm->name) {
|
|
|
|
if (sm->id == getStretchMode())
|
|
|
|
break;
|
|
|
|
sm++;
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
index++;
|
|
|
|
if (!stretchModes[index].name)
|
|
|
|
index = 0;
|
|
|
|
beginGFXTransaction();
|
|
|
|
setStretchMode(stretchModes[index].id);
|
|
|
|
endGFXTransaction();
|
2018-05-12 19:57:21 +01:00
|
|
|
|
|
|
|
#ifdef USE_OSD
|
2020-09-08 21:23:47 +01:00
|
|
|
Common::U32String message = Common::U32String::format("%S: %S",
|
2020-08-20 00:26:11 +05:30
|
|
|
_("Stretch mode").c_str(),
|
|
|
|
_(stretchModes[index].description).c_str()
|
|
|
|
);
|
2020-06-13 22:12:25 +05:30
|
|
|
displayMessageOnOSD(message);
|
2018-05-12 19:57:21 +01:00
|
|
|
#endif
|
2013-08-18 16:56:34 +02:00
|
|
|
|
2017-08-15 15:48:40 +02:00
|
|
|
return true;
|
2013-08-18 16:56:34 +02:00
|
|
|
}
|
2019-03-10 16:25:25 +00:00
|
|
|
|
2017-08-15 15:48:40 +02:00
|
|
|
default:
|
|
|
|
return SdlGraphicsManager::notifyEvent(event);
|
2013-08-18 16:56:34 +02:00
|
|
|
}
|
|
|
|
}
|