all repos — mgba @ 74edd964daeebe53f6b1d9f86e91aecced1149a8

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 <QOpenGLContext>
 21#include <QList>
 22#include <QMouseEvent>
 23#include <QPainter>
 24#include <QQueue>
 25#include <QThread>
 26#include <QTimer>
 27
 28#include <array>
 29
 30#include "VideoProxy.h"
 31
 32#include "platform/video-backend.h"
 33
 34class QOpenGLPaintDevice;
 35
 36namespace QGBA {
 37
 38class PainterGL;
 39class DisplayGL : public Display {
 40Q_OBJECT
 41
 42public:
 43	DisplayGL(const QSurfaceFormat& format, QWidget* parent = nullptr);
 44	~DisplayGL();
 45
 46	void startDrawing(std::shared_ptr<CoreController>) override;
 47	bool isDrawing() const override { return m_isDrawing; }
 48	bool supportsShaders() const override;
 49	VideoShader* shaders() override;
 50	void setVideoProxy(std::shared_ptr<VideoProxy>) override;
 51	int framebufferHandle() 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 interframeBlending(bool enable) override;
 61	void showOSDMessages(bool enable) override;
 62	void filter(bool filter) override;
 63	void framePosted() override;
 64	void setShaders(struct VDir*) override;
 65	void clearShaders() override;
 66	void resizeContext() override;
 67	void setVideoScale(int scale) override;
 68
 69protected:
 70	virtual void paintEvent(QPaintEvent*) override { forceDraw(); }
 71	virtual void resizeEvent(QResizeEvent*) override;
 72
 73private:
 74	void resizePainter();
 75
 76	bool m_isDrawing = false;
 77	std::unique_ptr<PainterGL> m_painter;
 78	QThread* m_drawThread = nullptr;
 79	std::shared_ptr<CoreController> m_context;
 80};
 81
 82class PainterGL : public QObject {
 83Q_OBJECT
 84
 85public:
 86	PainterGL(QWindow* surface, const QSurfaceFormat& format);
 87	~PainterGL();
 88
 89	void setContext(std::shared_ptr<CoreController>);
 90	void setMessagePainter(MessagePainter*);
 91	void enqueue(const uint32_t* backing);
 92
 93	bool supportsShaders() const { return m_supportsShaders; }
 94
 95	void setVideoProxy(std::shared_ptr<VideoProxy>);
 96
 97public slots:
 98	void forceDraw();
 99	void draw();
100	void start();
101	void stop();
102	void pause();
103	void unpause();
104	void resize(const QSize& size);
105	void lockAspectRatio(bool lock);
106	void lockIntegerScaling(bool lock);
107	void interframeBlending(bool enable);
108	void showOSD(bool enable);
109	void filter(bool filter);
110	void resizeContext();
111
112	void setShaders(struct VDir*);
113	void clearShaders();
114	VideoShader* shaders();
115
116	int glTex();
117
118private:
119	void performDraw();
120	void dequeue();
121	void dequeueAll();
122	void create();
123	void destroy();
124
125	std::array<std::array<uint32_t, 0x100000>, 3> m_buffers;
126	QList<uint32_t*> m_free;
127	QQueue<uint32_t*> m_queue;
128	uint32_t* m_buffer;
129	QPainter m_painter;
130	QMutex m_mutex;
131	QWindow* m_surface;
132	QSurfaceFormat m_format;
133	std::unique_ptr<QOpenGLPaintDevice> m_window;
134	std::unique_ptr<QOpenGLContext> m_gl;
135	bool m_active = false;
136	bool m_started = false;
137	std::shared_ptr<CoreController> m_context = nullptr;
138	bool m_supportsShaders;
139	bool m_showOSD;
140	VideoShader m_shader{};
141	VideoBackend* m_backend = nullptr;
142	QSize m_size;
143	MessagePainter* m_messagePainter = nullptr;
144	QElapsedTimer m_delayTimer;
145	std::shared_ptr<VideoProxy> m_videoProxy;
146};
147
148}
149
150#endif