EGL: Try again with ES 2 if we fail to create an ES 3 context.

This commit is contained in:
Henrik Rydgard 2016-01-24 11:32:03 +01:00
parent b575596585
commit e0cba1dd5a
2 changed files with 50 additions and 38 deletions

View File

@ -71,7 +71,7 @@ void cInterfaceEGL::DetectMode() {
if ((attribVal & EGL_OPENGL_BIT) && s_opengl_mode != GLInterfaceMode::MODE_DETECT_ES)
supportsGL = true;
if (attribVal & (1 << 6)) /* EGL_OPENGL_ES3_BIT_KHR */
supportsGLES3 = true;
supportsGLES3 = true; // Apparently, this cannot be completely trusted so we implement a fallback to ES 2.0 below.
if (attribVal & EGL_OPENGL_ES2_BIT)
supportsGLES2 = true;
}
@ -144,27 +144,7 @@ const char *cInterfaceEGL::EGLGetErrorString(EGLint error) {
}
}
// Create rendering window.
bool cInterfaceEGL::Create(void *window_handle, bool core, bool use565) {
const char *s;
EGLint egl_major, egl_minor;
egl_dpy = OpenDisplay();
if (!egl_dpy) {
EGL_ILOG("Error: eglGetDisplay() failed\n");
return false;
}
if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) {
EGL_ILOG("Error: eglInitialize() failed\n");
return false;
}
EGL_ILOG("eglInitialize() succeeded (use16bit=%d)\n", (int)use565);
if (s_opengl_mode == MODE_DETECT || s_opengl_mode == MODE_DETECT_ES)
DetectMode();
bool cInterfaceEGL::ChooseAndCreate(void *window_handle, bool core, bool use565) {
int attribs32[] = {
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, // Keep this first!
EGL_RED_SIZE, 8,
@ -299,7 +279,7 @@ bool cInterfaceEGL::Create(void *window_handle, bool core, bool use565) {
EGLNativeWindowType host_window = (EGLNativeWindowType)window_handle;
EGLNativeWindowType native_window = InitializePlatform(host_window, configs[chosenConfig]);
s = eglQueryString(egl_dpy, EGL_VERSION);
const char *s = eglQueryString(egl_dpy, EGL_VERSION);
EGL_ILOG("EGL_VERSION = %s\n", s);
s = eglQueryString(egl_dpy, EGL_VENDOR);
@ -314,7 +294,6 @@ bool cInterfaceEGL::Create(void *window_handle, bool core, bool use565) {
egl_ctx = eglCreateContext(egl_dpy, configs[chosenConfig], EGL_NO_CONTEXT, ctx_attribs);
if (!egl_ctx) {
EGL_ILOG("Error: eglCreateContext failed: %s\n", EGLGetErrorString(eglGetError()));
eglTerminate(egl_dpy);
delete[] configs;
return false;
}
@ -322,9 +301,7 @@ bool cInterfaceEGL::Create(void *window_handle, bool core, bool use565) {
egl_surf = eglCreateWindowSurface(egl_dpy, configs[chosenConfig], native_window, nullptr);
if (!egl_surf) {
EGL_ILOG("Error: eglCreateWindowSurface failed: native_window=%p error=%s ctx_attribs[1]==%d\n", native_window, EGLGetErrorString(eglGetError()), ctx_attribs[1]);
eglDestroyContext(egl_dpy, egl_ctx);
eglTerminate(egl_dpy);
delete[] configs;
return false;
}
@ -333,6 +310,39 @@ bool cInterfaceEGL::Create(void *window_handle, bool core, bool use565) {
return true;
}
// Create rendering window.
bool cInterfaceEGL::Create(void *window_handle, bool core, bool use565) {
EGLint egl_major, egl_minor;
egl_dpy = OpenDisplay();
if (!egl_dpy) {
EGL_ILOG("Error: eglGetDisplay() failed\n");
return false;
}
if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) {
EGL_ILOG("Error: eglInitialize() failed\n");
return false;
}
EGL_ILOG("eglInitialize() succeeded (use16bit=%d)\n", (int)use565);
if (s_opengl_mode == MODE_DETECT || s_opengl_mode == MODE_DETECT_ES)
DetectMode();
if (!ChooseAndCreate(window_handle, core, use565) && s_opengl_mode == MODE_OPENGLES3) {
// Fallback to ES 2.0 and try again.
s_opengl_mode = MODE_OPENGLES2;
if (!ChooseAndCreate(window_handle, core, use565)) {
eglTerminate(egl_dpy);
egl_dpy = nullptr;
return false;
}
}
return true;
}
bool cInterfaceEGL::MakeCurrent() {
return eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx);
}

View File

@ -24,10 +24,18 @@
#endif
class cInterfaceEGL : public cInterfaceBase
{
class cInterfaceEGL : public cInterfaceBase {
public:
void SwapInterval(int Interval);
void Swap();
void SetMode(u32 mode) { s_opengl_mode = mode; }
void* GetFuncAddress(const std::string& name);
bool Create(void *window_handle, bool core, bool use565) override;
bool MakeCurrent();
bool ClearCurrent();
void Shutdown();
protected:
void DetectMode();
EGLSurface egl_surf;
EGLContext egl_ctx;
EGLDisplay egl_dpy;
@ -38,13 +46,7 @@ protected:
virtual void SetInternalResolution(int internalWidth, int internalHeight) {}
const char *EGLGetErrorString(EGLint error);
public:
void SwapInterval(int Interval);
void Swap();
void SetMode(u32 mode) { s_opengl_mode = mode; }
void* GetFuncAddress(const std::string& name);
bool Create(void *window_handle, bool core, bool use16bit) override;
bool MakeCurrent();
bool ClearCurrent();
void Shutdown();
private:
bool ChooseAndCreate(void *window_handle, bool core, bool use565);
void DetectMode();
};