all repos — mgba @ 9ddf82bebc1915ce8bee833e44b0a8eaa6451bbc

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 "VideoProxy.h"
 29
 30#include "platform/video-backend.h"
 31
 32class QOpenGLPaintDevice;
 33
 34namespace QGBA {
 35
 36class PainterGL;
 37class DisplayGL : public Display {
 38Q_OBJECT
 39
 40public:
 41	DisplayGL(const QSurfaceFormat& format, QWidget* parent = nullptr);
 42	~DisplayGL();
 43
 44	void startDrawing(std::shared_ptr<CoreController>) override;
 45	bool isDrawing() const override { return m_isDrawing; }
 46	bool supportsShaders() const override;
 47	VideoShader* shaders() override;
 48	void setVideoProxy(std::shared_ptr<VideoProxy>) override;
 49	int framebufferHandle() override;
 50
 51public slots:
 52	void stopDrawing() override;
 53	void pauseDrawing() override;
 54	void unpauseDrawing() override;
 55	void forceDraw() override;
 56	void lockAspectRatio(bool lock) override;
 57	void lockIntegerScaling(bool lock) override;
 58	void interframeBlending(bool enable) override;
 59	void showOSDMessages(bool enable) override;
 60	void filter(bool filter) override;
 61	void framePosted() override;
 62	void setShaders(struct VDir*) override;
 63	void clearShaders() override;
 64	void resizeContext() override;
 65	void setVideoScale(int scale) override;
 66
 67protected:
 68	virtual void paintEvent(QPaintEvent*) override { forceDraw(); }
 69	virtual void resizeEvent(QResizeEvent*) override;
 70
 71private:
 72	void resizePainter();
 73
 74	bool m_isDrawing = false;
 75	QOpenGLContext* m_gl;
 76	PainterGL* m_painter;
 77	QThread* m_drawThread = nullptr;
 78	std::shared_ptr<CoreController> m_context;
 79};
 80
 81class PainterGL : public QObject {
 82Q_OBJECT
 83
 84public:
 85	PainterGL(QWindow* surface, QOpenGLContext* parent, int forceVersion = 0);
 86	~PainterGL();
 87
 88	void setContext(std::shared_ptr<CoreController>);
 89	void setMessagePainter(MessagePainter*);
 90	void enqueue(const uint32_t* backing);
 91
 92	bool supportsShaders() const { return m_supportsShaders; }
 93
 94	void setVideoProxy(std::shared_ptr<VideoProxy>);
 95
 96public slots:
 97	void forceDraw();
 98	void draw();
 99	void start();
100	void stop();
101	void pause();
102	void unpause();
103	void resize(const QSize& size);
104	void lockAspectRatio(bool lock);
105	void lockIntegerScaling(bool lock);
106	void interframeBlending(bool enable);
107	void showOSD(bool enable);
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	uint32_t* m_buffer;
125	QPainter m_painter;
126	QMutex m_mutex;
127	QWindow* m_surface;
128	QOpenGLPaintDevice* m_window;
129	QOpenGLContext* m_gl;
130	bool m_active = false;
131	bool m_started = false;
132	std::shared_ptr<CoreController> m_context = nullptr;
133	bool m_supportsShaders;
134	bool m_showOSD;
135	VideoShader m_shader{};
136	VideoBackend* m_backend = nullptr;
137	QSize m_size;
138	MessagePainter* m_messagePainter = nullptr;
139	QElapsedTimer m_delayTimer;
140	std::shared_ptr<VideoProxy> m_videoProxy;
141};
142
143}
144
145#endif