Make Qt work

This commit is contained in:
offtkp 2024-08-08 23:15:53 +03:00
parent 67069a8826
commit a4fcb1c4dc
7 changed files with 61 additions and 20 deletions

View file

@ -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()

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -139,4 +139,17 @@ int AndroidUtils::openDocument(const char* path, const char* perms) {
env->DeleteLocalRef(jmode);
return (int)result;
}
}
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) {
}
}

View file

@ -6,8 +6,10 @@
#include <cmath>
#include <cstdio>
#include <fstream>
#include <memory>
#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<GL::Context*>(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<GL::Context>* newContext = new std::unique_ptr<GL::Context>(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<GL::Context>* glContext = static_cast<std::unique_ptr<GL::Context>*>(context);
(*glContext)->MakeCurrent();
}
void destroyContext(void* context) {
std::unique_ptr<GL::Context>* glContext = static_cast<std::unique_ptr<GL::Context>*>(context);
delete glContext;
}
}

View file

@ -74,14 +74,7 @@ std::unique_ptr<GL::Context> 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);