mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-24 06:51:17 +01: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.
|
# unique name here.
|
||||||
set(DISTRIBUTOR "None" CACHE STRING "Name of the distributor.")
|
set(DISTRIBUTOR "None" CACHE STRING "Name of the distributor.")
|
||||||
|
|
||||||
option(USE_EGL "Enables EGL OpenGL Interface" OFF)
|
if(UNIX AND NOT APPLE AND NOT ANDROID)
|
||||||
option(TRY_X11 "Enables X11 Support" ON)
|
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_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(USE_UPNP "Enables UPnP port mapping support" ON)
|
||||||
option(ENABLE_QT "Enable Qt (Default)" ON)
|
option(ENABLE_QT "Enable Qt (Default)" ON)
|
||||||
@ -365,9 +370,7 @@ if(ANDROID)
|
|||||||
# but not as a shared library. We want an executable.
|
# but not as a shared library. We want an executable.
|
||||||
set(ANDROID 0)
|
set(ANDROID 0)
|
||||||
endif()
|
endif()
|
||||||
set(USE_X11 0)
|
|
||||||
set(USE_UPNP 0)
|
set(USE_UPNP 0)
|
||||||
set(USE_EGL 1)
|
|
||||||
set(ENABLE_QT 0)
|
set(ENABLE_QT 0)
|
||||||
set(USE_DISCORD_PRESENCE 0)
|
set(USE_DISCORD_PRESENCE 0)
|
||||||
|
|
||||||
@ -379,13 +382,7 @@ if(ANDROID)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(ENABLE_HEADLESS)
|
if(ENABLE_HEADLESS)
|
||||||
if(APPLE)
|
|
||||||
message(STATUS "Enabling Headless! Disabling GUI.")
|
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)
|
|
||||||
set(ENABLE_QT 0)
|
set(ENABLE_QT 0)
|
||||||
set(USE_DISCORD_PRESENCE 0)
|
set(USE_DISCORD_PRESENCE 0)
|
||||||
add_definitions(-DUSE_HEADLESS)
|
add_definitions(-DUSE_HEADLESS)
|
||||||
@ -416,30 +413,11 @@ if (OPENGL_GL)
|
|||||||
include_directories(${OPENGL_INCLUDE_DIR})
|
include_directories(${OPENGL_INCLUDE_DIR})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(USE_X11 0)
|
if(ENABLE_X11)
|
||||||
|
find_package(X11 REQUIRED)
|
||||||
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)
|
add_definitions(-DHAVE_X11=1)
|
||||||
include_directories(${X11_INCLUDE_DIR})
|
|
||||||
message(STATUS "X11 support enabled")
|
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)
|
check_lib(XRANDR xrandr Xrandr)
|
||||||
if(XRANDR_FOUND)
|
if(XRANDR_FOUND)
|
||||||
add_definitions(-DHAVE_XRANDR=1)
|
add_definitions(-DHAVE_XRANDR=1)
|
||||||
@ -473,7 +451,7 @@ if(OPROFILING)
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(USE_EGL)
|
if(ENABLE_EGL)
|
||||||
message(STATUS "EGL OpenGL interface enabled")
|
message(STATUS "EGL OpenGL interface enabled")
|
||||||
add_definitions(-DUSE_EGL=1)
|
add_definitions(-DUSE_EGL=1)
|
||||||
endif()
|
endif()
|
||||||
|
@ -113,12 +113,10 @@ target_sources(common PRIVATE
|
|||||||
GL/GLContext.cpp
|
GL/GLContext.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
if(USE_EGL)
|
if(ENABLE_EGL)
|
||||||
target_sources(common PRIVATE GL/GLInterface/EGL.cpp)
|
target_sources(common PRIVATE GL/GLInterface/EGL.cpp)
|
||||||
if(ANDROID)
|
if(ANDROID)
|
||||||
target_sources(common PRIVATE GL/GLInterface/EGLAndroid.cpp)
|
target_sources(common PRIVATE GL/GLInterface/EGLAndroid.cpp)
|
||||||
elseif(USE_X11)
|
|
||||||
target_sources(common PRIVATE GL/GLInterface/EGLX11.cpp)
|
|
||||||
endif()
|
endif()
|
||||||
target_link_libraries(common PUBLIC EGL)
|
target_link_libraries(common PUBLIC EGL)
|
||||||
endif()
|
endif()
|
||||||
@ -130,15 +128,18 @@ if(WIN32)
|
|||||||
)
|
)
|
||||||
elseif(APPLE)
|
elseif(APPLE)
|
||||||
target_sources(common PRIVATE GL/GLInterface/AGL.mm)
|
target_sources(common PRIVATE GL/GLInterface/AGL.mm)
|
||||||
elseif(USE_X11)
|
elseif(ENABLE_X11)
|
||||||
if (NOT USE_EGL)
|
target_sources(common PRIVATE
|
||||||
target_sources(common PRIVATE GL/GLInterface/GLX.cpp)
|
GL/GLX11Window.cpp
|
||||||
|
GL/GLInterface/GLX.cpp)
|
||||||
|
|
||||||
# GLX has a hard dependency on libGL.
|
# GLX has a hard dependency on libGL.
|
||||||
# Make sure to link to it if using GLX.
|
# Make sure to link to it if using GLX.
|
||||||
target_link_libraries(common PUBLIC ${OPENGL_LIBRARIES})
|
target_link_libraries(common PUBLIC ${OPENGL_LIBRARIES})
|
||||||
|
|
||||||
|
if (ENABLE_EGL)
|
||||||
|
target_sources(common PRIVATE GL/GLInterface/EGLX11.cpp)
|
||||||
endif()
|
endif()
|
||||||
target_sources(common PRIVATE GL/GLX11Window.cpp)
|
|
||||||
target_link_libraries(common PUBLIC ${XRANDR_LIBRARIES})
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||||
|
@ -10,17 +10,13 @@
|
|||||||
#include "Common/GL/GLInterface/AGL.h"
|
#include "Common/GL/GLInterface/AGL.h"
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
#include "Common/GL/GLInterface/WGL.h"
|
#include "Common/GL/GLInterface/WGL.h"
|
||||||
#elif HAVE_X11
|
#elif defined(ANDROID)
|
||||||
#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"
|
#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
|
#endif
|
||||||
|
|
||||||
GLContext::~GLContext() = default;
|
GLContext::~GLContext() = default;
|
||||||
@ -71,26 +67,32 @@ void* GLContext::GetFuncAddress(const std::string& name)
|
|||||||
return nullptr;
|
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;
|
std::unique_ptr<GLContext> context;
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
context = std::make_unique<GLContextAGL>();
|
context = std::make_unique<GLContextAGL>();
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
context = std::make_unique<GLContextWGL>();
|
context = std::make_unique<GLContextWGL>();
|
||||||
#elif defined(USE_EGL) && defined(USE_HEADLESS)
|
#elif defined(ANDROID)
|
||||||
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
|
|
||||||
context = std::make_unique<GLContextEGLAndroid>();
|
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
|
#else
|
||||||
return nullptr;
|
return nullptr;
|
||||||
#endif
|
#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))
|
if (!context->Initialize(wsi.display_connection, wsi.render_surface, stereo, core))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
@ -46,7 +46,8 @@ public:
|
|||||||
// Creates an instance of GLContext specific to the platform we are running on.
|
// Creates an instance of GLContext specific to the platform we are running on.
|
||||||
// If successful, the context is made current on the calling thread.
|
// If successful, the context is made current on the calling thread.
|
||||||
static std::unique_ptr<GLContext> Create(const WindowSystemInfo& wsi, bool stereo = false,
|
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:
|
protected:
|
||||||
virtual bool Initialize(void* display_handle, void* window_handle, bool stereo, bool core);
|
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/GL/GLInterface/EGL.h"
|
||||||
#include "Common/Logging/Log.h"
|
#include "Common/Logging/Log.h"
|
||||||
#include "Core/Config/GraphicsSettings.h"
|
|
||||||
|
|
||||||
#ifndef EGL_KHR_create_context
|
#ifndef EGL_KHR_create_context
|
||||||
#define EGL_KHR_create_context 1
|
#define EGL_KHR_create_context 1
|
||||||
@ -56,8 +55,6 @@ void* GLContextEGL::GetFuncAddress(const std::string& name)
|
|||||||
|
|
||||||
void GLContextEGL::DetectMode(bool has_handle)
|
void GLContextEGL::DetectMode(bool has_handle)
|
||||||
{
|
{
|
||||||
bool preferGLES = Config::Get(Config::GFX_PREFER_GLES);
|
|
||||||
|
|
||||||
EGLint num_configs;
|
EGLint num_configs;
|
||||||
bool supportsGL = false, supportsGLES3 = false;
|
bool supportsGL = false, supportsGLES3 = false;
|
||||||
std::array<int, 3> renderable_types{{EGL_OPENGL_BIT, EGL_OPENGL_ES3_BIT_KHR}};
|
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;
|
delete[] config;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preferGLES)
|
|
||||||
{
|
|
||||||
if (supportsGLES3)
|
|
||||||
m_opengl_mode = Mode::OpenGLES;
|
|
||||||
else if (supportsGL)
|
|
||||||
m_opengl_mode = Mode::OpenGL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (supportsGL)
|
if (supportsGL)
|
||||||
m_opengl_mode = Mode::OpenGL;
|
|
||||||
else if (supportsGLES3)
|
|
||||||
m_opengl_mode = Mode::OpenGLES;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_opengl_mode == Mode::OpenGL)
|
|
||||||
{
|
{
|
||||||
INFO_LOG(VIDEO, "Using OpenGL");
|
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");
|
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
|
// Errored before we found a mode
|
||||||
ERROR_LOG(VIDEO, "Error: Failed to detect OpenGL flavour, falling back to OpenGL");
|
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)
|
target_link_libraries(uicommon PRIVATE bdisasm)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(USE_X11)
|
if(ENABLE_X11)
|
||||||
|
target_include_directories(uicommon PRIVATE ${X11_INCLUDE_DIR})
|
||||||
target_sources(uicommon PRIVATE X11Utils.cpp)
|
target_sources(uicommon PRIVATE X11Utils.cpp)
|
||||||
|
target_link_libraries(uicommon PUBLIC ${XRANDR_LIBRARIES})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(LIBUSB_FOUND)
|
if(LIBUSB_FOUND)
|
||||||
|
@ -43,6 +43,8 @@ Make AA apply instantly during gameplay if possible
|
|||||||
#include "Common/GL/GLUtil.h"
|
#include "Common/GL/GLUtil.h"
|
||||||
#include "Common/MsgHandler.h"
|
#include "Common/MsgHandler.h"
|
||||||
|
|
||||||
|
#include "Core/Config/GraphicsSettings.h"
|
||||||
|
|
||||||
#include "VideoBackends/OGL/BoundingBox.h"
|
#include "VideoBackends/OGL/BoundingBox.h"
|
||||||
#include "VideoBackends/OGL/PerfQuery.h"
|
#include "VideoBackends/OGL/PerfQuery.h"
|
||||||
#include "VideoBackends/OGL/ProgramShaderCache.h"
|
#include "VideoBackends/OGL/ProgramShaderCache.h"
|
||||||
@ -162,7 +164,8 @@ bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
|
|||||||
InitializeShared();
|
InitializeShared();
|
||||||
|
|
||||||
std::unique_ptr<GLContext> main_gl_context =
|
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)
|
if (!main_gl_context)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user