mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-24 22:59:58 -06:00
No more context mess (#1531)
* WIP: use Duckstation's context code to directly render into QT Widget from separate thread without two OpenGL contexts currently only works on Windows * reenable gay OSD * add back vsync * make it atleast a little more thread safe * linux support * don't segfault on closing * reorganise and cleanup build system it's still not good, but better than before * macos? * try to get it working on Ubuntu CI also update instructions * let's try this * ok how about this * try creating an OGL 4.3 context first (https://i.kym-cdn.com/photos/images/original/001/264/842/220.png) * fix Ubuntu * hm * try again for Windows * let's try this * make the OpenGL renderer work again that was stupid * do OGL surface resizing from the mainthread * Fix small mistake in GL context creation on macOS causing version 3.2 to be considered invalid * C stupidness * cleanup * don't let the emuthread deinit OGL if there's no OGL * reset lastScreenWidth/Height when deiniting OpenGL * disable stencil test while drawing framebuffers * macOS: Link Cocoa framework explicitly when not building with Qt6 Seems to be needed for the classes used by DuckStation's GL context code. * Set ScreenPanelGL's minimum size immediately Fixes GL context creation for OpenGL display on macOS using the wrong size as the underlying window was not resized to the correct size by Qt yet. * don't emit window updates when OGL display is used * stuff Arisotura said Co-authored-by: Nadia Holmquist Pedersen <nadia@nhp.sh>
This commit is contained in:
@ -19,6 +19,8 @@
|
||||
#ifndef MAIN_H
|
||||
#define MAIN_H
|
||||
|
||||
#include "glad/glad.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QThread>
|
||||
#include <QWidget>
|
||||
@ -28,15 +30,15 @@
|
||||
#include <QActionGroup>
|
||||
#include <QTimer>
|
||||
#include <QMutex>
|
||||
#include <QScreen>
|
||||
#include <QCloseEvent>
|
||||
|
||||
#include <QOffscreenSurface>
|
||||
#include <QOpenGLWidget>
|
||||
#include <QOpenGLContext>
|
||||
#include <QOpenGLFunctions>
|
||||
#include <QOpenGLFunctions_3_2_Core>
|
||||
#include <QOpenGLShaderProgram>
|
||||
#include <atomic>
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "FrontendUtil.h"
|
||||
#include "duckstation/gl/context.h"
|
||||
|
||||
class EmuThread : public QThread
|
||||
{
|
||||
@ -46,9 +48,6 @@ class EmuThread : public QThread
|
||||
public:
|
||||
explicit EmuThread(QObject* parent = nullptr);
|
||||
|
||||
void initOpenGL();
|
||||
void deinitOpenGL();
|
||||
|
||||
void changeWindowTitle(char* title);
|
||||
|
||||
// to be called from the UI thread
|
||||
@ -61,11 +60,13 @@ public:
|
||||
bool emuIsRunning();
|
||||
bool emuIsActive();
|
||||
|
||||
void initContext();
|
||||
void deinitContext();
|
||||
|
||||
int FrontBuffer = 0;
|
||||
QMutex FrontBufferLock;
|
||||
|
||||
GLsync FrontBufferReverseSyncs[2] = {nullptr, nullptr};
|
||||
GLsync FrontBufferSyncs[2] = {nullptr, nullptr};
|
||||
void updateScreenSettings(bool filter, const WindowInfo& windowInfo, int numScreens, int* screenKind, float* screenMatrix);
|
||||
|
||||
signals:
|
||||
void windowUpdate();
|
||||
@ -86,13 +87,31 @@ signals:
|
||||
void swapScreensToggle();
|
||||
|
||||
private:
|
||||
volatile int EmuStatus;
|
||||
void drawScreenGL();
|
||||
void initOpenGL();
|
||||
void deinitOpenGL();
|
||||
|
||||
std::atomic<int> EmuStatus;
|
||||
int PrevEmuStatus;
|
||||
int EmuRunning;
|
||||
int EmuPause;
|
||||
|
||||
QOffscreenSurface* oglSurface;
|
||||
QOpenGLContext* oglContext;
|
||||
std::atomic<int> ContextRequest = 0;
|
||||
|
||||
GL::Context* oglContext = nullptr;
|
||||
GLuint screenVertexBuffer, screenVertexArray;
|
||||
GLuint screenTexture;
|
||||
GLuint screenShaderProgram[3];
|
||||
GLuint screenShaderTransformULoc, screenShaderScreenSizeULoc;
|
||||
|
||||
QMutex screenSettingsLock;
|
||||
WindowInfo windowInfo;
|
||||
float screenMatrix[Frontend::MaxScreenTransforms][6];
|
||||
int screenKind[Frontend::MaxScreenTransforms];
|
||||
int numScreens;
|
||||
bool filter;
|
||||
|
||||
int lastScreenWidth = -1, lastScreenHeight = -1;
|
||||
};
|
||||
|
||||
|
||||
@ -158,7 +177,7 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class ScreenPanelGL : public QOpenGLWidget, public ScreenHandler, protected QOpenGLFunctions_3_2_Core
|
||||
class ScreenPanelGL : public QWidget, public ScreenHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -166,13 +185,22 @@ public:
|
||||
explicit ScreenPanelGL(QWidget* parent);
|
||||
virtual ~ScreenPanelGL();
|
||||
|
||||
protected:
|
||||
void initializeGL() override;
|
||||
std::optional<WindowInfo> getWindowInfo();
|
||||
|
||||
void paintGL() override;
|
||||
bool createContext();
|
||||
|
||||
GL::Context* getContext() { return glContext.get(); }
|
||||
|
||||
void transferLayout(EmuThread* thread);
|
||||
protected:
|
||||
|
||||
qreal devicePixelRatioFromScreen() const;
|
||||
int scaledWindowWidth() const;
|
||||
int scaledWindowHeight() const;
|
||||
|
||||
QPaintEngine* paintEngine() const override;
|
||||
|
||||
void resizeEvent(QResizeEvent* event) override;
|
||||
void resizeGL(int w, int h) override;
|
||||
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
void mouseReleaseEvent(QMouseEvent* event) override;
|
||||
@ -180,16 +208,14 @@ protected:
|
||||
|
||||
void tabletEvent(QTabletEvent* event) override;
|
||||
bool event(QEvent* event) override;
|
||||
|
||||
private slots:
|
||||
void onScreenLayoutChanged();
|
||||
|
||||
private:
|
||||
void setupScreenLayout();
|
||||
|
||||
QOpenGLShaderProgram* screenShader;
|
||||
GLuint screenVertexBuffer;
|
||||
GLuint screenVertexArray;
|
||||
GLuint screenTexture;
|
||||
std::unique_ptr<GL::Context> glContext;
|
||||
};
|
||||
|
||||
class MelonApplication : public QApplication
|
||||
@ -210,7 +236,7 @@ public:
|
||||
~MainWindow();
|
||||
|
||||
bool hasOGL;
|
||||
QOpenGLContext* getOGLContext();
|
||||
GL::Context* getOGLContext();
|
||||
|
||||
bool preloadROMs(QString filename, QString gbafilename);
|
||||
|
||||
@ -306,6 +332,8 @@ private slots:
|
||||
void onFullscreenToggled();
|
||||
|
||||
private:
|
||||
void closeEvent(QCloseEvent* event);
|
||||
|
||||
QStringList currentROM;
|
||||
QStringList currentGBAROM;
|
||||
QList<QString> recentFileList;
|
||||
|
Reference in New Issue
Block a user