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#ifndef GLdouble
14#define GLdouble GLdouble
15#endif
16#endif
17
18#include <QGLWidget>
19#include <QList>
20#include <QMouseEvent>
21#include <QQueue>
22#include <QThread>
23#include <QTimer>
24
25#include "platform/video-backend.h"
26
27namespace QGBA {
28
29class EmptyGLWidget : public QGLWidget {
30public:
31 EmptyGLWidget(const QGLFormat& format, QWidget* parent) : QGLWidget(format, parent) { setAutoBufferSwap(false); }
32
33protected:
34 void paintEvent(QPaintEvent*) override {}
35 void resizeEvent(QResizeEvent*) override {}
36 void mouseMoveEvent(QMouseEvent* event) override { event->ignore(); }
37};
38
39class PainterGL;
40class DisplayGL : public Display {
41Q_OBJECT
42
43public:
44 DisplayGL(const QGLFormat& format, QWidget* parent = nullptr);
45 ~DisplayGL();
46
47 bool isDrawing() const override { return m_isDrawing; }
48 bool supportsShaders() const override;
49 VideoShader* shaders() override;
50
51public slots:
52 void startDrawing(mCoreThread* context) override;
53 void stopDrawing() override;
54 void pauseDrawing() override;
55 void unpauseDrawing() override;
56 void forceDraw() override;
57 void lockAspectRatio(bool lock) override;
58 void filter(bool filter) override;
59 void framePosted(const uint32_t*) override;
60 void setShaders(struct VDir*) override;
61 void clearShaders() 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 mCoreThread* m_context;
75};
76
77class PainterGL : public QObject {
78Q_OBJECT
79
80public:
81 PainterGL(int majorVersion, QGLWidget* parent);
82 ~PainterGL();
83
84 void setContext(mCoreThread*);
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 void clearShaders();
103 VideoShader* shaders();
104
105private:
106 void performDraw();
107 void dequeue();
108 void dequeueAll();
109
110 QList<uint32_t*> m_free;
111 QQueue<uint32_t*> m_queue;
112 QPainter m_painter;
113 QMutex m_mutex;
114 QGLWidget* m_gl;
115 bool m_active;
116 bool m_started;
117 mCoreThread* m_context;
118 bool m_supportsShaders;
119 VideoShader m_shader;
120 VideoBackend* m_backend;
121 QSize m_size;
122 MessagePainter* m_messagePainter;
123};
124
125}
126
127#endif