GLContext: Runtime selection of EGL/GLX on Linux

This commit is contained in:
Stenzek
2018-10-03 23:03:36 +10:00
parent 025e909773
commit 0559311f92
7 changed files with 61 additions and 90 deletions

View File

@ -113,12 +113,10 @@ target_sources(common PRIVATE
GL/GLContext.cpp
)
if(USE_EGL)
if(ENABLE_EGL)
target_sources(common PRIVATE GL/GLInterface/EGL.cpp)
if(ANDROID)
target_sources(common PRIVATE GL/GLInterface/EGLAndroid.cpp)
elseif(USE_X11)
target_sources(common PRIVATE GL/GLInterface/EGLX11.cpp)
endif()
target_link_libraries(common PUBLIC EGL)
endif()
@ -130,15 +128,18 @@ if(WIN32)
)
elseif(APPLE)
target_sources(common PRIVATE GL/GLInterface/AGL.mm)
elseif(USE_X11)
if (NOT USE_EGL)
target_sources(common PRIVATE GL/GLInterface/GLX.cpp)
# GLX has a hard dependency on libGL.
# Make sure to link to it if using GLX.
target_link_libraries(common PUBLIC ${OPENGL_LIBRARIES})
elseif(ENABLE_X11)
target_sources(common PRIVATE
GL/GLX11Window.cpp
GL/GLInterface/GLX.cpp)
# GLX has a hard dependency on libGL.
# Make sure to link to it if using GLX.
target_link_libraries(common PUBLIC ${OPENGL_LIBRARIES})
if (ENABLE_EGL)
target_sources(common PRIVATE GL/GLInterface/EGLX11.cpp)
endif()
target_sources(common PRIVATE GL/GLX11Window.cpp)
target_link_libraries(common PUBLIC ${XRANDR_LIBRARIES})
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")

View File

@ -10,17 +10,13 @@
#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
#elif defined(ANDROID)
#include "Common/GL/GLInterface/EGLAndroid.h"
#error Platform doesnt have a GLInterface
#elif HAVE_X11
#include "Common/GL/GLInterface/EGLX11.h"
#include "Common/GL/GLInterface/GLX.h"
#elif HAVE_EGL
#include "Common/GL/GLInterface/EGL.h"
#endif
GLContext::~GLContext() = default;
@ -71,26 +67,32 @@ void* GLContext::GetFuncAddress(const std::string& name)
return nullptr;
}
std::unique_ptr<GLContext> GLContext::Create(const WindowSystemInfo& wsi, bool stereo, bool core)
std::unique_ptr<GLContext> GLContext::Create(const WindowSystemInfo& wsi, bool stereo, bool core,
bool prefer_egl, bool prefer_gles)
{
std::unique_ptr<GLContext> context;
#if defined(__APPLE__)
context = std::make_unique<GLContextAGL>();
#elif defined(_WIN32)
context = std::make_unique<GLContextWGL>();
#elif defined(USE_EGL) && defined(USE_HEADLESS)
context = std::make_unique<GLContextEGL>();
#elif defined(HAVE_X11) && HAVE_X11
#if defined(USE_EGL) && USE_EGL
context = std::make_unique<GLContextEGLX11>();
#else
context = std::make_unique<GLContextGLX>();
#endif
#elif ANDROID
#elif defined(ANDROID)
context = std::make_unique<GLContextEGLAndroid>();
#elif HAVE_X11
// GLES is not supported via GLX?
if (prefer_egl || prefer_gles)
context = std::make_unique<GLContextEGLX11>();
else
context = std::make_unique<GLContextGLX>();
#elif HAVE_EGL
context = std::make_unique<GLContextEGL>();
#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;

View File

@ -46,7 +46,8 @@ public:
// Creates an instance of GLContext specific to the platform we are running on.
// If successful, the context is made current on the calling thread.
static std::unique_ptr<GLContext> Create(const WindowSystemInfo& wsi, bool stereo = false,
bool core = true);
bool core = true, bool prefer_egl = false,
bool prefer_gles = false);
protected:
virtual bool Initialize(void* display_handle, void* window_handle, bool stereo, bool core);

View File

@ -9,7 +9,6 @@
#include "Common/GL/GLInterface/EGL.h"
#include "Common/Logging/Log.h"
#include "Core/Config/GraphicsSettings.h"
#ifndef EGL_KHR_create_context
#define EGL_KHR_create_context 1
@ -56,8 +55,6 @@ void* GLContextEGL::GetFuncAddress(const std::string& name)
void GLContextEGL::DetectMode(bool has_handle)
{
bool preferGLES = Config::Get(Config::GFX_PREFER_GLES);
EGLint num_configs;
bool supportsGL = false, supportsGLES3 = false;
std::array<int, 3> renderable_types{{EGL_OPENGL_BIT, EGL_OPENGL_ES3_BIT_KHR}};
@ -111,30 +108,17 @@ void GLContextEGL::DetectMode(bool has_handle)
delete[] config;
}
if (preferGLES)
{
if (supportsGLES3)
m_opengl_mode = Mode::OpenGLES;
else if (supportsGL)
m_opengl_mode = Mode::OpenGL;
}
else
{
if (supportsGL)
m_opengl_mode = Mode::OpenGL;
else if (supportsGLES3)
m_opengl_mode = Mode::OpenGLES;
}
if (m_opengl_mode == Mode::OpenGL)
if (supportsGL)
{
INFO_LOG(VIDEO, "Using OpenGL");
m_opengl_mode = Mode::OpenGL;
}
else if (m_opengl_mode == Mode::OpenGLES)
else if (supportsGLES3)
{
INFO_LOG(VIDEO, "Using OpenGL|ES");
m_opengl_mode = Mode::OpenGLES;
}
else if (m_opengl_mode == Mode::Detect)
else
{
// Errored before we found a mode
ERROR_LOG(VIDEO, "Error: Failed to detect OpenGL flavour, falling back to OpenGL");

View File

@ -24,8 +24,10 @@ if ((DEFINED CMAKE_ANDROID_ARCH_ABI AND CMAKE_ANDROID_ARCH_ABI MATCHES "x86|x86_
target_link_libraries(uicommon PRIVATE bdisasm)
endif()
if(USE_X11)
if(ENABLE_X11)
target_include_directories(uicommon PRIVATE ${X11_INCLUDE_DIR})
target_sources(uicommon PRIVATE X11Utils.cpp)
target_link_libraries(uicommon PUBLIC ${XRANDR_LIBRARIES})
endif()
if(LIBUSB_FOUND)

View File

@ -43,6 +43,8 @@ Make AA apply instantly during gameplay if possible
#include "Common/GL/GLUtil.h"
#include "Common/MsgHandler.h"
#include "Core/Config/GraphicsSettings.h"
#include "VideoBackends/OGL/BoundingBox.h"
#include "VideoBackends/OGL/PerfQuery.h"
#include "VideoBackends/OGL/ProgramShaderCache.h"
@ -162,7 +164,8 @@ bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
InitializeShared();
std::unique_ptr<GLContext> main_gl_context =
GLContext::Create(wsi, g_ActiveConfig.stereo_mode == StereoMode::QuadBuffer);
GLContext::Create(wsi, g_ActiveConfig.stereo_mode == StereoMode::QuadBuffer, true, false,
Config::Get(Config::GFX_PREFER_GLES));
if (!main_gl_context)
return false;