all repos — mgba @ 65543bdd69d97d4d8e9da098f2661cfc09191fc7

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 Painter;
20class DisplayGL : public Display {
21Q_OBJECT
22
23public:
24	DisplayGL(const QGLFormat& format, QWidget* parent = nullptr);
25
26public slots:
27	void startDrawing(GBAThread* context) override;
28	void stopDrawing() override;
29	void pauseDrawing() override;
30	void unpauseDrawing() override;
31	void forceDraw() override;
32	void lockAspectRatio(bool lock) override;
33	void filter(bool filter) override;
34	void framePosted(const uint32_t*) override;
35
36protected:
37	virtual void paintEvent(QPaintEvent*) override {};
38	virtual void resizeEvent(QResizeEvent*) override;
39
40private:
41	Painter* m_painter;
42	bool m_started;
43	GBAThread* m_context;
44	bool m_lockAspectRatio;
45	bool m_filter;
46};
47
48class Painter : public QGLWidget {
49Q_OBJECT
50
51public:
52	Painter(const QGLFormat& format, QWidget* parent);
53
54	void setContext(GBAThread*);
55	void setBacking(const uint32_t*);
56
57public slots:
58	void forceDraw();
59	void draw();
60	void start();
61	void stop();
62	void pause();
63	void unpause();
64	void resize(const QSize& size);
65	void lockAspectRatio(bool lock);
66	void filter(bool filter);
67
68protected:
69	virtual void initializeGL() override;
70	virtual void paintEvent(QPaintEvent*) override {}
71
72private:
73	void performDraw();
74
75	QTimer* m_drawTimer;
76	GBAThread* m_context;
77	GLuint m_tex;
78	QSize m_size;
79	bool m_lockAspectRatio;
80	bool m_filter;
81};
82
83}
84
85#endif