all repos — mgba @ f039234055a00181becf186ebceee71bfbbdc597

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#pragma once
  7
  8#if defined(BUILD_GL) || defined(BUILD_GLES2)
  9
 10#include "Display.h"
 11
 12#ifdef USE_EPOXY
 13#include <epoxy/gl.h>
 14#ifndef GLdouble
 15#define GLdouble GLdouble
 16#endif
 17#endif
 18
 19#include <QElapsedTimer>
 20#include <QGLWidget>
 21#include <QList>
 22#include <QMouseEvent>
 23#include <QQueue>
 24#include <QThread>
 25
 26#include "platform/video-backend.h"
 27
 28namespace QGBA {
 29
 30class EmptyGLWidget : public QGLWidget {
 31public:
 32	EmptyGLWidget(const QGLFormat& format, QWidget* parent) : QGLWidget(format, parent) { setAutoBufferSwap(false); }
 33
 34protected:
 35	void paintEvent(QPaintEvent*) override {}
 36	void resizeEvent(QResizeEvent*) override {}
 37	void mouseMoveEvent(QMouseEvent* event) override { event->ignore(); }
 38};
 39
 40class PainterGL;
 41class DisplayGL : public Display {
 42Q_OBJECT
 43
 44public:
 45	DisplayGL(const QGLFormat& format, QWidget* parent = nullptr);
 46	~DisplayGL();
 47
 48	void startDrawing(std::shared_ptr<CoreController>) override;
 49	bool isDrawing() const override { return m_isDrawing; }
 50	bool supportsShaders() const override;
 51	VideoShader* shaders() override;
 52
 53public slots:
 54	void stopDrawing() override;
 55	void pauseDrawing() override;
 56	void unpauseDrawing() override;
 57	void forceDraw() override;
 58	void lockAspectRatio(bool lock) override;
 59	void lockIntegerScaling(bool lock) override;
 60	void filter(bool filter) override;
 61	void framePosted() 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 = false;
 73	QGLWidget* m_gl;
 74	PainterGL* m_painter;
 75	QThread* m_drawThread = nullptr;
 76	std::shared_ptr<CoreController> m_context;
 77};
 78
 79class PainterGL : public QObject {
 80Q_OBJECT
 81
 82public:
 83	PainterGL(int majorVersion, QGLWidget* parent);
 84	~PainterGL();
 85
 86	void setContext(std::shared_ptr<CoreController>);
 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 lockIntegerScaling(bool lock);
102	void filter(bool filter);
103
104	void setShaders(struct VDir*);
105	void clearShaders();
106	VideoShader* shaders();
107
108private:
109	void performDraw();
110	void dequeue();
111	void dequeueAll();
112
113	QList<uint32_t*> m_free;
114	QQueue<uint32_t*> m_queue;
115	QPainter m_painter;
116	QMutex m_mutex;
117	QGLWidget* m_gl;
118	bool m_active = false;
119	bool m_started = false;
120	std::shared_ptr<CoreController> m_context = nullptr;
121	bool m_supportsShaders;
122	VideoShader m_shader{};
123	VideoBackend* m_backend = nullptr;
124	QSize m_size;
125	MessagePainter* m_messagePainter = nullptr;
126	QElapsedTimer m_delayTimer;
127};
128
129}
130
131#endif