aboutsummaryrefslogtreecommitdiff
path: root/backends/graphics
diff options
context:
space:
mode:
authorJohannes Schickel2015-12-18 21:14:48 +0100
committerJohannes Schickel2016-03-16 20:29:25 +0100
commitaf727afe0ceb66eaf51985ceceb2ac842b3358ee (patch)
tree90a7194bb25c83c5a50e25358e340d2a31595d4c /backends/graphics
parentda062ad1ea2d933ae7c4b56f84f34c5fb2186196 (diff)
downloadscummvm-rg350-af727afe0ceb66eaf51985ceceb2ac842b3358ee.tar.gz
scummvm-rg350-af727afe0ceb66eaf51985ceceb2ac842b3358ee.tar.bz2
scummvm-rg350-af727afe0ceb66eaf51985ceceb2ac842b3358ee.zip
OPENGL: Simplify context type setting.
Diffstat (limited to 'backends/graphics')
-rw-r--r--backends/graphics/opengl/context.cpp25
-rw-r--r--backends/graphics/opengl/opengl-graphics.cpp6
-rw-r--r--backends/graphics/opengl/opengl-graphics.h22
-rw-r--r--backends/graphics/opengl/opengl-sys.h5
-rw-r--r--backends/graphics/openglsdl/openglsdl-graphics.cpp21
-rw-r--r--backends/graphics/openglsdl/openglsdl-graphics.h1
6 files changed, 44 insertions, 36 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
@@ -117,11 +117,6 @@ public:
protected:
/**
- * Whether an OpenGL (context) is active.
- */
- bool isInitialized() const { return g_context.ready; }
-
- /**
* Whether an GLES context is active.
*/
bool isGLESContext() const { return g_context.type == kContextGLES; }
@@ -136,6 +131,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<Graphics::PixelFormat> 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;