OpenHantek
glscope.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0+
2 
3 #pragma once
4 
5 #include <list>
6 #include <memory>
7 
8 #include <QOpenGLBuffer>
9 #include <QOpenGLFunctions>
10 #include <QOpenGLShaderProgram>
11 #include <QOpenGLVertexArrayObject>
12 #include <QOpenGLWidget>
13 #include <QtGlobal>
14 
15 #include "glscopegraph.h"
16 #include "hantekdso/enums.h"
17 #include "hantekprotocol/types.h"
18 
19 struct DsoSettingsView;
20 struct DsoSettingsScope;
22 class PPresult;
23 
24 #define GLES100 "1.00 ES"
25 #define GLSL120 "1.20"
26 #define GLSL150 "1.50"
27 
29 class GlScope : public QOpenGLWidget {
30  Q_OBJECT
31 
32  public:
33  static GlScope *createNormal( DsoSettingsScope *scope, DsoSettingsView *view, QWidget *parent = nullptr );
34  static GlScope *createZoomed( DsoSettingsScope *scope, DsoSettingsView *view, QWidget *parent = nullptr );
35 
36  static void useOpenGLSLversion( QString version = GLSL120 );
37  static QString getOpenGLversion();
38  static QString getGLSLversion() { return GLSLversion; }
43  void showData( std::shared_ptr< PPresult > newData );
44  void updateCursor( unsigned index = 0 );
45  void cursorSelected( unsigned index ) {
46  selectedCursor = index;
47  updateCursor( index );
48  }
49  void generateGrid( int index = -1, double value = 0.0, bool pressed = false );
50 
51  protected:
55  GlScope( DsoSettingsScope *scope, DsoSettingsView *view, QWidget *parent = nullptr );
56  ~GlScope() override;
57  GlScope( const GlScope & ) = delete;
58 
60  void initializeGL() override;
61 
63  void paintGL() override;
64 
68  void resizeGL( int width, int height ) override;
69 
70  void mousePressEvent( QMouseEvent *event ) override;
71  void mouseMoveEvent( QMouseEvent *event ) override;
72  void mouseReleaseEvent( QMouseEvent *event ) override;
73  void mouseDoubleClickEvent( QMouseEvent *event ) override;
74  void wheelEvent( QWheelEvent *event ) override;
75  void paintEvent( QPaintEvent *event ) override;
76 
78  void drawGrid();
80  void drawMarkers();
81  void generateVertices( unsigned marker, const DsoSettingsScopeCursor &cursor );
82  void drawVertices( QOpenGLFunctions *gl, unsigned marker, QColor color );
83 
84  void drawVoltageChannelGraph( ChannelID channel, Graph &graph, int historyIndex );
85  void drawHistogramChannelGraph( ChannelID channel, Graph &graph, int historyIndex );
86  void drawSpectrumChannelGraph( ChannelID channel, Graph &graph, int historyIndex );
87  QPointF posToPosition( QPointF pos );
88  signals:
89  void markerMoved( unsigned cursorIndex, unsigned marker );
90 
91  private:
92  // User settings
95  bool zoomed = false;
96 
97  // Marker
98  const unsigned NO_MARKER = UINT_MAX;
99 #pragma pack( push, 1 )
100  struct Vertices {
101  QVector3D a, b, c, d;
102  };
103 #pragma pack( pop )
104  const unsigned VERTICES_ARRAY_SIZE = sizeof( Vertices ) / sizeof( QVector3D );
105  std::vector< Vertices > vaMarker;
107  QOpenGLBuffer m_marker;
108  QOpenGLVertexArrayObject m_vaoMarker;
109 
110  // Cursors
111  std::vector< DsoSettingsScopeCursor * > cursorInfo;
112  unsigned selectedCursor = 0;
113 
114  // Grid
115  QOpenGLBuffer m_grid;
116  static const int gridItems = 4;
117  QOpenGLVertexArrayObject m_vaoGrid[ gridItems ];
119  void draw4Cross( std::vector< QVector3D > &va, int section, float x, float y );
120  QColor triggerLineColor = QColor( "black" );
121 
122  // Graphs
123  std::list< Graph > m_GraphHistory;
124  unsigned currentGraphInHistory = 0;
125 
126  // OpenGL shader, matrix, var-locations
127  static QString OpenGLversion;
128  static QString GLSLversion;
129  QString renderInfo;
130  bool shaderCompileSuccess = false;
131  QString errorMessage;
132  std::unique_ptr< QOpenGLShaderProgram > m_program;
133  QMatrix4x4 pmvMatrix;
138 };
unsigned selectedMarker
Definition: glscope.h:106
QOpenGLVertexArrayObject m_vaoGrid[gridItems]
Definition: glscope.h:117
void drawSpectrumChannelGraph(ChannelID channel, Graph &graph, int historyIndex)
Definition: glscope.cpp:856
void updateCursor(unsigned index=0)
Definition: glscope.cpp:504
int colorLocation
Definition: glscope.h:134
void mouseReleaseEvent(QMouseEvent *event) override
Definition: glscope.cpp:195
DsoSettingsScope * scope
Definition: glscope.h:93
std::vector< DsoSettingsScopeCursor *> cursorInfo
Definition: glscope.h:111
std::unique_ptr< QOpenGLShaderProgram > m_program
Definition: glscope.h:132
bool zoomed
Definition: glscope.h:95
void resizeGL(int width, int height) override
Resize the widget.
Definition: glscope.cpp:567
int vertexLocation
Definition: glscope.h:135
void wheelEvent(QWheelEvent *event) override
Definition: glscope.cpp:244
DsoSettingsView * view
Definition: glscope.h:94
static QString getGLSLversion()
Definition: glscope.h:38
QVector3D a
Definition: glscope.h:101
int selectionLocation
Definition: glscope.h:137
void markerMoved(unsigned cursorIndex, unsigned marker)
Definition: glscope.h:100
std::vector< Vertices > vaMarker
Definition: glscope.h:105
QOpenGLBuffer m_marker
Definition: glscope.h:107
QVector3D b
Definition: glscope.h:101
void draw4Cross(std::vector< QVector3D > &va, int section, float x, float y)
Definition: glscope.cpp:591
~GlScope() override
Definition: glscope.cpp:82
QString renderInfo
Definition: glscope.h:129
void drawHistogramChannelGraph(ChannelID channel, Graph &graph, int historyIndex)
Definition: glscope.cpp:843
void generateVertices(unsigned marker, const DsoSettingsScopeCursor &cursor)
Definition: glscope.cpp:468
void drawMarkers()
Draw vertical lines at marker positions.
Definition: glscope.cpp:802
QPointF posToPosition(QPointF pos)
Definition: glscope.cpp:104
QMatrix4x4 pmvMatrix
projection, view matrix
Definition: glscope.h:133
bool shaderCompileSuccess
Definition: glscope.h:130
void initializeGL() override
Initializes OpenGL output.
Definition: glscope.cpp:298
QVector3D d
Definition: glscope.h:101
const unsigned NO_MARKER
Definition: glscope.h:98
QOpenGLBuffer m_grid
Definition: glscope.h:115
QOpenGLVertexArrayObject m_vaoMarker
Definition: glscope.h:108
QColor triggerLineColor
Definition: glscope.h:120
void mouseMoveEvent(QMouseEvent *event) override
Definition: glscope.cpp:172
QVector3D c
Definition: glscope.h:101
void drawVoltageChannelGraph(ChannelID channel, Graph &graph, int historyIndex)
Definition: glscope.cpp:830
const unsigned VERTICES_ARRAY_SIZE
Definition: glscope.h:104
Holds the cursor parameters.
Definition: scopesettings.h:16
unsigned currentGraphInHistory
Definition: glscope.h:124
OpenGL accelerated widget that displays the oscilloscope screen.
Definition: glscope.h:29
void drawVertices(QOpenGLFunctions *gl, unsigned marker, QColor color)
Definition: glscope.cpp:791
Definition: glscopegraph.h:16
void drawGrid()
Draw the grid.
Definition: glscope.cpp:756
Holds all view settings.
Definition: viewsettings.h:35
void mouseDoubleClickEvent(QMouseEvent *event) override
Definition: glscope.cpp:211
static GlScope * createNormal(DsoSettingsScope *scope, DsoSettingsView *view, QWidget *parent=nullptr)
Definition: glscope.cpp:89
void generateGrid(int index=-1, double value=0.0, bool pressed=false)
Definition: glscope.cpp:608
void showData(std::shared_ptr< PPresult > newData)
Definition: glscope.cpp:444
static const int gridItems
Definition: glscope.h:116
unsigned ChannelID
Definition: types.h:6
int matrixLocation
Definition: glscope.h:136
static QString getOpenGLversion()
Definition: glscope.cpp:32
QString errorMessage
Definition: glscope.h:131
GLsizei gridDrawCounts[gridItems]
Definition: glscope.h:118
Holds the settings for the oscilloscope.
Definition: scopesettings.h:82
void paintGL() override
Draw the graphs, marker and the grid.
Definition: glscope.cpp:518
GlScope(DsoSettingsScope *scope, DsoSettingsView *view, QWidget *parent=nullptr)
Initializes the scope widget.
Definition: glscope.cpp:65
static QString OpenGLversion
Definition: glscope.h:127
unsigned selectedCursor
Definition: glscope.h:112
static GlScope * createZoomed(DsoSettingsScope *scope, DsoSettingsView *view, QWidget *parent=nullptr)
Definition: glscope.cpp:97
std::list< Graph > m_GraphHistory
Definition: glscope.h:123
void paintEvent(QPaintEvent *event) override
Definition: glscope.cpp:282
#define GLSL120
Definition: glscope.h:25
static void useOpenGLSLversion(QString version=GLSL120)
Definition: glscope.cpp:48
void cursorSelected(unsigned index)
Definition: glscope.h:45
static QString GLSLversion
Definition: glscope.h:128
Post processing results.
Definition: ppresult.h:37
void mousePressEvent(QMouseEvent *event) override
Definition: glscope.cpp:118