ALL: Merge ResidualVM

This commit is contained in:
Paweł Kołodziejski 2020-10-09 19:04:07 +02:00
commit 35b9cccbde
1315 changed files with 289278 additions and 146 deletions

View file

@ -49,10 +49,14 @@
#include "backends/mutex/sdl/sdl-mutex.h"
#include "backends/timer/sdl/sdl-timer.h"
#include "backends/graphics/surfacesdl/surfacesdl-graphics.h"
#include "backends/graphics3d/surfacesdl/surfacesdl-graphics3d.h"
#ifdef USE_OPENGL
#include "backends/graphics/openglsdl/openglsdl-graphics.h"
#include "backends/graphics3d/openglsdl/openglsdl-graphics3d.h"
#include "graphics/opengl/context.h"
#include "graphics/cursorman.h"
#endif
#include "graphics/renderer.h"
#include <time.h> // for getTimeAndDate()
@ -100,7 +104,11 @@ OSystem_SDL::~OSystem_SDL() {
delete _savefileManager;
_savefileManager = 0;
if (_graphicsManager) {
dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->deactivateManager();
if (dynamic_cast<SdlGraphics3dManager *>(_graphicsManager)) {
dynamic_cast<SdlGraphics3dManager *>(_graphicsManager)->deactivateManager();
} else {
dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->deactivateManager();
}
}
delete _graphicsManager;
_graphicsManager = 0;
@ -206,6 +214,11 @@ void OSystem_SDL::initBackend() {
#endif
debug(1, "Using SDL Video Driver \"%s\"", sdlDriverName);
#ifdef USE_OPENGL
detectFramebufferSupport();
detectAntiAliasingSupport();
#endif
// Create the default event source, in case a custom backend
// manager didn't provide one yet.
if (!_eventSource)
@ -284,12 +297,96 @@ void OSystem_SDL::initBackend() {
// so the virtual keyboard can be initialized, but we have to add the
// graphics manager as an event observer after initializing the event
// manager.
dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->activateManager();
if (dynamic_cast<SdlGraphics3dManager *>(_graphicsManager)) {
dynamic_cast<SdlGraphics3dManager *>(_graphicsManager)->activateManager();
} else {
dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->activateManager();
}
}
#ifdef USE_OPENGL
void OSystem_SDL::detectFramebufferSupport() {
_capabilities.openGLFrameBuffer = false;
#if defined(USE_GLES2)
// Framebuffers are always available with GLES2
_capabilities.openGLFrameBuffer = true;
#elif !defined(AMIGAOS)
// Spawn a 32x32 window off-screen with a GL context to test if framebuffers are supported
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_Window *window = SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 32, 32, SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN);
if (window) {
SDL_GLContext glContext = SDL_GL_CreateContext(window);
if (glContext) {
OpenGLContext.initialize(OpenGL::kOGLContextGL);
_capabilities.openGLFrameBuffer = OpenGLContext.framebufferObjectSupported;
OpenGLContext.reset();
SDL_GL_DeleteContext(glContext);
}
SDL_DestroyWindow(window);
}
#else
SDL_putenv(const_cast<char *>("SDL_VIDEO_WINDOW_POS=9000,9000"));
SDL_SetVideoMode(32, 32, 0, SDL_OPENGL);
SDL_putenv(const_cast<char *>("SDL_VIDEO_WINDOW_POS=center"));
OpenGLContext.initialize(OpenGL::kOGLContextGL);
_capabilities.openGLFrameBuffer = OpenGLContext.framebufferObjectSupported;
OpenGLContext.reset();
#endif
#endif
}
void OSystem_SDL::detectAntiAliasingSupport() {
_capabilities.openGLAntiAliasLevels.clear();
int requestedSamples = 2;
while (requestedSamples <= 32) {
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, requestedSamples);
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_Window *window = SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 32, 32, SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN);
if (window) {
SDL_GLContext glContext = SDL_GL_CreateContext(window);
if (glContext) {
int actualSamples = 0;
SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &actualSamples);
if (actualSamples == requestedSamples) {
_capabilities.openGLAntiAliasLevels.push_back(requestedSamples);
}
SDL_GL_DeleteContext(glContext);
}
SDL_DestroyWindow(window);
}
#else
SDL_putenv(const_cast<char *>("SDL_VIDEO_WINDOW_POS=9000,9000"));
SDL_SetVideoMode(32, 32, 0, SDL_OPENGL);
SDL_putenv(const_cast<char *>("SDL_VIDEO_WINDOW_POS=center"));
int actualSamples = 0;
SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &actualSamples);
if (actualSamples == requestedSamples) {
_capabilities.openGLAntiAliasLevels.push_back(requestedSamples);
}
#endif
requestedSamples *= 2;
}
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
}
#endif // USE_OPENGL
void OSystem_SDL::engineInit() {
#if SDL_VERSION_ATLEAST(2, 0, 0)
dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->unlockWindowSize();
if (dynamic_cast<SdlGraphicsManager *>(_graphicsManager)) {
dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->unlockWindowSize();
}
// Disable screen saver when engine starts
SDL_DisableScreenSaver();
#endif
@ -311,7 +408,9 @@ void OSystem_SDL::engineInit() {
void OSystem_SDL::engineDone() {
#if SDL_VERSION_ATLEAST(2, 0, 0)
dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->unlockWindowSize();
if (dynamic_cast<SdlGraphicsManager *>(_graphicsManager)) {
dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->unlockWindowSize();
}
SDL_EnableScreenSaver();
#endif
#ifdef USE_TASKBAR
@ -387,6 +486,12 @@ void OSystem_SDL::setWindowCaption(const char *caption) {
_window->setWindowCaption(cap);
}
#ifdef USE_OPENGL
Common::Array<uint> OSystem_SDL::getSupportedAntiAliasingLevels() const {
return _capabilities.openGLAntiAliasLevels;
}
#endif
void OSystem_SDL::quit() {
destroy();
exit(0);
@ -400,8 +505,13 @@ void OSystem_SDL::fatalError() {
Common::KeymapArray OSystem_SDL::getGlobalKeymaps() {
Common::KeymapArray globalMaps = BaseBackend::getGlobalKeymaps();
SdlGraphicsManager *graphicsManager = dynamic_cast<SdlGraphicsManager *>(_graphicsManager);
globalMaps.push_back(graphicsManager->getKeymap());
Common::Keymap *keymap;
if (dynamic_cast<SdlGraphics3dManager *>(_graphicsManager)) {
keymap = dynamic_cast<SdlGraphics3dManager *>(_graphicsManager)->getKeymap();
} else {
keymap = dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->getKeymap();
}
globalMaps.push_back(keymap);
return globalMaps;
}
@ -609,8 +719,12 @@ int OSystem_SDL::getDefaultGraphicsMode() const {
}
}
bool OSystem_SDL::setGraphicsMode(int mode) {
if (_graphicsModes.empty()) {
bool OSystem_SDL::setGraphicsMode(int mode, uint flags) {
bool render3d = flags & OSystem::kGfxModeRender3d;
bool accel3d = flags & OSystem::kGfxModeAcceleration3d;
// In 3d render mode gfx mode param is ignored.
if (_graphicsModes.empty() && !render3d) {
return _graphicsManager->setGraphicsMode(mode);
}
@ -619,42 +733,95 @@ bool OSystem_SDL::setGraphicsMode(int mode) {
return false;
}
// Very hacky way to set up the old graphics manager state, in case we
// switch from SDL->OpenGL or OpenGL->SDL.
//
// This is a probably temporary workaround to fix bugs like #3368143
// "SDL/OpenGL: Crash when switching renderer backend".
SdlGraphicsManager *sdlGraphicsManager = dynamic_cast<SdlGraphicsManager *>(_graphicsManager);
SdlGraphicsManager::State state = sdlGraphicsManager->getState();
bool switchedManager = false;
SdlGraphicsManager *sdlGraphicsManager = dynamic_cast<SdlGraphicsManager *>(_graphicsManager);
SdlGraphics3dManager *sdlGraphics3dManager = dynamic_cast<SdlGraphics3dManager *>(_graphicsManager);
assert(sdlGraphicsManager || sdlGraphics3dManager);
if (sdlGraphicsManager) {
// Very hacky way to set up the old graphics manager state, in case we
// switch from SDL->OpenGL or OpenGL->SDL.
//
// This is a probably temporary workaround to fix bugs like #3368143
// "SDL/OpenGL: Crash when switching renderer backend".
//
// It's also used to restore state from 3D to 2D GFX manager
_gfxManagerState = sdlGraphicsManager->getState();
}
// If the new mode and the current mode are not from the same graphics
// manager, delete and create the new mode graphics manager
if (_graphicsMode >= _firstGLMode && mode < _firstGLMode) {
debug(1, "switching to plain SDL graphics");
sdlGraphicsManager->deactivateManager();
delete _graphicsManager;
_graphicsManager = sdlGraphicsManager = new SurfaceSdlGraphicsManager(_eventSource, _window);
if (!render3d) {
if (sdlGraphics3dManager) {
sdlGraphics3dManager->deactivateManager();
delete sdlGraphics3dManager;
}
switchedManager = true;
} else if (_graphicsMode < _firstGLMode && mode >= _firstGLMode) {
debug(1, "switching to OpenGL graphics");
sdlGraphicsManager->deactivateManager();
delete _graphicsManager;
_graphicsManager = sdlGraphicsManager = new OpenGLSdlGraphicsManager(_eventSource, _window);
if ((sdlGraphics3dManager || _graphicsMode >= _firstGLMode) && mode < _firstGLMode) {
debug(1, "switching to plain SDL graphics");
if (sdlGraphicsManager) {
sdlGraphicsManager->deactivateManager();
delete sdlGraphicsManager;
}
_graphicsManager = sdlGraphicsManager = new SurfaceSdlGraphicsManager(_eventSource, _window);
switchedManager = true;
} else if ((sdlGraphics3dManager || _graphicsMode < _firstGLMode) && mode >= _firstGLMode) {
debug(1, "switching to OpenGL graphics");
if (sdlGraphicsManager) {
sdlGraphicsManager->deactivateManager();
delete sdlGraphicsManager;
}
_graphicsManager = sdlGraphicsManager = new OpenGLSdlGraphicsManager(_eventSource, _window);
switchedManager = true;
}
switchedManager = true;
if (sdlGraphics3dManager) {
sdlGraphics3dManager = nullptr;
}
} else {
if (sdlGraphicsManager) {
sdlGraphicsManager->deactivateManager();
delete sdlGraphicsManager;
}
if (accel3d && !dynamic_cast<OpenGLSdlGraphics3dManager *>(sdlGraphics3dManager)) {
if (sdlGraphics3dManager) {
sdlGraphics3dManager->deactivateManager();
delete sdlGraphics3dManager;
}
_graphicsManager = sdlGraphics3dManager = new OpenGLSdlGraphics3dManager(_eventSource, _window, _capabilities);
// Setup feature defaults for 3D gfx while switching from 2D
if (sdlGraphicsManager)
sdlGraphics3dManager->setDefaultFeatureState();
switchedManager = true;
} else if (!accel3d && !dynamic_cast<SurfaceSdlGraphics3dManager *>(sdlGraphics3dManager)) {
if (sdlGraphics3dManager) {
sdlGraphics3dManager->deactivateManager();
delete sdlGraphics3dManager;
}
_graphicsManager = sdlGraphics3dManager = new SurfaceSdlGraphics3dManager(_eventSource, _window);
// Setup feature defaults for 3D gfx while switching from 2D
if (sdlGraphicsManager)
sdlGraphics3dManager->setDefaultFeatureState();
switchedManager = true;
}
if (sdlGraphicsManager) {
sdlGraphicsManager = nullptr;
}
}
_graphicsMode = mode;
if (switchedManager) {
sdlGraphicsManager->activateManager();
// This failing will probably have bad consequences...
if (!sdlGraphicsManager->setState(state)) {
return false;
if (sdlGraphicsManager) {
sdlGraphicsManager->activateManager();
// This failing will probably have bad consequences...
if (!sdlGraphicsManager->setState(_gfxManagerState)) {
return false;
}
} else if (sdlGraphics3dManager) {
sdlGraphics3dManager->activateManager();
}
// Next setup the cursor again
@ -669,9 +836,9 @@ bool OSystem_SDL::setGraphicsMode(int mode) {
_graphicsManager->beginGFXTransaction();
// Oh my god if this failed the client code might just explode.
return _graphicsManager->setGraphicsMode(_graphicsModeIds[mode]);
return _graphicsManager->setGraphicsMode(_graphicsModeIds[mode], flags);
} else {
return _graphicsManager->setGraphicsMode(_graphicsModeIds[mode]);
return _graphicsManager->setGraphicsMode(_graphicsModeIds[mode], flags);
}
}