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

@ -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;