all repos — mgba @ 1baa9287f34855f9eaceab89eb7703cb928f5599

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