diff --git a/3rdparty/imgui/CMakeLists.txt b/3rdparty/imgui/CMakeLists.txt index 622695386d..3d3c084ffb 100644 --- a/3rdparty/imgui/CMakeLists.txt +++ b/3rdparty/imgui/CMakeLists.txt @@ -10,17 +10,21 @@ add_library(imgui imgui/imstb_rectpack.h imgui/imstb_textedit.h imgui/imstb_truetype.h - include/imgui_impl_opengl3.h - src/imgui_impl_opengl3.cpp ) +target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/imgui" "${CMAKE_CURRENT_SOURCE_DIR}/include") + +if(USE_OPENGL) + target_sources(imgui PRIVATE + include/imgui_impl_opengl3.h + src/imgui_impl_opengl3.cpp + ) + target_link_libraries(imgui glad) +endif() + if(WIN32) target_sources(imgui PRIVATE include/imgui_impl_dx11.h src/imgui_impl_dx11.cpp ) endif() - -target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/imgui" "${CMAKE_CURRENT_SOURCE_DIR}/include") -target_link_libraries(imgui glad) - diff --git a/cmake/BuildParameters.cmake b/cmake/BuildParameters.cmake index dbb4f0bfbd..981524dc6d 100644 --- a/cmake/BuildParameters.cmake +++ b/cmake/BuildParameters.cmake @@ -38,6 +38,7 @@ option(USE_VTUNE "Plug VTUNE to profile GS JIT.") # Graphical option #------------------------------------------------------------------------------- option(BUILD_REPLAY_LOADERS "Build GS replayer to ease testing (developer option)") +option(USE_OPENGL "Enable OpenGL GS renderer" ON) option(USE_VULKAN "Enable Vulkan GS renderer" ON) #------------------------------------------------------------------------------- @@ -206,6 +207,10 @@ if(USE_VTUNE) list(APPEND PCSX2_DEFS ENABLE_VTUNE) endif() +if(USE_OPENGL) + list(APPEND PCSX2_DEFS ENABLE_OPENGL) +endif() + if(USE_VULKAN) list(APPEND PCSX2_DEFS ENABLE_VULKAN) endif() diff --git a/cmake/SearchForStuff.cmake b/cmake/SearchForStuff.cmake index f65acc7b06..db50994554 100644 --- a/cmake/SearchForStuff.cmake +++ b/cmake/SearchForStuff.cmake @@ -29,8 +29,10 @@ else() # Using find_package OpenGL without either setting your opengl preference to GLVND or LEGACY # is deprecated as of cmake 3.11. - set(OpenGL_GL_PREFERENCE GLVND) - find_package(OpenGL REQUIRED) + if(USE_OPENGL) + set(OpenGL_GL_PREFERENCE GLVND) + find_package(OpenGL REQUIRED) + endif() find_package(PNG REQUIRED) find_package(Vtune) @@ -115,7 +117,9 @@ else() include(CheckLib) if(UNIX AND NOT APPLE) - check_lib(EGL EGL EGL/egl.h) + if(USE_OPENGL) + check_lib(EGL EGL EGL/egl.h) + endif() if(X11_API) check_lib(X11_XCB X11-xcb X11/Xlib-xcb.h) check_lib(XCB xcb xcb/xcb.h) @@ -259,10 +263,13 @@ else() set(BIN2CPPDEP ${CMAKE_SOURCE_DIR}/linux_various/hex2h.pl) endif() -add_subdirectory(3rdparty/glad EXCLUDE_FROM_ALL) add_subdirectory(3rdparty/simpleini EXCLUDE_FROM_ALL) add_subdirectory(3rdparty/imgui EXCLUDE_FROM_ALL) +if(USE_OPENGL) + add_subdirectory(3rdparty/glad EXCLUDE_FROM_ALL) +endif() + if(USE_VULKAN) add_subdirectory(3rdparty/glslang EXCLUDE_FROM_ALL) add_subdirectory(3rdparty/vulkan-headers EXCLUDE_FROM_ALL) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 163f31aeff..d784155a0f 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -18,10 +18,6 @@ target_sources(common PRIVATE Exceptions.cpp FastFormatString.cpp FastJmp.cpp - GL/Context.cpp - GL/Program.cpp - GL/ShaderCache.cpp - GL/StreamBuffer.cpp FileSystem.cpp IniInterface.cpp Mutex.cpp @@ -78,10 +74,6 @@ target_sources(common PRIVATE FastJmp.h FileSystem.h General.h - GL/Context.h - GL/Program.h - GL/ShaderCache.h - GL/StreamBuffer.h HashCombine.h MemcpyFast.h MemsetFast.inl @@ -134,6 +126,22 @@ target_sources(common PRIVATE emitter/x86types.h ) +if(USE_OPENGL) + target_sources(common PRIVATE + GL/Context.cpp + GL/Program.cpp + GL/ShaderCache.cpp + GL/StreamBuffer.cpp + ) + target_sources(common PRIVATE + GL/Context.h + GL/Program.h + GL/ShaderCache.h + GL/StreamBuffer.h + ) + target_link_libraries(common PUBLIC glad) +endif() + if(USE_VULKAN) target_link_libraries(common PUBLIC Vulkan-Headers glslang @@ -176,46 +184,66 @@ if(WIN32) D3D11/ShaderCache.h D3D11/ShaderCompiler.cpp D3D11/ShaderCompiler.h - GL/ContextWGL.cpp - GL/ContextWGL.h ) - target_link_libraries(common PUBLIC pthreads4w Winmm.lib opengl32.lib) -elseif(APPLE) - target_sources(common PRIVATE - GL/ContextAGL.mm - GL/ContextAGL.h - ) - set_source_files_properties(GL/ContextAGL.mm PROPERTIES SKIP_PRECOMPILE_HEADERS ON) - target_compile_options(common PRIVATE -fobjc-arc) - target_link_options(common PRIVATE -fobjc-link-runtime) -else() - if(X11_API OR WAYLAND_API) - target_sources(common PRIVATE - GL/ContextEGL.cpp - GL/ContextEGL.h - ) - target_link_libraries(common PRIVATE PkgConfig::EGL) - endif() +endif() - if(X11_API) +if(USE_OPENGL) + if(WIN32) target_sources(common PRIVATE - GL/ContextEGLX11.cpp - GL/ContextEGLX11.h + GL/ContextWGL.cpp + GL/ContextWGL.h ) - target_compile_definitions(common PUBLIC "VULKAN_USE_X11=1") - if(TARGET PkgConfig::XRANDR) - target_link_libraries(common PRIVATE PkgConfig::XRANDR) - target_compile_definitions(common PRIVATE "HAS_XRANDR=1") + target_link_libraries(common PUBLIC opengl32.lib) + elseif(APPLE) + target_sources(common PRIVATE + GL/ContextAGL.mm + GL/ContextAGL.h + ) + set_source_files_properties(GL/ContextAGL.mm PROPERTIES SKIP_PRECOMPILE_HEADERS ON) + target_compile_options(common PRIVATE -fobjc-arc) + target_link_options(common PRIVATE -fobjc-link-runtime) + else() + if(X11_API OR WAYLAND_API) + target_sources(common PRIVATE + GL/ContextEGL.cpp + GL/ContextEGL.h + ) + target_link_libraries(common PRIVATE PkgConfig::EGL) + endif() + + if(X11_API) + target_sources(common PRIVATE + GL/ContextEGLX11.cpp + GL/ContextEGLX11.h + ) + if(TARGET PkgConfig::XRANDR) + target_link_libraries(common PRIVATE PkgConfig::XRANDR) + target_compile_definitions(common PRIVATE "HAS_XRANDR=1") + endif() + endif() + + if(WAYLAND_API) + target_sources(common PRIVATE + GL/ContextEGLWayland.cpp + GL/ContextEGLWayland.h + ) + target_link_libraries(common PRIVATE ${WAYLAND_EGL_LIBRARIES}) endif() endif() +endif() - if(WAYLAND_API) - target_sources(common PRIVATE - GL/ContextEGLWayland.cpp - GL/ContextEGLWayland.h - ) - target_link_libraries(common PRIVATE ${WAYLAND_EGL_LIBRARIES}) - target_compile_definitions(common PUBLIC "VULKAN_USE_WAYLAND=1") +if(USE_VULKAN) + if(APPLE) + # Needed for Metal surface creation. + target_compile_options(common PRIVATE -fobjc-arc) + target_link_options(common PRIVATE -fobjc-link-runtime) + elseif(NOT WIN32) + if(X11_API) + target_compile_definitions(common PUBLIC "VULKAN_USE_X11=1") + endif() + if(WAYLAND_API) + target_compile_definitions(common PUBLIC "VULKAN_USE_WAYLAND=1") + endif() endif() endif() @@ -224,7 +252,7 @@ if (USE_GCC AND CMAKE_INTERPROCEDURAL_OPTIMIZATION) set_source_files_properties(FastJmp.cpp PROPERTIES COMPILE_FLAGS -fno-lto) endif() -target_link_libraries(common PRIVATE ${LIBC_LIBRARIES} PUBLIC wxWidgets::all glad) +target_link_libraries(common PRIVATE ${LIBC_LIBRARIES} PUBLIC wxWidgets::all) target_compile_features(common PUBLIC cxx_std_17) target_include_directories(common PUBLIC ../3rdparty/include ../) target_compile_definitions(common PUBLIC "${PCSX2_DEFS}") diff --git a/pcsx2-qt/Settings/GraphicsSettingsWidget.cpp b/pcsx2-qt/Settings/GraphicsSettingsWidget.cpp index fb08628102..8f40aa1ac4 100644 --- a/pcsx2-qt/Settings/GraphicsSettingsWidget.cpp +++ b/pcsx2-qt/Settings/GraphicsSettingsWidget.cpp @@ -43,10 +43,18 @@ static constexpr RendererInfo s_renderer_info[] = { QT_TRANSLATE_NOOP("GraphicsSettingsWidget", "Direct3D 11"), GSRendererType::DX11, #endif +#ifdef ENABLE_OPENGL QT_TRANSLATE_NOOP("GraphicsSettingsWidget", "OpenGL"), GSRendererType::OGL, +#endif +#ifdef ENABLE_VULKAN QT_TRANSLATE_NOOP("GraphicsSettingsWidget", "Vulkan"), GSRendererType::VK, +#endif +#ifdef __APPLE__ + QT_TRANSLATE_NOOP("GraphicsSettingsWidget", "Metal"), + GSRendererType::Metal, +#endif QT_TRANSLATE_NOOP("GraphicsSettingsWidget", "Software"), GSRendererType::SW, QT_TRANSLATE_NOOP("GraphicsSettingsWidget", "Null"), diff --git a/pcsx2-qt/pcsx2-qt.vcxproj b/pcsx2-qt/pcsx2-qt.vcxproj index 14e458e6b6..d19024a462 100644 --- a/pcsx2-qt/pcsx2-qt.vcxproj +++ b/pcsx2-qt/pcsx2-qt.vcxproj @@ -50,7 +50,7 @@ Use PrecompiledHeader.h NoExtensions - WIN32_LEAN_AND_MEAN;LZMA_API_STATIC;BUILD_DX=1;SPU2X_PORTAUDIO;DIRECTINPUT_VERSION=0x0800;PCSX2_CORE;DISABLE_RECORDING;%(PreprocessorDefinitions) + WIN32_LEAN_AND_MEAN;LZMA_API_STATIC;BUILD_DX=1;ENABLE_OPENGL;ENABLE_VULKAN;DIRECTINPUT_VERSION=0x0800;PCSX2_CORE;DISABLE_RECORDING;%(PreprocessorDefinitions) PCSX2_DEBUG;PCSX2_DEVBUILD;_SECURE_SCL_=1;%(PreprocessorDefinitions) PCSX2_DEVEL;PCSX2_DEVBUILD;NDEBUG;_SECURE_SCL_=1;%(PreprocessorDefinitions) NDEBUG;_SECURE_SCL_=0;%(PreprocessorDefinitions) diff --git a/pcsx2/CMakeLists.txt b/pcsx2/CMakeLists.txt index 51885679ac..8f3c0f3d6a 100644 --- a/pcsx2/CMakeLists.txt +++ b/pcsx2/CMakeLists.txt @@ -699,10 +699,6 @@ set(pcsx2GSSources GS/Renderers/SW/GSSetupPrimCodeGenerator.all.cpp GS/Renderers/SW/GSTextureCacheSW.cpp GS/Renderers/SW/GSTextureSW.cpp - GS/Renderers/OpenGL/GLLoader.cpp - GS/Renderers/OpenGL/GLState.cpp - GS/Renderers/OpenGL/GSDeviceOGL.cpp - GS/Renderers/OpenGL/GSTextureOGL.cpp GS/Window/GSSetting.cpp ) @@ -767,16 +763,28 @@ set(pcsx2GSHeaders GS/Renderers/SW/GSTextureCacheSW.h GS/Renderers/SW/GSTextureSW.h GS/Renderers/SW/GSVertexSW.h - GS/Renderers/OpenGL/GLLoader.h - GS/Renderers/OpenGL/GLState.h - GS/Renderers/OpenGL/GSDeviceOGL.h - GS/Renderers/OpenGL/GSTextureOGL.h - GS/Renderers/OpenGL/GSUniformBufferOGL.h GS/Window/GSCaptureDlg.h GS/Window/GSDialog.h GS/Window/GSSetting.h ) +if(USE_OPENGL) + list(APPEND pcsx2GSSources + GS/Renderers/OpenGL/GLLoader.cpp + GS/Renderers/OpenGL/GLState.cpp + GS/Renderers/OpenGL/GSDeviceOGL.cpp + GS/Renderers/OpenGL/GSTextureOGL.cpp + ) + list(APPEND pcsx2GSHeaders + GS/Renderers/OpenGL/GLLoader.h + GS/Renderers/OpenGL/GLState.h + GS/Renderers/OpenGL/GSDeviceOGL.h + GS/Renderers/OpenGL/GSTextureOGL.h + GS/Renderers/OpenGL/GSUniformBufferOGL.h + ) + target_link_libraries(PCSX2_FLAGS INTERFACE glad) +endif() + if(USE_VULKAN) list(APPEND pcsx2GSSources GS/Renderers/Vulkan/GSDeviceVK.cpp @@ -984,15 +992,22 @@ set(pcsx2DebugToolsHeaders # Frontend sources set(pcsx2FrontendSources Frontend/ImGuiManager.cpp - Frontend/OpenGLHostDisplay.cpp ) # Frontend headers set(pcsx2FrontendHeaders Frontend/ImGuiManager.h - Frontend/OpenGLHostDisplay.h ) +if(USE_OPENGL) + list(APPEND pcsx2FrontendSources + Frontend/OpenGLHostDisplay.cpp + ) + list(APPEND pcsx2FrontendHeaders + Frontend/OpenGLHostDisplay.h + ) +endif() + if(USE_VULKAN) list(APPEND pcsx2FrontendSources Frontend/VulkanHostDisplay.cpp @@ -1579,7 +1594,6 @@ endif() target_link_libraries(PCSX2_FLAGS INTERFACE common - glad imgui fmt::fmt ryml diff --git a/pcsx2/GS/GS.cpp b/pcsx2/GS/GS.cpp index 7c2a73b4ae..2b197b6c04 100644 --- a/pcsx2/GS/GS.cpp +++ b/pcsx2/GS/GS.cpp @@ -25,8 +25,6 @@ #include "Renderers/SW/GSRendererSW.h" #include "Renderers/Null/GSRendererNull.h" #include "Renderers/Null/GSDeviceNull.h" -#include "Renderers/OpenGL/GSDeviceOGL.h" -#include "Renderers/Metal/GSMetalCPPAccessible.h" #include "Renderers/HW/GSRendererNew.h" #include "Renderers/HW/GSTextureReplacements.h" #include "GSLzma.h" @@ -45,6 +43,14 @@ #include "pcsx2/Frontend/InputManager.h" #endif +#ifdef ENABLE_OPENGL +#include "Renderers/OpenGL/GSDeviceOGL.h" +#endif + +#ifdef __APPLE__ +#include "Renderers/Metal/GSMetalCPPAccessible.h" +#endif + #ifdef ENABLE_VULKAN #include "Renderers/Vulkan/GSDeviceVK.h" #endif @@ -157,27 +163,44 @@ void GSclose() static HostDisplay::RenderAPI GetAPIForRenderer(GSRendererType renderer) { +#if defined(_WIN32) + // On Windows, we use DX11 for software, since it's always available. + constexpr HostDisplay::RenderAPI default_api = HostDisplay::RenderAPI::D3D11; +#elif defined(__APPLE__) + // For Macs, default to Metal. + constexpr HostDisplay::RenderAPI default_api = HostDisplay::RenderAPI::Metal; +#else + // For Linux, default to OpenGL (because of hardware compatibility), if we + // have it, otherwise Vulkan (if we have it). +#if defined(ENABLE_OPENGL) + constexpr HostDisplay::RenderAPI default_api = HostDisplay::RenderAPI::OpenGL; +#elif defined(ENABLE_VULKAN) + constexpr HostDisplay::RenderAPI default_api = HostDisplay::RenderAPI::Vulkan; +#else + constexpr HostDisplay::RenderAPI default_api = HostDisplay::RenderAPI::None; +#endif +#endif + switch (renderer) { case GSRendererType::OGL: -#ifndef _WIN32 - default: -#endif return HostDisplay::RenderAPI::OpenGL; case GSRendererType::VK: return HostDisplay::RenderAPI::Vulkan; +#ifdef _WIN32 + case GSRendererType::DX11: + return HostDisplay::RenderAPI::D3D11; +#endif + #ifdef __APPLE__ case GSRendererType::Metal: return HostDisplay::RenderAPI::Metal; #endif -#ifdef _WIN32 - case GSRendererType::DX11: - case GSRendererType::SW: + default: - return HostDisplay::RenderAPI::D3D11; -#endif + return default_api; } } @@ -200,10 +223,12 @@ static bool DoGSOpen(GSRendererType renderer, u8* basemem) g_gs_device = std::unique_ptr(MakeGSDeviceMTL()); break; #endif +#ifdef ENABLE_OPENGL case HostDisplay::RenderAPI::OpenGL: case HostDisplay::RenderAPI::OpenGLES: g_gs_device = std::make_unique(); break; +#endif #ifdef ENABLE_VULKAN case HostDisplay::RenderAPI::Vulkan: @@ -1200,7 +1225,9 @@ void GSApp::Init() #ifdef __APPLE__ m_gs_renderers.push_back(GSSetting(static_cast(GSRendererType::Metal), "Metal", "")); #endif +#ifdef ENABLE_OPENGL m_gs_renderers.push_back(GSSetting(static_cast(GSRendererType::OGL), "OpenGL", "")); +#endif #ifdef ENABLE_VULKAN m_gs_renderers.push_back(GSSetting(static_cast(GSRendererType::VK), "Vulkan", "")); #endif diff --git a/pcsx2/GS/GSUtil.cpp b/pcsx2/GS/GSUtil.cpp index e12ed986d6..f0ee91865b 100644 --- a/pcsx2/GS/GSUtil.cpp +++ b/pcsx2/GS/GSUtil.cpp @@ -190,14 +190,30 @@ CRCHackLevel GSUtil::GetRecommendedCRCHackLevel(GSRendererType type) GSRendererType GSUtil::GetPreferredRenderer() { -#ifdef __APPLE__ +#if defined(__APPLE__) + // Mac: Prefer Metal hardware. return GSRendererType::Metal; -#endif -#ifdef _WIN32 +#elif defined(_WIN32) +#if defined(ENABLE_OPENGL) + // Windows: Prefer GL if available. if (D3D::ShouldPreferD3D()) return GSRendererType::DX11; + else + return GSRendererType::OGL; +#else + // DX11 is always available, otherwise. + return GSRendererType::DX11; #endif +#else + // Linux: Prefer GL/Vulkan, whatever is available. +#if defined(ENABLE_OPENGL) return GSRendererType::OGL; +#elif defined(ENABLE_VULKAN) + return GSRendererType::Vulkan; +#else + return GSRendererType::SW; +#endif +#endif } #ifdef _WIN32 diff --git a/pcsx2/HostDisplay.cpp b/pcsx2/HostDisplay.cpp index a8c3ce6e58..de2d1c0469 100644 --- a/pcsx2/HostDisplay.cpp +++ b/pcsx2/HostDisplay.cpp @@ -124,7 +124,9 @@ std::string HostDisplay::GetFullscreenModeString(u32 width, u32 height, float re return StringUtil::StdStringFromFormat("%u x %u @ %f hz", width, height, refresh_rate); } +#ifdef ENABLE_OPENGL #include "Frontend/OpenGLHostDisplay.h" +#endif #ifdef ENABLE_VULKAN #include "Frontend/VulkanHostDisplay.h" @@ -148,9 +150,11 @@ std::unique_ptr HostDisplay::CreateDisplayForAPI(RenderAPI api) return std::unique_ptr(MakeMetalHostDisplay()); #endif +#ifdef ENABLE_OPENGL case RenderAPI::OpenGL: case RenderAPI::OpenGLES: return std::make_unique(); +#endif #ifdef ENABLE_VULKAN case RenderAPI::Vulkan: diff --git a/pcsx2/gui/AppHost.cpp b/pcsx2/gui/AppHost.cpp index 382573747d..45b50c72d8 100644 --- a/pcsx2/gui/AppHost.cpp +++ b/pcsx2/gui/AppHost.cpp @@ -27,10 +27,6 @@ #include "common/Assertions.h" #include "Frontend/ImGuiManager.h" -#include "Frontend/OpenGLHostDisplay.h" -#ifdef _WIN32 -#include "Frontend/D3D11HostDisplay.h" -#endif #include "gui/App.h" #include "gui/AppHost.h" diff --git a/pcsx2/pcsx2.vcxproj b/pcsx2/pcsx2.vcxproj index 8033ed647d..83b4572e43 100644 --- a/pcsx2/pcsx2.vcxproj +++ b/pcsx2/pcsx2.vcxproj @@ -48,7 +48,7 @@ PrecompiledHeader.h;%(ForcedIncludeFiles) NoExtensions /Zc:externConstexpr %(AdditionalOptions) - WIN32_LEAN_AND_MEAN;LZMA_API_STATIC;BUILD_DX=1;ENABLE_VULKAN;SPU2X_CUBEB;DIRECTINPUT_VERSION=0x0800;%(PreprocessorDefinitions) + WIN32_LEAN_AND_MEAN;LZMA_API_STATIC;BUILD_DX=1;ENABLE_OPENGL;ENABLE_VULKAN;SPU2X_CUBEB;DIRECTINPUT_VERSION=0x0800;%(PreprocessorDefinitions) PCSX2_DEBUG;PCSX2_DEVBUILD;_SECURE_SCL_=1;%(PreprocessorDefinitions) PCSX2_DEVEL;PCSX2_DEVBUILD;NDEBUG;_SECURE_SCL_=1;%(PreprocessorDefinitions) NDEBUG;_SECURE_SCL_=0;%(PreprocessorDefinitions) diff --git a/pcsx2/pcsx2core.vcxproj b/pcsx2/pcsx2core.vcxproj index 6748a20a5f..b11984aaa2 100644 --- a/pcsx2/pcsx2core.vcxproj +++ b/pcsx2/pcsx2core.vcxproj @@ -52,7 +52,7 @@ PrecompiledHeader.h;%(ForcedIncludeFiles) NoExtensions /Zc:externConstexpr %(AdditionalOptions) - WIN32_LEAN_AND_MEAN;LZMA_API_STATIC;BUILD_DX=1;ENABLE_VULKAN;SPU2X_CUBEB;SDL_BUILD;PCSX2_CORE;DISABLE_RECORDING;%(PreprocessorDefinitions) + WIN32_LEAN_AND_MEAN;LZMA_API_STATIC;BUILD_DX=1;ENABLE_OPENGL;ENABLE_VULKAN;SPU2X_CUBEB;SDL_BUILD;PCSX2_CORE;DISABLE_RECORDING;%(PreprocessorDefinitions) PCSX2_DEBUG;PCSX2_DEVBUILD;_SECURE_SCL_=1;%(PreprocessorDefinitions) PCSX2_DEVEL;PCSX2_DEVBUILD;NDEBUG;_SECURE_SCL_=1;%(PreprocessorDefinitions) NDEBUG;_SECURE_SCL_=0;%(PreprocessorDefinitions)