From 134d967be2dd4ba9531abb8ba8494c3ac423ca72 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 3 Oct 2018 23:02:45 +1000 Subject: Refactoring and cleanup of GLInterface (now GLContext) --- Source/Core/Common/GL/GLContext.cpp | 115 ++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 Source/Core/Common/GL/GLContext.cpp (limited to 'Source/Core/Common/GL/GLContext.cpp') diff --git a/Source/Core/Common/GL/GLContext.cpp b/Source/Core/Common/GL/GLContext.cpp new file mode 100644 index 0000000000..da22f45c3b --- /dev/null +++ b/Source/Core/Common/GL/GLContext.cpp @@ -0,0 +1,115 @@ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include + +#include "Common/GL/GLContext.h" + +#if defined(__APPLE__) +#include "Common/GL/GLInterface/AGL.h" +#elif defined(_WIN32) +#include "Common/GL/GLInterface/WGL.h" +#elif HAVE_X11 +#if defined(USE_EGL) && USE_EGL +#include "Common/GL/GLInterface/EGLX11.h" +#else +#include "Common/GL/GLInterface/GLX.h" +#endif +#elif defined(USE_EGL) && USE_EGL && defined(USE_HEADLESS) +#include "Common/GL/GLInterface/EGL.h" +#elif ANDROID +#include "Common/GL/GLInterface/EGLAndroid.h" +#error Platform doesnt have a GLInterface +#endif + +std::unique_ptr g_main_gl_context; + +GLContext::~GLContext() = default; + +bool GLContext::Initialize(void* window_handle, bool stereo, bool core) +{ + return false; +} + +bool GLContext::Initialize(GLContext* main_context) +{ + return false; +} + +void GLContext::SetBackBufferDimensions(u32 w, u32 h) +{ + m_backbuffer_width = w; + m_backbuffer_height = h; +} + +bool GLContext::IsHeadless() const +{ + return true; +} + +std::unique_ptr GLContext::CreateSharedContext() +{ + return nullptr; +} + +bool GLContext::MakeCurrent() +{ + return false; +} + +bool GLContext::ClearCurrent() +{ + return false; +} + +void GLContext::Shutdown() +{ +} + +void GLContext::Update() +{ +} + +void GLContext::UpdateSurface(void* window_handle) +{ +} + +void GLContext::Swap() +{ +} + +void GLContext::SwapInterval(int interval) +{ +} + +void* GLContext::GetFuncAddress(const std::string& name) +{ + return nullptr; +} + +std::unique_ptr GLContext::Create(void* window_handle, bool stereo, bool core) +{ + std::unique_ptr context; +#if defined(__APPLE__) + context = std::make_unique(); +#elif defined(_WIN32) + context = std::make_unique(); +#elif defined(USE_EGL) && defined(USE_HEADLESS) + context = std::make_unique(); +#elif defined(HAVE_X11) && HAVE_X11 +#if defined(USE_EGL) && USE_EGL + context = std::make_unique(); +#else + context = std::make_unique(); +#endif +#elif ANDROID + context = std::make_unique(); +#else + return nullptr; +#endif + if (!context->Initialize(window_handle, stereo, core)) + return nullptr; + + return context; +} -- cgit v1.2.3 From 9c57a98723997736adea94383668fbdf8a993fd8 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 3 Oct 2018 23:03:19 +1000 Subject: GLContext: Use host connection This also removes the need for a sleeping event thread. --- Source/Core/Common/GL/GLContext.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'Source/Core/Common/GL/GLContext.cpp') diff --git a/Source/Core/Common/GL/GLContext.cpp b/Source/Core/Common/GL/GLContext.cpp index da22f45c3b..0b7f0238c1 100644 --- a/Source/Core/Common/GL/GLContext.cpp +++ b/Source/Core/Common/GL/GLContext.cpp @@ -27,7 +27,7 @@ std::unique_ptr g_main_gl_context; GLContext::~GLContext() = default; -bool GLContext::Initialize(void* window_handle, bool stereo, bool core) +bool GLContext::Initialize(void* display_handle, void* window_handle, bool stereo, bool core) { return false; } @@ -37,12 +37,6 @@ bool GLContext::Initialize(GLContext* main_context) return false; } -void GLContext::SetBackBufferDimensions(u32 w, u32 h) -{ - m_backbuffer_width = w; - m_backbuffer_height = h; -} - bool GLContext::IsHeadless() const { return true; @@ -88,7 +82,8 @@ void* GLContext::GetFuncAddress(const std::string& name) return nullptr; } -std::unique_ptr GLContext::Create(void* window_handle, bool stereo, bool core) +std::unique_ptr GLContext::Create(void* display_handle, void* window_handle, bool stereo, + bool core) { std::unique_ptr context; #if defined(__APPLE__) @@ -108,7 +103,7 @@ std::unique_ptr GLContext::Create(void* window_handle, bool stereo, b #else return nullptr; #endif - if (!context->Initialize(window_handle, stereo, core)) + if (!context->Initialize(display_handle, window_handle, stereo, core)) return nullptr; return context; -- cgit v1.2.3 From eb284b5d661cab6aed770e0e51b790917249ef21 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 3 Oct 2018 23:03:22 +1000 Subject: VideoBackends: Pass window system info from host on creation --- Source/Core/Common/GL/GLContext.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'Source/Core/Common/GL/GLContext.cpp') diff --git a/Source/Core/Common/GL/GLContext.cpp b/Source/Core/Common/GL/GLContext.cpp index 0b7f0238c1..da3e47aa26 100644 --- a/Source/Core/Common/GL/GLContext.cpp +++ b/Source/Core/Common/GL/GLContext.cpp @@ -82,8 +82,7 @@ void* GLContext::GetFuncAddress(const std::string& name) return nullptr; } -std::unique_ptr GLContext::Create(void* display_handle, void* window_handle, bool stereo, - bool core) +std::unique_ptr GLContext::Create(const WindowSystemInfo& wsi, bool stereo, bool core) { std::unique_ptr context; #if defined(__APPLE__) @@ -103,7 +102,7 @@ std::unique_ptr GLContext::Create(void* display_handle, void* window_ #else return nullptr; #endif - if (!context->Initialize(display_handle, window_handle, stereo, core)) + if (!context->Initialize(wsi.display_connection, wsi.render_surface, stereo, core)) return nullptr; return context; -- cgit v1.2.3 From dcdd02d646230e7903520a41dc9f86e57ae16dbe Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 3 Oct 2018 23:03:26 +1000 Subject: GLContext: Remove global context pointer --- Source/Core/Common/GL/GLContext.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'Source/Core/Common/GL/GLContext.cpp') diff --git a/Source/Core/Common/GL/GLContext.cpp b/Source/Core/Common/GL/GLContext.cpp index da3e47aa26..d56d048d1b 100644 --- a/Source/Core/Common/GL/GLContext.cpp +++ b/Source/Core/Common/GL/GLContext.cpp @@ -23,8 +23,6 @@ #error Platform doesnt have a GLInterface #endif -std::unique_ptr g_main_gl_context; - GLContext::~GLContext() = default; bool GLContext::Initialize(void* display_handle, void* window_handle, bool stereo, bool core) -- cgit v1.2.3 From 4b8d1c2b429485d54d7dad2fdc142ed43b34b992 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 3 Oct 2018 23:03:30 +1000 Subject: GLContext: Combine shared context initialization and creation --- Source/Core/Common/GL/GLContext.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'Source/Core/Common/GL/GLContext.cpp') diff --git a/Source/Core/Common/GL/GLContext.cpp b/Source/Core/Common/GL/GLContext.cpp index d56d048d1b..90cb833302 100644 --- a/Source/Core/Common/GL/GLContext.cpp +++ b/Source/Core/Common/GL/GLContext.cpp @@ -30,11 +30,6 @@ bool GLContext::Initialize(void* display_handle, void* window_handle, bool stere return false; } -bool GLContext::Initialize(GLContext* main_context) -{ - return false; -} - bool GLContext::IsHeadless() const { return true; -- cgit v1.2.3 From 025e909773a2761cad8a3954498fe800f6f94963 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 3 Oct 2018 23:03:33 +1000 Subject: GLContext: Use destructor instead of Shutdown() to cleanup Also uses the Initialize() method to make the context current. --- Source/Core/Common/GL/GLContext.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'Source/Core/Common/GL/GLContext.cpp') diff --git a/Source/Core/Common/GL/GLContext.cpp b/Source/Core/Common/GL/GLContext.cpp index 90cb833302..23f0255cd3 100644 --- a/Source/Core/Common/GL/GLContext.cpp +++ b/Source/Core/Common/GL/GLContext.cpp @@ -50,10 +50,6 @@ bool GLContext::ClearCurrent() return false; } -void GLContext::Shutdown() -{ -} - void GLContext::Update() { } -- cgit v1.2.3 From 0559311f929d62904c6f14c67d3944fb4142aaaf Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 3 Oct 2018 23:03:36 +1000 Subject: GLContext: Runtime selection of EGL/GLX on Linux --- Source/Core/Common/GL/GLContext.cpp | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'Source/Core/Common/GL/GLContext.cpp') diff --git a/Source/Core/Common/GL/GLContext.cpp b/Source/Core/Common/GL/GLContext.cpp index 23f0255cd3..81bf4e12b6 100644 --- a/Source/Core/Common/GL/GLContext.cpp +++ b/Source/Core/Common/GL/GLContext.cpp @@ -10,17 +10,13 @@ #include "Common/GL/GLInterface/AGL.h" #elif defined(_WIN32) #include "Common/GL/GLInterface/WGL.h" +#elif defined(ANDROID) +#include "Common/GL/GLInterface/EGLAndroid.h" #elif HAVE_X11 -#if defined(USE_EGL) && USE_EGL #include "Common/GL/GLInterface/EGLX11.h" -#else #include "Common/GL/GLInterface/GLX.h" -#endif -#elif defined(USE_EGL) && USE_EGL && defined(USE_HEADLESS) +#elif HAVE_EGL #include "Common/GL/GLInterface/EGL.h" -#elif ANDROID -#include "Common/GL/GLInterface/EGLAndroid.h" -#error Platform doesnt have a GLInterface #endif GLContext::~GLContext() = default; @@ -71,26 +67,32 @@ void* GLContext::GetFuncAddress(const std::string& name) return nullptr; } -std::unique_ptr GLContext::Create(const WindowSystemInfo& wsi, bool stereo, bool core) +std::unique_ptr GLContext::Create(const WindowSystemInfo& wsi, bool stereo, bool core, + bool prefer_egl, bool prefer_gles) { std::unique_ptr context; #if defined(__APPLE__) context = std::make_unique(); #elif defined(_WIN32) context = std::make_unique(); -#elif defined(USE_EGL) && defined(USE_HEADLESS) - context = std::make_unique(); -#elif defined(HAVE_X11) && HAVE_X11 -#if defined(USE_EGL) && USE_EGL - context = std::make_unique(); -#else - context = std::make_unique(); -#endif -#elif ANDROID +#elif defined(ANDROID) context = std::make_unique(); +#elif HAVE_X11 + // GLES is not supported via GLX? + if (prefer_egl || prefer_gles) + context = std::make_unique(); + else + context = std::make_unique(); +#elif HAVE_EGL + context = std::make_unique(); #else return nullptr; #endif + + // Option to prefer GLES on desktop platforms, useful for testing. + if (prefer_gles) + context->m_opengl_mode = Mode::OpenGLES; + if (!context->Initialize(wsi.display_connection, wsi.render_surface, stereo, core)) return nullptr; -- cgit v1.2.3 From c95802afeb2ebc702bed61a9437f6e85e4f833e0 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 14 Oct 2018 23:17:31 +1000 Subject: CMake: Make X11 and EGL optional --- Source/Core/Common/GL/GLContext.cpp | 63 +++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 20 deletions(-) (limited to 'Source/Core/Common/GL/GLContext.cpp') diff --git a/Source/Core/Common/GL/GLContext.cpp b/Source/Core/Common/GL/GLContext.cpp index 81bf4e12b6..d4a9ed2e7a 100644 --- a/Source/Core/Common/GL/GLContext.cpp +++ b/Source/Core/Common/GL/GLContext.cpp @@ -8,15 +8,21 @@ #if defined(__APPLE__) #include "Common/GL/GLInterface/AGL.h" -#elif defined(_WIN32) +#endif +#if defined(WIN32) #include "Common/GL/GLInterface/WGL.h" -#elif defined(ANDROID) -#include "Common/GL/GLInterface/EGLAndroid.h" -#elif HAVE_X11 -#include "Common/GL/GLInterface/EGLX11.h" +#endif +#if HAVE_X11 #include "Common/GL/GLInterface/GLX.h" -#elif HAVE_EGL +#endif +#if HAVE_EGL #include "Common/GL/GLInterface/EGL.h" +#if HAVE_X11 +#include "Common/GL/GLInterface/EGLX11.h" +#endif +#if defined(ANDROID) +#include "Common/GL/GLInterface/EGLAndroid.h" +#endif #endif GLContext::~GLContext() = default; @@ -72,22 +78,39 @@ std::unique_ptr GLContext::Create(const WindowSystemInfo& wsi, bool s { std::unique_ptr context; #if defined(__APPLE__) - context = std::make_unique(); -#elif defined(_WIN32) - context = std::make_unique(); -#elif defined(ANDROID) - context = std::make_unique(); -#elif HAVE_X11 - // GLES is not supported via GLX? - if (prefer_egl || prefer_gles) - context = std::make_unique(); - else - context = std::make_unique(); -#elif HAVE_EGL - context = std::make_unique(); + if (wsi.type == WindowSystemType::MacOS || wsi.type == WindowSystemType::Headless) + context = std::make_unique(); +#endif +#if defined(_WIN32) + if (wsi.type == WindowSystemType::Windows) + context = std::make_unique(); +#endif +#if defined(ANDROID) + if (wsi.type == WindowSystemType::Android) + context = std::make_unique(); +#endif +#if HAVE_X11 + if (wsi.type == WindowSystemType::X11) + { + // GLES 3 is not supported via GLX. + const bool use_egl = prefer_egl || prefer_gles; +#if defined(HAVE_EGL) + if (use_egl) + context = std::make_unique(); + else + context = std::make_unique(); #else - return nullptr; + context = std::make_unique(); #endif + } +#endif +#if HAVE_EGL + if (wsi.type == WindowSystemType::Headless) + context = std::make_unique(); +#endif + + if (!context) + return nullptr; // Option to prefer GLES on desktop platforms, useful for testing. if (prefer_gles) -- cgit v1.2.3 From 2c6d96433c322b50470705d43005fd6308506d49 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 14 Oct 2018 23:32:50 +1000 Subject: GLContext: Try GL versions 3.2-4.6 when getting a context GLX previously was only creating a 4.0 context. --- Source/Core/Common/GL/GLContext.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Source/Core/Common/GL/GLContext.cpp') diff --git a/Source/Core/Common/GL/GLContext.cpp b/Source/Core/Common/GL/GLContext.cpp index d4a9ed2e7a..b02e27778f 100644 --- a/Source/Core/Common/GL/GLContext.cpp +++ b/Source/Core/Common/GL/GLContext.cpp @@ -25,6 +25,9 @@ #endif #endif +const std::array, 9> GLContext::s_desktop_opengl_versions = { + {{4, 6}, {4, 5}, {4, 4}, {4, 3}, {4, 2}, {4, 1}, {4, 0}, {3, 3}, {3, 2}}}; + GLContext::~GLContext() = default; bool GLContext::Initialize(void* display_handle, void* window_handle, bool stereo, bool core) -- cgit v1.2.3