mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 13:27:45 -07:00
GLContext: Runtime selection of EGL/GLX on Linux
This commit is contained in:
parent
025e909773
commit
0559311f92
@ -16,8 +16,13 @@ project(dolphin-emu)
|
||||
# unique name here.
|
||||
set(DISTRIBUTOR "None" CACHE STRING "Name of the distributor.")
|
||||
|
||||
option(USE_EGL "Enables EGL OpenGL Interface" OFF)
|
||||
option(TRY_X11 "Enables X11 Support" ON)
|
||||
if(UNIX AND NOT APPLE AND NOT ANDROID)
|
||||
option(ENABLE_X11 "Enables X11 Support" ON)
|
||||
endif()
|
||||
if(NOT WIN32 AND NOT APPLE)
|
||||
option(ENABLE_EGL "Enables EGL OpenGL Interface" ON)
|
||||
endif()
|
||||
|
||||
option(USE_SHARED_ENET "Use shared libenet if found rather than Dolphin's soon-to-compatibly-diverge version" OFF)
|
||||
option(USE_UPNP "Enables UPnP port mapping support" ON)
|
||||
option(ENABLE_QT "Enable Qt (Default)" ON)
|
||||
@ -365,9 +370,7 @@ if(ANDROID)
|
||||
# but not as a shared library. We want an executable.
|
||||
set(ANDROID 0)
|
||||
endif()
|
||||
set(USE_X11 0)
|
||||
set(USE_UPNP 0)
|
||||
set(USE_EGL 1)
|
||||
set(ENABLE_QT 0)
|
||||
set(USE_DISCORD_PRESENCE 0)
|
||||
|
||||
@ -379,13 +382,7 @@ if(ANDROID)
|
||||
endif()
|
||||
|
||||
if(ENABLE_HEADLESS)
|
||||
if(APPLE)
|
||||
message(STATUS "Enabling Headless! Disabling GUI.")
|
||||
else()
|
||||
message(STATUS "Enabling Headless! Disabling GUI, force enabling EGL!")
|
||||
set(USE_EGL 1)
|
||||
endif()
|
||||
set(USE_X11 0)
|
||||
message(STATUS "Enabling Headless! Disabling GUI.")
|
||||
set(ENABLE_QT 0)
|
||||
set(USE_DISCORD_PRESENCE 0)
|
||||
add_definitions(-DUSE_HEADLESS)
|
||||
@ -416,30 +413,11 @@ if (OPENGL_GL)
|
||||
include_directories(${OPENGL_INCLUDE_DIR})
|
||||
endif()
|
||||
|
||||
set(USE_X11 0)
|
||||
if(ENABLE_X11)
|
||||
find_package(X11 REQUIRED)
|
||||
add_definitions(-DHAVE_X11=1)
|
||||
message(STATUS "X11 support enabled")
|
||||
|
||||
if(UNIX AND NOT APPLE AND NOT ANDROID AND NOT ENABLE_HEADLESS)
|
||||
find_package(X11)
|
||||
if(TRY_X11 AND X11_FOUND)
|
||||
set(USE_X11 1)
|
||||
add_definitions(-DHAVE_X11=1)
|
||||
include_directories(${X11_INCLUDE_DIR})
|
||||
message(STATUS "X11 support enabled")
|
||||
else()
|
||||
set(USE_X11 0)
|
||||
SET(X11_FOUND "")
|
||||
message(STATUS "X11 support disabled")
|
||||
add_definitions(-DHAVE_X11=0)
|
||||
endif()
|
||||
|
||||
if (NOT USE_X11)
|
||||
message(FATAL_ERROR "\n"
|
||||
"No suitable display platform found\n"
|
||||
"Requires x11 to run")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(USE_X11)
|
||||
check_lib(XRANDR xrandr Xrandr)
|
||||
if(XRANDR_FOUND)
|
||||
add_definitions(-DHAVE_XRANDR=1)
|
||||
@ -473,7 +451,7 @@ if(OPROFILING)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(USE_EGL)
|
||||
if(ENABLE_EGL)
|
||||
message(STATUS "EGL OpenGL interface enabled")
|
||||
add_definitions(-DUSE_EGL=1)
|
||||
endif()
|
||||
|
@ -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")
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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");
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user