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 void clearShaders() override;
63
64protected:
65 virtual void paintEvent(QPaintEvent*) override {}
66 virtual void resizeEvent(QResizeEvent*) override;
67
68private:
69 void resizePainter();
70
71 bool m_isDrawing;
72 QGLWidget* m_gl;
73 PainterGL* m_painter;
74 QThread* m_drawThread;
75 GBAThread* m_context;
76};
77
78class PainterGL : public QObject {
79Q_OBJECT
80
81public:
82 PainterGL(QGLWidget* parent, QGLFormat::OpenGLVersionFlags = QGLFormat::OpenGL_Version_1_1);
83 ~PainterGL();
84
85 void setContext(GBAThread*);
86 void setMessagePainter(MessagePainter*);
87 void enqueue(const uint32_t* backing);
88
89 bool supportsShaders() const { return m_supportsShaders; }
90
91public slots:
92 void forceDraw();
93 void draw();
94 void start();
95 void stop();
96 void pause();
97 void unpause();
98 void resize(const QSize& size);
99 void lockAspectRatio(bool lock);
100 void filter(bool filter);
101
102 void setShaders(struct VDir*);
103 void clearShaders();
104 VideoShader* shaders();
105
106private:
107 void performDraw();
108 void dequeue();
109 void dequeueAll();
110
111 QList<uint32_t*> m_free;
112 QQueue<uint32_t*> m_queue;
113 QPainter m_painter;
114 QMutex m_mutex;
115 QGLWidget* m_gl;
116 bool m_active;
117 bool m_started;
118 GBAThread* m_context;
119 bool m_supportsShaders;
120 VideoShader m_shader;
121 VideoBackend* m_backend;
122 QSize m_size;
123 MessagePainter* m_messagePainter;
124};
125
126}
127
128#endif