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