all repos — mgba @ 2448ff715fcb1216db8a9d7c51087a4e8255015c

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