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#if defined(BUILD_GL) || defined(BUILD_GLES)
10
11#include "Display.h"
12
13#ifdef USE_EPOXY
14#include <epoxy/gl.h>
15#ifndef GLdouble
16#define GLdouble GLdouble
17#endif
18#endif
19
20#include <QElapsedTimer>
21#include <QGLWidget>
22#include <QList>
23#include <QMouseEvent>
24#include <QQueue>
25#include <QThread>
26
27#include "platform/video-backend.h"
28
29namespace QGBA {
30
31class EmptyGLWidget : public QGLWidget {
32public:
33 EmptyGLWidget(const QGLFormat& format, QWidget* parent) : QGLWidget(format, parent) { setAutoBufferSwap(false); }
34
35protected:
36 void paintEvent(QPaintEvent*) override {}
37 void resizeEvent(QResizeEvent*) override {}
38 void mouseMoveEvent(QMouseEvent* event) override { event->ignore(); }
39};
40
41class PainterGL;
42class DisplayGL : public Display {
43Q_OBJECT
44
45public:
46 DisplayGL(const QGLFormat& format, QWidget* parent = nullptr);
47 ~DisplayGL();
48
49 bool isDrawing() const override { return m_isDrawing; }
50 bool supportsShaders() const override;
51 VideoShader* shaders() override;
52
53public slots:
54 void startDrawing(mCoreThread* context) override;
55 void stopDrawing() override;
56 void pauseDrawing() override;
57 void unpauseDrawing() override;
58 void forceDraw() override;
59 void lockAspectRatio(bool lock) override;
60 void lockIntegerScaling(bool lock) override;
61 void filter(bool filter) override;
62 void framePosted(const uint32_t*) override;
63 void setShaders(struct VDir*) override;
64 void clearShaders() override;
65
66protected:
67 virtual void paintEvent(QPaintEvent*) override {}
68 virtual void resizeEvent(QResizeEvent*) override;
69
70private:
71 void resizePainter();
72
73 bool m_isDrawing = false;
74 QGLWidget* m_gl;
75 PainterGL* m_painter;
76 QThread* m_drawThread = nullptr;
77 mCoreThread* m_context = nullptr;
78};
79
80class PainterGL : public QObject {
81Q_OBJECT
82
83public:
84 PainterGL(int majorVersion, QGLWidget* parent);
85 ~PainterGL();
86
87 void setContext(mCoreThread*);
88 void setMessagePainter(MessagePainter*);
89 void enqueue(const uint32_t* backing);
90
91 bool supportsShaders() const { return m_supportsShaders; }
92
93public slots:
94 void forceDraw();
95 void draw();
96 void start();
97 void stop();
98 void pause();
99 void unpause();
100 void resize(const QSize& size);
101 void lockAspectRatio(bool lock);
102 void lockIntegerScaling(bool lock);
103 void filter(bool filter);
104
105 void setShaders(struct VDir*);
106 void clearShaders();
107 VideoShader* shaders();
108
109private:
110 void performDraw();
111 void dequeue();
112 void dequeueAll();
113
114 QList<uint32_t*> m_free;
115 QQueue<uint32_t*> m_queue;
116 QPainter m_painter;
117 QMutex m_mutex;
118 QGLWidget* m_gl;
119 bool m_active;
120 bool m_started;
121 mCoreThread* m_context;
122 bool m_supportsShaders;
123 VideoShader m_shader;
124 VideoBackend* m_backend;
125 QSize m_size;
126 MessagePainter* m_messagePainter;
127 QElapsedTimer m_delayTimer;
128};
129
130}
131
132#endif
133
134#endif