all repos — mgba @ 782f6191e51b16211d1f783d0ae61aac722c54d3

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