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