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#include <QGLWidget>
12#include <QMouseEvent>
13#include <QThread>
14#include <QTimer>
15
16extern "C" {
17#ifdef BUILD_GL
18#include "platform/opengl/gl.h"
19#elif defined(BUILD_GLES2)
20#include "platform/opengl/gles2.h"
21#endif
22}
23
24struct GBAThread;
25
26namespace QGBA {
27
28class EmptyGLWidget : public QGLWidget {
29public:
30 EmptyGLWidget(const QGLFormat& format, QWidget* parent) : QGLWidget(format, parent) { setAutoBufferSwap(false); }
31
32protected:
33 void paintEvent(QPaintEvent*) override {}
34 void resizeEvent(QResizeEvent*) override {}
35 void mouseMoveEvent(QMouseEvent* event) override { event->ignore(); }
36};
37
38class PainterGL;
39class DisplayGL : public Display {
40Q_OBJECT
41
42public:
43 DisplayGL(const QGLFormat& format, QWidget* parent = nullptr);
44 ~DisplayGL();
45
46public slots:
47 void startDrawing(GBAThread* context) override;
48 void stopDrawing() override;
49 void pauseDrawing() override;
50 void unpauseDrawing() override;
51 void forceDraw() override;
52 void lockAspectRatio(bool lock) override;
53 void filter(bool filter) override;
54 void framePosted(const uint32_t*) override;
55
56protected:
57 virtual void paintEvent(QPaintEvent*) override {}
58 virtual void resizeEvent(QResizeEvent*) override;
59
60private:
61 void resizePainter();
62
63 QGLWidget* m_gl;
64 PainterGL* m_painter;
65 QThread* m_drawThread;
66 GBAThread* m_context;
67};
68
69class PainterGL : public QObject {
70Q_OBJECT
71
72public:
73 PainterGL(QGLWidget* parent);
74
75 void setContext(GBAThread*);
76 void setMessagePainter(MessagePainter*);
77
78public slots:
79 void setBacking(const uint32_t*);
80 void forceDraw();
81 void draw();
82 void start();
83 void stop();
84 void pause();
85 void unpause();
86 void resize(const QSize& size);
87 void lockAspectRatio(bool lock);
88 void filter(bool filter);
89
90private:
91 void performDraw();
92
93 QPainter m_painter;
94 QGLWidget* m_gl;
95 bool m_active;
96 GBAThread* m_context;
97#ifdef BUILD_GL
98 GBAGLContext m_backend;
99#elif defined(BUILD_GLES2)
100 GBAGLES2Context m_backend;
101#endif
102 QSize m_size;
103 MessagePainter* m_messagePainter;
104};
105
106}
107
108#endif