OPENGL: Allow runtime specification of OpenGL mode.

Formerly, we required that the OpenGL mode was fixed at compile time. Now we
allow the code to work with whatever it is given at runtime.

It is still possible to force a context type on compile time.
This commit is contained in:
Johannes Schickel 2015-12-12 22:08:33 +01:00
parent 9816e4f350
commit d6d3e17d53
8 changed files with 164 additions and 52 deletions

View file

@ -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

View file

@ -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));

View file

@ -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;
}

View file

@ -116,6 +116,16 @@ 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.
*/
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:
/**

View file

@ -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.
*

View file

@ -210,16 +210,22 @@ Common::List<Graphics::PixelFormat> OpenGLSdlGraphicsManager::getSupportedFormat
// RGBA4444
formats.push_back(Graphics::PixelFormat(2, 4, 4, 4, 4, 12, 8, 4, 0));
#ifndef USE_GLES
#ifdef SCUMM_LITTLE_ENDIAN
// RGBA8888
formats.push_back(Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0));
#else
// ABGR8888
formats.push_back(Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24));
#if !USE_FORCED_GLES
#if !USE_FORCED_GL
if (isInitialized() && !isGLESContext()) {
#endif
#ifdef SCUMM_LITTLE_ENDIAN
// RGBA8888
formats.push_back(Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0));
#else
// ABGR8888
formats.push_back(Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24));
#endif
// RGB555, this is used by SCUMM HE 16 bit games.
formats.push_back(Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0));
#if !USE_FORCED_GL
}
#endif
// RGB555, this is used by SCUMM HE 16 bit games.
formats.push_back(Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0));
#endif
formats.push_back(Graphics::PixelFormat::createFormatCLUT8());
@ -391,7 +397,7 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) {
}
}
#ifdef USE_GLES
#if USE_FORCED_GLES
// SDL2 will create a GLES2 context by default, so this is needed for GLES1-profile
// functions to work.
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
@ -403,7 +409,13 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) {
return false;
}
notifyContextCreate(rgba8888, rgba8888);
notifyContextCreate(rgba8888, rgba8888,
#if USE_FORCED_GLES
OpenGL::kContextGLES
#else
OpenGL::kContextGL
#endif
);
int actualWidth, actualHeight;
getWindowDimensions(&actualWidth, &actualHeight);
setActualScreenSize(actualWidth, actualHeight);
@ -451,7 +463,7 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) {
_lastVideoModeLoad = SDL_GetTicks();
if (_hwScreen) {
notifyContextCreate(rgba8888, rgba8888);
notifyContextCreate(rgba8888, rgba8888, OpenGL::kContextGL);
setActualScreenSize(_hwScreen->w, _hwScreen->h);
_eventSource->resetKeyboadEmulation(_hwScreen->w - 1, _hwScreen->h - 1);
}

View file

@ -59,7 +59,7 @@ result TizenGraphicsManager::Construct() {
// 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));
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);
// Tell our size.
int x, y, width, height;

100
configure vendored
View file

@ -133,8 +133,7 @@ _png=auto
_theoradec=auto
_faad=auto
_fluidsynth=auto
_opengl=auto
_opengles=no
_opengl_mode=auto
_readline=auto
_freetype2=auto
_taskbar=auto
@ -940,6 +939,14 @@ Optional Features:
--enable-verbose-build enable regular echoing of commands during build
process
--disable-bink don't build with Bink video support
--opengl-mode=MODE OpenGL (ES) mode to use for OpenGL output [auto]
available modes: auto for autodetection
none for disabling any OpenGL usage
any for runtime detection
gl for forcing OpenGL
gles for forcing OpenGL ES
WARNING: only specify this manually if you know what
you are doing!
Optional Libraries:
--with-alsa-prefix=DIR Prefix where alsa is installed (optional)
@ -964,9 +971,6 @@ Optional Libraries:
--with-mpeg2-prefix=DIR Prefix where libmpeg2 is installed (optional)
--enable-mpeg2 enable mpeg2 codec for cutscenes [autodetect]
--disable-opengl disable OpenGL (ES) support [autodetect]
--enable-opengles enable forced OpenGL ES mode [disabled]
--with-jpeg-prefix=DIR Prefix where libjpeg is installed (optional)
--disable-jpeg disable JPEG decoder [autodetect]
@ -1071,12 +1075,11 @@ for ac_option in $@; do
--disable-updates) _updates=no ;;
--enable-libunity) _libunity=yes ;;
--disable-libunity) _libunity=no ;;
--enable-opengl) _opengl=yes ;;
--disable-opengl) _opengl=no ;;
--enable-opengles) _opengles=yes ;;
--disable-opengles) _opengles=no ;;
--enable-bink) _bink=yes ;;
--disable-bink) _bink=no ;;
--opengl-mode=*)
_opengl_mode=`echo $ac_option | cut -d '=' -f 2`
;;
--enable-verbose-build) _verbose_build=yes ;;
--enable-plugins) _dynamic_modules=yes ;;
--default-dynamic) _plugins_default=dynamic ;;
@ -2658,8 +2661,7 @@ if test -n "$_host"; then
_sdlconfig=sdl2-config
# OpenGL(ES) support is mature enough as to be the best option on
# the Raspberry Pi, so it's enabled by default.
_opengl=yes
_opengles=yes
_opengl_mode=gles
;;
dreamcast)
append_var DEFINES "-DDISABLE_DEFAULT_SAVEFILEMANAGER"
@ -2988,8 +2990,7 @@ if test -n "$_host"; then
_timidity=no
_vkeybd=yes
# Tizen relies on the OpenGL ES output thus we always enable it.
_opengl=yes
_opengles=yes
_opengl_mode=gles
;;
webos)
_backend="webos"
@ -4150,35 +4151,82 @@ echocheck "OpenGL"
case $_backend in
openpandora)
# Only enable OpenGL ES on the OpanPandora if --enable-opengl is passed in explicitly.
if test "$_opengl" = yes ; then
_opengl=yes
_opengles=yes
# Only enable OpenGL ES on the OpanPandora if --opengl-mode=gles is passed in explicitly.
if test "$_opengl_mode" = "gles" ; then
append_var LIBS "-lGLES_CM -lEGL -lX11"
else
_opengl_mode=none
fi
;;
esac
if test "$_opengl" = auto ; then
if test "$_opengl_mode" = auto ; then
case $_backend in
sdl)
_opengl=yes
case $_sdlversion in
1.2.*)
# Stock SDL 1.2 only supports OpenGL contexts.
_opengl_mode=gl
;;
2.0.*)
# SDL2 supports both OpenGL + OpenGL ES contexts.
# However, Mac OS X only allows OpenGL context creation at
# this time, thus we limit us to OpenGL on that platform.
case $_host_os in
darwin*)
_opengl_mode=gl
;;
*)
_opengl_mode=any
;;
esac
;;
esac
;;
tizen)
# Tizen always runs in GLES mode
_opengl_mode=gles
;;
*)
_opengl=no
_opengl_mode=none
;;
esac
fi
if test "$_opengles" = "yes" ; then
echo "yes (OpenGL ES)"
else
echo "$_opengl"
fi
_opengl=yes
case $_opengl_mode in
auto)
# This case should never occur but better safe than sorry.
echo "no"
_opengl=no
;;
none)
echo "no"
_opengl=no
;;
any)
echo "yes (runtime detection)"
add_line_to_config_h "#undef USE_GLES_MODE"
;;
gl)
echo "yes (OpenGL)"
add_line_to_config_h "#define USE_GLES_MODE 0"
;;
gles)
echo "yes (OpenGL ES)"
add_line_to_config_h "#define USE_GLES_MODE 1"
;;
esac
define_in_config_if_yes "$_opengl" "USE_OPENGL"
define_in_config_if_yes "$_opengles" "USE_GLES"
#
# Check for nasm