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.
|
|
|
|
|
2015-10-06 03:45:55 +00:00
|
|
|
#include <array>
|
|
|
|
#include <cstdlib>
|
2016-02-05 16:50:08 +00:00
|
|
|
#include <sstream>
|
|
|
|
#include <vector>
|
2015-10-06 03:45:55 +00:00
|
|
|
|
2015-09-18 16:40:00 +00:00
|
|
|
#include "Common/GL/GLInterface/EGL.h"
|
2015-09-26 21:13:07 +00:00
|
|
|
#include "Common/Logging/Log.h"
|
2017-07-01 17:42:42 +00:00
|
|
|
#include "Core/Config/GraphicsSettings.h"
|
2012-12-17 21:01:52 +00:00
|
|
|
|
2016-01-23 12:22:14 +00:00
|
|
|
#ifndef EGL_KHR_create_context
|
|
|
|
#define EGL_KHR_create_context 1
|
2016-06-24 08:43:46 +00:00
|
|
|
#define EGL_CONTEXT_MAJOR_VERSION_KHR 0x3098
|
|
|
|
#define EGL_CONTEXT_MINOR_VERSION_KHR 0x30FB
|
|
|
|
#define EGL_CONTEXT_FLAGS_KHR 0x30FC
|
2016-01-23 12:22:14 +00:00
|
|
|
#define EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR 0x30FD
|
|
|
|
#define EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR 0x31BD
|
2016-06-24 08:43:46 +00:00
|
|
|
#define EGL_NO_RESET_NOTIFICATION_KHR 0x31BE
|
|
|
|
#define EGL_LOSE_CONTEXT_ON_RESET_KHR 0x31BF
|
|
|
|
#define EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR 0x00000001
|
2016-01-23 12:22:14 +00:00
|
|
|
#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
|
2016-06-24 08:43:46 +00:00
|
|
|
#define EGL_OPENGL_ES3_BIT_KHR 0x00000040
|
2016-01-23 12:22:14 +00:00
|
|
|
#endif /* EGL_KHR_create_context */
|
|
|
|
|
2018-10-03 13:02:45 +00:00
|
|
|
GLContextEGL::~GLContextEGL() = default;
|
|
|
|
|
|
|
|
bool GLContextEGL::IsHeadless() const
|
2012-12-17 21:01:52 +00:00
|
|
|
{
|
2018-10-03 13:02:45 +00:00
|
|
|
return m_host_window == nullptr;
|
2012-12-17 21:01:52 +00:00
|
|
|
}
|
2018-10-03 13:02:45 +00:00
|
|
|
|
|
|
|
void GLContextEGL::Swap()
|
2013-03-25 02:06:34 +00:00
|
|
|
{
|
2018-10-03 13:02:45 +00:00
|
|
|
if (m_egl_surface != EGL_NO_SURFACE)
|
|
|
|
eglSwapBuffers(m_egl_display, m_egl_surface);
|
|
|
|
}
|
|
|
|
void GLContextEGL::SwapInterval(int interval)
|
|
|
|
{
|
|
|
|
eglSwapInterval(m_egl_display, interval);
|
2013-03-25 02:06:34 +00:00
|
|
|
}
|
2012-12-17 21:01:52 +00:00
|
|
|
|
2018-10-03 13:02:45 +00:00
|
|
|
void* GLContextEGL::GetFuncAddress(const std::string& name)
|
2013-12-30 13:22:50 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
return (void*)eglGetProcAddress(name.c_str());
|
2013-12-30 13:22:50 +00:00
|
|
|
}
|
|
|
|
|
2018-10-03 13:02:45 +00:00
|
|
|
void GLContextEGL::DetectMode(bool has_handle)
|
2014-01-18 04:11:59 +00:00
|
|
|
{
|
2017-07-01 17:42:42 +00:00
|
|
|
bool preferGLES = Config::Get(Config::GFX_PREFER_GLES);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
EGLint num_configs;
|
2018-10-03 13:02:45 +00:00
|
|
|
bool supportsGL = false, supportsGLES3 = false;
|
|
|
|
std::array<int, 3> renderable_types{{EGL_OPENGL_BIT, EGL_OPENGL_ES3_BIT_KHR}};
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
for (auto renderable_type : renderable_types)
|
|
|
|
{
|
|
|
|
// attributes for a visual in RGBA format with at least
|
|
|
|
// 8 bits per color
|
2017-12-30 04:20:16 +00:00
|
|
|
int attribs[] = {EGL_RED_SIZE,
|
|
|
|
8,
|
|
|
|
EGL_GREEN_SIZE,
|
|
|
|
8,
|
|
|
|
EGL_BLUE_SIZE,
|
|
|
|
8,
|
|
|
|
EGL_RENDERABLE_TYPE,
|
|
|
|
renderable_type,
|
|
|
|
EGL_SURFACE_TYPE,
|
2018-10-03 13:02:45 +00:00
|
|
|
has_handle ? EGL_WINDOW_BIT : 0,
|
2016-06-24 08:43:46 +00:00
|
|
|
EGL_NONE};
|
|
|
|
|
|
|
|
// Get how many configs there are
|
2018-10-03 13:02:45 +00:00
|
|
|
if (!eglChooseConfig(m_egl_display, attribs, nullptr, 0, &num_configs))
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2016-11-02 01:19:00 +00:00
|
|
|
INFO_LOG(VIDEO, "Error: couldn't get an EGL visual config");
|
2016-06-24 08:43:46 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
EGLConfig* config = new EGLConfig[num_configs];
|
|
|
|
|
|
|
|
// Get all the configurations
|
2018-10-03 13:02:45 +00:00
|
|
|
if (!eglChooseConfig(m_egl_display, attribs, config, num_configs, &num_configs))
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2016-11-02 01:19:00 +00:00
|
|
|
INFO_LOG(VIDEO, "Error: couldn't get an EGL visual config");
|
2016-06-24 08:43:46 +00:00
|
|
|
delete[] config;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < num_configs; ++i)
|
|
|
|
{
|
|
|
|
EGLint attribVal;
|
|
|
|
bool ret;
|
2018-10-03 13:02:45 +00:00
|
|
|
ret = eglGetConfigAttrib(m_egl_display, config[i], EGL_RENDERABLE_TYPE, &attribVal);
|
2016-06-24 08:43:46 +00:00
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (attribVal & EGL_OPENGL_BIT)
|
|
|
|
supportsGL = true;
|
2018-10-03 13:02:45 +00:00
|
|
|
if (attribVal & EGL_OPENGL_ES3_BIT_KHR)
|
2016-06-24 08:43:46 +00:00
|
|
|
supportsGLES3 = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete[] config;
|
|
|
|
}
|
|
|
|
|
2017-07-01 17:42:42 +00:00
|
|
|
if (preferGLES)
|
|
|
|
{
|
|
|
|
if (supportsGLES3)
|
2018-10-03 13:02:45 +00:00
|
|
|
m_opengl_mode = Mode::OpenGLES;
|
2017-07-01 17:42:42 +00:00
|
|
|
else if (supportsGL)
|
2018-10-03 13:02:45 +00:00
|
|
|
m_opengl_mode = Mode::OpenGL;
|
2017-07-01 17:42:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (supportsGL)
|
2018-10-03 13:02:45 +00:00
|
|
|
m_opengl_mode = Mode::OpenGL;
|
2017-07-01 17:42:42 +00:00
|
|
|
else if (supportsGLES3)
|
2018-10-03 13:02:45 +00:00
|
|
|
m_opengl_mode = Mode::OpenGLES;
|
2017-07-01 17:42:42 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2018-10-03 13:02:45 +00:00
|
|
|
if (m_opengl_mode == Mode::OpenGL)
|
2017-07-01 17:42:42 +00:00
|
|
|
{
|
|
|
|
INFO_LOG(VIDEO, "Using OpenGL");
|
|
|
|
}
|
2018-10-03 13:02:45 +00:00
|
|
|
else if (m_opengl_mode == Mode::OpenGLES)
|
2017-07-01 17:42:42 +00:00
|
|
|
{
|
2018-10-03 13:02:45 +00:00
|
|
|
INFO_LOG(VIDEO, "Using OpenGL|ES");
|
2017-07-01 17:42:42 +00:00
|
|
|
}
|
2018-10-03 13:02:45 +00:00
|
|
|
else if (m_opengl_mode == Mode::Detect)
|
2017-07-01 17:42:42 +00:00
|
|
|
{
|
|
|
|
// Errored before we found a mode
|
|
|
|
ERROR_LOG(VIDEO, "Error: Failed to detect OpenGL flavour, falling back to OpenGL");
|
|
|
|
// This will fail to create a context, as it'll try to use the same attribs we just failed to
|
|
|
|
// find a matching config with
|
2018-10-03 13:02:45 +00:00
|
|
|
m_opengl_mode = Mode::OpenGL;
|
2017-07-01 17:42:42 +00:00
|
|
|
}
|
2014-01-18 04:11:59 +00:00
|
|
|
}
|
|
|
|
|
2018-10-03 13:02:45 +00:00
|
|
|
EGLDisplay GLContextEGL::OpenEGLDisplay()
|
|
|
|
{
|
|
|
|
return eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
|
|
|
}
|
|
|
|
|
|
|
|
EGLNativeWindowType GLContextEGL::GetEGLNativeWindow(EGLConfig config)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<EGLNativeWindowType>(EGL_DEFAULT_DISPLAY);
|
|
|
|
}
|
|
|
|
|
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()
|
2018-10-03 13:03:19 +00:00
|
|
|
bool GLContextEGL::Initialize(void* display_handle, void* window_handle, bool stereo, bool core)
|
2012-12-17 21:01:52 +00:00
|
|
|
{
|
2018-10-03 13:02:45 +00:00
|
|
|
const bool has_handle = !!window_handle;
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
EGLint egl_major, egl_minor;
|
|
|
|
bool supports_core_profile = false;
|
|
|
|
|
2018-10-03 13:03:19 +00:00
|
|
|
m_host_display = display_handle;
|
2018-10-03 13:02:45 +00:00
|
|
|
m_host_window = window_handle;
|
2018-10-03 13:03:19 +00:00
|
|
|
m_egl_display = OpenEGLDisplay();
|
2018-10-03 13:02:45 +00:00
|
|
|
m_is_core_context = core;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2018-10-03 13:02:45 +00:00
|
|
|
if (!m_egl_display)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2016-11-02 01:19:00 +00:00
|
|
|
INFO_LOG(VIDEO, "Error: eglGetDisplay() failed");
|
2016-06-24 08:43:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-03 13:02:45 +00:00
|
|
|
if (!eglInitialize(m_egl_display, &egl_major, &egl_minor))
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2016-11-02 01:19:00 +00:00
|
|
|
INFO_LOG(VIDEO, "Error: eglInitialize() failed");
|
2016-06-24 08:43:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Detection code */
|
|
|
|
EGLint num_configs;
|
|
|
|
|
2018-10-03 13:02:45 +00:00
|
|
|
if (m_opengl_mode == Mode::Detect)
|
|
|
|
DetectMode(has_handle);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
// attributes for a visual in RGBA format with at least
|
|
|
|
// 8 bits per color
|
|
|
|
int attribs[] = {EGL_RENDERABLE_TYPE,
|
2018-10-03 13:02:45 +00:00
|
|
|
0,
|
2016-06-24 08:43:46 +00:00
|
|
|
EGL_RED_SIZE,
|
|
|
|
8,
|
|
|
|
EGL_GREEN_SIZE,
|
|
|
|
8,
|
|
|
|
EGL_BLUE_SIZE,
|
|
|
|
8,
|
2017-12-30 04:20:16 +00:00
|
|
|
EGL_SURFACE_TYPE,
|
2018-10-03 13:02:45 +00:00
|
|
|
has_handle ? EGL_WINDOW_BIT : 0,
|
2016-06-24 08:43:46 +00:00
|
|
|
EGL_NONE};
|
|
|
|
|
|
|
|
std::vector<EGLint> ctx_attribs;
|
2018-10-03 13:02:45 +00:00
|
|
|
switch (m_opengl_mode)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2018-10-03 13:02:45 +00:00
|
|
|
case Mode::OpenGL:
|
2016-06-24 08:43:46 +00:00
|
|
|
attribs[1] = EGL_OPENGL_BIT;
|
|
|
|
ctx_attribs = {EGL_NONE};
|
|
|
|
break;
|
2018-10-03 13:02:45 +00:00
|
|
|
case Mode::OpenGLES:
|
|
|
|
attribs[1] = EGL_OPENGL_ES3_BIT_KHR;
|
2016-06-24 08:43:46 +00:00
|
|
|
ctx_attribs = {EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE};
|
|
|
|
break;
|
|
|
|
default:
|
2016-11-02 01:19:00 +00:00
|
|
|
ERROR_LOG(VIDEO, "Unknown opengl mode set");
|
2016-06-24 08:43:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-03 13:02:45 +00:00
|
|
|
if (!eglChooseConfig(m_egl_display, attribs, &m_config, 1, &num_configs))
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2016-11-02 01:19:00 +00:00
|
|
|
INFO_LOG(VIDEO, "Error: couldn't get an EGL visual config");
|
2016-06-24 08:43:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-03 13:02:45 +00:00
|
|
|
if (m_opengl_mode == Mode::OpenGL)
|
2016-06-24 08:43:46 +00:00
|
|
|
eglBindAPI(EGL_OPENGL_API);
|
|
|
|
else
|
|
|
|
eglBindAPI(EGL_OPENGL_ES_API);
|
|
|
|
|
|
|
|
std::string tmp;
|
2018-10-03 13:02:45 +00:00
|
|
|
std::istringstream buffer(eglQueryString(m_egl_display, EGL_EXTENSIONS));
|
2016-06-24 08:43:46 +00:00
|
|
|
while (buffer >> tmp)
|
|
|
|
{
|
|
|
|
if (tmp == "EGL_KHR_surfaceless_context")
|
|
|
|
m_supports_surfaceless = true;
|
|
|
|
else if (tmp == "EGL_KHR_create_context")
|
|
|
|
supports_core_profile = true;
|
|
|
|
}
|
|
|
|
|
2018-10-03 13:02:45 +00:00
|
|
|
if (supports_core_profile && core && m_opengl_mode == Mode::OpenGL)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
|
|
|
std::array<std::pair<int, int>, 7> versions_to_try = {{
|
2018-04-12 12:18:04 +00:00
|
|
|
{4, 5},
|
|
|
|
{4, 4},
|
|
|
|
{4, 3},
|
|
|
|
{4, 2},
|
|
|
|
{4, 1},
|
|
|
|
{4, 0},
|
|
|
|
{3, 3},
|
2016-06-24 08:43:46 +00:00
|
|
|
}};
|
|
|
|
|
|
|
|
for (const auto& version : versions_to_try)
|
|
|
|
{
|
|
|
|
std::vector<EGLint> core_attribs = {EGL_CONTEXT_MAJOR_VERSION_KHR,
|
|
|
|
version.first,
|
|
|
|
EGL_CONTEXT_MINOR_VERSION_KHR,
|
|
|
|
version.second,
|
|
|
|
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_NONE};
|
|
|
|
|
2018-10-03 13:02:45 +00:00
|
|
|
m_egl_context = eglCreateContext(m_egl_display, m_config, EGL_NO_CONTEXT, &core_attribs[0]);
|
|
|
|
if (m_egl_context)
|
2017-07-27 01:57:32 +00:00
|
|
|
{
|
|
|
|
m_attribs = std::move(core_attribs);
|
2016-06-24 08:43:46 +00:00
|
|
|
break;
|
2017-07-27 01:57:32 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-03 13:02:45 +00:00
|
|
|
if (!m_egl_context)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2018-10-03 13:02:45 +00:00
|
|
|
m_is_core_context = false;
|
|
|
|
m_egl_context = eglCreateContext(m_egl_display, m_config, EGL_NO_CONTEXT, &ctx_attribs[0]);
|
2017-07-27 01:57:32 +00:00
|
|
|
m_attribs = std::move(ctx_attribs);
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
|
2018-10-03 13:02:45 +00:00
|
|
|
if (!m_egl_context)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2016-11-02 01:19:00 +00:00
|
|
|
INFO_LOG(VIDEO, "Error: eglCreateContext failed");
|
2016-06-24 08:43:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CreateWindowSurface())
|
|
|
|
{
|
2016-11-02 01:19:00 +00:00
|
|
|
ERROR_LOG(VIDEO, "Error: CreateWindowSurface failed 0x%04x", eglGetError());
|
2016-06-24 08:43:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2016-01-22 01:03:58 +00:00
|
|
|
}
|
2016-01-10 18:28:05 +00:00
|
|
|
|
2018-10-03 13:02:45 +00:00
|
|
|
std::unique_ptr<GLContext> GLContextEGL::CreateSharedContext()
|
2016-01-22 01:03:58 +00:00
|
|
|
{
|
2018-10-03 13:03:30 +00:00
|
|
|
eglBindAPI(m_opengl_mode == Mode::OpenGL ? EGL_OPENGL_API : EGL_OPENGL_ES_API);
|
|
|
|
EGLContext new_egl_context =
|
|
|
|
eglCreateContext(m_egl_display, m_config, m_egl_context, m_attribs.data());
|
|
|
|
if (!new_egl_context)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2016-11-02 01:19:00 +00:00
|
|
|
INFO_LOG(VIDEO, "Error: eglCreateContext failed 0x%04x", eglGetError());
|
2018-10-03 13:03:30 +00:00
|
|
|
return nullptr;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
|
2018-10-03 13:03:30 +00:00
|
|
|
std::unique_ptr<GLContextEGL> new_context = std::make_unique<GLContextEGL>();
|
|
|
|
new_context->m_opengl_mode = m_opengl_mode;
|
|
|
|
new_context->m_egl_context = new_egl_context;
|
|
|
|
new_context->m_host_display = m_host_display;
|
|
|
|
new_context->m_egl_display = m_egl_display;
|
|
|
|
new_context->m_is_core_context = m_is_core_context;
|
|
|
|
new_context->m_config = m_config;
|
|
|
|
new_context->m_supports_surfaceless = m_supports_surfaceless;
|
|
|
|
new_context->m_is_shared = true;
|
|
|
|
if (!new_context->CreateWindowSurface())
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2016-11-02 01:19:00 +00:00
|
|
|
ERROR_LOG(VIDEO, "Error: CreateWindowSurface failed 0x%04x", eglGetError());
|
2018-10-03 13:03:30 +00:00
|
|
|
return nullptr;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2018-10-03 13:03:30 +00:00
|
|
|
|
|
|
|
return new_context;
|
2012-12-17 21:01:52 +00:00
|
|
|
}
|
|
|
|
|
2018-10-03 13:02:45 +00:00
|
|
|
bool GLContextEGL::CreateWindowSurface()
|
2016-01-10 18:28:05 +00:00
|
|
|
{
|
2018-10-03 13:02:45 +00:00
|
|
|
if (m_host_window)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2018-10-03 13:02:45 +00:00
|
|
|
EGLNativeWindowType native_window = GetEGLNativeWindow(m_config);
|
|
|
|
m_egl_surface = eglCreateWindowSurface(m_egl_display, m_config, native_window, nullptr);
|
|
|
|
if (!m_egl_surface)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2016-11-02 01:19:00 +00:00
|
|
|
INFO_LOG(VIDEO, "Error: eglCreateWindowSurface failed");
|
2016-06-24 08:43:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!m_supports_surfaceless)
|
|
|
|
{
|
|
|
|
EGLint attrib_list[] = {
|
|
|
|
EGL_NONE,
|
|
|
|
};
|
2018-10-03 13:02:45 +00:00
|
|
|
m_egl_surface = eglCreatePbufferSurface(m_egl_display, m_config, attrib_list);
|
|
|
|
if (!m_egl_surface)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
|
|
|
INFO_LOG(VIDEO, "Error: eglCreatePbufferSurface failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-03 13:02:45 +00:00
|
|
|
m_egl_surface = EGL_NO_SURFACE;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
return true;
|
2016-01-10 18:28:05 +00:00
|
|
|
}
|
|
|
|
|
2018-10-03 13:02:45 +00:00
|
|
|
void GLContextEGL::DestroyWindowSurface()
|
2016-01-10 18:28:05 +00:00
|
|
|
{
|
2018-10-03 13:02:45 +00:00
|
|
|
if (m_egl_surface != EGL_NO_SURFACE && !eglDestroySurface(m_egl_display, m_egl_surface))
|
2016-06-24 08:43:46 +00:00
|
|
|
NOTICE_LOG(VIDEO, "Could not destroy window surface.");
|
2018-10-03 13:02:45 +00:00
|
|
|
m_egl_surface = EGL_NO_SURFACE;
|
2012-12-17 21:01:52 +00:00
|
|
|
}
|
2015-09-05 00:58:58 +00:00
|
|
|
|
2018-10-03 13:02:45 +00:00
|
|
|
bool GLContextEGL::MakeCurrent()
|
2016-01-10 18:28:05 +00:00
|
|
|
{
|
2018-10-03 13:02:45 +00:00
|
|
|
return eglMakeCurrent(m_egl_display, m_egl_surface, m_egl_surface, m_egl_context);
|
2016-01-10 18:28:05 +00:00
|
|
|
}
|
|
|
|
|
2018-10-03 13:02:45 +00:00
|
|
|
void GLContextEGL::UpdateSurface(void* window_handle)
|
2016-01-10 18:28:05 +00:00
|
|
|
{
|
2018-10-03 13:02:45 +00:00
|
|
|
m_host_window = window_handle;
|
2016-06-24 08:43:46 +00:00
|
|
|
ClearCurrent();
|
|
|
|
DestroyWindowSurface();
|
|
|
|
CreateWindowSurface();
|
|
|
|
MakeCurrent();
|
2016-01-10 18:28:05 +00:00
|
|
|
}
|
|
|
|
|
2018-10-03 13:02:45 +00:00
|
|
|
bool GLContextEGL::ClearCurrent()
|
2015-09-05 00:58:58 +00:00
|
|
|
{
|
2018-10-03 13:02:45 +00:00
|
|
|
return eglMakeCurrent(m_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
2015-09-05 00:58:58 +00:00
|
|
|
}
|
|
|
|
|
2012-12-17 21:01:52 +00:00
|
|
|
// Close backend
|
2018-10-03 13:02:45 +00:00
|
|
|
void GLContextEGL::Shutdown()
|
2012-12-17 21:01:52 +00:00
|
|
|
{
|
2018-10-03 13:02:45 +00:00
|
|
|
if (m_egl_context)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2018-10-03 13:02:45 +00:00
|
|
|
if (!eglMakeCurrent(m_egl_display, m_egl_surface, m_egl_surface, m_egl_context))
|
2016-06-24 08:43:46 +00:00
|
|
|
NOTICE_LOG(VIDEO, "Could not release drawing context.");
|
2018-10-03 13:02:45 +00:00
|
|
|
eglMakeCurrent(m_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
|
|
|
if (!eglDestroyContext(m_egl_display, m_egl_context))
|
2016-06-24 08:43:46 +00:00
|
|
|
NOTICE_LOG(VIDEO, "Could not destroy drawing context.");
|
|
|
|
DestroyWindowSurface();
|
2018-10-03 13:02:45 +00:00
|
|
|
if (!m_is_shared && !eglTerminate(m_egl_display))
|
2016-06-24 08:43:46 +00:00
|
|
|
NOTICE_LOG(VIDEO, "Could not destroy display connection.");
|
2018-10-03 13:02:45 +00:00
|
|
|
m_egl_context = nullptr;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2012-12-17 21:01:52 +00:00
|
|
|
}
|