Files
86Box/src/qt/qt_hardwarerenderer.hpp

80 lines
1.9 KiB
C++
Raw Normal View History

#pragma once
#include <QOpenGLFunctions>
2021-12-27 16:32:03 +06:00
#include <QOpenGLBuffer>
2021-12-17 12:17:54 +06:00
#include <QOpenGLWindow>
2021-12-27 16:32:03 +06:00
#include <QOpenGLVertexArrayObject>
#include <QOpenGLTexture>
#include <QOpenGLShader>
#include <QOpenGLShaderProgram>
#include <QOpenGLTextureBlitter>
#include <QPainter>
#include <QEvent>
#include <QKeyEvent>
2021-12-31 16:47:49 +06:00
#include <QWidget>
#include <atomic>
#include <mutex>
#include <QApplication>
2021-12-07 13:47:42 +01:00
#include "qt_renderercomon.hpp"
#ifdef WAYLAND
#include "wl_mouse.hpp"
#endif
2021-12-17 12:17:54 +06:00
class HardwareRenderer : public QOpenGLWindow, protected QOpenGLFunctions, public RendererCommon
{
Q_OBJECT
private:
bool wayland = false;
QOpenGLContext* m_context;
2021-12-27 16:32:03 +06:00
QOpenGLTexture* m_texture{nullptr};
QOpenGLShaderProgram* m_prog{nullptr};
QOpenGLTextureBlitter* m_blt{nullptr};
QOpenGLBuffer m_vbo[2];
QOpenGLVertexArrayObject m_vao;
public:
enum class RenderType {
OpenGL,
OpenGLES,
2021-12-27 16:32:03 +06:00
OpenGL3,
};
void resizeGL(int w, int h) override;
void initializeGL() override;
void paintGL() override;
HardwareRenderer(QWidget* parent = nullptr, RenderType rtype = RenderType::OpenGL)
: QOpenGLWindow(QOpenGLWindow::NoPartialUpdate, parent->windowHandle()), QOpenGLFunctions()
{
2021-12-17 12:17:54 +06:00
setMinimumSize(QSize(16, 16));
setFlags(Qt::FramelessWindowHint);
parentWidget = parent;
setRenderType(rtype);
m_context = new QOpenGLContext();
m_context->setFormat(format());
m_context->create();
}
~HardwareRenderer()
{
m_context->makeCurrent(this);
if (m_blt) m_blt->destroy();
2021-12-27 16:32:03 +06:00
m_prog->release();
delete m_prog;
m_prog = nullptr;
m_context->doneCurrent();
delete m_context;
}
void setRenderType(RenderType type);
public slots:
void onBlit(const std::unique_ptr<uint8_t>* img, int, int, int, int, std::atomic_flag* in_use);
2021-12-07 13:47:42 +01:00
protected:
void resizeEvent(QResizeEvent *event) override;
bool event(QEvent* event) override;
};