2012-12-16 09:47:51 +00:00
|
|
|
#ifndef QTMAIN_H
|
|
|
|
#define QTMAIN_H
|
2012-12-13 06:38:33 +00:00
|
|
|
|
|
|
|
#include <QTouchEvent>
|
2012-12-23 07:47:52 +00:00
|
|
|
#include <QMouseEvent>
|
2013-12-08 10:14:49 +00:00
|
|
|
#include <QInputDialog>
|
2012-12-23 07:47:52 +00:00
|
|
|
#include "gfx_es2/glsl_program.h"
|
2012-12-13 06:38:33 +00:00
|
|
|
#include <QGLWidget>
|
|
|
|
|
2014-12-18 22:57:59 +00:00
|
|
|
#ifndef SDL
|
2012-12-16 09:47:51 +00:00
|
|
|
#include <QAudioOutput>
|
|
|
|
#include <QAudioFormat>
|
2014-07-01 07:14:46 +00:00
|
|
|
#endif
|
2016-10-12 10:32:20 +00:00
|
|
|
#if defined(MOBILE_DEVICE)
|
2013-03-11 01:51:10 +00:00
|
|
|
#include <QAccelerometer>
|
2014-06-29 14:15:37 +00:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
2013-03-11 01:51:10 +00:00
|
|
|
QTM_USE_NAMESPACE
|
|
|
|
#endif
|
2014-06-02 23:03:09 +00:00
|
|
|
#endif
|
2012-12-13 06:38:33 +00:00
|
|
|
|
2017-10-20 09:53:07 +00:00
|
|
|
#include <cassert>
|
2018-01-31 11:05:18 +00:00
|
|
|
#include <atomic>
|
|
|
|
#include <thread>
|
2017-10-20 09:53:07 +00:00
|
|
|
|
2012-12-13 06:38:33 +00:00
|
|
|
#include "base/display.h"
|
|
|
|
#include "base/logging.h"
|
|
|
|
#include "base/timeutil.h"
|
|
|
|
#include "file/zip_read.h"
|
2015-09-06 11:44:06 +00:00
|
|
|
#include "gfx/gl_common.h"
|
2017-12-27 00:04:19 +00:00
|
|
|
#include "gfx_es2/gpu_features.h"
|
2012-12-13 06:38:33 +00:00
|
|
|
#include "input/input_state.h"
|
2013-07-08 00:04:20 +00:00
|
|
|
#include "input/keycodes.h"
|
2016-01-03 14:03:08 +00:00
|
|
|
#include "thin3d/thin3d.h"
|
2012-12-13 06:38:33 +00:00
|
|
|
#include "base/NativeApp.h"
|
|
|
|
#include "net/resolve.h"
|
2019-08-06 15:12:19 +00:00
|
|
|
#include "NKCodeFromQt.h"
|
2012-12-13 06:38:33 +00:00
|
|
|
|
2016-01-03 14:03:08 +00:00
|
|
|
#include "Common/GraphicsContext.h"
|
2013-11-26 15:30:10 +00:00
|
|
|
#include "Core/Core.h"
|
|
|
|
#include "Core/Config.h"
|
2018-06-17 01:42:31 +00:00
|
|
|
#include "Core/ConfigValues.h"
|
2017-12-26 23:59:02 +00:00
|
|
|
#include "Core/System.h"
|
2018-02-25 09:27:59 +00:00
|
|
|
#include "thin3d/thin3d_create.h"
|
2018-01-31 11:05:18 +00:00
|
|
|
#include "thin3d/GLRenderManager.h"
|
2013-11-26 15:30:10 +00:00
|
|
|
|
2013-01-10 08:06:11 +00:00
|
|
|
// Input
|
2017-03-15 05:01:18 +00:00
|
|
|
void SimulateGamepad();
|
2013-01-10 08:06:11 +00:00
|
|
|
|
2018-02-08 10:19:48 +00:00
|
|
|
class QtGLGraphicsContext : public GraphicsContext {
|
2016-01-03 14:03:08 +00:00
|
|
|
public:
|
2018-02-08 10:19:48 +00:00
|
|
|
QtGLGraphicsContext() {
|
2017-12-27 00:04:19 +00:00
|
|
|
CheckGLExtensions();
|
2017-02-06 10:20:27 +00:00
|
|
|
draw_ = Draw::T3DCreateGLContext();
|
2017-12-26 23:59:02 +00:00
|
|
|
SetGPUBackend(GPUBackend::OPENGL);
|
2018-01-31 11:05:18 +00:00
|
|
|
renderManager_ = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
|
2020-03-03 03:21:15 +00:00
|
|
|
renderManager_->SetInflightFrames(g_Config.iInflightFrames);
|
2017-10-20 12:45:00 +00:00
|
|
|
bool success = draw_->CreatePresets();
|
2018-11-21 17:13:48 +00:00
|
|
|
_assert_msg_(G3D, success, "Failed to compile preset shaders");
|
2016-01-03 14:03:08 +00:00
|
|
|
}
|
2018-01-31 11:05:18 +00:00
|
|
|
|
2018-02-08 10:19:48 +00:00
|
|
|
~QtGLGraphicsContext() {
|
2017-02-06 10:20:27 +00:00
|
|
|
delete draw_;
|
2018-01-31 11:05:18 +00:00
|
|
|
draw_ = nullptr;
|
|
|
|
renderManager_ = nullptr;
|
2017-02-06 10:20:27 +00:00
|
|
|
}
|
|
|
|
|
2018-02-08 10:19:48 +00:00
|
|
|
void Shutdown() override {}
|
|
|
|
void SwapInterval(int interval) override {}
|
|
|
|
void SwapBuffers() override {}
|
|
|
|
void Resize() override {}
|
|
|
|
|
2017-02-06 10:20:27 +00:00
|
|
|
Draw::DrawContext *GetDrawContext() override {
|
|
|
|
return draw_;
|
|
|
|
}
|
2018-01-31 11:05:18 +00:00
|
|
|
|
|
|
|
void ThreadStart() override {
|
2018-12-23 20:46:48 +00:00
|
|
|
renderManager_->ThreadStart(draw_);
|
2018-01-31 11:05:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ThreadFrame() override {
|
|
|
|
return renderManager_->ThreadFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThreadEnd() override {
|
|
|
|
renderManager_->ThreadEnd();
|
|
|
|
}
|
|
|
|
|
2018-02-11 00:23:05 +00:00
|
|
|
void StopThread() override {
|
|
|
|
renderManager_->WaitUntilQueueIdle();
|
|
|
|
renderManager_->StopThread();
|
|
|
|
}
|
|
|
|
|
2017-02-06 10:20:27 +00:00
|
|
|
private:
|
2018-01-31 11:05:18 +00:00
|
|
|
Draw::DrawContext *draw_ = nullptr;
|
|
|
|
GLRenderManager *renderManager_ = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class EmuThreadState {
|
|
|
|
DISABLED,
|
|
|
|
START_REQUESTED,
|
|
|
|
RUNNING,
|
|
|
|
QUIT_REQUESTED,
|
|
|
|
STOPPED,
|
2016-01-03 14:03:08 +00:00
|
|
|
};
|
|
|
|
|
2018-01-31 11:05:18 +00:00
|
|
|
|
|
|
|
// GUI, thread manager
|
2012-12-13 06:38:33 +00:00
|
|
|
class MainUI : public QGLWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2017-02-06 10:20:27 +00:00
|
|
|
explicit MainUI(QWidget *parent = 0);
|
|
|
|
~MainUI();
|
2012-12-13 06:38:33 +00:00
|
|
|
|
2018-06-09 23:28:15 +00:00
|
|
|
void resizeGL(int w, int h);
|
|
|
|
|
2013-12-08 10:14:49 +00:00
|
|
|
public slots:
|
2017-02-06 10:20:27 +00:00
|
|
|
QString InputBoxGetQString(QString title, QString defaultValue);
|
2013-12-08 10:14:49 +00:00
|
|
|
|
2013-11-26 15:30:10 +00:00
|
|
|
signals:
|
|
|
|
void doubleClick();
|
|
|
|
void newFrame();
|
|
|
|
|
2012-12-13 06:38:33 +00:00
|
|
|
protected:
|
2017-02-06 10:20:27 +00:00
|
|
|
void timerEvent(QTimerEvent *);
|
|
|
|
void changeEvent(QEvent *e);
|
|
|
|
bool event(QEvent *e);
|
2013-07-25 04:28:18 +00:00
|
|
|
|
2017-02-06 10:20:27 +00:00
|
|
|
void initializeGL();
|
|
|
|
void paintGL();
|
2013-07-25 04:28:18 +00:00
|
|
|
|
2017-02-06 10:20:27 +00:00
|
|
|
void updateAccelerometer();
|
2013-03-11 01:51:10 +00:00
|
|
|
|
2018-01-31 11:05:18 +00:00
|
|
|
void EmuThreadFunc();
|
|
|
|
void EmuThreadStart();
|
|
|
|
void EmuThreadStop();
|
2018-02-07 15:43:49 +00:00
|
|
|
void EmuThreadJoin();
|
2018-01-31 11:05:18 +00:00
|
|
|
|
2012-12-13 06:38:33 +00:00
|
|
|
private:
|
2018-02-08 10:19:48 +00:00
|
|
|
QtGLGraphicsContext *graphicsContext;
|
2016-02-10 16:25:02 +00:00
|
|
|
|
2017-02-06 10:20:27 +00:00
|
|
|
float xscale, yscale;
|
2016-10-12 10:32:20 +00:00
|
|
|
#if defined(MOBILE_DEVICE)
|
2013-03-11 01:51:10 +00:00
|
|
|
QAccelerometer* acc;
|
|
|
|
#endif
|
2018-01-31 11:05:18 +00:00
|
|
|
|
|
|
|
std::thread emuThread;
|
|
|
|
std::atomic<int> emuThreadState;
|
2012-12-13 06:38:33 +00:00
|
|
|
};
|
|
|
|
|
2020-01-25 08:06:00 +00: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 11:37:47 +00:00
|
|
|
extern MainUI* emugl;
|
2013-12-08 10:14:49 +00:00
|
|
|
|
2014-12-18 22:57:59 +00:00
|
|
|
#ifndef SDL
|
2014-07-01 07:14:46 +00:00
|
|
|
|
2013-01-10 08:06:11 +00:00
|
|
|
// Audio
|
2018-02-08 10:19:48 +00:00
|
|
|
class MainAudio : public QObject {
|
2012-12-16 09:47:51 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2016-02-10 11:37:47 +00:00
|
|
|
MainAudio() {}
|
2017-02-06 10:20:27 +00:00
|
|
|
~MainAudio();
|
2013-10-26 09:51:29 +00:00
|
|
|
public slots:
|
2017-02-06 10:20:27 +00:00
|
|
|
void run();
|
2013-01-15 10:45:26 +00:00
|
|
|
protected:
|
2017-02-06 10:20:27 +00:00
|
|
|
void timerEvent(QTimerEvent *);
|
2012-12-16 09:47:51 +00:00
|
|
|
private:
|
|
|
|
QIODevice* feed;
|
|
|
|
QAudioOutput* output;
|
|
|
|
int mixlen;
|
|
|
|
char* mixbuf;
|
2013-01-31 22:49:37 +00:00
|
|
|
int timer;
|
2012-12-16 09:47:51 +00:00
|
|
|
};
|
|
|
|
|
2014-12-18 22:57:59 +00:00
|
|
|
#endif //SDL
|
2014-07-01 07:14:46 +00:00
|
|
|
|
2012-12-13 06:38:33 +00:00
|
|
|
#endif
|
|
|
|
|