137 lines
3.6 KiB
C++
137 lines
3.6 KiB
C++
#ifndef DISPLAYMOVIEGLWIDGET_H
|
|
#define DISPLAYMOVIEGLWIDGET_H
|
|
|
|
#include <QOpenGLWidget>
|
|
#include <QOpenGLFunctions>
|
|
#include <QOpenGLShaderProgram>
|
|
#include <QOpenGLVertexArrayObject>
|
|
#include <QOpenGLTexture>
|
|
#include <QOpenGLBuffer>
|
|
#include <QTimer>
|
|
#include <QVector>
|
|
#include <QRunnable>
|
|
|
|
#include "CmdReceiver.h"
|
|
#include "VlcMediaListPlayer.h"
|
|
|
|
#define FPS_DISPLAY 0
|
|
|
|
#if 0
|
|
#define BG_VLC 1
|
|
#endif
|
|
|
|
|
|
class SourImasgeHandler : public QObject, public QRunnable {
|
|
Q_OBJECT
|
|
public:
|
|
SourImasgeHandler(const QString& path, const QSize& size, QObject* parent = nullptr)
|
|
: QObject(parent), path_(path), size_(size) {}
|
|
~SourImasgeHandler() override;
|
|
|
|
public:
|
|
void run() override;
|
|
|
|
signals:
|
|
void Finish(QImage source, QImage sourceAlpha);
|
|
private:
|
|
QString path_;
|
|
QSize size_;
|
|
};
|
|
|
|
class DisplayMovieGLWidget : public QOpenGLWidget, protected QOpenGLFunctions, public CmdReceiver {
|
|
Q_OBJECT
|
|
|
|
public:
|
|
DisplayMovieGLWidget(QWidget* parent = nullptr);
|
|
~DisplayMovieGLWidget();
|
|
|
|
void InitBackgroundImages();
|
|
void InitMaskImages();
|
|
|
|
void ReInit();
|
|
|
|
void SetNetConnectStatus(int connected);
|
|
|
|
void OnMessage(const QString& cmd) override;
|
|
|
|
void OnTimeout();
|
|
|
|
void OnMoveFrame(const QImage& movieImage);
|
|
|
|
Q_SIGNALS:
|
|
void AlphaChanged(float alpha);
|
|
|
|
protected:
|
|
void initializeGL() override;
|
|
void paintGL() override;
|
|
void resizeGL(int w, int h) override;
|
|
|
|
#if FPS_DISPLAY
|
|
void paintEvent(QPaintEvent* event) override;
|
|
#else
|
|
QPaintEngine* paintEngine() const override {
|
|
return nullptr;
|
|
}
|
|
#endif
|
|
|
|
private:
|
|
void LoadBackgroundTexture();
|
|
void LoadMaskTexture();
|
|
|
|
void InitBackgroundTexture();
|
|
void InitMaskTexture();
|
|
void InitForeMovieTextImage();
|
|
|
|
void UpdateSourceImage(const QString& path);
|
|
void UpdateTextImage();
|
|
|
|
|
|
void PlayBackgroundMovie();
|
|
void SlotSetOneFrame(QImage image);
|
|
void OnUpdateSourceImage(QImage source, QImage sourceAlpha);
|
|
|
|
private:
|
|
QOpenGLVertexArrayObject* m_vao{ nullptr }; //顶点数组对象
|
|
QOpenGLBuffer* m_vbo{ nullptr }; //顶点缓冲对象
|
|
QOpenGLBuffer* m_ebo{ nullptr }; //元素缓冲对象
|
|
QOpenGLShader* m_vshader{ nullptr }; //顶点着色器
|
|
QOpenGLShader* m_fshader{ nullptr }; //片段着色器
|
|
QOpenGLShaderProgram* m_program{ nullptr }; //着色器程序对象
|
|
QOpenGLTexture* m_background{ nullptr }; //纹理对象
|
|
QOpenGLTexture* m_backgroundMask{ nullptr }; //纹理对象
|
|
QOpenGLTexture* m_mask{ nullptr }; //纹理对象
|
|
QOpenGLTexture* m_source{ nullptr }; //纹理对象
|
|
QOpenGLTexture* m_sourceAlpha{ nullptr }; //纹理对象
|
|
QOpenGLTexture* m_textSource{ nullptr }; //纹理对象
|
|
QOpenGLTexture* m_movieSource{ nullptr }; //纹理对象
|
|
qint64 m_startTimestamp{ 0 };
|
|
|
|
int m_maskFrameCount{ 0 };
|
|
int m_maskFrame{ 0 };
|
|
int m_colorMaskFrame{ 0 };
|
|
bool m_showSource{ false };
|
|
QVector<QString> m_maskTexturePaths;
|
|
QVector<QImage> m_maskTextureData;
|
|
|
|
int32_t m_place{ 0 };
|
|
bool m_isPlayingMask { false };
|
|
bool m_fusion{ false };
|
|
bool m_connected{ 0 };
|
|
QString m_showText;
|
|
int m_delayTime{ 0 };
|
|
float m_alpha{ 0.0f };
|
|
|
|
#ifdef BG_VLC
|
|
VlcMediaListPlayer vlcPlayer_;
|
|
QImage videoImage_;
|
|
#else
|
|
int m_backgroundCurrentFrame{ 0 };
|
|
int m_backgroundFrameCount{ 0 };
|
|
QVector<QString> m_backgourndTexturePaths;
|
|
QVector<QImage> m_textureData;
|
|
#endif
|
|
QImage videoForeImage_;
|
|
};
|
|
|
|
#endif // DISPLAYMOVIEGLWIDGET_H
|