diff options
Diffstat (limited to 'backends/graphics/opengl')
-rw-r--r-- | backends/graphics/opengl/context.cpp | 13 | ||||
-rw-r--r-- | backends/graphics/opengl/opengl-func.h | 5 | ||||
-rw-r--r-- | backends/graphics/opengl/opengl-graphics.cpp | 24 | ||||
-rw-r--r-- | backends/graphics/opengl/opengl-graphics.h | 17 | ||||
-rw-r--r-- | backends/graphics/opengl/opengl-sys.h | 19 |
5 files changed, 65 insertions, 13 deletions
diff --git a/backends/graphics/opengl/context.cpp b/backends/graphics/opengl/context.cpp index c4869c2ae6..d1776f851d 100644 --- a/backends/graphics/opengl/context.cpp +++ b/backends/graphics/opengl/context.cpp @@ -28,15 +28,23 @@ namespace OpenGL { void Context::reset() { + ready = false; + type = kContextGL; NPOTSupported = false; } Context g_context; -void OpenGLGraphicsManager::initializeGLContext() { +void OpenGLGraphicsManager::initializeGLContext(ContextType type) { // Initialize default state. g_context.reset(); +#if USE_FORCED_GL + type = kContextGL; +#elif USE_FORCED_GLES + type = kContextGLES; +#endif + // Load all functions. // We use horrible trickery to silence C++ compilers. // See backends/plugins/sdl/sdl-provider.cpp for more information. @@ -64,6 +72,9 @@ void OpenGLGraphicsManager::initializeGLContext() { g_context.NPOTSupported = true; } } + + g_context.ready = true; + g_context.type = type; } } // End of namespace OpenGL diff --git a/backends/graphics/opengl/opengl-func.h b/backends/graphics/opengl/opengl-func.h index 75bc0b4e81..0ff39c845a 100644 --- a/backends/graphics/opengl/opengl-func.h +++ b/backends/graphics/opengl/opengl-func.h @@ -70,9 +70,10 @@ GL_FUNC_DEF(void, glColor4f, (GLfloat red, GLfloat green, GLfloat blue, GLfloat GL_FUNC_DEF(void, glViewport, (GLint x, GLint y, GLsizei width, GLsizei height)); GL_FUNC_DEF(void, glMatrixMode, (GLenum mode)); GL_FUNC_DEF(void, glLoadIdentity, ()); -#ifdef USE_GLES +#if !USE_FORCED_GL GL_FUNC_DEF(void, glOrthof, (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar)); -#else +#endif +#if !USE_FORCED_GLES GL_FUNC_DEF(void, glOrtho, (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val)); #endif GL_FUNC_DEF(void, glShadeModel, (GLenum mode)); diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 1024ee546e..78ae27d8a6 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -759,10 +759,16 @@ void OpenGLGraphicsManager::setActualScreenSize(uint width, uint height) { GL_CALL(glMatrixMode(GL_PROJECTION)); GL_CALL(glLoadIdentity()); -#ifdef USE_GLES +#if USE_FORCED_GLES GL_CALL(glOrthof(0, _outputScreenWidth, _outputScreenHeight, 0, -1, 1)); -#else +#elif USE_FORCED_GL GL_CALL(glOrtho(0, _outputScreenWidth, _outputScreenHeight, 0, -1, 1)); +#else + if (isGLESContext()) { + GL_CALL(glOrthof(0, _outputScreenWidth, _outputScreenHeight, 0, -1, 1)); + } else { + GL_CALL(glOrtho(0, _outputScreenWidth, _outputScreenHeight, 0, -1, 1)); + } #endif GL_CALL(glMatrixMode(GL_MODELVIEW)); GL_CALL(glLoadIdentity()); @@ -834,9 +840,9 @@ void OpenGLGraphicsManager::setActualScreenSize(uint width, uint height) { ++_screenChangeID; } -void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &defaultFormat, const Graphics::PixelFormat &defaultFormatAlpha) { +void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &defaultFormat, const Graphics::PixelFormat &defaultFormatAlpha, ContextType type) { // Initialize context for use. - initializeGLContext(); + initializeGLContext(type); // Disable 3D properties. GL_CALL(glDisable(GL_CULL_FACE)); @@ -1014,7 +1020,11 @@ bool OpenGLGraphicsManager::getGLPixelFormat(const Graphics::PixelFormat &pixelF glFormat = GL_RGBA; glType = GL_UNSIGNED_SHORT_4_4_4_4; return true; -#ifndef USE_GLES +#if !USE_FORCED_GLES + // The formats below are not supported by every GLES implementation. + // Thus, we do not mark them as supported when a GLES context is setup. + } else if (isGLESContext()) { + return false; #ifdef SCUMM_LITTLE_ENDIAN } else if (pixelFormat == Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0)) { // RGBA8888 glIntFormat = GL_RGBA; @@ -1023,8 +1033,6 @@ bool OpenGLGraphicsManager::getGLPixelFormat(const Graphics::PixelFormat &pixelF return true; #endif } else if (pixelFormat == Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0)) { // RGB555 - // GL_BGRA does not exist in every GLES implementation so should not be configured if - // USE_GLES is set. glIntFormat = GL_RGB; glFormat = GL_BGRA; glType = GL_UNSIGNED_SHORT_1_5_5_5_REV; @@ -1066,7 +1074,7 @@ bool OpenGLGraphicsManager::getGLPixelFormat(const Graphics::PixelFormat &pixelF glFormat = GL_BGRA; glType = GL_UNSIGNED_SHORT_4_4_4_4; return true; -#endif +#endif // !USE_FORCED_GLES } else { return false; } diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h index 3d5f74b387..5f0436c0b5 100644 --- a/backends/graphics/opengl/opengl-graphics.h +++ b/backends/graphics/opengl/opengl-graphics.h @@ -117,6 +117,16 @@ 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; } + + /** * Set up the actual screen size available for the OpenGL code to do any * drawing. * @@ -133,8 +143,9 @@ 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); + void notifyContextCreate(const Graphics::PixelFormat &defaultFormat, const Graphics::PixelFormat &defaultFormatAlpha, ContextType type); /** * Notify the manager that the OpenGL context is about to be destroyed. @@ -282,8 +293,10 @@ private: /** * Initialize the active context for use. + * + * @param type Type of the context to initialize. */ - void initializeGLContext(); + void initializeGLContext(ContextType type); protected: /** diff --git a/backends/graphics/opengl/opengl-sys.h b/backends/graphics/opengl/opengl-sys.h index f78b3377b3..550dbb44c5 100644 --- a/backends/graphics/opengl/opengl-sys.h +++ b/backends/graphics/opengl/opengl-sys.h @@ -30,6 +30,14 @@ #include "backends/platform/sdl/sdl-sys.h" #endif +// We allow to force GL or GLES modes on compile time. +// For this the USE_GLES_MODE define is used. The following values represent +// the given selection choices: +// 0 - Force OpenGL context +// 1 - Force OpenGL ES context +#define USE_FORCED_GL (defined(USE_GLES_MODE) && USE_GLES_MODE == 0) +#define USE_FORCED_GLES (defined(USE_GLES_MODE) && USE_GLES_MODE == 1) + // On Tizen we include the toolchain's OpenGL file. This is something we // actually want to avoid. However, since Tizen uses eglGetProcAddress which // is not required to return valid function pointers to non OpenGL extension @@ -59,10 +67,21 @@ namespace OpenGL { +enum ContextType { + kContextGL, + kContextGLES +}; + /** * 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; + /** * Reset context. * |