all repos — mgba @ 74ac89a584b068b9d9c02e5117eddbe6da22d9c5

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 <QMouseEvent>
 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	void mouseMoveEvent(QMouseEvent* event) override { event->ignore(); }
 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
 52protected:
 53	virtual void paintEvent(QPaintEvent*) override {}
 54	virtual void resizeEvent(QResizeEvent*) override;
 55
 56private:
 57	void resizePainter();
 58
 59	QGLWidget* m_gl;
 60	PainterGL* m_painter;
 61	QThread* m_drawThread;
 62	GBAThread* m_context;
 63};
 64
 65class PainterGL : public QObject {
 66Q_OBJECT
 67
 68public:
 69	PainterGL(QGLWidget* parent);
 70
 71	void setContext(GBAThread*);
 72	void setMessagePainter(MessagePainter*);
 73
 74public slots:
 75	void setBacking(const uint32_t*);
 76	void forceDraw();
 77	void draw();
 78	void start();
 79	void stop();
 80	void pause();
 81	void unpause();
 82	void resize(const QSize& size);
 83	void lockAspectRatio(bool lock);
 84	void filter(bool filter);
 85
 86private:
 87	void performDraw();
 88
 89	QPainter m_painter;
 90	QGLWidget* m_gl;
 91	bool m_active;
 92	GBAThread* m_context;
 93	GBAGLContext m_backend;
 94	QSize m_size;
 95	MessagePainter* m_messagePainter;
 96};
 97
 98}
 99
100#endif