48 lines
1.3 KiB
C
48 lines
1.3 KiB
C
|
|
#pragma once
|
||
|
|
|
||
|
|
#include "videoframe.h"
|
||
|
|
|
||
|
|
#include <QImage>
|
||
|
|
#include <QOpenGLFunctions>
|
||
|
|
#include <QOpenGLWidget>
|
||
|
|
#include <QString>
|
||
|
|
|
||
|
|
#include <memory>
|
||
|
|
|
||
|
|
class QOpenGLShaderProgram;
|
||
|
|
|
||
|
|
class VideoRenderWidget : public QOpenGLWidget, protected QOpenGLFunctions
|
||
|
|
{
|
||
|
|
Q_OBJECT
|
||
|
|
|
||
|
|
public:
|
||
|
|
explicit VideoRenderWidget(QWidget *parent = nullptr);
|
||
|
|
~VideoRenderWidget() override;
|
||
|
|
|
||
|
|
void setFrame(const VideoFrame &frame);
|
||
|
|
void setImage(const QImage &image);
|
||
|
|
void clearFrame(const QString &message = QStringLiteral("暂无画面"));
|
||
|
|
bool hasFrame() const { return m_frame.isValid(); }
|
||
|
|
|
||
|
|
protected:
|
||
|
|
void initializeGL() override;
|
||
|
|
void paintGL() override;
|
||
|
|
|
||
|
|
private:
|
||
|
|
void releaseTextures();
|
||
|
|
void uploadPlane(unsigned int texture, int unit, int width, int height,
|
||
|
|
unsigned int format, const QByteArray &data,
|
||
|
|
int textureIndex);
|
||
|
|
void drawMessage(const QString &message);
|
||
|
|
|
||
|
|
std::unique_ptr<QOpenGLShaderProgram> m_program;
|
||
|
|
VideoFrame m_frame;
|
||
|
|
QString m_message = QStringLiteral("暂无画面");
|
||
|
|
unsigned int m_textures[3] = {0, 0, 0};
|
||
|
|
int m_textureWidths[3] = {0, 0, 0};
|
||
|
|
int m_textureHeights[3] = {0, 0, 0};
|
||
|
|
unsigned int m_textureFormats[3] = {0, 0, 0};
|
||
|
|
bool m_frameDirty = false;
|
||
|
|
bool m_glReady = false;
|
||
|
|
};
|