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