2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2012 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2014-02-17 10:18:15 +00:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2014-08-09 13:49:45 +00:00
|
|
|
#include "VideoBackends/OGL/GLInterfaceBase.h"
|
2014-11-01 14:33:02 +00:00
|
|
|
#include "VideoBackends/OGL/GLInterface/EGL.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoCommon/RenderBase.h"
|
2012-12-17 21:01:52 +00:00
|
|
|
|
|
|
|
// Show the current FPS
|
2012-12-26 06:34:09 +00:00
|
|
|
void cInterfaceEGL::Swap()
|
2012-12-17 21:01:52 +00:00
|
|
|
{
|
2014-08-09 13:49:45 +00:00
|
|
|
eglSwapBuffers(egl_dpy, egl_surf);
|
2012-12-17 21:01:52 +00:00
|
|
|
}
|
2013-03-25 02:06:34 +00:00
|
|
|
void cInterfaceEGL::SwapInterval(int Interval)
|
|
|
|
{
|
2014-08-09 13:49:45 +00:00
|
|
|
eglSwapInterval(egl_dpy, Interval);
|
2013-03-25 02:06:34 +00:00
|
|
|
}
|
2012-12-17 21:01:52 +00:00
|
|
|
|
2014-03-12 19:33:41 +00:00
|
|
|
void* cInterfaceEGL::GetFuncAddress(const std::string& name)
|
2013-12-30 13:22:50 +00:00
|
|
|
{
|
|
|
|
return (void*)eglGetProcAddress(name.c_str());
|
|
|
|
}
|
|
|
|
|
2014-01-18 04:11:59 +00:00
|
|
|
void cInterfaceEGL::DetectMode()
|
|
|
|
{
|
|
|
|
if (s_opengl_mode != MODE_DETECT)
|
|
|
|
return;
|
|
|
|
|
|
|
|
EGLint num_configs;
|
2014-03-09 20:14:26 +00:00
|
|
|
EGLConfig *config = nullptr;
|
2014-01-18 04:11:59 +00:00
|
|
|
bool supportsGL = false, supportsGLES2 = false, supportsGLES3 = false;
|
2015-07-21 16:29:15 +00:00
|
|
|
std::array<int, 3> renderable_types = {
|
|
|
|
EGL_OPENGL_BIT,
|
|
|
|
(1 << 6), /* EGL_OPENGL_ES3_BIT_KHR */
|
|
|
|
EGL_OPENGL_ES2_BIT,
|
|
|
|
};
|
2014-01-18 04:11:59 +00:00
|
|
|
|
2015-07-21 16:29:15 +00:00
|
|
|
for (auto renderable_type : renderable_types)
|
2014-02-17 04:51:41 +00:00
|
|
|
{
|
2015-07-21 16:29:15 +00:00
|
|
|
// attributes for a visual in RGBA format with at least
|
|
|
|
// 8 bits per color
|
|
|
|
int attribs[] = {
|
|
|
|
EGL_RED_SIZE, 8,
|
|
|
|
EGL_GREEN_SIZE, 8,
|
|
|
|
EGL_BLUE_SIZE, 8,
|
|
|
|
EGL_RENDERABLE_TYPE, renderable_type,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
2014-01-18 04:11:59 +00:00
|
|
|
|
2015-07-21 16:29:15 +00:00
|
|
|
// Get how many configs there are
|
|
|
|
if (!eglChooseConfig( egl_dpy, attribs, nullptr, 0, &num_configs))
|
|
|
|
{
|
|
|
|
INFO_LOG(VIDEO, "Error: couldn't get an EGL visual config\n");
|
|
|
|
goto err_exit;
|
|
|
|
}
|
2014-01-18 04:11:59 +00:00
|
|
|
|
2015-07-21 16:29:15 +00:00
|
|
|
config = new EGLConfig[num_configs];
|
2014-01-18 04:11:59 +00:00
|
|
|
|
2015-07-21 16:29:15 +00:00
|
|
|
// Get all the configurations
|
|
|
|
if (!eglChooseConfig(egl_dpy, attribs, config, num_configs, &num_configs))
|
|
|
|
{
|
|
|
|
INFO_LOG(VIDEO, "Error: couldn't get an EGL visual config\n");
|
|
|
|
goto err_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < num_configs; ++i)
|
2014-01-18 04:11:59 +00:00
|
|
|
{
|
2015-07-21 16:29:15 +00:00
|
|
|
EGLint attribVal;
|
|
|
|
bool ret;
|
|
|
|
ret = eglGetConfigAttrib(egl_dpy, config[i], EGL_RENDERABLE_TYPE, &attribVal);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (attribVal & EGL_OPENGL_BIT)
|
|
|
|
supportsGL = true;
|
|
|
|
if (attribVal & (1 << 6)) /* EGL_OPENGL_ES3_BIT_KHR */
|
|
|
|
supportsGLES3 = true;
|
|
|
|
if (attribVal & EGL_OPENGL_ES2_BIT)
|
|
|
|
supportsGLES2 = true;
|
|
|
|
}
|
2014-01-18 04:11:59 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-21 16:29:15 +00:00
|
|
|
|
2014-01-18 04:11:59 +00:00
|
|
|
if (supportsGL)
|
|
|
|
s_opengl_mode = GLInterfaceMode::MODE_OPENGL;
|
|
|
|
else if (supportsGLES3)
|
|
|
|
s_opengl_mode = GLInterfaceMode::MODE_OPENGLES3;
|
|
|
|
else if (supportsGLES2)
|
|
|
|
s_opengl_mode = GLInterfaceMode::MODE_OPENGLES2;
|
2015-07-21 16:29:15 +00:00
|
|
|
|
2014-01-18 04:11:59 +00:00
|
|
|
err_exit:
|
|
|
|
if (s_opengl_mode == GLInterfaceMode::MODE_DETECT) // Errored before we found a mode
|
|
|
|
s_opengl_mode = GLInterfaceMode::MODE_OPENGL; // Fall back to OpenGL
|
|
|
|
if (config)
|
|
|
|
delete[] config;
|
|
|
|
}
|
|
|
|
|
2012-12-17 21:01:52 +00:00
|
|
|
// Create rendering window.
|
2014-02-17 04:51:41 +00:00
|
|
|
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
|
2014-08-06 04:44:21 +00:00
|
|
|
bool cInterfaceEGL::Create(void *window_handle)
|
2012-12-17 21:01:52 +00:00
|
|
|
{
|
2013-03-25 02:06:34 +00:00
|
|
|
const char *s;
|
2013-01-24 16:39:38 +00:00
|
|
|
EGLint egl_major, egl_minor;
|
2014-01-18 04:11:59 +00:00
|
|
|
|
2014-08-09 14:31:27 +00:00
|
|
|
egl_dpy = OpenDisplay();
|
2014-01-18 04:11:59 +00:00
|
|
|
|
2014-08-09 13:49:45 +00:00
|
|
|
if (!egl_dpy)
|
2014-02-17 04:51:41 +00:00
|
|
|
{
|
2014-01-18 04:11:59 +00:00
|
|
|
INFO_LOG(VIDEO, "Error: eglGetDisplay() failed\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-08-09 13:49:45 +00:00
|
|
|
if (!eglInitialize(egl_dpy, &egl_major, &egl_minor))
|
2014-02-17 04:51:41 +00:00
|
|
|
{
|
2014-01-18 04:11:59 +00:00
|
|
|
INFO_LOG(VIDEO, "Error: eglInitialize() failed\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Detection code */
|
2013-03-25 02:06:34 +00:00
|
|
|
EGLConfig config;
|
|
|
|
EGLint num_configs;
|
2012-12-17 21:01:52 +00:00
|
|
|
|
2014-01-18 04:11:59 +00:00
|
|
|
DetectMode();
|
|
|
|
|
2012-12-17 21:01:52 +00:00
|
|
|
// attributes for a visual in RGBA format with at least
|
2013-10-29 18:19:56 +00:00
|
|
|
// 8 bits per color
|
2012-12-17 21:01:52 +00:00
|
|
|
int attribs[] = {
|
2013-12-12 18:43:49 +00:00
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
2012-12-17 21:01:52 +00:00
|
|
|
EGL_RED_SIZE, 8,
|
|
|
|
EGL_GREEN_SIZE, 8,
|
|
|
|
EGL_BLUE_SIZE, 8,
|
|
|
|
EGL_NONE };
|
|
|
|
|
2013-12-12 18:43:49 +00:00
|
|
|
EGLint ctx_attribs[] = {
|
2012-12-17 21:01:52 +00:00
|
|
|
EGL_CONTEXT_CLIENT_VERSION, 2,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
2014-03-10 11:30:55 +00:00
|
|
|
switch (s_opengl_mode)
|
2013-12-12 18:43:49 +00:00
|
|
|
{
|
|
|
|
case MODE_OPENGL:
|
|
|
|
attribs[1] = EGL_OPENGL_BIT;
|
2014-02-17 04:51:41 +00:00
|
|
|
ctx_attribs[0] = EGL_NONE;
|
2013-12-12 18:43:49 +00:00
|
|
|
break;
|
|
|
|
case MODE_OPENGLES2:
|
|
|
|
attribs[1] = EGL_OPENGL_ES2_BIT;
|
|
|
|
ctx_attribs[1] = 2;
|
|
|
|
break;
|
|
|
|
case MODE_OPENGLES3:
|
|
|
|
attribs[1] = (1 << 6); /* EGL_OPENGL_ES3_BIT_KHR */
|
|
|
|
ctx_attribs[1] = 3;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERROR_LOG(VIDEO, "Unknown opengl mode set\n");
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
2013-01-24 16:39:38 +00:00
|
|
|
|
2014-08-09 13:49:45 +00:00
|
|
|
if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs))
|
2014-02-17 04:51:41 +00:00
|
|
|
{
|
2014-01-18 04:11:59 +00:00
|
|
|
INFO_LOG(VIDEO, "Error: couldn't get an EGL visual config\n");
|
|
|
|
exit(1);
|
2013-01-24 16:39:38 +00:00
|
|
|
}
|
2012-12-17 21:01:52 +00:00
|
|
|
|
2013-12-12 22:08:54 +00:00
|
|
|
if (s_opengl_mode == MODE_OPENGL)
|
|
|
|
eglBindAPI(EGL_OPENGL_API);
|
|
|
|
else
|
|
|
|
eglBindAPI(EGL_OPENGL_ES_API);
|
2013-03-25 02:06:34 +00:00
|
|
|
|
2014-08-09 14:31:27 +00:00
|
|
|
EGLNativeWindowType host_window = (EGLNativeWindowType) window_handle;
|
|
|
|
EGLNativeWindowType native_window = InitializePlatform(host_window, config);
|
2013-03-25 02:06:34 +00:00
|
|
|
|
2014-08-09 13:49:45 +00:00
|
|
|
s = eglQueryString(egl_dpy, EGL_VERSION);
|
2013-04-23 19:17:16 +00:00
|
|
|
INFO_LOG(VIDEO, "EGL_VERSION = %s\n", s);
|
2013-03-25 02:06:34 +00:00
|
|
|
|
2014-08-09 13:49:45 +00:00
|
|
|
s = eglQueryString(egl_dpy, EGL_VENDOR);
|
2013-04-23 19:17:16 +00:00
|
|
|
INFO_LOG(VIDEO, "EGL_VENDOR = %s\n", s);
|
2013-03-25 02:06:34 +00:00
|
|
|
|
2014-08-09 13:49:45 +00:00
|
|
|
s = eglQueryString(egl_dpy, EGL_EXTENSIONS);
|
2013-04-23 19:17:16 +00:00
|
|
|
INFO_LOG(VIDEO, "EGL_EXTENSIONS = %s\n", s);
|
2013-03-25 02:06:34 +00:00
|
|
|
|
2014-08-09 13:49:45 +00:00
|
|
|
s = eglQueryString(egl_dpy, EGL_CLIENT_APIS);
|
2013-04-23 19:17:16 +00:00
|
|
|
INFO_LOG(VIDEO, "EGL_CLIENT_APIS = %s\n", s);
|
2013-03-25 02:06:34 +00:00
|
|
|
|
2014-08-09 13:49:45 +00:00
|
|
|
egl_ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, ctx_attribs );
|
|
|
|
if (!egl_ctx)
|
2014-02-17 04:51:41 +00:00
|
|
|
{
|
2013-04-23 19:17:16 +00:00
|
|
|
INFO_LOG(VIDEO, "Error: eglCreateContext failed\n");
|
2013-03-25 02:06:34 +00:00
|
|
|
exit(1);
|
2013-01-24 16:39:38 +00:00
|
|
|
}
|
|
|
|
|
2014-08-09 13:49:45 +00:00
|
|
|
egl_surf = eglCreateWindowSurface(egl_dpy, config, native_window, nullptr);
|
|
|
|
if (!egl_surf)
|
2014-02-17 04:51:41 +00:00
|
|
|
{
|
2013-04-23 19:17:16 +00:00
|
|
|
INFO_LOG(VIDEO, "Error: eglCreateWindowSurface failed\n");
|
2013-03-25 02:06:34 +00:00
|
|
|
exit(1);
|
2013-01-24 16:39:38 +00:00
|
|
|
}
|
|
|
|
|
2012-12-17 21:01:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cInterfaceEGL::MakeCurrent()
|
|
|
|
{
|
2014-08-09 13:49:45 +00:00
|
|
|
return eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx);
|
2012-12-17 21:01:52 +00:00
|
|
|
}
|
|
|
|
// Close backend
|
|
|
|
void cInterfaceEGL::Shutdown()
|
|
|
|
{
|
2014-08-09 14:31:27 +00:00
|
|
|
ShutdownPlatform();
|
2014-08-09 13:49:45 +00:00
|
|
|
if (egl_ctx && !eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx))
|
2012-12-17 21:01:52 +00:00
|
|
|
NOTICE_LOG(VIDEO, "Could not release drawing context.");
|
2014-08-09 13:49:45 +00:00
|
|
|
if (egl_ctx)
|
2012-12-17 21:01:52 +00:00
|
|
|
{
|
2014-08-09 13:49:45 +00:00
|
|
|
eglMakeCurrent(egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
|
|
|
if (!eglDestroyContext(egl_dpy, egl_ctx))
|
2013-04-23 19:17:16 +00:00
|
|
|
NOTICE_LOG(VIDEO, "Could not destroy drawing context.");
|
2014-08-09 13:49:45 +00:00
|
|
|
if (!eglDestroySurface(egl_dpy, egl_surf))
|
2013-04-23 19:17:16 +00:00
|
|
|
NOTICE_LOG(VIDEO, "Could not destroy window surface.");
|
2014-08-09 13:49:45 +00:00
|
|
|
if (!eglTerminate(egl_dpy))
|
2013-04-23 19:17:16 +00:00
|
|
|
NOTICE_LOG(VIDEO, "Could not destroy display connection.");
|
2014-08-09 13:49:45 +00:00
|
|
|
egl_ctx = nullptr;
|
2012-12-17 21:01:52 +00:00
|
|
|
}
|
|
|
|
}
|