From 281672e1718d5f960061b714f79924125922e1e5 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 24 Oct 2013 00:03:09 +0200 Subject: SDL: Let SdlGraphicsManager inherit from GraphicsManager. --- backends/graphics/opengl/opengl-graphics.h | 2 +- backends/graphics/sdl/sdl-graphics.h | 7 +++---- backends/graphics/surfacesdl/surfacesdl-graphics.h | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) (limited to 'backends/graphics') diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h index d2d0358407..93c0c5bc83 100644 --- a/backends/graphics/opengl/opengl-graphics.h +++ b/backends/graphics/opengl/opengl-graphics.h @@ -47,7 +47,7 @@ enum { GFX_NEAREST = 1 }; -class OpenGLGraphicsManager : public GraphicsManager { +class OpenGLGraphicsManager : virtual public GraphicsManager { public: OpenGLGraphicsManager(); virtual ~OpenGLGraphicsManager(); diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h index 4d4338af16..ebf8078f23 100644 --- a/backends/graphics/sdl/sdl-graphics.h +++ b/backends/graphics/sdl/sdl-graphics.h @@ -23,6 +23,8 @@ #ifndef BACKENDS_GRAPHICS_SDL_SDLGRAPHICS_H #define BACKENDS_GRAPHICS_SDL_SDLGRAPHICS_H +#include "backends/graphics/graphics.h" + #include "common/rect.h" class SdlEventSource; @@ -31,11 +33,8 @@ class SdlEventSource; * Base class for a SDL based graphics manager. * * It features a few extra a few extra features required by SdlEventSource. - * FIXME/HACK: - * Note it does not inherit from GraphicsManager to avoid a diamond inheritance - * in the current OpenGLSdlGraphicsManager. */ -class SdlGraphicsManager { +class SdlGraphicsManager : virtual public GraphicsManager { public: SdlGraphicsManager(SdlEventSource *source); virtual ~SdlGraphicsManager(); diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.h b/backends/graphics/surfacesdl/surfacesdl-graphics.h index 00c05ff2bf..22b7780675 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.h +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.h @@ -75,7 +75,7 @@ public: /** * SDL graphics manager */ -class SurfaceSdlGraphicsManager : public GraphicsManager, public SdlGraphicsManager, public Common::EventObserver { +class SurfaceSdlGraphicsManager : public SdlGraphicsManager, public Common::EventObserver { public: SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSource); virtual ~SurfaceSdlGraphicsManager(); -- cgit v1.2.3 From ea6d38d5f3b123b765e5bf8e2dc4f957e4b43eb6 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 24 Oct 2013 00:06:32 +0200 Subject: SDL: Make activateManager/deactivateManager SdlGraphicsManager specific. We can do this now that we can use virtual inheritance and dynamic_cast because we enabled RTTI. --- backends/graphics/graphics.h | 21 --------------------- backends/graphics/openglsdl/openglsdl-graphics.cpp | 4 ++-- backends/graphics/sdl/sdl-graphics.h | 13 +++++++++++++ .../graphics/surfacesdl/surfacesdl-graphics.cpp | 4 ++-- 4 files changed, 17 insertions(+), 25 deletions(-) (limited to 'backends/graphics') diff --git a/backends/graphics/graphics.h b/backends/graphics/graphics.h index 74258b8910..24397228e6 100644 --- a/backends/graphics/graphics.h +++ b/backends/graphics/graphics.h @@ -37,27 +37,6 @@ class GraphicsManager : public PaletteManager { public: virtual ~GraphicsManager() {} - /** - * Makes this graphics manager active. That means it should be ready to - * process inputs now. However, even without being active it should be - * able to query the supported modes and other bits. - * - * HACK: Actually this is specific to SdlGraphicsManager subclasses. - * But sadly we cannot cast from GraphicsManager to SdlGraphicsManager - * because there is no relation between these two. - */ - virtual void activateManager() {} - - /** - * Makes this graphics manager inactive. This should allow another - * graphics manager to become active again. - * - * HACK: Actually this is specific to SdlGraphicsManager subclasses. - * But sadly we cannot cast from GraphicsManager to SdlGraphicsManager - * because there is no relation between these two. - */ - virtual void deactivateManager() {} - virtual bool hasFeature(OSystem::Feature f) = 0; virtual void setFeatureState(OSystem::Feature f, bool enable) = 0; virtual bool getFeatureState(OSystem::Feature f) = 0; diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp index e39cd35870..f76d7b2ec0 100644 --- a/backends/graphics/openglsdl/openglsdl-graphics.cpp +++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp @@ -73,7 +73,7 @@ OpenGLSdlGraphicsManager::~OpenGLSdlGraphicsManager() { } void OpenGLSdlGraphicsManager::activateManager() { - OpenGLGraphicsManager::activateManager(); + SdlGraphicsManager::activateManager(); initEventSource(); // Register the graphics manager as a event observer @@ -87,7 +87,7 @@ void OpenGLSdlGraphicsManager::deactivateManager() { } deinitEventSource(); - OpenGLGraphicsManager::deactivateManager(); + SdlGraphicsManager::deactivateManager(); } bool OpenGLSdlGraphicsManager::hasFeature(OSystem::Feature f) { diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h index ebf8078f23..fea743b3ca 100644 --- a/backends/graphics/sdl/sdl-graphics.h +++ b/backends/graphics/sdl/sdl-graphics.h @@ -39,6 +39,19 @@ public: SdlGraphicsManager(SdlEventSource *source); virtual ~SdlGraphicsManager(); + /** + * Makes this graphics manager active. That means it should be ready to + * process inputs now. However, even without being active it should be + * able to query the supported modes and other bits. + */ + virtual void activateManager() {} + + /** + * Makes this graphics manager inactive. This should allow another + * graphics manager to become active again. + */ + virtual void deactivateManager() {} + /** * Notify the graphics manager that the graphics needs to be redrawn, since * the application window was modified. diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp index c946b8e747..15193e2da4 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp @@ -198,7 +198,7 @@ SurfaceSdlGraphicsManager::~SurfaceSdlGraphicsManager() { } void SurfaceSdlGraphicsManager::activateManager() { - GraphicsManager::activateManager(); + SdlGraphicsManager::activateManager(); initEventSource(); // Register the graphics manager as a event observer @@ -212,7 +212,7 @@ void SurfaceSdlGraphicsManager::deactivateManager() { } deinitEventSource(); - GraphicsManager::deactivateManager(); + SdlGraphicsManager::deactivateManager(); } bool SurfaceSdlGraphicsManager::hasFeature(OSystem::Feature f) { -- cgit v1.2.3 From cfa6b1b4ae690a6712ef9b2fa6a5f21ff3c2173b Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 24 Oct 2013 00:09:17 +0200 Subject: SDL: Further small cleanup related to manager switching. --- backends/graphics/openglsdl/openglsdl-graphics.cpp | 2 -- backends/graphics/sdl/sdl-graphics.cpp | 4 ++-- backends/graphics/sdl/sdl-graphics.h | 7 ++----- backends/graphics/surfacesdl/surfacesdl-graphics.cpp | 2 -- 4 files changed, 4 insertions(+), 11 deletions(-) (limited to 'backends/graphics') diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp index f76d7b2ec0..3f9fc1fbd5 100644 --- a/backends/graphics/openglsdl/openglsdl-graphics.cpp +++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp @@ -74,7 +74,6 @@ OpenGLSdlGraphicsManager::~OpenGLSdlGraphicsManager() { void OpenGLSdlGraphicsManager::activateManager() { SdlGraphicsManager::activateManager(); - initEventSource(); // Register the graphics manager as a event observer g_system->getEventManager()->getEventDispatcher()->registerObserver(this, 10, false); @@ -86,7 +85,6 @@ void OpenGLSdlGraphicsManager::deactivateManager() { g_system->getEventManager()->getEventDispatcher()->unregisterObserver(this); } - deinitEventSource(); SdlGraphicsManager::deactivateManager(); } diff --git a/backends/graphics/sdl/sdl-graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp index 417f4faf54..40b97b267b 100644 --- a/backends/graphics/sdl/sdl-graphics.cpp +++ b/backends/graphics/sdl/sdl-graphics.cpp @@ -31,10 +31,10 @@ SdlGraphicsManager::SdlGraphicsManager(SdlEventSource *source) SdlGraphicsManager::~SdlGraphicsManager() { } -void SdlGraphicsManager::initEventSource() { +void SdlGraphicsManager::activateManager() { _eventSource->setGraphicsManager(this); } -void SdlGraphicsManager::deinitEventSource() { +void SdlGraphicsManager::deactivateManager() { _eventSource->setGraphicsManager(0); } diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h index fea743b3ca..3791961cfa 100644 --- a/backends/graphics/sdl/sdl-graphics.h +++ b/backends/graphics/sdl/sdl-graphics.h @@ -44,13 +44,13 @@ public: * process inputs now. However, even without being active it should be * able to query the supported modes and other bits. */ - virtual void activateManager() {} + virtual void activateManager(); /** * Makes this graphics manager inactive. This should allow another * graphics manager to become active again. */ - virtual void deactivateManager() {} + virtual void deactivateManager(); /** * Notify the graphics manager that the graphics needs to be redrawn, since @@ -92,9 +92,6 @@ public: virtual void notifyMousePos(Common::Point mouse) = 0; protected: - void initEventSource(); - void deinitEventSource(); - SdlEventSource *_eventSource; }; diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp index 15193e2da4..d15fd6d8ef 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp @@ -199,7 +199,6 @@ SurfaceSdlGraphicsManager::~SurfaceSdlGraphicsManager() { void SurfaceSdlGraphicsManager::activateManager() { SdlGraphicsManager::activateManager(); - initEventSource(); // Register the graphics manager as a event observer g_system->getEventManager()->getEventDispatcher()->registerObserver(this, 10, false); @@ -211,7 +210,6 @@ void SurfaceSdlGraphicsManager::deactivateManager() { g_system->getEventManager()->getEventDispatcher()->unregisterObserver(this); } - deinitEventSource(); SdlGraphicsManager::deactivateManager(); } -- cgit v1.2.3 From 6677a973c2b9b742897441d3b8571b81b41fd297 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Sat, 11 Jan 2014 16:36:04 +0100 Subject: SDL: Avoid having SDL_SRCALPHA set even if we have alpha in the pixelformat. --- backends/graphics/surfacesdl/surfacesdl-graphics.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'backends/graphics') diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp index 0a4dcf3ea3..89802ac8ab 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp @@ -746,6 +746,8 @@ bool SurfaceSdlGraphicsManager::loadGFXMode() { if (_screen == NULL) error("allocating _screen failed"); + // Avoid having SDL_SRCALPHA set even if we supplied an alpha-channel in the format. + SDL_SetAlpha(_screen, 0, 255); #else _screen = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.screenWidth, _videoMode.screenHeight, 8, 0, 0, 0, 0); if (_screen == NULL) -- cgit v1.2.3 From 0f36a56b813c4270033804de8dd4f3412bedca55 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Tue, 21 Jan 2014 23:52:20 +0100 Subject: OPENGL: Properly query for OpenGL errors. There might be various error flags and we need to clear all of them to get precise error results. Thus, we need to call glGetError in a loop to achieve that. --- backends/graphics/opengl/debug.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'backends/graphics') diff --git a/backends/graphics/opengl/debug.cpp b/backends/graphics/opengl/debug.cpp index 69006bb975..d5d73fb5ec 100644 --- a/backends/graphics/opengl/debug.cpp +++ b/backends/graphics/opengl/debug.cpp @@ -52,9 +52,9 @@ Common::String getGLErrStr(GLenum error) { } // End of anonymous namespace void checkGLError(const char *expr, const char *file, int line) { - GLenum error = glGetError(); + GLenum error; - if (error != GL_NO_ERROR) { + while ((error = glGetError()) != GL_NO_ERROR) { // We cannot use error here because we do not know whether we have a // working screen or not. warning("GL ERROR: %s on %s (%s:%d)", getGLErrStr(error).c_str(), expr, file, line); -- cgit v1.2.3