all repos — mgba @ a6ff9f6c60e2b745a2e27323bf89bc4d2d08005e

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