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.

171 lines
4.8 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __FULL_SCREEN_GL_VIDEO_WIDGET_HEADER__
  2. #define __FULL_SCREEN_GL_VIDEO_WIDGET_HEADER__
  3. #include <vector>
  4. #include "../guiClass.h"
  5. #include <QtWidgets/QOpenGLWidget>
  6. #include <QtGui/QOpenGLFunctions>
  7. #include <QtGui/QOpenGLBuffer>
  8. #include <QtGui/QVector3D>
  9. #include <QtGui/QMatrix4x4>
  10. #include <QtCore/QTime>
  11. #include <QtCore/QVector>
  12. #include <QtWidgets/QPushButton>
  13. #include <QtGui/QOpenGLShaderProgram>
  14. #include <QtGui/QOpenGLTexture>
  15. #include <opencv2/opencv.hpp>
  16. #include "../../components/base/basicLIBAV.h"
  17. #include "../../components/base/basicMediaDestination.h"
  18. #include "../../components/base/basicMutex.h"
  19. #include "../../components/base/basicCameraPTZ.h"
  20. #include "../../components/base/basicStatus.h"
  21. #include <string.h> // for memcpy
  22. #include <stdexcept>
  23. #include <assert.h>
  24. // It's important to keep these unique so that glEnableVertexAttribArray only needs to be called a minimal amount as it is an expensive call on the raspberry pi
  25. #define MY_VERTEX_ARRAY 0
  26. #define MY_TEXCOORD_ARRAY 1
  27. #define PROGRAM_VERTEX_ATTRIBUTE 0
  28. #define PROGRAM_TEXCOORD_ATTRIBUTE 1
  29. // this can be replaced with whatever
  30. #define GL_ASSERT(str) assert(glGetError() == GL_NO_ERROR)
  31. // макрос приведения к типу const GLvoid *
  32. #define GL_OFFSET_(x) ((const GLvoid *)(x))
  33. // структура с описанием вершины для полноэкранного прямоугольника
  34. typedef struct S_fsqVertex {
  35. GLfloat position[3];
  36. GLfloat texcoord[2];
  37. } fsqVertex;
  38. // VAO и VBO для полноэкранного прямоугольника
  39. //GLuint fsqVAO = 0, fsqVBO = 0;
  40. //class MainWindow;
  41. class FSGLVideoWidget : public QOpenGLWidget, protected QOpenGLFunctions, public basicMediaDestination {
  42. //friend class QPixmap;
  43. private:
  44. U8 m_bStatus;
  45. int m_nMouseX;
  46. int m_nMouseY;
  47. int m_nSourceWidth;
  48. int m_nSourceHeight;
  49. U32 m_nKeyCode;
  50. U32 m_nOldKeyCode;
  51. ControlDirection m_nManualControlMode;
  52. //bool m_bMouseActive;
  53. int m_nMenuActivityCounter;
  54. bool m_bGrayScale;
  55. bool m_bEnhanced;
  56. bool m_bDirectDrawing;
  57. FrameAspectRatio m_eWidgetAspectRatio;
  58. FrameAspectRatio m_eStreamAspectRatio;
  59. IplImage *m_pGraber;
  60. cv::Mat *m_mFrame;
  61. cv::Mat *m_mOutput;
  62. QOpenGLTexture *m_pTexture;
  63. QOpenGLShader *m_pVertexShader;
  64. QOpenGLShader *m_pFragmentShader;
  65. QOpenGLShaderProgram *m_pShaderProgram;
  66. QColor m_background;
  67. int m_vertexAttr;
  68. int m_normalAttr;
  69. int m_matrixUniform;
  70. int m_textureUniform;
  71. int m_texCoordAttr;
  72. qreal m_fAngle;
  73. qreal m_fScale;
  74. QVector<QVector3D> m_vertices;
  75. QVector<QVector3D> m_normals;
  76. QOpenGLBuffer m_vbo;
  77. GLuint m_nTextureID;
  78. GLuint m_uTexCoordBuffer;
  79. GLuint m_uTexCoordFlippedBuffer;
  80. GLuint m_uVertexBufferFullScreen;
  81. GLsizei m_nTextureWidth;
  82. GLsizei m_nTextureHeight;
  83. objectCaps m_nCameraCaps;
  84. basicCamera *m_pCamera;
  85. basicMediaDestination *m_pParentViewer;
  86. basicMutex *m_pPropertiesProtectorMutex;
  87. basicMutex *m_pWidgetProtectorMutex;
  88. void m_fThreadProc(void);
  89. GLuint fsqVAO, fsqVBO;
  90. QOpenGLBuffer m_vbo1;
  91. QOpenGLBuffer m_vbo2;
  92. /* Initers */
  93. void InitGLAttributes(void);
  94. void InitTextures(void);
  95. void InitShaders(void);
  96. void InitSamplers(void);
  97. void InitBuffers(void);
  98. void InitProjectionMatrices(void);
  99. void InitViewMatrices(void);
  100. protected:
  101. QImage m_iFrame;
  102. /* Main Video */
  103. QPixmap *m_pPixmap;
  104. /* OSD Pixmaps */
  105. QPixmap *m_pManualMode;
  106. QPixmap *m_pPixUp;
  107. QPixmap *m_pPixDown;
  108. QPixmap *m_pPixLeft;
  109. QPixmap *m_pPixRight;
  110. QPixmap *m_pPixWide;
  111. QPixmap *m_pPixTele;
  112. protected:
  113. void resizeGL( int w, int h) Q_DECL_OVERRIDE;
  114. void paintGL() Q_DECL_OVERRIDE;
  115. void initializeGL() Q_DECL_OVERRIDE;
  116. public:
  117. explicit FSGLVideoWidget( QWidget *parent, int sizeX, int sizeY, const QColor &background );
  118. ~FSGLVideoWidget();
  119. virtual void render( QPainter *painter);
  120. bool init( void );
  121. void pushFrame( cv::Mat *Frame );
  122. void setSourceSize( int sizeX, int sizeY );
  123. void setSoutceType( int Type );
  124. /* Binding to parent Video Viewer */
  125. void setCameraControl( basicCamera *C, objectCaps CC);
  126. void setBindingSize( basicMediaDestination *P, int x, int y);
  127. //public slots:
  128. //void renderLater();
  129. //void renderNow();
  130. protected:
  131. bool event(QEvent *event);
  132. //void resizeEvent(QResizeEvent *event);
  133. void exposeEvent(QExposeEvent *event);
  134. //void paintEvent(QPaintEvent *event);
  135. //void drawContents(QPainter * p, const QRectF & rect = QRectF());
  136. private:
  137. bool m_bUpdateIsPending;
  138. QTimer *m_pTimer;
  139. };
  140. #endif