CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Qt/QtMain.h
Views: 1401
#ifndef QTMAIN_H1#define QTMAIN_H23#include <QTouchEvent>4#include <QMouseEvent>5#include <QInputDialog>6#include "Common/GPU/OpenGL/GLSLProgram.h"7#include <QGLWidget>89#ifndef SDL10#include <QAudioOutput>11#include <QAudioFormat>12#endif13#if defined(MOBILE_DEVICE)14#include <QAccelerometer>15#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)16QTM_USE_NAMESPACE17#endif18#endif1920#include <cassert>21#include <atomic>22#include <thread>2324#include "Common/System/Display.h"25#include "Common/TimeUtil.h"26#include "Common/File/VFS/VFS.h"27#include "Common/File/VFS/DirectoryReader.h"28#include "Common/GPU/OpenGL/GLCommon.h"29#include "Common/GPU/OpenGL/GLFeatures.h"30#include "Common/Input/InputState.h"31#include "Common/Input/KeyCodes.h"32#include "Common/GPU/thin3d.h"33#include "Common/Net/Resolve.h"34#include "NKCodeFromQt.h"3536#include "Common/GraphicsContext.h"37#include "Core/Core.h"38#include "Core/Config.h"39#include "Core/ConfigValues.h"40#include "Core/System.h"41#include "Common/GPU/thin3d_create.h"42#include "Common/GPU/OpenGL/GLRenderManager.h"4344// Input45void SimulateGamepad();4647class QtGLGraphicsContext : public GraphicsContext {48public:49QtGLGraphicsContext() {50CheckGLExtensions();51draw_ = Draw::T3DCreateGLContext(false);52SetGPUBackend(GPUBackend::OPENGL);53renderManager_ = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);54renderManager_->SetInflightFrames(g_Config.iInflightFrames);55bool success = draw_->CreatePresets();56_assert_msg_(success, "Failed to compile preset shaders");5758// TODO: Need to figure out how to implement SetSwapInterval for Qt.59}6061~QtGLGraphicsContext() {62delete draw_;63draw_ = nullptr;64renderManager_ = nullptr;65}6667void Shutdown() override {}68void Resize() override {}6970Draw::DrawContext *GetDrawContext() override {71return draw_;72}7374void ThreadStart() override {75renderManager_->ThreadStart(draw_);76}7778bool ThreadFrame() override {79return renderManager_->ThreadFrame();80}8182void ThreadEnd() override {83renderManager_->ThreadEnd();84}8586void StopThread() override {87renderManager_->StopThread();88}8990private:91Draw::DrawContext *draw_ = nullptr;92GLRenderManager *renderManager_ = nullptr;93};9495enum class EmuThreadState {96DISABLED,97START_REQUESTED,98RUNNING,99QUIT_REQUESTED,100STOPPED,101};102103104// GUI, thread manager105class MainUI : public QGLWidget106{107Q_OBJECT108public:109explicit MainUI(QWidget *parent = 0);110~MainUI();111112void resizeGL(int w, int h);113114public slots:115QString InputBoxGetQString(QString title, QString defaultValue);116117signals:118void doubleClick();119void newFrame();120121protected:122void timerEvent(QTimerEvent *);123void changeEvent(QEvent *e);124bool event(QEvent *e);125126void initializeGL();127void paintGL();128129void updateAccelerometer();130131void EmuThreadFunc();132void EmuThreadStart();133void EmuThreadStop();134void EmuThreadJoin();135136private:137bool HandleCustomEvent(QEvent *e);138QtGLGraphicsContext *graphicsContext;139140float xscale, yscale;141#if defined(MOBILE_DEVICE)142QAccelerometer* acc;143#endif144145std::thread emuThread;146std::atomic<int> emuThreadState;147};148149class QTCamera : public QObject {150Q_OBJECT151public:152QTCamera() {}153~QTCamera() {};154155signals:156void onStartCamera(int width, int height);157void onStopCamera();158159public slots:160void startCamera(int width, int height);161void stopCamera();162};163164extern MainUI* emugl;165166#ifndef SDL167168// AUDIO169class MainAudio : public QObject {170Q_OBJECT171public:172MainAudio() {}173~MainAudio();174public slots:175void run();176protected:177void timerEvent(QTimerEvent *);178private:179QIODevice* feed;180QAudioOutput* output;181int mixlen;182char* mixbuf;183int timer;184};185186#endif //SDL187188#endif189190191