all repos — mgba @ ded463ea25eb4752a612cbe0c53a578ec3b4666f

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#ifdef USE_EPOXY
 12#include <epoxy/gl.h>
 13#endif
 14
 15#include <QGLWidget>
 16#include <QList>
 17#include <QMouseEvent>
 18#include <QQueue>
 19#include <QThread>
 20#include <QTimer>
 21
 22struct GBAThread;
 23struct VideoBackend;
 24struct GBAGLES2Shader;
 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	bool supportsShaders() const override;
 48
 49public slots:
 50	void startDrawing(GBAThread* context) override;
 51	void stopDrawing() override;
 52	void pauseDrawing() override;
 53	void unpauseDrawing() override;
 54	void forceDraw() override;
 55	void lockAspectRatio(bool lock) override;
 56	void filter(bool filter) override;
 57	void framePosted(const uint32_t*) override;
 58	void setShaders(struct VDir*) override;
 59
 60protected:
 61	virtual void paintEvent(QPaintEvent*) override {}
 62	virtual void resizeEvent(QResizeEvent*) override;
 63
 64private:
 65	void resizePainter();
 66
 67	bool m_isDrawing;
 68	QGLWidget* m_gl;
 69	PainterGL* m_painter;
 70	QThread* m_drawThread;
 71	GBAThread* m_context;
 72};
 73
 74class PainterGL : public QObject {
 75Q_OBJECT
 76
 77public:
 78	PainterGL(QGLWidget* parent, QGLFormat::OpenGLVersionFlags = QGLFormat::OpenGL_Version_1_1);
 79	~PainterGL();
 80
 81	void setContext(GBAThread*);
 82	void setMessagePainter(MessagePainter*);
 83	void enqueue(const uint32_t* backing);
 84
 85	bool supportsShaders() const { return m_supportsShaders; }
 86
 87public slots:
 88	void forceDraw();
 89	void draw();
 90	void start();
 91	void stop();
 92	void pause();
 93	void unpause();
 94	void resize(const QSize& size);
 95	void lockAspectRatio(bool lock);
 96	void filter(bool filter);
 97
 98	void setShaders(struct VDir*);
 99
100private:
101	void performDraw();
102	void dequeue();
103	void dequeueAll();
104
105	QList<uint32_t*> m_free;
106	QQueue<uint32_t*> m_queue;
107	QPainter m_painter;
108	QMutex m_mutex;
109	QGLWidget* m_gl;
110	bool m_active;
111	bool m_started;
112	GBAThread* m_context;
113	bool m_supportsShaders;
114	GBAGLES2Shader* m_shaders;
115	size_t m_nShaders;
116	VideoBackend* m_backend;
117	QSize m_size;
118	MessagePainter* m_messagePainter;
119};
120
121}
122
123#endif