all repos — mgba @ d0771b78e22e89b5523badee256ec6e15467dc54

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