all repos — mgba @ e902a253946efa4abcd2c8c930a7733998c5f337

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	QOpenGLContext* m_gl;
 78	PainterGL* m_painter;
 79	QThread* m_drawThread = nullptr;
 80	std::shared_ptr<CoreController> m_context;
 81};
 82
 83class PainterGL : public QObject {
 84Q_OBJECT
 85
 86public:
 87	PainterGL(QWindow* surface, QOpenGLContext* parent, int forceVersion = 0);
 88	~PainterGL();
 89
 90	void setContext(std::shared_ptr<CoreController>);
 91	void setMessagePainter(MessagePainter*);
 92	void enqueue(const uint32_t* backing);
 93
 94	bool supportsShaders() const { return m_supportsShaders; }
 95
 96	void setVideoProxy(std::shared_ptr<VideoProxy>);
 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 interframeBlending(bool enable);
109	void showOSD(bool enable);
110	void filter(bool filter);
111	void resizeContext();
112
113	void setShaders(struct VDir*);
114	void clearShaders();
115	VideoShader* shaders();
116
117	int glTex();
118
119private:
120	void performDraw();
121	void dequeue();
122	void dequeueAll();
123
124	std::array<std::array<uint32_t, 0x100000>, 3> m_buffers;
125	QList<uint32_t*> m_free;
126	QQueue<uint32_t*> m_queue;
127	uint32_t* m_buffer;
128	QPainter m_painter;
129	QMutex m_mutex;
130	QWindow* m_surface;
131	QOpenGLPaintDevice* m_window;
132	QOpenGLContext* m_gl;
133	bool m_active = false;
134	bool m_started = false;
135	std::shared_ptr<CoreController> m_context = nullptr;
136	bool m_supportsShaders;
137	bool m_showOSD;
138	VideoShader m_shader{};
139	VideoBackend* m_backend = nullptr;
140	QSize m_size;
141	MessagePainter* m_messagePainter = nullptr;
142	QElapsedTimer m_delayTimer;
143	std::shared_ptr<VideoProxy> m_videoProxy;
144};
145
146}
147
148#endif