all repos — mgba @ 91ee44c4580f296690e9f995d45b24f74ee8be17

mGBA Game Boy Advance Emulator

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