You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#ifndef QYUVOPENGLWIDGET_H
#define QYUVOPENGLWIDGET_H
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <QOpenGLShaderProgram>
#include <QOpenGLBuffer>
class QYUVOpenGLWidget : public QOpenGLWidget, protected QOpenGLFunctions
{
Q_OBJECT
public:
explicit QYUVOpenGLWidget(QWidget *parent = nullptr);
virtual ~QYUVOpenGLWidget();
QSize minimumSizeHint() const override;
QSize sizeHint() const override;
void setFrameSize(const QSize& frameSize);
void updateTextures(quint8* dataY, quint8* dataU, quint8* dataV, quint32 linesizeY, quint32 linesizeU, quint32 linesizeV);
protected:
void initializeGL();
void paintGL();
void resizeGL(int width, int height);
private:
void initShader();
void initTextures();
void deInitTextures();
void updateTexture(GLuint texture, quint32 textureType, quint8* pixels, quint32 stride);
private:
// 视频帧尺寸
QSize m_frameSize = {-1, -1};
bool m_needUpdate = false;
// 顶点缓冲对象(Vertex Buffer Objects, VBO)默认即为VertexBuffer(GL_ARRAY_BUFFER)类型
QOpenGLBuffer m_vbo;
// 着色器程序:编译链接着色器
QOpenGLShaderProgram m_shaderProgram;
// YUV纹理用于生成纹理贴图
GLuint m_texture[3] = {0};
};
#endif // QYUVOPENGLWIDGET_H