ppsspp/Qt/QtMain.h

190 lines
3.5 KiB
C
Raw Normal View History

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