From 34d0e7835b4925878afe7a82b6f48cc4c00984d1 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Fri, 22 Jan 2016 10:58:19 -0600 Subject: [PATCH 1/2] Support the OpenGL core profile in EGL. This should make our Mesa EGL users happy. --- Source/Core/Common/GL/GLInterface/EGL.cpp | 61 ++++++++++++++++------- Source/Core/Common/GL/GLInterface/EGL.h | 1 + 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/Source/Core/Common/GL/GLInterface/EGL.cpp b/Source/Core/Common/GL/GLInterface/EGL.cpp index 3edee9e478..35238e3818 100644 --- a/Source/Core/Common/GL/GLInterface/EGL.cpp +++ b/Source/Core/Common/GL/GLInterface/EGL.cpp @@ -100,11 +100,12 @@ void cInterfaceEGL::DetectMode() bool cInterfaceEGL::Create(void *window_handle, bool core) { EGLint egl_major, egl_minor; + bool supports_core_profile = false; egl_dpy = OpenDisplay(); m_host_window = (EGLNativeWindowType) window_handle; m_has_handle = !!window_handle; - m_core = false; + m_core = core; if (!egl_dpy) { @@ -132,23 +133,20 @@ bool cInterfaceEGL::Create(void *window_handle, bool core) EGL_BLUE_SIZE, 8, EGL_NONE }; - EGLint ctx_attribs[] = { - EGL_CONTEXT_CLIENT_VERSION, 2, - EGL_NONE - }; + std::vector ctx_attribs; switch (s_opengl_mode) { case GLInterfaceMode::MODE_OPENGL: attribs[1] = EGL_OPENGL_BIT; - ctx_attribs[0] = EGL_NONE; + ctx_attribs = { EGL_NONE }; break; case GLInterfaceMode::MODE_OPENGLES2: attribs[1] = EGL_OPENGL_ES2_BIT; - ctx_attribs[1] = 2; + ctx_attribs = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; break; case GLInterfaceMode::MODE_OPENGLES3: attribs[1] = (1 << 6); /* EGL_OPENGL_ES3_BIT_KHR */ - ctx_attribs[1] = 3; + ctx_attribs = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE }; break; default: ERROR_LOG(VIDEO, "Unknown opengl mode set\n"); @@ -167,24 +165,53 @@ bool cInterfaceEGL::Create(void *window_handle, bool core) else eglBindAPI(EGL_OPENGL_ES_API); - egl_ctx = eglCreateContext(egl_dpy, m_config, EGL_NO_CONTEXT, ctx_attribs ); - if (!egl_ctx) - { - INFO_LOG(VIDEO, "Error: eglCreateContext failed\n"); - return false; - } - std::string tmp; std::istringstream buffer(eglQueryString(egl_dpy, EGL_EXTENSIONS)); while (buffer >> tmp) { if (tmp == "EGL_KHR_surfaceless_context") - { m_supports_surfaceless = true; - break; + else if (tmp == "EGL_KHR_create_context") + supports_core_profile = true; + } + + if (supports_core_profile && core && s_opengl_mode == GLInterfaceMode::MODE_OPENGL) + { + std::array, 2> versions_to_try = + {{ + { 4, 0 }, + { 3, 3 }, + }}; + + for (const auto& version : versions_to_try) + { + std::vector core_attribs = + { + EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR, + EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR, + EGL_CONTEXT_MAJOR_VERSION_KHR, version.first, + EGL_CONTEXT_MINOR_VERSION_KHR, version.second, + EGL_NONE + }; + + egl_ctx = eglCreateContext(egl_dpy, m_config, EGL_NO_CONTEXT, &core_attribs[0]); + if (egl_ctx) + break; } } + if (!egl_ctx) + { + m_core = false; + egl_ctx = eglCreateContext(egl_dpy, m_config, EGL_NO_CONTEXT, &ctx_attribs[0]); + } + + if (!egl_ctx) + { + INFO_LOG(VIDEO, "Error: eglCreateContext failed\n"); + return false; + } + if (!CreateWindowSurface()) { ERROR_LOG(VIDEO, "Error: CreateWindowSurface failed 0x%04x\n", eglGetError()); diff --git a/Source/Core/Common/GL/GLInterface/EGL.h b/Source/Core/Common/GL/GLInterface/EGL.h index fec46ec9e9..570844f954 100644 --- a/Source/Core/Common/GL/GLInterface/EGL.h +++ b/Source/Core/Common/GL/GLInterface/EGL.h @@ -6,6 +6,7 @@ #include #include +#include #include "Common/GL/GLInterfaceBase.h" From 184a7a3e0d2285776e0d4d033adacb7ce27d6887 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Sat, 23 Jan 2016 06:22:14 -0600 Subject: [PATCH 2/2] Include the EGL defines we need for KHR_create_context ourselves. This is because Google decided it was in their best interest to update eglext.h for android-21/arch-arm only and completely neglect all the other architectures. Sucks to suck. --- Source/Core/Common/GL/GLInterface/EGL.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Source/Core/Common/GL/GLInterface/EGL.cpp b/Source/Core/Common/GL/GLInterface/EGL.cpp index 35238e3818..a267f08c61 100644 --- a/Source/Core/Common/GL/GLInterface/EGL.cpp +++ b/Source/Core/Common/GL/GLInterface/EGL.cpp @@ -8,6 +8,23 @@ #include "Common/GL/GLInterface/EGL.h" #include "Common/Logging/Log.h" +#ifndef EGL_KHR_create_context +#define EGL_KHR_create_context 1 +#define EGL_CONTEXT_MAJOR_VERSION_KHR 0x3098 +#define EGL_CONTEXT_MINOR_VERSION_KHR 0x30FB +#define EGL_CONTEXT_FLAGS_KHR 0x30FC +#define EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR 0x30FD +#define EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR 0x31BD +#define EGL_NO_RESET_NOTIFICATION_KHR 0x31BE +#define EGL_LOSE_CONTEXT_ON_RESET_KHR 0x31BF +#define EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR 0x00000001 +#define EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR 0x00000002 +#define EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR 0x00000004 +#define EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR 0x00000001 +#define EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR 0x00000002 +#define EGL_OPENGL_ES3_BIT_KHR 0x00000040 +#endif /* EGL_KHR_create_context */ + // Show the current FPS void cInterfaceEGL::Swap() {