all repos — mgba @ fc905657adeba406a2c280bbb94b09533a89e3f8

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