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#pragma once
7
8#if defined(BUILD_GL) || defined(BUILD_GLES2)
9
10#include "Display.h"
11
12#ifdef USE_EPOXY
13#include <epoxy/gl.h>
14#ifndef GLdouble
15#define GLdouble GLdouble
16#endif
17#endif
18
19#include <QElapsedTimer>
20#include <QGLWidget>
21#include <QList>
22#include <QMouseEvent>
23#include <QQueue>
24#include <QThread>
25
26#include "platform/video-backend.h"
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 void startDrawing(std::shared_ptr<CoreController>) override;
49 bool isDrawing() const override { return m_isDrawing; }
50 bool supportsShaders() const override;
51 VideoShader* shaders() override;
52
53public slots:
54 void stopDrawing() override;
55 void pauseDrawing() override;
56 void unpauseDrawing() override;
57 void forceDraw() override;
58 void lockAspectRatio(bool lock) override;
59 void lockIntegerScaling(bool lock) override;
60 void filter(bool filter) override;
61 void framePosted() override;
62 void setShaders(struct VDir*) override;
63 void clearShaders() override;
64 void resizeContext() 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 std::shared_ptr<CoreController> m_context;
78};
79
80class PainterGL : public QObject {
81Q_OBJECT
82
83public:
84 PainterGL(int majorVersion, QGLWidget* parent);
85 ~PainterGL();
86
87 void setContext(std::shared_ptr<CoreController>);
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 void resizeContext();
105
106 void setShaders(struct VDir*);
107 void clearShaders();
108 VideoShader* shaders();
109
110private:
111 void performDraw();
112 void dequeue();
113 void dequeueAll();
114
115 QList<uint32_t*> m_free;
116 QQueue<uint32_t*> m_queue;
117 QPainter m_painter;
118 QMutex m_mutex;
119 QGLWidget* m_gl;
120 bool m_active = false;
121 bool m_started = false;
122 std::shared_ptr<CoreController> m_context = nullptr;
123 bool m_supportsShaders;
124 VideoShader m_shader{};
125 VideoBackend* m_backend = nullptr;
126 QSize m_size;
127 MessagePainter* m_messagePainter = nullptr;
128 QElapsedTimer m_delayTimer;
129};
130
131}
132
133#endif