2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2012 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2014-02-17 10:18:15 +00:00
|
|
|
|
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"
|
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
|
|
|
|
#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 */
|
|
|
|
|
2018-10-03 13:03:33 +00:00
|
|
|
GLContextEGL::~GLContextEGL()
|
|
|
|
{
|
|
|
|
DestroyWindowSurface();
|
|
|
|
DestroyContext();
|
|
|
|
}
|
2018-10-03 13:02:45 +00:00
|
|
|
|
|
|
|
bool GLContextEGL::IsHeadless() const
|
2012-12-17 21:01:52 +00:00
|
|
|
{
|
2019-04-10 14:40:19 +00:00
|
|
|
return m_wsi.type == WindowSystemType::Headless;
|
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
|
|
|
{
|
|
|
|
return (void*)eglGetProcAddress(name.c_str());
|
|
|
|
}
|
|
|
|
|
2019-04-10 14:40:19 +00:00
|
|
|
void GLContextEGL::DetectMode()
|
2014-01-18 04:11:59 +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
|
|
|
|
2015-07-21 16:29:15 +00:00
|
|
|
for (auto renderable_type : renderable_types)
|
2014-01-18 04:11:59 +00:00
|
|
|
{
|
2015-07-21 16:29:15 +00:00
|
|
|
// 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,
|
2019-04-10 14:40:19 +00:00
|
|
|
IsHeadless() ? 0 : EGL_WINDOW_BIT,
|
2015-07-21 16:29:15 +00:00
|
|
|
EGL_NONE};
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-07-21 16:29:15 +00:00
|
|
|
// Get how many configs there are
|
2018-10-03 13:02:45 +00:00
|
|
|
if (!eglChooseConfig(m_egl_display, attribs, nullptr, 0, &num_configs))
|
2015-07-21 16:29:15 +00:00
|
|
|
{
|
2020-10-23 18:41:30 +00:00
|
|
|
INFO_LOG_FMT(VIDEO, "Error: couldn't get an EGL visual config");
|
2015-08-17 23:52:17 +00:00
|
|
|
continue;
|
2015-07-21 16:29:15 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-08-17 23:52:17 +00:00
|
|
|
EGLConfig* config = new EGLConfig[num_configs];
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-07-21 16:29:15 +00:00
|
|
|
// Get all the configurations
|
2018-10-03 13:02:45 +00:00
|
|
|
if (!eglChooseConfig(m_egl_display, attribs, config, num_configs, &num_configs))
|
2015-07-21 16:29:15 +00:00
|
|
|
{
|
2020-10-23 18:41:30 +00:00
|
|
|
INFO_LOG_FMT(VIDEO, "Error: couldn't get an EGL visual config");
|
2015-08-17 23:52:17 +00:00
|
|
|
delete[] config;
|
|
|
|
continue;
|
2015-07-21 16:29:15 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-07-21 16:29:15 +00:00
|
|
|
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;
|
2018-10-03 13:02:45 +00:00
|
|
|
ret = eglGetConfigAttrib(m_egl_display, config[i], EGL_RENDERABLE_TYPE, &attribVal);
|
2015-07-21 16:29:15 +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)
|
2015-07-21 16:29:15 +00:00
|
|
|
supportsGLES3 = true;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2015-07-21 16:29:15 +00:00
|
|
|
}
|
2015-08-17 23:52:17 +00:00
|
|
|
delete[] config;
|
2014-01-18 04:11:59 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2018-10-03 13:03:36 +00:00
|
|
|
if (supportsGL)
|
2017-07-01 17:42:42 +00:00
|
|
|
{
|
2020-10-23 18:41:30 +00:00
|
|
|
INFO_LOG_FMT(VIDEO, "Using OpenGL");
|
2018-10-03 13:03:36 +00:00
|
|
|
m_opengl_mode = Mode::OpenGL;
|
2017-07-01 17:42:42 +00:00
|
|
|
}
|
2018-10-03 13:03:36 +00:00
|
|
|
else if (supportsGLES3)
|
2017-07-01 17:42:42 +00:00
|
|
|
{
|
2020-10-23 18:41:30 +00:00
|
|
|
INFO_LOG_FMT(VIDEO, "Using OpenGL|ES");
|
2018-10-03 13:03:36 +00:00
|
|
|
m_opengl_mode = Mode::OpenGLES;
|
2017-07-01 17:42:42 +00:00
|
|
|
}
|
2018-10-03 13:03:36 +00:00
|
|
|
else
|
2017-07-01 17:42:42 +00:00
|
|
|
{
|
|
|
|
// Errored before we found a mode
|
2020-10-23 18:41:30 +00:00
|
|
|
ERROR_LOG_FMT(VIDEO, "Error: Failed to detect OpenGL flavour, falling back to OpenGL");
|
2017-07-01 17:42:42 +00:00
|
|
|
// 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()
|
|
|
|
{
|
2019-04-10 14:40:19 +00:00
|
|
|
return eglGetDisplay(static_cast<EGLNativeDisplayType>(m_wsi.render_surface));
|
2018-10-03 13:02:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EGLNativeWindowType GLContextEGL::GetEGLNativeWindow(EGLConfig config)
|
|
|
|
{
|
2019-04-10 14:40:19 +00:00
|
|
|
return reinterpret_cast<EGLNativeWindowType>(m_wsi.display_connection);
|
2018-10-03 13:02:45 +00:00
|
|
|
}
|
|
|
|
|
2012-12-17 21:01:52 +00:00
|
|
|
// Create rendering window.
|
|
|
|
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
|
2019-04-10 14:40:19 +00:00
|
|
|
bool GLContextEGL::Initialize(const WindowSystemInfo& wsi, bool stereo, bool core)
|
2012-12-17 21:01:52 +00:00
|
|
|
{
|
2013-01-24 16:39:38 +00:00
|
|
|
EGLint egl_major, egl_minor;
|
2016-01-22 16:58:19 +00:00
|
|
|
bool supports_core_profile = false;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2019-04-10 14:40:19 +00:00
|
|
|
m_wsi = wsi;
|
2018-10-03 13:03:19 +00:00
|
|
|
m_egl_display = OpenEGLDisplay();
|
2018-10-03 13:02:45 +00:00
|
|
|
if (!m_egl_display)
|
2014-01-18 04:11:59 +00:00
|
|
|
{
|
2020-10-23 18:41:30 +00:00
|
|
|
INFO_LOG_FMT(VIDEO, "Error: eglGetDisplay() failed");
|
2014-01-18 04:11:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2018-10-03 13:02:45 +00:00
|
|
|
if (!eglInitialize(m_egl_display, &egl_major, &egl_minor))
|
2014-01-18 04:11:59 +00:00
|
|
|
{
|
2020-10-23 18:41:30 +00:00
|
|
|
INFO_LOG_FMT(VIDEO, "Error: eglInitialize() failed");
|
2014-01-18 04:11:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-01-18 04:11:59 +00:00
|
|
|
/* Detection code */
|
2013-03-25 02:06:34 +00:00
|
|
|
EGLint num_configs;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2018-10-03 13:02:45 +00:00
|
|
|
if (m_opengl_mode == Mode::Detect)
|
2019-04-10 14:40:19 +00:00
|
|
|
DetectMode();
|
2016-06-24 08:43:46 +00:00
|
|
|
|
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
|
2013-12-12 18:43:49 +00:00
|
|
|
int attribs[] = {EGL_RENDERABLE_TYPE,
|
2018-10-03 13:02:45 +00:00
|
|
|
0,
|
2012-12-17 21:01:52 +00:00
|
|
|
EGL_RED_SIZE,
|
|
|
|
8,
|
|
|
|
EGL_GREEN_SIZE,
|
|
|
|
8,
|
|
|
|
EGL_BLUE_SIZE,
|
2016-06-24 08:43:46 +00:00
|
|
|
8,
|
2017-12-30 04:20:16 +00:00
|
|
|
EGL_SURFACE_TYPE,
|
2019-04-10 14:40:19 +00:00
|
|
|
IsHeadless() ? 0 : EGL_WINDOW_BIT,
|
2012-12-17 21:01:52 +00:00
|
|
|
EGL_NONE};
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-01-22 16:58:19 +00:00
|
|
|
std::vector<EGLint> ctx_attribs;
|
2018-10-03 13:02:45 +00:00
|
|
|
switch (m_opengl_mode)
|
2013-12-12 18:43:49 +00:00
|
|
|
{
|
2018-10-03 13:02:45 +00:00
|
|
|
case Mode::OpenGL:
|
2016-01-22 01:03:58 +00:00
|
|
|
attribs[1] = EGL_OPENGL_BIT;
|
2016-01-22 16:58:19 +00:00
|
|
|
ctx_attribs = {EGL_NONE};
|
2016-01-22 01:03:58 +00:00
|
|
|
break;
|
2018-10-03 13:02:45 +00:00
|
|
|
case Mode::OpenGLES:
|
|
|
|
attribs[1] = EGL_OPENGL_ES3_BIT_KHR;
|
2016-01-22 16:58:19 +00:00
|
|
|
ctx_attribs = {EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE};
|
2016-01-22 01:03:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
2020-10-23 18:41:30 +00:00
|
|
|
ERROR_LOG_FMT(VIDEO, "Unknown opengl mode set");
|
2016-01-22 01:03:58 +00:00
|
|
|
return false;
|
2013-12-12 18:43:49 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2018-10-03 13:02:45 +00:00
|
|
|
if (!eglChooseConfig(m_egl_display, attribs, &m_config, 1, &num_configs))
|
2014-01-18 04:11:59 +00:00
|
|
|
{
|
2020-10-23 18:41:30 +00:00
|
|
|
INFO_LOG_FMT(VIDEO, "Error: couldn't get an EGL visual config");
|
2016-01-22 01:03:58 +00:00
|
|
|
return false;
|
2013-01-24 16:39:38 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2018-10-03 13:02:45 +00:00
|
|
|
if (m_opengl_mode == Mode::OpenGL)
|
2013-12-12 22:08:54 +00:00
|
|
|
eglBindAPI(EGL_OPENGL_API);
|
|
|
|
else
|
|
|
|
eglBindAPI(EGL_OPENGL_ES_API);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-01-10 18:28:05 +00:00
|
|
|
std::string tmp;
|
2018-10-03 13:02:45 +00:00
|
|
|
std::istringstream buffer(eglQueryString(m_egl_display, EGL_EXTENSIONS));
|
2016-01-10 18:28:05 +00:00
|
|
|
while (buffer >> tmp)
|
2013-01-24 16:39:38 +00:00
|
|
|
{
|
2016-01-10 18:28:05 +00:00
|
|
|
if (tmp == "EGL_KHR_surfaceless_context")
|
|
|
|
m_supports_surfaceless = true;
|
2016-01-22 16:58:19 +00:00
|
|
|
else if (tmp == "EGL_KHR_create_context")
|
|
|
|
supports_core_profile = true;
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2018-10-03 13:02:45 +00:00
|
|
|
if (supports_core_profile && core && m_opengl_mode == Mode::OpenGL)
|
2016-01-22 16:58:19 +00:00
|
|
|
{
|
2018-10-14 13:32:50 +00:00
|
|
|
for (const auto& version : s_desktop_opengl_versions)
|
2016-01-22 16:58:19 +00:00
|
|
|
{
|
|
|
|
std::vector<EGLint> core_attribs = {EGL_CONTEXT_MAJOR_VERSION_KHR,
|
|
|
|
version.first,
|
|
|
|
EGL_CONTEXT_MINOR_VERSION_KHR,
|
|
|
|
version.second,
|
2016-05-29 20:12:27 +00:00
|
|
|
EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR,
|
|
|
|
EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR,
|
|
|
|
EGL_CONTEXT_FLAGS_KHR,
|
|
|
|
EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR,
|
2016-01-22 16:58:19 +00:00
|
|
|
EGL_NONE};
|
2016-06-24 08:43:46 +00:00
|
|
|
|
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-01-22 16:58:19 +00:00
|
|
|
break;
|
2017-07-27 01:57:32 +00:00
|
|
|
}
|
2016-01-10 18:28:05 +00:00
|
|
|
}
|
2013-01-24 16:39:38 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2018-10-03 13:02:45 +00:00
|
|
|
if (!m_egl_context)
|
2016-01-22 16:58:19 +00:00
|
|
|
{
|
2018-10-03 13:02:45 +00:00
|
|
|
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-01-22 16:58:19 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2018-10-03 13:02:45 +00:00
|
|
|
if (!m_egl_context)
|
2016-01-22 16:58:19 +00:00
|
|
|
{
|
2020-10-23 18:41:30 +00:00
|
|
|
INFO_LOG_FMT(VIDEO, "Error: eglCreateContext failed");
|
2016-01-22 16:58:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-01-22 01:03:58 +00:00
|
|
|
if (!CreateWindowSurface())
|
|
|
|
{
|
2020-10-23 18:41:30 +00:00
|
|
|
ERROR_LOG_FMT(VIDEO, "Error: CreateWindowSurface failed {:#06x}", eglGetError());
|
2016-01-22 01:03:58 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-10-03 13:03:33 +00:00
|
|
|
|
|
|
|
return MakeCurrent();
|
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-01-22 01:03:58 +00:00
|
|
|
{
|
2020-10-23 18:41:30 +00:00
|
|
|
INFO_LOG_FMT(VIDEO, "Error: eglCreateContext failed {:#06x}", eglGetError());
|
2018-10-03 13:03:30 +00:00
|
|
|
return nullptr;
|
2016-01-22 01:03:58 +00:00
|
|
|
}
|
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;
|
2019-04-10 14:40:19 +00:00
|
|
|
new_context->m_wsi.display_connection = m_wsi.display_connection;
|
2018-10-03 13:03:30 +00:00
|
|
|
new_context->m_egl_display = m_egl_display;
|
|
|
|
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-01-22 01:03:58 +00:00
|
|
|
{
|
2020-10-23 18:41:30 +00:00
|
|
|
ERROR_LOG_FMT(VIDEO, "Error: CreateWindowSurface failed {:#06x}", eglGetError());
|
2018-10-03 13:03:30 +00:00
|
|
|
return nullptr;
|
2016-01-22 01:03:58 +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
|
|
|
{
|
2019-04-10 14:40:19 +00:00
|
|
|
if (!IsHeadless())
|
2016-01-10 18:28:05 +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-01-10 18:28:05 +00:00
|
|
|
{
|
2020-10-23 18:41:30 +00:00
|
|
|
INFO_LOG_FMT(VIDEO, "Error: eglCreateWindowSurface failed");
|
2016-01-22 01:03:58 +00:00
|
|
|
return false;
|
2016-01-10 18:28:05 +00:00
|
|
|
}
|
2019-04-10 14:40:19 +00:00
|
|
|
|
|
|
|
// Get dimensions from the surface.
|
|
|
|
EGLint surface_width = 1, surface_height = 1;
|
|
|
|
if (!eglQuerySurface(m_egl_display, m_egl_surface, EGL_WIDTH, &surface_width) ||
|
|
|
|
!eglQuerySurface(m_egl_display, m_egl_surface, EGL_HEIGHT, &surface_height))
|
|
|
|
{
|
2020-10-23 18:41:30 +00:00
|
|
|
WARN_LOG_FMT(VIDEO,
|
|
|
|
"Failed to get surface dimensions via eglQuerySurface. Size may be incorrect.");
|
2019-04-10 14:40:19 +00:00
|
|
|
}
|
|
|
|
m_backbuffer_width = static_cast<int>(surface_width);
|
|
|
|
m_backbuffer_height = static_cast<int>(surface_height);
|
2016-01-10 18:28:05 +00:00
|
|
|
}
|
|
|
|
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-01-10 18:28:05 +00:00
|
|
|
{
|
2020-10-23 18:41:30 +00:00
|
|
|
INFO_LOG_FMT(VIDEO, "Error: eglCreatePbufferSurface failed");
|
2016-01-22 01:03:58 +00:00
|
|
|
return false;
|
2016-01-10 18:28:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-03 13:02:45 +00:00
|
|
|
m_egl_surface = EGL_NO_SURFACE;
|
2016-01-10 18:28:05 +00:00
|
|
|
}
|
2016-01-22 01:03:58 +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:03:33 +00:00
|
|
|
if (m_egl_surface == EGL_NO_SURFACE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (eglGetCurrentSurface(EGL_DRAW) == m_egl_surface)
|
|
|
|
eglMakeCurrent(m_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
|
|
|
if (!eglDestroySurface(m_egl_display, m_egl_surface))
|
2020-10-23 18:41:30 +00:00
|
|
|
NOTICE_LOG_FMT(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
|
|
|
{
|
2019-04-10 14:40:19 +00:00
|
|
|
m_wsi.render_surface = window_handle;
|
2016-01-10 18:28:05 +00:00
|
|
|
ClearCurrent();
|
|
|
|
DestroyWindowSurface();
|
|
|
|
CreateWindowSurface();
|
|
|
|
MakeCurrent();
|
|
|
|
}
|
|
|
|
|
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:03:33 +00:00
|
|
|
void GLContextEGL::DestroyContext()
|
2012-12-17 21:01:52 +00:00
|
|
|
{
|
2018-10-03 13:03:33 +00:00
|
|
|
if (!m_egl_context)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (eglGetCurrentContext() == m_egl_context)
|
2018-10-03 13:02:45 +00:00
|
|
|
eglMakeCurrent(m_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
2018-10-03 13:03:33 +00:00
|
|
|
if (!eglDestroyContext(m_egl_display, m_egl_context))
|
2020-10-23 18:41:30 +00:00
|
|
|
NOTICE_LOG_FMT(VIDEO, "Could not destroy drawing context.");
|
2018-10-03 13:03:33 +00:00
|
|
|
if (!m_is_shared && !eglTerminate(m_egl_display))
|
2020-10-23 18:41:30 +00:00
|
|
|
NOTICE_LOG_FMT(VIDEO, "Could not destroy display connection.");
|
2018-10-03 13:03:33 +00:00
|
|
|
m_egl_context = EGL_NO_CONTEXT;
|
|
|
|
m_egl_display = EGL_NO_DISPLAY;
|
2012-12-17 21:01:52 +00:00
|
|
|
}
|