all repos — mgba @ 8538e99a089118d0dc004eddbf48f453fbf9ebbc

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