2021-12-04 21:33:04 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <QOpenGLFunctions>
|
2021-12-27 16:32:03 +06:00
|
|
|
#include <QOpenGLBuffer>
|
2021-12-04 21:33:04 +01:00
|
|
|
#include <QOpenGLWidget>
|
2021-12-17 12:17:54 +06:00
|
|
|
#include <QOpenGLWindow>
|
2021-12-27 16:32:03 +06:00
|
|
|
#include <QOpenGLVertexArrayObject>
|
2021-12-25 15:34:00 +06:00
|
|
|
#include <QOpenGLTexture>
|
|
|
|
|
#include <QOpenGLShader>
|
|
|
|
|
#include <QOpenGLShaderProgram>
|
|
|
|
|
#include <QOpenGLTextureBlitter>
|
2021-12-04 21:33:04 +01:00
|
|
|
#include <QPainter>
|
|
|
|
|
#include <QEvent>
|
|
|
|
|
#include <QKeyEvent>
|
|
|
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
|
#include <mutex>
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
|
2021-12-07 13:47:42 +01:00
|
|
|
#include "qt_renderercomon.hpp"
|
|
|
|
|
|
2021-12-04 21:33:04 +01:00
|
|
|
#ifdef WAYLAND
|
|
|
|
|
#include "wl_mouse.hpp"
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-12-17 12:17:54 +06:00
|
|
|
class HardwareRenderer : public QOpenGLWindow, protected QOpenGLFunctions, public RendererCommon
|
2021-12-04 21:33:04 +01:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool wayland = false;
|
2021-12-23 20:31:51 +02:00
|
|
|
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;
|
2021-12-04 21:33:04 +01:00
|
|
|
public:
|
2021-12-26 11:52:50 +06:00
|
|
|
enum class RenderType {
|
|
|
|
|
OpenGL,
|
|
|
|
|
OpenGLES,
|
2021-12-27 16:32:03 +06:00
|
|
|
OpenGL3,
|
2021-12-26 11:52:50 +06:00
|
|
|
};
|
2021-12-04 21:33:04 +01:00
|
|
|
void resizeGL(int w, int h) override;
|
|
|
|
|
void initializeGL() override;
|
|
|
|
|
void paintGL() override;
|
2021-12-26 11:52:50 +06:00
|
|
|
HardwareRenderer(QWidget* parent = nullptr, RenderType rtype = RenderType::OpenGL)
|
2021-12-18 00:37:30 +06:00
|
|
|
: QOpenGLWindow(QOpenGLWindow::NoPartialUpdate, parent->windowHandle()), QOpenGLFunctions()
|
2021-12-04 21:33:04 +01:00
|
|
|
{
|
2021-12-17 12:17:54 +06:00
|
|
|
setMinimumSize(QSize(16, 16));
|
|
|
|
|
setFlags(Qt::FramelessWindowHint);
|
2021-12-18 00:37:30 +06:00
|
|
|
parentWidget = parent;
|
2021-12-26 11:52:50 +06:00
|
|
|
setRenderType(rtype);
|
2021-12-23 20:31:51 +02:00
|
|
|
|
|
|
|
|
m_context = new QOpenGLContext();
|
2021-12-26 11:52:50 +06:00
|
|
|
m_context->setFormat(format());
|
2021-12-23 20:31:51 +02:00
|
|
|
m_context->create();
|
2021-12-04 21:33:04 +01:00
|
|
|
}
|
|
|
|
|
~HardwareRenderer()
|
|
|
|
|
{
|
2021-12-25 15:34:00 +06:00
|
|
|
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;
|
2021-12-04 21:33:04 +01:00
|
|
|
}
|
|
|
|
|
|
2021-12-26 11:52:50 +06:00
|
|
|
|
2021-12-04 21:33:04 +01:00
|
|
|
void setRenderType(RenderType type);
|
|
|
|
|
|
|
|
|
|
public slots:
|
2021-12-21 16:38:13 +06:00
|
|
|
void onBlit(const std::unique_ptr<uint8_t>* img, int, int, int, int, std::atomic_flag* in_use);
|
2021-12-04 21:33:04 +01:00
|
|
|
|
2021-12-07 13:47:42 +01:00
|
|
|
protected:
|
|
|
|
|
void resizeEvent(QResizeEvent *event) override;
|
2021-12-18 00:37:30 +06:00
|
|
|
bool event(QEvent* event) override;
|
2021-12-04 21:33:04 +01:00
|
|
|
};
|