CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Qt/QtMain.h
Views: 1401
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() override {
80
return renderManager_->ThreadFrame();
81
}
82
83
void ThreadEnd() override {
84
renderManager_->ThreadEnd();
85
}
86
87
void StopThread() override {
88
renderManager_->StopThread();
89
}
90
91
private:
92
Draw::DrawContext *draw_ = nullptr;
93
GLRenderManager *renderManager_ = nullptr;
94
};
95
96
enum class EmuThreadState {
97
DISABLED,
98
START_REQUESTED,
99
RUNNING,
100
QUIT_REQUESTED,
101
STOPPED,
102
};
103
104
105
// GUI, thread manager
106
class MainUI : public QGLWidget
107
{
108
Q_OBJECT
109
public:
110
explicit MainUI(QWidget *parent = 0);
111
~MainUI();
112
113
void resizeGL(int w, int h);
114
115
public slots:
116
QString InputBoxGetQString(QString title, QString defaultValue);
117
118
signals:
119
void doubleClick();
120
void newFrame();
121
122
protected:
123
void timerEvent(QTimerEvent *);
124
void changeEvent(QEvent *e);
125
bool event(QEvent *e);
126
127
void initializeGL();
128
void paintGL();
129
130
void updateAccelerometer();
131
132
void EmuThreadFunc();
133
void EmuThreadStart();
134
void EmuThreadStop();
135
void EmuThreadJoin();
136
137
private:
138
bool HandleCustomEvent(QEvent *e);
139
QtGLGraphicsContext *graphicsContext;
140
141
float xscale, yscale;
142
#if defined(MOBILE_DEVICE)
143
QAccelerometer* acc;
144
#endif
145
146
std::thread emuThread;
147
std::atomic<int> emuThreadState;
148
};
149
150
class QTCamera : public QObject {
151
Q_OBJECT
152
public:
153
QTCamera() {}
154
~QTCamera() {};
155
156
signals:
157
void onStartCamera(int width, int height);
158
void onStopCamera();
159
160
public slots:
161
void startCamera(int width, int height);
162
void stopCamera();
163
};
164
165
extern MainUI* emugl;
166
167
#ifndef SDL
168
169
// AUDIO
170
class MainAudio : public QObject {
171
Q_OBJECT
172
public:
173
MainAudio() {}
174
~MainAudio();
175
public slots:
176
void run();
177
protected:
178
void timerEvent(QTimerEvent *);
179
private:
180
QIODevice* feed;
181
QAudioOutput* output;
182
int mixlen;
183
char* mixbuf;
184
int timer;
185
};
186
187
#endif //SDL
188
189
#endif
190
191