all repos — mgba @ 12505766e1ab83954ab216a5828cd064834056e8

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 <QStaticText>
 13#include <QThread>
 14#include <QTimer>
 15
 16struct GBAThread;
 17
 18namespace QGBA {
 19
 20class EmptyGLWidget : public QGLWidget {
 21public:
 22	EmptyGLWidget(const QGLFormat& format, QWidget* parent) : QGLWidget(format, parent) { setAutoBufferSwap(false); }
 23
 24protected:
 25	void paintEvent(QPaintEvent*) override {}
 26	void resizeEvent(QResizeEvent*) override {}
 27};
 28
 29class PainterGL;
 30class DisplayGL : public Display {
 31Q_OBJECT
 32
 33public:
 34	DisplayGL(const QGLFormat& format, QWidget* parent = nullptr);
 35	~DisplayGL();
 36
 37public slots:
 38	void startDrawing(GBAThread* context) override;
 39	void stopDrawing() override;
 40	void pauseDrawing() override;
 41	void unpauseDrawing() override;
 42	void forceDraw() override;
 43	void lockAspectRatio(bool lock) override;
 44	void filter(bool filter) override;
 45	void framePosted(const uint32_t*) override;
 46
 47	void showMessage(const QString& message) override;
 48
 49protected:
 50	virtual void paintEvent(QPaintEvent*) override {}
 51	virtual void resizeEvent(QResizeEvent*) override;
 52
 53private:
 54	void resizePainter();
 55
 56	QGLWidget* m_gl;
 57	PainterGL* m_painter;
 58	QThread* m_drawThread;
 59	GBAThread* m_context;
 60	bool m_lockAspectRatio;
 61	bool m_filter;
 62};
 63
 64class PainterGL : public QObject {
 65Q_OBJECT
 66
 67public:
 68	PainterGL(QGLWidget* parent);
 69
 70	void setContext(GBAThread*);
 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
 84	void showMessage(const QString& message);
 85	void clearMessage();
 86
 87private:
 88	void performDraw();
 89
 90	QPainter m_painter;
 91	QStaticText m_message;
 92	QGLWidget* m_gl;
 93	QThread* m_thread;
 94	QTimer* m_drawTimer;
 95	QTimer m_messageTimer;
 96	GBAThread* m_context;
 97	GLuint m_tex;
 98	QSize m_size;
 99	bool m_lockAspectRatio;
100	bool m_filter;
101	QRect m_viewport;
102	QTransform m_world;
103	QFont m_messageFont;
104};
105
106}
107
108#endif