all repos — mgba @ f35136f8814b74518a3a0ba2d39f3b70876f3f3d

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
 66protected:
 67	virtual void paintEvent(QPaintEvent*) override { forceDraw(); }
 68	virtual void resizeEvent(QResizeEvent*) override;
 69
 70private:
 71	void resizePainter();
 72
 73	bool m_isDrawing = false;
 74	QOpenGLContext* m_gl;
 75	PainterGL* m_painter;
 76	QThread* m_drawThread = nullptr;
 77	std::shared_ptr<CoreController> m_context;
 78};
 79
 80class PainterGL : public QObject {
 81Q_OBJECT
 82
 83public:
 84	PainterGL(QWindow* surface, QOpenGLContext* parent, int forceVersion = 0);
 85	~PainterGL();
 86
 87	void setContext(std::shared_ptr<CoreController>);
 88	void setMessagePainter(MessagePainter*);
 89	void enqueue(const uint32_t* backing);
 90
 91	bool supportsShaders() const { return m_supportsShaders; }
 92
 93	void setVideoProxy(std::shared_ptr<VideoProxy>);
 94
 95public slots:
 96	void forceDraw();
 97	void draw();
 98	void start();
 99	void stop();
100	void pause();
101	void unpause();
102	void resize(const QSize& size);
103	void lockAspectRatio(bool lock);
104	void lockIntegerScaling(bool lock);
105	void interframeBlending(bool enable);
106	void showOSD(bool enable);
107	void filter(bool filter);
108	void resizeContext();
109
110	void setShaders(struct VDir*);
111	void clearShaders();
112	VideoShader* shaders();
113
114	int glTex();
115
116private:
117	void performDraw();
118	void dequeue();
119	void dequeueAll();
120
121	QList<uint32_t*> m_free;
122	QQueue<uint32_t*> m_queue;
123	QPainter m_painter;
124	QMutex m_mutex;
125	QWindow* m_surface;
126	QOpenGLPaintDevice* m_window;
127	QOpenGLContext* m_gl;
128	bool m_active = false;
129	bool m_started = false;
130	std::shared_ptr<CoreController> m_context = nullptr;
131	bool m_supportsShaders;
132	bool m_showOSD;
133	VideoShader m_shader{};
134	VideoBackend* m_backend = nullptr;
135	QSize m_size;
136	MessagePainter* m_messagePainter = nullptr;
137	QElapsedTimer m_delayTimer;
138	std::shared_ptr<VideoProxy> m_videoProxy;
139};
140
141}
142
143#endif