src/platform/qt/DisplayGL.h (view raw)
1/* Copyright (c) 2013-2015 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#ifndef QGBA_DISPLAY_GL
7#define QGBA_DISPLAY_GL
8
9#include "Display.h"
10
11#ifdef USE_EPOXY
12#include <epoxy/gl.h>
13#endif
14
15#include <QGLWidget>
16#include <QList>
17#include <QMouseEvent>
18#include <QQueue>
19#include <QThread>
20#include <QTimer>
21
22extern "C" {
23#include "platform/video-backend.h"
24}
25
26struct GBAThread;
27
28namespace QGBA {
29
30class EmptyGLWidget : public QGLWidget {
31public:
32 EmptyGLWidget(const QGLFormat& format, QWidget* parent) : QGLWidget(format, parent) { setAutoBufferSwap(false); }
33
34protected:
35 void paintEvent(QPaintEvent*) override {}
36 void resizeEvent(QResizeEvent*) override {}
37 void mouseMoveEvent(QMouseEvent* event) override { event->ignore(); }
38};
39
40class PainterGL;
41class DisplayGL : public Display {
42Q_OBJECT
43
44public:
45 DisplayGL(const QGLFormat& format, QWidget* parent = nullptr);
46 ~DisplayGL();
47
48 bool isDrawing() const override { return m_isDrawing; }
49 bool supportsShaders() const override;
50 VideoShader* shaders() override;
51
52public slots:
53 void startDrawing(GBAThread* context) override;
54 void stopDrawing() override;
55 void pauseDrawing() override;
56 void unpauseDrawing() override;
57 void forceDraw() override;
58 void lockAspectRatio(bool lock) override;
59 void filter(bool filter) override;
60 void framePosted(const uint32_t*) override;
61 void setShaders(struct VDir*) override;
62
63protected:
64 virtual void paintEvent(QPaintEvent*) override {}
65 virtual void resizeEvent(QResizeEvent*) override;
66
67private:
68 void resizePainter();
69
70 bool m_isDrawing;
71 QGLWidget* m_gl;
72 PainterGL* m_painter;
73 QThread* m_drawThread;
74 GBAThread* m_context;
75};
76
77class PainterGL : public QObject {
78Q_OBJECT
79
80public:
81 PainterGL(QGLWidget* parent, QGLFormat::OpenGLVersionFlags = QGLFormat::OpenGL_Version_1_1);
82 ~PainterGL();
83
84 void setContext(GBAThread*);
85 void setMessagePainter(MessagePainter*);
86 void enqueue(const uint32_t* backing);
87
88 bool supportsShaders() const { return m_supportsShaders; }
89
90public slots:
91 void forceDraw();
92 void draw();
93 void start();
94 void stop();
95 void pause();
96 void unpause();
97 void resize(const QSize& size);
98 void lockAspectRatio(bool lock);
99 void filter(bool filter);
100
101 void setShaders(struct VDir*);
102 VideoShader* shaders();
103
104private:
105 void performDraw();
106 void dequeue();
107 void dequeueAll();
108
109 QList<uint32_t*> m_free;
110 QQueue<uint32_t*> m_queue;
111 QPainter m_painter;
112 QMutex m_mutex;
113 QGLWidget* m_gl;
114 bool m_active;
115 bool m_started;
116 GBAThread* m_context;
117 bool m_supportsShaders;
118 VideoShader m_shader;
119 VideoBackend* m_backend;
120 QSize m_size;
121 MessagePainter* m_messagePainter;
122};
123
124}
125
126#endif