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) diff --git a/Source/Core/Common/GL/GLContext.h b/Source/Core/Common/GL/GLContext.h index d4854a21cf..074ea3cc6d 100644 --- a/Source/Core/Common/GL/GLContext.h +++ b/Source/Core/Common/GL/GLContext.h @@ -4,8 +4,10 @@ #pragma once +#include #include #include +#include #include "Common/CommonTypes.h" #include "Common/WindowSystemInfo.h" @@ -58,4 +60,8 @@ protected: u32 m_backbuffer_width = 0; u32 m_backbuffer_height = 0; bool m_is_shared = false; + + // A list of desktop OpenGL versions to attempt to create a context for. + // (4.6-3.2, geometry shaders is a minimum requirement since we're using core profile). + static const std::array, 9> s_desktop_opengl_versions; }; diff --git a/Source/Core/Common/GL/GLInterface/EGL.cpp b/Source/Core/Common/GL/GLInterface/EGL.cpp index b472d2b984..93a60ca9d8 100644 --- a/Source/Core/Common/GL/GLInterface/EGL.cpp +++ b/Source/Core/Common/GL/GLInterface/EGL.cpp @@ -222,17 +222,7 @@ bool GLContextEGL::Initialize(void* display_handle, void* window_handle, bool st if (supports_core_profile && core && m_opengl_mode == Mode::OpenGL) { - std::array, 7> versions_to_try = {{ - {4, 5}, - {4, 4}, - {4, 3}, - {4, 2}, - {4, 1}, - {4, 0}, - {3, 3}, - }}; - - for (const auto& version : versions_to_try) + for (const auto& version : s_desktop_opengl_versions) { std::vector core_attribs = {EGL_CONTEXT_MAJOR_VERSION_KHR, version.first, diff --git a/Source/Core/Common/GL/GLInterface/GLX.cpp b/Source/Core/Common/GL/GLInterface/GLX.cpp index d74bccf8a4..c2e4491ff5 100644 --- a/Source/Core/Common/GL/GLInterface/GLX.cpp +++ b/Source/Core/Common/GL/GLInterface/GLX.cpp @@ -134,30 +134,29 @@ bool GLContextGLX::Initialize(void* display_handle, void* window_handle, bool st XErrorHandler oldHandler = XSetErrorHandler(&ctxErrorHandler); // Create a GLX context. - // We try to get a 4.0 core profile, else we try 3.3, else try it with anything we get. - std::array context_attribs = { - {GLX_CONTEXT_MAJOR_VERSION_ARB, 4, GLX_CONTEXT_MINOR_VERSION_ARB, 0, - GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB, GLX_CONTEXT_FLAGS_ARB, - GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, None}}; - m_context = nullptr; if (core) { - m_context = glXCreateContextAttribs(m_display, m_fbconfig, 0, True, &context_attribs[0]); - XSync(m_display, False); - m_attribs.insert(m_attribs.end(), context_attribs.begin(), context_attribs.end()); - } - if (core && (!m_context || s_glxError)) - { - std::array context_attribs_33 = { - {GLX_CONTEXT_MAJOR_VERSION_ARB, 3, GLX_CONTEXT_MINOR_VERSION_ARB, 3, - GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB, GLX_CONTEXT_FLAGS_ARB, - GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, None}}; - s_glxError = false; - m_context = glXCreateContextAttribs(m_display, m_fbconfig, 0, True, &context_attribs_33[0]); - XSync(m_display, False); - m_attribs.clear(); - m_attribs.insert(m_attribs.end(), context_attribs_33.begin(), context_attribs_33.end()); + for (const auto& version : s_desktop_opengl_versions) + { + std::array context_attribs = { + {GLX_CONTEXT_MAJOR_VERSION_ARB, version.first, GLX_CONTEXT_MINOR_VERSION_ARB, + version.second, GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB, + GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, None}}; + + s_glxError = false; + m_context = glXCreateContextAttribs(m_display, m_fbconfig, 0, True, &context_attribs[0]); + XSync(m_display, False); + m_attribs.insert(m_attribs.end(), context_attribs.begin(), context_attribs.end()); + if (!m_context || s_glxError) + continue; + + // Got a context. + INFO_LOG(VIDEO, "Created a GLX context with version %d.%d", version.first, version.second); + break; + } } + + // Failed to create any core contexts, try for anything. if (!m_context || s_glxError) { std::array context_attribs_legacy = { diff --git a/Source/Core/Common/GL/GLInterface/WGL.cpp b/Source/Core/Common/GL/GLInterface/WGL.cpp index 98b6bd5a3a..e168f94e51 100644 --- a/Source/Core/Common/GL/GLInterface/WGL.cpp +++ b/Source/Core/Common/GL/GLInterface/WGL.cpp @@ -371,12 +371,7 @@ HGLRC GLContextWGL::CreateCoreContext(HDC dc, HGLRC share_context) return nullptr; } - // List of versions to attempt context creation for. (4.5-3.2, geometry shaders is a minimum - // requirement since we're using core profile) - static constexpr std::array, 8> try_versions = { - {{4, 5}, {4, 4}, {4, 3}, {4, 2}, {4, 1}, {4, 0}, {3, 3}, {3, 2}}}; - - for (const auto& version : try_versions) + for (const auto& version : s_desktop_opengl_versions) { // Construct list of attributes. Prefer a forward-compatible, core context. std::array attribs = {WGL_CONTEXT_PROFILE_MASK_ARB,