From a4fcb1c4dc78d6a4eee0f97f5316fb2d8485fe31 Mon Sep 17 00:00:00 2001 From: offtkp Date: Thu, 8 Aug 2024 23:15:53 +0300 Subject: [PATCH] Make Qt work --- CMakeLists.txt | 2 +- include/emulator.hpp | 2 +- include/renderer_gl/renderer_gl.hpp | 5 ++--- src/core/renderer_gl/renderer_gl.cpp | 17 +++++++++----- src/jni_driver.cpp | 15 ++++++++++++- src/panda_qt/main_window.cpp | 31 ++++++++++++++++++++++++++ third_party/duckstation/gl/context.cpp | 9 +------- 7 files changed, 61 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ef275edc..2b456f4a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -302,7 +302,7 @@ if(ENABLE_QT_GUI) set(THIRD_PARTY_SOURCE_FILES ${THIRD_PARTY_SOURCE_FILES} third_party/duckstation/gl/context_wgl.cpp) else() set(THIRD_PARTY_SOURCE_FILES ${THIRD_PARTY_SOURCE_FILES} third_party/duckstation/gl/context_egl.cpp third_party/duckstation/gl/context_egl_wayland.cpp - third_party/duckstation/gl/context_egl_x11.cpp third_party/duckstation/gl/context_glx.cpp third_party/duckstation/gl/x11_window.cpp) + third_party/duckstation/gl/context_egl_x11.cpp third_party/duckstation/gl/x11_window.cpp) endif() endif() diff --git a/include/emulator.hpp b/include/emulator.hpp index de04648e..ffbebd9c 100644 --- a/include/emulator.hpp +++ b/include/emulator.hpp @@ -109,7 +109,7 @@ class Emulator { #ifdef PANDA3DS_FRONTEND_QT // For passing the GL context from Qt to the renderer - void initGraphicsContext(GL::Context* glContext) { gpu.initGraphicsContext(nullptr); } + void initGraphicsContext(GL::Context* glContext) { gpu.initGraphicsContext(glContext); } #else void initGraphicsContext(SDL_Window* window) { gpu.initGraphicsContext(window); } #endif diff --git a/include/renderer_gl/renderer_gl.hpp b/include/renderer_gl/renderer_gl.hpp index 53a34935..8f2cd96d 100644 --- a/include/renderer_gl/renderer_gl.hpp +++ b/include/renderer_gl/renderer_gl.hpp @@ -108,6 +108,7 @@ class RendererGL final : public Renderer { void reset() override; void display() override; // Display the 3DS screen contents to the window + void initGraphicsContext(SDL_Window* window) override; // Initialize graphics context void clearBuffer(u32 startAddress, u32 endAddress, u32 value, u32 control) override; // Clear a GPU buffer in VRAM void displayTransfer(u32 inputAddr, u32 outputAddr, u32 inputSize, u32 outputSize, u32 flags) override; // Perform display transfer void textureCopy(u32 inputAddr, u32 outputAddr, u32 totalBytes, u32 inputSize, u32 outputSize, u32 flags) override; @@ -129,9 +130,7 @@ class RendererGL final : public Renderer { void initUbershader(OpenGL::Program& program); #ifdef PANDA3DS_FRONTEND_QT - virtual void initGraphicsContext(GL::Context* context) override; -#elif defined(PANDA3DS_FRONTEND_SDL) - virtual void initGraphicsContext(SDL_Window* window) override; + void initGraphicsContext(GL::Context* context) override; #endif // Take a screenshot of the screen and store it in a file diff --git a/src/core/renderer_gl/renderer_gl.cpp b/src/core/renderer_gl/renderer_gl.cpp index 1d2accf7..8945f6e9 100644 --- a/src/core/renderer_gl/renderer_gl.cpp +++ b/src/core/renderer_gl/renderer_gl.cpp @@ -173,12 +173,7 @@ void RendererGL::initGraphicsContextInternal() { defaultShadergenVs.create({defaultShadergenVSSource.c_str(), defaultShadergenVSSource.size()}, OpenGL::Vertex); } -#ifdef PANDA3DS_FRONTEND_QT - void RendererGL::initGraphicsContext(GL::Context* context) -#elif defined(PANDA3DS_FRONTEND_SDL) - void RendererGL::initGraphicsContext(SDL_Window* context) -#endif -{ +void RendererGL::initGraphicsContext(SDL_Window* context) { if (shaderMode == ShaderMode::Hybrid) { asyncCompiler = new AsyncCompilerThread(fragShaderGen, context); } @@ -186,6 +181,16 @@ void RendererGL::initGraphicsContextInternal() { initGraphicsContextInternal(); } +#ifdef PANDA3DS_FRONTEND_QT +void RendererGL::initGraphicsContext(GL::Context* context) { + if (shaderMode == ShaderMode::Hybrid) { + asyncCompiler = new AsyncCompilerThread(fragShaderGen, context); + } + + initGraphicsContextInternal(); +} +#endif + // Set up the OpenGL blending context to match the emulated PICA void RendererGL::setupBlending() { // Map of PICA blending equations to OpenGL blending equations. The unused blending equations are equivalent to equation 0 (add) diff --git a/src/jni_driver.cpp b/src/jni_driver.cpp index e4ce2b39..3f8c7eef 100644 --- a/src/jni_driver.cpp +++ b/src/jni_driver.cpp @@ -139,4 +139,17 @@ int AndroidUtils::openDocument(const char* path, const char* perms) { env->DeleteLocalRef(jmode); return (int)result; -} \ No newline at end of file +} + +namespace AsyncCompiler { + void* createContext(void* mainContext) { + throwException(jniEnv(), "AsyncCompiler not supported on Android, how did you manage to enable this?"); + return nullptr; + } + + void makeCurrent(void* mainContext, void* context) { + } + + void destroyContext(void* context) { + } +} diff --git a/src/panda_qt/main_window.cpp b/src/panda_qt/main_window.cpp index 65769116..5cf08648 100644 --- a/src/panda_qt/main_window.cpp +++ b/src/panda_qt/main_window.cpp @@ -6,8 +6,10 @@ #include #include #include +#include #include "cheats.hpp" +#include "gl/context.h" #include "input_mappings.hpp" #include "services/dsp.hpp" @@ -601,3 +603,32 @@ void MainWindow::pollControllers() { } } } + +namespace AsyncCompiler { + void* createContext(void* mainContext) { + GL::Context* glContext = static_cast(mainContext); + + // Unlike the SDL function, this doesn't make it current so we don't + // need to call MakeCurrent on the mainContext + WindowInfo wi = glContext->GetWindowInfo(); + wi.type = WindowInfo::Type::Surfaceless; + + std::unique_ptr* newContext = new std::unique_ptr(glContext->CreateSharedContext(wi)); + + if (newContext->get() == nullptr) { + Helpers::panic("Failed to create shared GL context"); + } + + return newContext; + } + + void makeCurrent(void* mainContext, void* context) { + std::unique_ptr* glContext = static_cast*>(context); + (*glContext)->MakeCurrent(); + } + + void destroyContext(void* context) { + std::unique_ptr* glContext = static_cast*>(context); + delete glContext; + } +} \ No newline at end of file diff --git a/third_party/duckstation/gl/context.cpp b/third_party/duckstation/gl/context.cpp index 69401bd9..e06fc535 100644 --- a/third_party/duckstation/gl/context.cpp +++ b/third_party/duckstation/gl/context.cpp @@ -74,14 +74,7 @@ std::unique_ptr Context::Create(const WindowInfo& wi, const Version context = ContextAGL::Create(wi, versions_to_try, num_versions_to_try); #else if (wi.type == WindowInfo::Type::X11) - { - const char* use_egl_x11 = std::getenv("USE_EGL_X11"); - if (use_egl_x11 && std::strcmp(use_egl_x11, "1") == 0) - context = ContextEGLX11::Create(wi, versions_to_try, num_versions_to_try); - else - context = ContextGLX::Create(wi, versions_to_try, num_versions_to_try); - } - + context = ContextEGLX11::Create(wi, versions_to_try, num_versions_to_try); #ifdef WAYLAND_ENABLED if (wi.type == WindowInfo::Type::Wayland) context = ContextEGLWayland::Create(wi, versions_to_try, num_versions_to_try);