Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Qt/QtMain.h
5757 views
1
#ifndef QTMAIN_H
2
#define QTMAIN_H
3
4
#include <QTouchEvent>
5
#include <QMouseEvent>
6
#include <QInputDialog>
7
#include "Common/GPU/OpenGL/GLSLProgram.h"
8
#include <QGLWidget>
9
10
#ifndef SDL
11
#include <QAudioOutput>
12
#include <QAudioFormat>
13
#endif
14
#if defined(MOBILE_DEVICE)
15
#include <QAccelerometer>
16
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
17
QTM_USE_NAMESPACE
18
#endif
19
#endif
20
21
#include <cassert>
22
#include <atomic>
23
#include <thread>
24
25
#include "Common/System/Display.h"
26
#include "Common/TimeUtil.h"
27
#include "Common/File/VFS/VFS.h"
28
#include "Common/File/VFS/DirectoryReader.h"
29
#include "Common/GPU/OpenGL/GLCommon.h"
30
#include "Common/GPU/OpenGL/GLFeatures.h"
31
#include "Common/Input/InputState.h"
32
#include "Common/Input/KeyCodes.h"
33
#include "Common/GPU/thin3d.h"
34
#include "Common/Net/Resolve.h"
35
#include "NKCodeFromQt.h"
36
37
#include "Common/GraphicsContext.h"
38
#include "Core/Core.h"
39
#include "Core/Config.h"
40
#include "Core/ConfigValues.h"
41
#include "Core/System.h"
42
#include "Common/GPU/thin3d_create.h"
43
#include "Common/GPU/OpenGL/GLRenderManager.h"
44
45
// Input
46
void SimulateGamepad();
47
48
class QtGLGraphicsContext : public GraphicsContext {
49
public:
50
QtGLGraphicsContext() {
51
CheckGLExtensions();
52
draw_ = Draw::T3DCreateGLContext(false);
53
SetGPUBackend(GPUBackend::OPENGL);
54
renderManager_ = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
55
renderManager_->SetInflightFrames(g_Config.iInflightFrames);
56
bool success = draw_->CreatePresets();
57
_assert_msg_(success, "Failed to compile preset shaders");
58
59
// TODO: Need to figure out how to implement SetSwapInterval for Qt.
60
}
61
62
~QtGLGraphicsContext() {
63
delete draw_;
64
draw_ = nullptr;
65
renderManager_ = nullptr;
66
}
67
68
void Shutdown() override {}
69
void Resize() override {}
70
71
Draw::DrawContext *GetDrawContext() override {
72
return draw_;
73
}
74
75
void ThreadStart() override {
76
renderManager_->ThreadStart(draw_);
77
}
78
79
bool ThreadFrame(bool waitIfEmpty) override {
80
return renderManager_->ThreadFrame(waitIfEmpty);
81
}
82
83
void ThreadEnd() override {
84
renderManager_->ThreadEnd();
85
}
86
87
private:
88
Draw::DrawContext *draw_ = nullptr;
89
GLRenderManager *renderManager_ = nullptr;
90
};
91
92
enum class EmuThreadState {
93
DISABLED,
94
START_REQUESTED,
95
RUNNING,
96
QUIT_REQUESTED,
97
STOPPED,
98
};
99
100
101
// GUI, thread manager
102
class MainUI : public QGLWidget
103
{
104
Q_OBJECT
105
public:
106
explicit MainUI(QWidget *parent = 0);
107
~MainUI();
108
109
void resizeGL(int w, int h);
110
111
public slots:
112
QString InputBoxGetQString(QString title, QString defaultValue);
113
114
signals:
115
void doubleClick();
116
void newFrame();
117
118
protected:
119
void timerEvent(QTimerEvent *);
120
void changeEvent(QEvent *e);
121
bool event(QEvent *e);
122
123
void initializeGL();
124
void paintGL();
125
126
void updateAccelerometer();
127
128
void EmuThreadFunc();
129
void EmuThreadStart();
130
void EmuThreadStop();
131
void EmuThreadJoin();
132
133
private:
134
bool HandleCustomEvent(QEvent *e);
135
QtGLGraphicsContext *graphicsContext;
136
137
float xscale, yscale;
138
#if defined(MOBILE_DEVICE)
139
QAccelerometer* acc;
140
#endif
141
142
std::thread emuThread;
143
std::atomic<int> emuThreadState;
144
};
145
146
class QTCamera : public QObject {
147
Q_OBJECT
148
public:
149
QTCamera() {}
150
~QTCamera() {};
151
152
signals:
153
void onStartCamera(int width, int height);
154
void onStopCamera();
155
156
public slots:
157
void startCamera(int width, int height);
158
void stopCamera();
159
};
160
161
extern MainUI* emugl;
162
163
#ifndef SDL
164
165
// AUDIO
166
class MainAudio : public QObject {
167
Q_OBJECT
168
public:
169
MainAudio() {}
170
~MainAudio();
171
public slots:
172
void run();
173
protected:
174
void timerEvent(QTimerEvent *);
175
private:
176
QIODevice* feed;
177
QAudioOutput* output;
178
int mixlen;
179
char* mixbuf;
180
int timer;
181
};
182
183
#endif //SDL
184
185
#endif
186
187