From af727afe0ceb66eaf51985ceceb2ac842b3358ee Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Fri, 18 Dec 2015 21:14:48 +0100 Subject: OPENGL: Simplify context type setting. --- backends/graphics/opengl/context.cpp | 25 +++++++++++++--------- backends/graphics/opengl/opengl-graphics.cpp | 6 +++--- backends/graphics/opengl/opengl-graphics.h | 22 ++++++++++--------- backends/graphics/opengl/opengl-sys.h | 5 +---- backends/graphics/openglsdl/openglsdl-graphics.cpp | 21 +++++++++++------- backends/graphics/openglsdl/openglsdl-graphics.h | 1 - backends/platform/tizen/graphics.cpp | 3 ++- 7 files changed, 46 insertions(+), 37 deletions(-) diff --git a/backends/graphics/opengl/context.cpp b/backends/graphics/opengl/context.cpp index d1776f851d..0077cc2746 100644 --- a/backends/graphics/opengl/context.cpp +++ b/backends/graphics/opengl/context.cpp @@ -27,24 +27,32 @@ namespace OpenGL { -void Context::reset() { - ready = false; - type = kContextGL; +void Context::reset(bool full) { + if (full) { + // GLES supports least features, thus we initialize the context type + // to this on full reset. + type = kContextGLES; + } + NPOTSupported = false; } Context g_context; -void OpenGLGraphicsManager::initializeGLContext(ContextType type) { - // Initialize default state. - g_context.reset(); - +void OpenGLGraphicsManager::setContextType(ContextType type) { #if USE_FORCED_GL type = kContextGL; #elif USE_FORCED_GLES type = kContextGLES; #endif + g_context.type = type; +} + +void OpenGLGraphicsManager::initializeGLContext() { + // Initialize default state. + g_context.reset(); + // Load all functions. // We use horrible trickery to silence C++ compilers. // See backends/plugins/sdl/sdl-provider.cpp for more information. @@ -72,9 +80,6 @@ void OpenGLGraphicsManager::initializeGLContext(ContextType type) { g_context.NPOTSupported = true; } } - - g_context.ready = true; - g_context.type = type; } } // End of namespace OpenGL diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 8db5f6a934..78c6b2aff1 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -56,7 +56,7 @@ OpenGLGraphicsManager::OpenGLGraphicsManager() #endif { memset(_gamePalette, 0, sizeof(_gamePalette)); - g_context.reset(); + g_context.reset(true); } OpenGLGraphicsManager::~OpenGLGraphicsManager() { @@ -840,9 +840,9 @@ void OpenGLGraphicsManager::setActualScreenSize(uint width, uint height) { ++_screenChangeID; } -void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &defaultFormat, const Graphics::PixelFormat &defaultFormatAlpha, ContextType type) { +void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &defaultFormat, const Graphics::PixelFormat &defaultFormatAlpha) { // Initialize context for use. - initializeGLContext(type); + initializeGLContext(); // Disable 3D properties. GL_CALL(glDisable(GL_CULL_FACE)); diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h index 5f0436c0b5..5a2b1bb373 100644 --- a/backends/graphics/opengl/opengl-graphics.h +++ b/backends/graphics/opengl/opengl-graphics.h @@ -116,11 +116,6 @@ public: virtual void grabPalette(byte *colors, uint start, uint num); protected: - /** - * Whether an OpenGL (context) is active. - */ - bool isInitialized() const { return g_context.ready; } - /** * Whether an GLES context is active. */ @@ -135,6 +130,16 @@ protected: */ void setActualScreenSize(uint width, uint height); + /** + * Sets the OpenGL (ES) type the graphics manager shall work with. + * + * This needs to be called at least once (and before ever calling + * notifyContextCreate). + * + * @param type Type of the OpenGL (ES) contexts to be created. + */ + void setContextType(ContextType type); + /** * Notify the manager of a OpenGL context change. This should be the first * thing to call after you created an OpenGL (ES) context! @@ -143,9 +148,8 @@ protected: * (this is used for the CLUT8 game screens). * @param defaultFormatAlpha The new default format with an alpha channel * (this is used for the overlay and cursor). - * @param type Type of the created context. */ - void notifyContextCreate(const Graphics::PixelFormat &defaultFormat, const Graphics::PixelFormat &defaultFormatAlpha, ContextType type); + void notifyContextCreate(const Graphics::PixelFormat &defaultFormat, const Graphics::PixelFormat &defaultFormatAlpha); /** * Notify the manager that the OpenGL context is about to be destroyed. @@ -293,10 +297,8 @@ private: /** * Initialize the active context for use. - * - * @param type Type of the context to initialize. */ - void initializeGLContext(ContextType type); + void initializeGLContext(); protected: /** diff --git a/backends/graphics/opengl/opengl-sys.h b/backends/graphics/opengl/opengl-sys.h index 550dbb44c5..250357f92a 100644 --- a/backends/graphics/opengl/opengl-sys.h +++ b/backends/graphics/opengl/opengl-sys.h @@ -76,9 +76,6 @@ enum ContextType { * Description structure of the OpenGL (ES) context. */ struct Context { - /** Whether the context is properly initalized or not. */ - bool ready; - /** The type of the active context. */ ContextType type; @@ -87,7 +84,7 @@ struct Context { * * This marks all extensions as unavailable. */ - void reset(); + void reset(bool full = false); /** Whether GL_ARB_texture_non_power_of_two is available or not. */ bool NPOTSupported; diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp index e7b6da206e..75d3fa1ebb 100644 --- a/backends/graphics/openglsdl/openglsdl-graphics.cpp +++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp @@ -47,15 +47,17 @@ OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(uint desktopWidth, uint deskt // Setup proper SDL OpenGL context creation. #if SDL_VERSION_ATLEAST(2, 0, 0) + OpenGL::ContextType glContextType; + #if USE_FORCED_GL - _glContextType = OpenGL::kContextGL; + glContextType = OpenGL::kContextGL; _glContextProfileMask = SDL_GL_CONTEXT_PROFILE_COMPATIBILITY; // Context version 1.4 is choosen arbitrarily based on what most shader // extensions were written against. _glContextMajor = 1; _glContextMinor = 4; #elif USE_FORCED_GLES - _glContextType = OpenGL::kContextGLES; + glContextType = OpenGL::kContextGLES; _glContextProfileMask = SDL_GL_CONTEXT_PROFILE_ES; _glContextMajor = 1; _glContextMinor = 1; @@ -103,7 +105,7 @@ OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(uint desktopWidth, uint deskt } if (_glContextProfileMask == SDL_GL_CONTEXT_PROFILE_ES) { - _glContextType = OpenGL::kContextGLES; + glContextType = OpenGL::kContextGLES; // We do not support GLES2 contexts right now. Force a GLES1 context. if (_glContextMajor >= 2) { @@ -111,7 +113,7 @@ OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(uint desktopWidth, uint deskt _glContextMinor = 1; } } else if (_glContextProfileMask == SDL_GL_CONTEXT_PROFILE_CORE) { - _glContextType = OpenGL::kContextGL; + glContextType = OpenGL::kContextGL; // Core profile does not allow legacy functionality, which we use. // Thus we always request a compatibility profile. @@ -121,9 +123,12 @@ OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(uint desktopWidth, uint deskt _glContextMajor = 1; _glContextMinor = 4; } else { - _glContextType = OpenGL::kContextGL; + glContextType = OpenGL::kContextGL; } #endif + setContextType(glContextType); +#else + setContextType(OpenGL::kContextGL); #endif // Retrieve a list of working fullscreen modes @@ -293,7 +298,7 @@ Common::List OpenGLSdlGraphicsManager::getSupportedFormat #if !USE_FORCED_GLES #if !USE_FORCED_GL - if (isInitialized() && !isGLESContext()) { + if (!isGLESContext()) { #endif #ifdef SCUMM_LITTLE_ENDIAN // RGBA8888 @@ -491,7 +496,7 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) { return false; } - notifyContextCreate(rgba8888, rgba8888, _glContextType); + notifyContextCreate(rgba8888, rgba8888); int actualWidth, actualHeight; getWindowDimensions(&actualWidth, &actualHeight); setActualScreenSize(actualWidth, actualHeight); @@ -539,7 +544,7 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) { _lastVideoModeLoad = SDL_GetTicks(); if (_hwScreen) { - notifyContextCreate(rgba8888, rgba8888, OpenGL::kContextGL); + notifyContextCreate(rgba8888, rgba8888); setActualScreenSize(_hwScreen->w, _hwScreen->h); _eventSource->resetKeyboadEmulation(_hwScreen->w - 1, _hwScreen->h - 1); } diff --git a/backends/graphics/openglsdl/openglsdl-graphics.h b/backends/graphics/openglsdl/openglsdl-graphics.h index 792116358b..51edcb4363 100644 --- a/backends/graphics/openglsdl/openglsdl-graphics.h +++ b/backends/graphics/openglsdl/openglsdl-graphics.h @@ -74,7 +74,6 @@ private: #if SDL_VERSION_ATLEAST(2, 0, 0) int _glContextProfileMask, _glContextMajor, _glContextMinor; - OpenGL::ContextType _glContextType; SDL_GLContext _glContext; #else uint32 _lastVideoModeLoad; diff --git a/backends/platform/tizen/graphics.cpp b/backends/platform/tizen/graphics.cpp index caa18c556f..61dbfc38fb 100644 --- a/backends/platform/tizen/graphics.cpp +++ b/backends/platform/tizen/graphics.cpp @@ -56,10 +56,11 @@ result TizenGraphicsManager::Construct() { loadEgl(); // Notify the OpenGL code about our context. + setContextType(OpenGL::kContextGLES); // We default to RGB565 and RGBA5551 which is closest to the actual output // mode we setup. - notifyContextCreate(Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0), Graphics::PixelFormat(2, 5, 5, 5, 1, 11, 6, 1, 0), OpenGL::kContextGLES); + notifyContextCreate(Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0), Graphics::PixelFormat(2, 5, 5, 5, 1, 11, 6, 1, 0)); // Tell our size. int x, y, width, height; -- cgit v1.2.3