Support the OpenGL core profile in EGL.

This should make our Mesa EGL users happy.
This commit is contained in:
Ryan Houdek 2016-01-22 10:58:19 -06:00
parent aed693eded
commit 34d0e7835b
2 changed files with 45 additions and 17 deletions

View File

@ -100,11 +100,12 @@ void cInterfaceEGL::DetectMode()
bool cInterfaceEGL::Create(void *window_handle, bool core) bool cInterfaceEGL::Create(void *window_handle, bool core)
{ {
EGLint egl_major, egl_minor; EGLint egl_major, egl_minor;
bool supports_core_profile = false;
egl_dpy = OpenDisplay(); egl_dpy = OpenDisplay();
m_host_window = (EGLNativeWindowType) window_handle; m_host_window = (EGLNativeWindowType) window_handle;
m_has_handle = !!window_handle; m_has_handle = !!window_handle;
m_core = false; m_core = core;
if (!egl_dpy) if (!egl_dpy)
{ {
@ -132,23 +133,20 @@ bool cInterfaceEGL::Create(void *window_handle, bool core)
EGL_BLUE_SIZE, 8, EGL_BLUE_SIZE, 8,
EGL_NONE }; EGL_NONE };
EGLint ctx_attribs[] = { std::vector<EGLint> ctx_attribs;
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
switch (s_opengl_mode) switch (s_opengl_mode)
{ {
case GLInterfaceMode::MODE_OPENGL: case GLInterfaceMode::MODE_OPENGL:
attribs[1] = EGL_OPENGL_BIT; attribs[1] = EGL_OPENGL_BIT;
ctx_attribs[0] = EGL_NONE; ctx_attribs = { EGL_NONE };
break; break;
case GLInterfaceMode::MODE_OPENGLES2: case GLInterfaceMode::MODE_OPENGLES2:
attribs[1] = EGL_OPENGL_ES2_BIT; attribs[1] = EGL_OPENGL_ES2_BIT;
ctx_attribs[1] = 2; ctx_attribs = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
break; break;
case GLInterfaceMode::MODE_OPENGLES3: case GLInterfaceMode::MODE_OPENGLES3:
attribs[1] = (1 << 6); /* EGL_OPENGL_ES3_BIT_KHR */ attribs[1] = (1 << 6); /* EGL_OPENGL_ES3_BIT_KHR */
ctx_attribs[1] = 3; ctx_attribs = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
break; break;
default: default:
ERROR_LOG(VIDEO, "Unknown opengl mode set\n"); ERROR_LOG(VIDEO, "Unknown opengl mode set\n");
@ -167,24 +165,53 @@ bool cInterfaceEGL::Create(void *window_handle, bool core)
else else
eglBindAPI(EGL_OPENGL_ES_API); 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::string tmp;
std::istringstream buffer(eglQueryString(egl_dpy, EGL_EXTENSIONS)); std::istringstream buffer(eglQueryString(egl_dpy, EGL_EXTENSIONS));
while (buffer >> tmp) while (buffer >> tmp)
{ {
if (tmp == "EGL_KHR_surfaceless_context") if (tmp == "EGL_KHR_surfaceless_context")
{
m_supports_surfaceless = true; 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<std::pair<int, int>, 2> versions_to_try =
{{
{ 4, 0 },
{ 3, 3 },
}};
for (const auto& version : versions_to_try)
{
std::vector<EGLint> 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()) if (!CreateWindowSurface())
{ {
ERROR_LOG(VIDEO, "Error: CreateWindowSurface failed 0x%04x\n", eglGetError()); ERROR_LOG(VIDEO, "Error: CreateWindowSurface failed 0x%04x\n", eglGetError());

View File

@ -6,6 +6,7 @@
#include <string> #include <string>
#include <EGL/egl.h> #include <EGL/egl.h>
#include <EGL/eglext.h>
#include "Common/GL/GLInterfaceBase.h" #include "Common/GL/GLInterfaceBase.h"