mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-07-20 14:01:44 +12:00
Get emulator rendering working with Qt
This commit is contained in:
parent
4329976dbc
commit
5155682e0f
12 changed files with 98 additions and 22 deletions
|
@ -86,10 +86,15 @@ class GPU {
|
|||
bool lightingLUTDirty = false;
|
||||
|
||||
GPU(Memory& mem, EmulatorConfig& config);
|
||||
void initGraphicsContext(SDL_Window* window) { renderer->initGraphicsContext(window); }
|
||||
void display() { renderer->display(); }
|
||||
void screenshot(const std::string& name) { renderer->screenshot(name); }
|
||||
|
||||
#if defined(PANDA3DS_FRONTEND_SDL)
|
||||
void initGraphicsContext(SDL_Window* window) { renderer->initGraphicsContext(window); }
|
||||
#elif defined(PANDA3DS_FRONTEND_QT)
|
||||
void initGraphicsContext(GL::Context* context) { renderer->initGraphicsContext(context); }
|
||||
#endif
|
||||
|
||||
void fireDMA(u32 dest, u32 source, u32 size);
|
||||
void reset();
|
||||
|
||||
|
|
|
@ -20,6 +20,10 @@
|
|||
#include "http_server.hpp"
|
||||
#endif
|
||||
|
||||
#ifdef PANDA3DS_FRONTEND_QT
|
||||
#include "gl/context.h"
|
||||
#endif
|
||||
|
||||
enum class ROMType {
|
||||
None,
|
||||
ELF,
|
||||
|
@ -37,10 +41,12 @@ class Emulator {
|
|||
Crypto::AESEngine aesEngine;
|
||||
Cheats cheats;
|
||||
|
||||
#ifdef PANDA3DS_FRONTEND_SDL
|
||||
SDL_Window* window;
|
||||
|
||||
#ifdef PANDA3DS_ENABLE_OPENGL
|
||||
SDL_GLContext glContext;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
SDL_GameController* gameController = nullptr;
|
||||
|
@ -106,5 +112,13 @@ class Emulator {
|
|||
bool load3DSX(const std::filesystem::path& path);
|
||||
bool loadELF(const std::filesystem::path& path);
|
||||
bool loadELF(std::ifstream& file);
|
||||
void initGraphicsContext();
|
||||
|
||||
#ifdef PANDA3DS_FRONTEND_QT
|
||||
// For passing the GL context from Qt to the renderer
|
||||
void initGraphicsContext(GL::Context* glContext) { gpu.initGraphicsContext(nullptr); }
|
||||
#else
|
||||
void initGraphicsContext() { gpu.initGraphicsContext(window); }
|
||||
#endif
|
||||
|
||||
EmulatorConfig& getConfig() { return config; }
|
||||
};
|
||||
|
|
|
@ -5,7 +5,9 @@
|
|||
#include <QMenuBar>
|
||||
#include <QPalette>
|
||||
#include <QtWidgets>
|
||||
#include <thread>
|
||||
|
||||
#include "emulator.hpp"
|
||||
#include "panda_qt/screen.hpp"
|
||||
|
||||
class MainWindow : public QMainWindow {
|
||||
|
@ -18,6 +20,10 @@ class MainWindow : public QMainWindow {
|
|||
Dark = 2,
|
||||
};
|
||||
|
||||
// This would normally be an std::unique_ptr but it's shared between threads so definitely not
|
||||
Emulator* emu = nullptr;
|
||||
std::thread emuThread;
|
||||
|
||||
QComboBox* themeSelect = nullptr;
|
||||
QMenuBar* menuBar = nullptr;
|
||||
ScreenWidget screen;
|
||||
|
|
|
@ -11,6 +11,7 @@ class ScreenWidget : public QWidget {
|
|||
|
||||
public:
|
||||
ScreenWidget(QWidget* parent = nullptr);
|
||||
GL::Context* getGLContext() { return glContext.get(); }
|
||||
|
||||
private:
|
||||
std::unique_ptr<GL::Context> glContext = nullptr;
|
||||
|
|
|
@ -7,6 +7,10 @@
|
|||
#include "PICA/regs.hpp"
|
||||
#include "helpers.hpp"
|
||||
|
||||
#ifdef PANDA3DS_FRONTEND_QT
|
||||
#include "gl/context.h"
|
||||
#endif
|
||||
|
||||
enum class RendererType : s8 {
|
||||
// Todo: Auto = -1,
|
||||
Null = 0,
|
||||
|
@ -50,10 +54,15 @@ class Renderer {
|
|||
virtual void clearBuffer(u32 startAddress, u32 endAddress, u32 value, u32 control) = 0; // Clear a GPU buffer in VRAM
|
||||
virtual void displayTransfer(u32 inputAddr, u32 outputAddr, u32 inputSize, u32 outputSize, u32 flags) = 0; // Perform display transfer
|
||||
virtual void textureCopy(u32 inputAddr, u32 outputAddr, u32 totalBytes, u32 inputSize, u32 outputSize, u32 flags) = 0;
|
||||
virtual void drawVertices(PICA::PrimType primType, std::span<const PICA::Vertex> vertices) = 0; // Draw the given vertices
|
||||
virtual void drawVertices(PICA::PrimType primType, std::span<const PICA::Vertex> vertices) = 0; // Draw the given vertices
|
||||
|
||||
virtual void screenshot(const std::string& name) = 0;
|
||||
|
||||
// Functions for initializing the graphics context for the Qt frontend, where we don't have the convenience of SDL_Window
|
||||
#ifdef PANDA3DS_FRONTEND_QT
|
||||
virtual void initGraphicsContext(GL::Context* context) { Helpers::panic("Tried to initialize incompatible renderer with GL context"); }
|
||||
#endif
|
||||
|
||||
void setFBSize(u32 width, u32 height) {
|
||||
fbSize[0] = width;
|
||||
fbSize[1] = height;
|
||||
|
|
|
@ -67,6 +67,7 @@ class RendererGL final : public Renderer {
|
|||
void setupTextureEnvState();
|
||||
void bindTexturesToSlots();
|
||||
void updateLightingLUT();
|
||||
void initGraphicsContextInternal();
|
||||
|
||||
public:
|
||||
RendererGL(GPU& gpu, const std::array<u32, regNum>& internalRegs, const std::array<u32, extRegNum>& externalRegs)
|
||||
|
@ -83,6 +84,10 @@ class RendererGL final : public Renderer {
|
|||
|
||||
std::optional<ColourBuffer> getColourBuffer(u32 addr, PICA::ColorFmt format, u32 width, u32 height, bool createIfnotFound = true);
|
||||
|
||||
#ifdef PANDA3DS_FRONTEND_QT
|
||||
virtual void initGraphicsContext([[maybe_unused]] GL::Context* context) override { initGraphicsContextInternal(); }
|
||||
#endif
|
||||
|
||||
// Take a screenshot of the screen and store it in a file
|
||||
void screenshot(const std::string& name) override;
|
||||
};
|
||||
|
|
|
@ -15,4 +15,8 @@ class RendererNull final : public Renderer {
|
|||
void textureCopy(u32 inputAddr, u32 outputAddr, u32 totalBytes, u32 inputSize, u32 outputSize, u32 flags) override;
|
||||
void drawVertices(PICA::PrimType primType, std::span<const PICA::Vertex> vertices) override;
|
||||
void screenshot(const std::string& name) override;
|
||||
|
||||
#ifdef PANDA3DS_FRONTEND_QT
|
||||
virtual void initGraphicsContext([[maybe_unused]] GL::Context* context) override {}
|
||||
#endif
|
||||
};
|
||||
|
|
|
@ -15,4 +15,8 @@ class RendererSw final : public Renderer {
|
|||
void textureCopy(u32 inputAddr, u32 outputAddr, u32 totalBytes, u32 inputSize, u32 outputSize, u32 flags) override;
|
||||
void drawVertices(PICA::PrimType primType, std::span<const PICA::Vertex> vertices) override;
|
||||
void screenshot(const std::string& name) override;
|
||||
|
||||
#ifdef PANDA3DS_FRONTEND_QT
|
||||
virtual void initGraphicsContext([[maybe_unused]] GL::Context* context) override {}
|
||||
#endif
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue