OPENGL: Allow engines to detect OpenGL info without switching
For now only OpenGL type and shaders support are available
This commit is contained in:
parent
06bc7a25fa
commit
b978cd1caa
7 changed files with 52 additions and 9 deletions
|
@ -509,6 +509,8 @@ bool OSystem_Android::hasFeature(Feature f) {
|
|||
/* Even if we are using the 2D graphics manager,
|
||||
* we are at one initGraphics3d call of supporting GLES2 */
|
||||
if (f == kFeatureOpenGLForGame) return true;
|
||||
/* GLES2 always supports shaders */
|
||||
if (f == kFeatureShadersForGame) return true;
|
||||
return ModularGraphicsBackend::hasFeature(f);
|
||||
}
|
||||
|
||||
|
|
|
@ -192,6 +192,8 @@ public:
|
|||
bool setGraphicsMode(int mode, uint flags) override;
|
||||
int getGraphicsMode() const override;
|
||||
|
||||
OpenGL::ContextOGLType getOpenGLType() const override { return OpenGL::kOGLContextGLES2; }
|
||||
|
||||
#ifdef ANDROID_DEBUG_GL_CALLS
|
||||
bool isRunningInMainThread() { return pthread_self() == _main_thread; }
|
||||
#endif
|
||||
|
|
|
@ -184,6 +184,7 @@ bool OSystem_SDL::hasFeature(Feature f) {
|
|||
/* Even if we are using the 2D graphics manager,
|
||||
* we are at one initGraphics3d call of supporting OpenGL */
|
||||
if (f == kFeatureOpenGLForGame) return true;
|
||||
if (f == kFeatureShadersForGame) return _supportsShaders;
|
||||
#endif
|
||||
return ModularGraphicsBackend::hasFeature(f);
|
||||
}
|
||||
|
@ -221,7 +222,7 @@ void OSystem_SDL::initBackend() {
|
|||
debug(1, "Using SDL Video Driver \"%s\"", sdlDriverName);
|
||||
|
||||
#if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS)
|
||||
detectFramebufferSupport();
|
||||
detectOpenGLFeaturesSupport();
|
||||
detectAntiAliasingSupport();
|
||||
#endif
|
||||
|
||||
|
@ -318,11 +319,15 @@ void OSystem_SDL::initBackend() {
|
|||
}
|
||||
|
||||
#if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS)
|
||||
void OSystem_SDL::detectFramebufferSupport() {
|
||||
void OSystem_SDL::detectOpenGLFeaturesSupport() {
|
||||
_oglType = OpenGL::kOGLContextNone;
|
||||
_supportsFrameBuffer = false;
|
||||
_supportsShaders = false;
|
||||
#if USE_FORCED_GLES2
|
||||
// Framebuffers are always available with GLES2
|
||||
// Framebuffers and shaders are always available with GLES2
|
||||
_oglType = kOGLContextGLES2;
|
||||
_supportsFrameBuffer = true;
|
||||
_supportsShaders = true;
|
||||
#elif !defined(AMIGAOS) && !defined(__MORPHOS__)
|
||||
// Spawn a 32x32 window off-screen with a GL context to test if framebuffers are supported
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
|
@ -332,7 +337,6 @@ void OSystem_SDL::detectFramebufferSupport() {
|
|||
}
|
||||
|
||||
int glContextProfileMask, glContextMajor;
|
||||
OpenGL::ContextOGLType glContextType;
|
||||
if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &glContextProfileMask) != 0) {
|
||||
SDL_DestroyWindow(window);
|
||||
return;
|
||||
|
@ -343,13 +347,13 @@ void OSystem_SDL::detectFramebufferSupport() {
|
|||
return;
|
||||
}
|
||||
if (glContextMajor == 2) {
|
||||
glContextType = OpenGL::kOGLContextGLES2;
|
||||
_oglType = OpenGL::kOGLContextGLES2;
|
||||
} else {
|
||||
SDL_DestroyWindow(window);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
glContextType = OpenGL::kOGLContextGL;
|
||||
_oglType = OpenGL::kOGLContextGL;
|
||||
}
|
||||
SDL_GLContext glContext = SDL_GL_CreateContext(window);
|
||||
if (!glContext) {
|
||||
|
@ -357,8 +361,9 @@ void OSystem_SDL::detectFramebufferSupport() {
|
|||
return;
|
||||
}
|
||||
|
||||
OpenGLContext.initialize(glContextType);
|
||||
OpenGLContext.initialize(_oglType);
|
||||
_supportsFrameBuffer = OpenGLContext.framebufferObjectSupported;
|
||||
_supportsShaders = OpenGLContext.shadersSupported;
|
||||
OpenGLContext.reset();
|
||||
SDL_GL_DeleteContext(glContext);
|
||||
SDL_DestroyWindow(window);
|
||||
|
@ -367,8 +372,10 @@ void OSystem_SDL::detectFramebufferSupport() {
|
|||
SDL_SetVideoMode(32, 32, 0, SDL_OPENGL);
|
||||
SDL_putenv(const_cast<char *>("SDL_VIDEO_WINDOW_POS=center"));
|
||||
// SDL 1.2 only supports OpenGL
|
||||
OpenGLContext.initialize(OpenGL::kOGLContextGL);
|
||||
_oglType = OpenGL::kOGLContextGL;
|
||||
OpenGLContext.initialize(_oglType);
|
||||
_supportsFrameBuffer = OpenGLContext.framebufferObjectSupported;
|
||||
_supportsShaders = OpenGLContext.shadersSupported;
|
||||
OpenGLContext.reset();
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -95,6 +95,7 @@ public:
|
|||
|
||||
#if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS)
|
||||
Common::Array<uint> getSupportedAntiAliasingLevels() const override;
|
||||
OpenGL::ContextOGLType getOpenGLType() const override { return _oglType; }
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
@ -139,10 +140,12 @@ protected:
|
|||
|
||||
#if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS)
|
||||
// Graphics capabilities
|
||||
void detectFramebufferSupport();
|
||||
void detectOpenGLFeaturesSupport();
|
||||
void detectAntiAliasingSupport();
|
||||
|
||||
OpenGL::ContextOGLType _oglType;
|
||||
bool _supportsFrameBuffer;
|
||||
bool _supportsShaders;
|
||||
Common::Array<uint> _antiAliasLevels;
|
||||
#endif
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "common/ustr.h"
|
||||
#include "graphics/pixelformat.h"
|
||||
#include "graphics/mode.h"
|
||||
#include "graphics/opengl/context.h"
|
||||
|
||||
namespace Audio {
|
||||
class Mixer;
|
||||
|
@ -406,6 +407,12 @@ public:
|
|||
*/
|
||||
kFeatureOpenGLForGame,
|
||||
|
||||
/**
|
||||
* This feature flag can be used to check if shaders are supported
|
||||
* and can be used for 3D game rendering.
|
||||
*/
|
||||
kFeatureShadersForGame,
|
||||
|
||||
/**
|
||||
* If supported, this feature flag can be used to check if
|
||||
* waiting for vertical sync before refreshing the screen to reduce
|
||||
|
@ -728,6 +735,20 @@ public:
|
|||
return Common::Array<uint>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the chosen OpenGL type.
|
||||
*
|
||||
* This function works even when a 2D graphical manager is active and
|
||||
* let to select a proper renderer before changing mode.
|
||||
* Implementation having feature kFeatureOpenGLForGame are expected to
|
||||
* override this function.
|
||||
*
|
||||
* @return the OpenGL type of context which is supported.
|
||||
*/
|
||||
virtual OpenGL::ContextOGLType getOpenGLType() const {
|
||||
return OpenGL::kOGLContextNone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a list of all hardware shaders supported by this backend.
|
||||
*
|
||||
|
|
|
@ -71,6 +71,7 @@ ContextGL::ContextGL() {
|
|||
}
|
||||
|
||||
void ContextGL::reset() {
|
||||
type = kOGLContextNone;
|
||||
maxTextureSize = 0;
|
||||
|
||||
NPOTSupported = false;
|
||||
|
@ -86,6 +87,9 @@ void ContextGL::reset() {
|
|||
void ContextGL::initialize(ContextOGLType contextType) {
|
||||
// Initialize default state.
|
||||
reset();
|
||||
if (contextType == kOGLContextNone) {
|
||||
return;
|
||||
}
|
||||
|
||||
type = contextType;
|
||||
|
||||
|
@ -178,6 +182,9 @@ void ContextGL::initialize(ContextOGLType contextType) {
|
|||
|
||||
// Log context type.
|
||||
switch (type) {
|
||||
case kOGLContextNone:
|
||||
/* Shouldn't happen */
|
||||
break;
|
||||
case kOGLContextGL:
|
||||
debug(5, "OpenGL: GL context initialized");
|
||||
break;
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
namespace OpenGL {
|
||||
|
||||
enum ContextOGLType {
|
||||
kOGLContextNone,
|
||||
kOGLContextGL,
|
||||
kOGLContextGLES2
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue