#pragma once #include "videoframe.h" #include #include #include #include #include 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(); } // Opt-in for calibration panels; other video pages keep their layout. void setFrameAspectLayoutEnabled(bool enabled); int heightForWidth(int width) const override; QSize sizeHint() const override; protected: void initializeGL() override; void paintGL() override; void resizeEvent(QResizeEvent *event) 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); void updateAspectHeight(); bool m_frameAspectLayout = false; QSize m_layoutFrameSize{640, 480}; // Placeholder until the first camera frame. std::unique_ptr 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; };