2012-12-16 19:47:51 +10:00
|
|
|
#ifndef QTMAIN_H
|
|
|
|
#define QTMAIN_H
|
2012-12-13 16:38:33 +10:00
|
|
|
|
|
|
|
#include <QTouchEvent>
|
2012-12-23 17:47:52 +10:00
|
|
|
#include <QMouseEvent>
|
2013-12-08 20:14:49 +10:00
|
|
|
#include <QInputDialog>
|
2020-10-04 23:24:14 +02:00
|
|
|
#include "Common/GPU/OpenGL/GLSLProgram.h"
|
2012-12-13 16:38:33 +10:00
|
|
|
#include <QGLWidget>
|
|
|
|
|
2014-12-18 23:57:59 +01:00
|
|
|
#ifndef SDL
|
2012-12-16 19:47:51 +10:00
|
|
|
#include <QAudioOutput>
|
|
|
|
#include <QAudioFormat>
|
2014-07-01 17:14:46 +10:00
|
|
|
#endif
|
2016-10-12 12:32:20 +02:00
|
|
|
#if defined(MOBILE_DEVICE)
|
2013-03-11 11:51:10 +10:00
|
|
|
#include <QAccelerometer>
|
2014-06-30 00:15:37 +10:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
2013-03-11 11:51:10 +10:00
|
|
|
QTM_USE_NAMESPACE
|
|
|
|
#endif
|
2014-06-03 09:03:09 +10:00
|
|
|
#endif
|
2012-12-13 16:38:33 +10:00
|
|
|
|
2017-10-20 11:53:07 +02:00
|
|
|
#include <cassert>
|
2018-01-31 12:05:18 +01:00
|
|
|
#include <atomic>
|
|
|
|
#include <thread>
|
2017-10-20 11:53:07 +02:00
|
|
|
|
2020-10-04 10:10:55 +02:00
|
|
|
#include "Common/System/Display.h"
|
2020-08-15 20:53:08 +02:00
|
|
|
#include "Common/TimeUtil.h"
|
2020-10-04 10:30:18 +02:00
|
|
|
#include "Common/File/VFS/VFS.h"
|
2023-03-06 15:30:39 +01:00
|
|
|
#include "Common/File/VFS/DirectoryReader.h"
|
2020-10-04 23:24:14 +02:00
|
|
|
#include "Common/GPU/OpenGL/GLCommon.h"
|
|
|
|
#include "Common/GPU/OpenGL/GLFeatures.h"
|
2020-10-01 09:36:43 +02:00
|
|
|
#include "Common/Input/InputState.h"
|
|
|
|
#include "Common/Input/KeyCodes.h"
|
2020-10-04 23:24:14 +02:00
|
|
|
#include "Common/GPU/thin3d.h"
|
2020-10-04 20:48:47 +02:00
|
|
|
#include "Common/Net/Resolve.h"
|
2019-08-06 16:12:19 +01:00
|
|
|
#include "NKCodeFromQt.h"
|
2012-12-13 16:38:33 +10:00
|
|
|
|
2016-01-03 15:03:08 +01:00
|
|
|
#include "Common/GraphicsContext.h"
|
2013-11-27 01:30:10 +10:00
|
|
|
#include "Core/Core.h"
|
|
|
|
#include "Core/Config.h"
|
2018-06-16 18:42:31 -07:00
|
|
|
#include "Core/ConfigValues.h"
|
2017-12-26 15:59:02 -08:00
|
|
|
#include "Core/System.h"
|
2020-10-04 23:24:14 +02:00
|
|
|
#include "Common/GPU/thin3d_create.h"
|
|
|
|
#include "Common/GPU/OpenGL/GLRenderManager.h"
|
2013-11-27 01:30:10 +10:00
|
|
|
|
2013-01-10 18:06:11 +10:00
|
|
|
// Input
|
2017-03-14 22:01:18 -07:00
|
|
|
void SimulateGamepad();
|
2013-01-10 18:06:11 +10:00
|
|
|
|
2018-02-08 11:19:48 +01:00
|
|
|
class QtGLGraphicsContext : public GraphicsContext {
|
2016-01-03 15:03:08 +01:00
|
|
|
public:
|
2018-02-08 11:19:48 +01:00
|
|
|
QtGLGraphicsContext() {
|
2017-12-26 16:04:19 -08:00
|
|
|
CheckGLExtensions();
|
2023-08-13 13:33:38 +02:00
|
|
|
draw_ = Draw::T3DCreateGLContext(false);
|
2017-12-26 15:59:02 -08:00
|
|
|
SetGPUBackend(GPUBackend::OPENGL);
|
2018-01-31 12:05:18 +01:00
|
|
|
renderManager_ = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
|
2020-03-02 19:21:15 -08:00
|
|
|
renderManager_->SetInflightFrames(g_Config.iInflightFrames);
|
2017-10-20 14:45:00 +02:00
|
|
|
bool success = draw_->CreatePresets();
|
2020-07-19 17:47:02 +02:00
|
|
|
_assert_msg_(success, "Failed to compile preset shaders");
|
2020-07-19 11:03:46 +02:00
|
|
|
|
|
|
|
// TODO: Need to figure out how to implement SetSwapInterval for Qt.
|
2016-01-03 15:03:08 +01:00
|
|
|
}
|
2018-01-31 12:05:18 +01:00
|
|
|
|
2018-02-08 11:19:48 +01:00
|
|
|
~QtGLGraphicsContext() {
|
2017-02-06 11:20:27 +01:00
|
|
|
delete draw_;
|
2018-01-31 12:05:18 +01:00
|
|
|
draw_ = nullptr;
|
|
|
|
renderManager_ = nullptr;
|
2017-02-06 11:20:27 +01:00
|
|
|
}
|
|
|
|
|
2018-02-08 11:19:48 +01:00
|
|
|
void Shutdown() override {}
|
|
|
|
void Resize() override {}
|
|
|
|
|
2017-02-06 11:20:27 +01:00
|
|
|
Draw::DrawContext *GetDrawContext() override {
|
|
|
|
return draw_;
|
|
|
|
}
|
2018-01-31 12:05:18 +01:00
|
|
|
|
|
|
|
void ThreadStart() override {
|
2018-12-23 12:46:48 -08:00
|
|
|
renderManager_->ThreadStart(draw_);
|
2018-01-31 12:05:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ThreadFrame() override {
|
|
|
|
return renderManager_->ThreadFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThreadEnd() override {
|
|
|
|
renderManager_->ThreadEnd();
|
|
|
|
}
|
|
|
|
|
2018-02-10 16:23:05 -08:00
|
|
|
void StopThread() override {
|
|
|
|
renderManager_->StopThread();
|
|
|
|
}
|
|
|
|
|
2017-02-06 11:20:27 +01:00
|
|
|
private:
|
2018-01-31 12:05:18 +01:00
|
|
|
Draw::DrawContext *draw_ = nullptr;
|
|
|
|
GLRenderManager *renderManager_ = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class EmuThreadState {
|
|
|
|
DISABLED,
|
|
|
|
START_REQUESTED,
|
|
|
|
RUNNING,
|
|
|
|
QUIT_REQUESTED,
|
|
|
|
STOPPED,
|
2016-01-03 15:03:08 +01:00
|
|
|
};
|
|
|
|
|
2018-01-31 12:05:18 +01:00
|
|
|
|
|
|
|
// GUI, thread manager
|
2012-12-13 16:38:33 +10:00
|
|
|
class MainUI : public QGLWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2017-02-06 11:20:27 +01:00
|
|
|
explicit MainUI(QWidget *parent = 0);
|
|
|
|
~MainUI();
|
2012-12-13 16:38:33 +10:00
|
|
|
|
2018-06-09 16:28:15 -07:00
|
|
|
void resizeGL(int w, int h);
|
|
|
|
|
2013-12-08 20:14:49 +10:00
|
|
|
public slots:
|
2017-02-06 11:20:27 +01:00
|
|
|
QString InputBoxGetQString(QString title, QString defaultValue);
|
2013-12-08 20:14:49 +10:00
|
|
|
|
2013-11-27 01:30:10 +10:00
|
|
|
signals:
|
|
|
|
void doubleClick();
|
|
|
|
void newFrame();
|
|
|
|
|
2012-12-13 16:38:33 +10:00
|
|
|
protected:
|
2017-02-06 11:20:27 +01:00
|
|
|
void timerEvent(QTimerEvent *);
|
|
|
|
void changeEvent(QEvent *e);
|
|
|
|
bool event(QEvent *e);
|
2013-07-25 14:28:18 +10:00
|
|
|
|
2017-02-06 11:20:27 +01:00
|
|
|
void initializeGL();
|
|
|
|
void paintGL();
|
2013-07-25 14:28:18 +10:00
|
|
|
|
2017-02-06 11:20:27 +01:00
|
|
|
void updateAccelerometer();
|
2013-03-11 11:51:10 +10:00
|
|
|
|
2018-01-31 12:05:18 +01:00
|
|
|
void EmuThreadFunc();
|
|
|
|
void EmuThreadStart();
|
|
|
|
void EmuThreadStop();
|
2018-02-07 16:43:49 +01:00
|
|
|
void EmuThreadJoin();
|
2018-01-31 12:05:18 +01:00
|
|
|
|
2012-12-13 16:38:33 +10:00
|
|
|
private:
|
2023-03-22 14:39:57 +01:00
|
|
|
bool HandleCustomEvent(QEvent *e);
|
2018-02-08 11:19:48 +01:00
|
|
|
QtGLGraphicsContext *graphicsContext;
|
2016-02-11 00:25:02 +08:00
|
|
|
|
2017-02-06 11:20:27 +01:00
|
|
|
float xscale, yscale;
|
2016-10-12 12:32:20 +02:00
|
|
|
#if defined(MOBILE_DEVICE)
|
2013-03-11 11:51:10 +10:00
|
|
|
QAccelerometer* acc;
|
|
|
|
#endif
|
2018-01-31 12:05:18 +01:00
|
|
|
|
|
|
|
std::thread emuThread;
|
|
|
|
std::atomic<int> emuThreadState;
|
2012-12-13 16:38:33 +10:00
|
|
|
};
|
|
|
|
|
2020-01-25 10:06:00 +02:00
|
|
|
class QTCamera : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
QTCamera() {}
|
|
|
|
~QTCamera() {};
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void onStartCamera(int width, int height);
|
|
|
|
void onStopCamera();
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void startCamera(int width, int height);
|
|
|
|
void stopCamera();
|
|
|
|
};
|
|
|
|
|
2016-02-10 19:37:47 +08:00
|
|
|
extern MainUI* emugl;
|
2013-12-08 20:14:49 +10:00
|
|
|
|
2014-12-18 23:57:59 +01:00
|
|
|
#ifndef SDL
|
2014-07-01 17:14:46 +10:00
|
|
|
|
2024-07-14 14:42:59 +02:00
|
|
|
// AUDIO
|
2018-02-08 11:19:48 +01:00
|
|
|
class MainAudio : public QObject {
|
2012-12-16 19:47:51 +10:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2016-02-10 19:37:47 +08:00
|
|
|
MainAudio() {}
|
2017-02-06 11:20:27 +01:00
|
|
|
~MainAudio();
|
2013-10-26 19:51:29 +10:00
|
|
|
public slots:
|
2017-02-06 11:20:27 +01:00
|
|
|
void run();
|
2013-01-15 20:45:26 +10:00
|
|
|
protected:
|
2017-02-06 11:20:27 +01:00
|
|
|
void timerEvent(QTimerEvent *);
|
2012-12-16 19:47:51 +10:00
|
|
|
private:
|
|
|
|
QIODevice* feed;
|
|
|
|
QAudioOutput* output;
|
|
|
|
int mixlen;
|
|
|
|
char* mixbuf;
|
2013-01-31 23:49:37 +01:00
|
|
|
int timer;
|
2012-12-16 19:47:51 +10:00
|
|
|
};
|
|
|
|
|
2014-12-18 23:57:59 +01:00
|
|
|
#endif //SDL
|
2014-07-01 17:14:46 +10:00
|
|
|
|
2012-12-13 16:38:33 +10:00
|
|
|
#endif
|