all repos — mgba @ 47bf26ff73d9bdf8a044773b20fc816f6e823e7e

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