all repos — mgba @ 36daee6de33f8b404d6238d285a4c0d20680a35c

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