From e83359b9d87ff5a4dca8bd8a9f332b5aaedd323b Mon Sep 17 00:00:00 2001 From: SSimco <37044560+SSimco@users.noreply.github.com> Date: Sun, 30 Jul 2023 11:50:23 +0300 Subject: [PATCH] Remove gui dependency from all projects except CemuBin --- src/CMakeLists.txt | 10 +++++--- .../Latte/Renderer/OpenGL/OpenGLRenderer.cpp | 25 +++++++++++++------ .../HW/Latte/Renderer/OpenGL/OpenGLRenderer.h | 14 +++++++++++ src/Cemu/CMakeLists.txt | 1 - src/audio/CMakeLists.txt | 1 - src/gui/canvas/OpenGLCanvas.cpp | 14 +++++++---- src/gui/canvas/VulkanCanvas.cpp | 2 +- src/gui/helpers/wxHelpers.cpp | 6 ++--- src/imgui/CMakeLists.txt | 1 - src/input/CMakeLists.txt | 1 - 10 files changed, 51 insertions(+), 24 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3e324308..d3bb5281 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -42,9 +42,10 @@ add_compile_definitions(VK_NO_PROTOTYPES) set(CMAKE_INCLUDE_CURRENT_DIR ON) add_subdirectory(Common) -add_subdirectory(gui) if(ANDROID) add_subdirectory(android/app/src/main/cpp) +else() + add_subdirectory(gui) endif() add_subdirectory(Cafe) add_subdirectory(Cemu) @@ -57,7 +58,7 @@ add_subdirectory(resource) add_subdirectory(asm) if(ANDROID) - add_library(CemuBin + add_library(CemuBin STATIC main.cpp mainLLE.cpp ) @@ -123,11 +124,14 @@ target_link_libraries(CemuBin PRIVATE CemuCommon CemuComponents CemuConfig - CemuGui CemuInput CemuUtil ) +if(NOT ANDROID) + target_link_libraries(CemuBin PRIVATE CemuGui) +endif() + if(ENABLE_OPENGL) target_link_libraries(CemuBin PRIVATE OpenGL::GL) endif() diff --git a/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp b/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp index 4bc451ed..6bfa890c 100644 --- a/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp @@ -126,7 +126,7 @@ bool OpenGLRenderer::ImguiBegin(bool mainWindow) { if (!mainWindow) { - GLCanvas_MakeCurrent(true); + m_openGLCallbacks->GLCanvas_MakeCurrent(true); m_isPadViewContext = true; } @@ -153,7 +153,7 @@ void OpenGLRenderer::ImguiEnd() if (m_isPadViewContext) { - GLCanvas_MakeCurrent(false); + m_openGLCallbacks->GLCanvas_MakeCurrent(false); m_isPadViewContext = false; } @@ -262,7 +262,7 @@ void OpenGLRenderer::Initialize() auto lock = cemuLog_acquire(); cemuLog_log(LogType::Force, "------- Init OpenGL graphics backend -------"); - GLCanvas_MakeCurrent(false); + m_openGLCallbacks->GLCanvas_MakeCurrent(false); LoadOpenGLImports(); GetVendorInformation(); @@ -354,7 +354,7 @@ void OpenGLRenderer::Initialize() bool OpenGLRenderer::IsPadWindowActive() { - return GLCanvas_HasPadViewOpen(); + return m_openGLCallbacks->GLCanvas_HasPadViewOpen(); } void OpenGLRenderer::Flush(bool waitIdle) @@ -369,6 +369,15 @@ void OpenGLRenderer::NotifyLatteCommandProcessorIdle() glFlush(); } +void OpenGLRenderer::RegisterOpenGLCallbacks(OpenGLCallbacks* openGLCallbacks) +{ + m_openGLCallbacks = openGLCallbacks; +} + +void OpenGLRenderer::UnregisterOpenGLCallbacks() +{ + m_openGLCallbacks = nullptr; +} bool IsRunningInWine(); @@ -445,7 +454,7 @@ void OpenGLRenderer::EnableDebugMode() void OpenGLRenderer::SwapBuffers(bool swapTV, bool swapDRC) { - GLCanvas_SwapBuffers(swapTV, swapDRC); + m_openGLCallbacks->GLCanvas_SwapBuffers(swapTV, swapDRC); if (swapTV) cleanupAfterFrame(); @@ -456,7 +465,7 @@ bool OpenGLRenderer::BeginFrame(bool mainWindow) if (!mainWindow && !IsPadWindowActive()) return false; - GLCanvas_MakeCurrent(!mainWindow); + m_openGLCallbacks->GLCanvas_MakeCurrent(!mainWindow); ClearColorbuffer(!mainWindow); return true; @@ -550,7 +559,7 @@ void OpenGLRenderer::DrawBackbufferQuad(LatteTextureView* texView, RendererOutpu return; catchOpenGLError(); - GLCanvas_MakeCurrent(padView); + m_openGLCallbacks->GLCanvas_MakeCurrent(padView); renderstate_resetColorControl(); renderstate_resetDepthControl(); @@ -609,7 +618,7 @@ void OpenGLRenderer::DrawBackbufferQuad(LatteTextureView* texView, RendererOutpu // switch back to TV context if (padView) - GLCanvas_MakeCurrent(false); + m_openGLCallbacks->GLCanvas_MakeCurrent(false); } void OpenGLRenderer::renderTarget_setViewport(float x, float y, float width, float height, float nearZ, float farZ, bool halfZ /*= false*/) diff --git a/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.h b/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.h index 600985ff..fe66348e 100644 --- a/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.h +++ b/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.h @@ -158,6 +158,18 @@ public: void occlusionQuery_updateState() override {}; private: + + class OpenGLCallbacks + { + public: + virtual bool GLCanvas_HasPadViewOpen() = 0; + virtual bool GLCanvas_MakeCurrent(bool padView) = 0; + virtual void GLCanvas_SwapBuffers(bool swapTV, bool swapDRC) = 0; + }; + + void RegisterOpenGLCallbacks(OpenGLCallbacks* openGLCallbacks); + void UnregisterOpenGLCallbacks(); + void GetVendorInformation() override; void texture_setActiveTextureUnit(sint32 index); @@ -165,6 +177,8 @@ private: void texture_syncSliceSpecialBC4(LatteTexture* srcTexture, sint32 srcSliceIndex, sint32 srcMipIndex, LatteTexture* dstTexture, sint32 dstSliceIndex, sint32 dstMipIndex); void texture_syncSliceSpecialIntegerToBC3(LatteTexture* srcTexture, sint32 srcSliceIndex, sint32 srcMipIndex, LatteTexture* dstTexture, sint32 dstSliceIndex, sint32 dstMipIndex); + OpenGLCallbacks* m_openGLCallbacks = nullptr; + GLuint m_defaultFramebufferId; GLuint m_pipeline = 0; diff --git a/src/Cemu/CMakeLists.txt b/src/Cemu/CMakeLists.txt index 2166dc5d..cceb7d06 100644 --- a/src/Cemu/CMakeLists.txt +++ b/src/Cemu/CMakeLists.txt @@ -42,7 +42,6 @@ target_link_libraries(CemuComponents PRIVATE CemuCafe CemuCommon CemuConfig - CemuGui CemuUtil Boost::headers CURL::libcurl diff --git a/src/audio/CMakeLists.txt b/src/audio/CMakeLists.txt index b78de255..df968047 100644 --- a/src/audio/CMakeLists.txt +++ b/src/audio/CMakeLists.txt @@ -34,7 +34,6 @@ target_link_libraries(CemuAudio PRIVATE CemuCafe CemuCommon CemuConfig - CemuGui CemuUtil ) diff --git a/src/gui/canvas/OpenGLCanvas.cpp b/src/gui/canvas/OpenGLCanvas.cpp index 7d9ec9c1..88b708f2 100644 --- a/src/gui/canvas/OpenGLCanvas.cpp +++ b/src/gui/canvas/OpenGLCanvas.cpp @@ -30,7 +30,7 @@ wxGLContext* sGLContext = nullptr; class OpenGLCanvas* sGLTVView = nullptr; class OpenGLCanvas* sGLPadView = nullptr; -class OpenGLCanvas : public IRenderCanvas, public wxGLCanvas +class OpenGLCanvas : public IRenderCanvas, public wxGLCanvas, public OpenGLRenderer::OpenGLCallbacks { public: OpenGLCanvas(wxWindow* parent, const wxSize& size, bool is_main_window) @@ -42,8 +42,8 @@ public: { sGLTVView = this; sGLContext = new wxGLContext(this); - g_renderer = std::make_unique(); + OpenGLRenderer::GetInstance()->RegisterOpenGLCallbacks(this); } else sGLPadView = this; @@ -64,6 +64,10 @@ public: delete sGLContext; } + bool GLCanvas_HasPadViewOpen() override; + bool GLCanvas_MakeCurrent(bool padView) override; + void GLCanvas_SwapBuffers(bool swapTV, bool swapDRC) override; + void UpdateVSyncState() { int configValue = GetConfig().vsync.GetValue(); @@ -97,12 +101,12 @@ wxWindow* GLCanvas_Create(wxWindow* parent, const wxSize& size, bool is_main_win return new OpenGLCanvas(parent, size, is_main_window); } -bool GLCanvas_HasPadViewOpen() +bool OpenGLCanvas::GLCanvas_HasPadViewOpen() { return sGLPadView != nullptr; } -bool GLCanvas_MakeCurrent(bool padView) +bool OpenGLCanvas::GLCanvas_MakeCurrent(bool padView) { OpenGLCanvas* canvas = padView ? sGLPadView : sGLTVView; if (!canvas) @@ -111,7 +115,7 @@ bool GLCanvas_MakeCurrent(bool padView) return true; } -void GLCanvas_SwapBuffers(bool swapTV, bool swapDRC) +void OpenGLCanvas::GLCanvas_SwapBuffers(bool swapTV, bool swapDRC) { if (swapTV && sGLTVView) { diff --git a/src/gui/canvas/VulkanCanvas.cpp b/src/gui/canvas/VulkanCanvas.cpp index 418f7c63..8f59c2c8 100644 --- a/src/gui/canvas/VulkanCanvas.cpp +++ b/src/gui/canvas/VulkanCanvas.cpp @@ -18,7 +18,7 @@ VulkanCanvas::VulkanCanvas(wxWindow* parent, const wxSize& size, bool is_main_wi auto& canvas = is_main_window ? GuiSystem::getWindowInfo().canvas_main : GuiSystem::getWindowInfo().canvas_pad; canvas = get_window_handle_info_for_wxWindow(this); #if BOOST_OS_LINUX && HAS_WAYLAND - if (canvas.backend == GuiSystem::WindowHandleInfo::Backend::WAYLAND) + if (canvas.backend == GuiSystem::WindowHandleInfo::Backend::Wayland) { m_subsurface = std::make_unique(this); canvas.surface = m_subsurface->getSurface(); diff --git a/src/gui/helpers/wxHelpers.cpp b/src/gui/helpers/wxHelpers.cpp index 5d1efcaa..9031cfb9 100644 --- a/src/gui/helpers/wxHelpers.cpp +++ b/src/gui/helpers/wxHelpers.cpp @@ -143,7 +143,7 @@ GuiSystem::WindowHandleInfo get_window_handle_info_for_wxWindow(wxWindow* wxw) { GuiSystem::WindowHandleInfo handleInfo; #if BOOST_OS_WINDOWS - handleInfo.backend = GuiSystem::WindowHandleInfo::Backend::WINDOWS; + handleInfo.backend = GuiSystem::WindowHandleInfo::Backend::Windows; handleInfo.surface = reinterpret_cast(wxw->GetHWND()); #elif BOOST_OS_LINUX GtkWidget* gtkWidget = (GtkWidget*)wxw->GetHandle(); // returns GtkWidget @@ -163,7 +163,7 @@ GuiSystem::WindowHandleInfo get_window_handle_info_for_wxWindow(wxWindow* wxw) #ifdef HAS_WAYLAND else if (GDK_IS_WAYLAND_WINDOW(gdkWindow)) { - handleInfo.backend = GuiSystem::WindowHandleInfo::Backend::WAYLAND; + handleInfo.backend = GuiSystem::WindowHandleInfo::Backend::Wayland; handleInfo.surface = gdk_wayland_window_get_wl_surface(gdkWindow); handleInfo.display = gdk_wayland_display_get_wl_display(gdkDisplay); } @@ -173,7 +173,7 @@ GuiSystem::WindowHandleInfo get_window_handle_info_for_wxWindow(wxWindow* wxw) cemuLog_log(LogType::Force, "Unsuported GTK backend"); } #elif BOOST_OS_MACOS - handleInfo.backend = GuiSystem::WindowHandleInfo::Backend::COCOA; + handleInfo.backend = GuiSystem::WindowHandleInfo::Backend::Cocoa; handleInfo.surface = reinterpret_cast(wxw->GetHandle()); #endif return handleInfo; diff --git a/src/imgui/CMakeLists.txt b/src/imgui/CMakeLists.txt index db7686bd..107e0409 100644 --- a/src/imgui/CMakeLists.txt +++ b/src/imgui/CMakeLists.txt @@ -24,7 +24,6 @@ target_include_directories(imguiImpl PUBLIC "../../dependencies/imgui/") target_link_libraries(imguiImpl PRIVATE CemuCafe CemuCommon - CemuGui CemuInput CemuResource CemuUtil diff --git a/src/input/CMakeLists.txt b/src/input/CMakeLists.txt index 65569ecb..1ee2fcc3 100644 --- a/src/input/CMakeLists.txt +++ b/src/input/CMakeLists.txt @@ -92,7 +92,6 @@ target_link_libraries(CemuInput PRIVATE CemuCafe CemuCommon CemuConfig - CemuGui CemuUtil Boost::headers Boost::program_options