PlayerGLWidget.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef PLAYEROPENGLWIDGET_H
  2. #define PLAYEROPENGLWIDGET_H
  3. #include <QOpenGLWidget>
  4. #include <QOpenGLFunctions>
  5. #include <QOpenGLShaderProgram>
  6. #include <QOpenGLTexture>
  7. #include <QTimer>
  8. #include "PlayerGlobalInfo.h"
  9. class PlayerGLWidget : public QOpenGLWidget , public QOpenGLFunctions
  10. {
  11. Q_OBJECT
  12. public:
  13. explicit PlayerGLWidget(QWidget *parent = nullptr);
  14. ~PlayerGLWidget();
  15. /* 刷新一帧 */
  16. void updateFrame(Image_YUV420& image);
  17. public slots:
  18. void updateYUVData(const QByteArray &y, const QByteArray &u, const QByteArray &v) {
  19. yData = y;
  20. uData = u;
  21. vData = v;
  22. update();
  23. }
  24. private:
  25. void initShaders();
  26. void initTextures();
  27. void initVertex();
  28. void initFrameBuffer();
  29. void renderYUV420P();
  30. protected:
  31. void initializeGL() override;
  32. void resizeGL(int w, int h) override;
  33. void paintGL() override;
  34. private:
  35. QOpenGLShaderProgram program;
  36. QOpenGLTexture *textureY = nullptr;
  37. QOpenGLTexture *textureU = nullptr;
  38. QOpenGLTexture *textureV = nullptr;
  39. QByteArray yData;
  40. QByteArray uData;
  41. QByteArray vData;
  42. };
  43. #endif /* PLAYEROPENGLWIDGET_H */