glscope.h
3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// SPDX-License-Identifier: GPL-2.0+
#pragma once
#include <memory>
#include <list>
#include <QtGlobal>
#include <QOpenGLBuffer>
#include <QOpenGLFunctions>
#include <QOpenGLShaderProgram>
#include <QOpenGLVertexArrayObject>
#include <QOpenGLWidget>
#include "glscopegraph.h"
#include "hantekdso/enums.h"
#include "hantekprotocol/types.h"
struct DsoSettingsView;
struct DsoSettingsScope;
class PPresult;
/// \brief OpenGL accelerated widget that displays the oscilloscope screen.
class GlScope : public QOpenGLWidget {
Q_OBJECT
public:
static GlScope *createNormal(DsoSettingsScope *scope, DsoSettingsView *view,
QWidget *parent = 0);
static GlScope *createZoomed(DsoSettingsScope *scope, DsoSettingsView *view,
QWidget *parent = 0);
/**
* We need at least OpenGL 3.2 with shader version 150 or
* OpenGL ES 2.0 with shader version 100.
*/
static void fixOpenGLversion(QSurfaceFormat::RenderableType t=QSurfaceFormat::DefaultRenderableType);
/**
* Show new post processed data
* @param data
*/
void showData(std::shared_ptr<PPresult> data);
void markerUpdated();
protected:
/// \brief Initializes the scope widget.
/// \param settings The settings that should be used.
/// \param parent The parent widget.
GlScope(DsoSettingsScope *scope, DsoSettingsView *view, QWidget *parent = 0);
virtual ~GlScope();
GlScope(const GlScope&) = delete;
/// \brief Initializes OpenGL output.
virtual void initializeGL() override;
/// \brief Draw the graphs, marker and the grid.
virtual void paintGL() override;
/// \brief Resize the widget.
/// \param width The new width of the widget.
/// \param height The new height of the widget.
virtual void resizeGL(int width, int height) override;
virtual void mousePressEvent(QMouseEvent *event) override;
virtual void mouseMoveEvent(QMouseEvent *event) override;
virtual void mouseReleaseEvent(QMouseEvent *event) override;
virtual void paintEvent(QPaintEvent *event) override;
/// \brief Draw the grid.
void drawGrid();
/// Draw vertical lines at marker positions
void drawMarkers();
void drawVoltageChannelGraph(ChannelID channel, Graph &graph, int historyIndex);
void drawSpectrumChannelGraph(ChannelID channel, Graph &graph, int historyIndex);
signals:
void markerMoved(unsigned marker, double position);
private:
// User settings
DsoSettingsScope *scope;
DsoSettingsView *view;
bool zoomed = false;
// Marker
const unsigned NO_MARKER = UINT_MAX;
#pragma pack(push, 1)
struct Line {
QVector3D x;
QVector3D y;
};
#pragma pack(pop)
std::vector<Line> vaMarker;
unsigned selectedMarker = NO_MARKER;
QOpenGLBuffer m_marker;
QOpenGLVertexArrayObject m_vaoMarker;
// Grid
QOpenGLBuffer m_grid;
QOpenGLVertexArrayObject m_vaoGrid[3];
GLsizei gridDrawCounts[3];
void generateGrid(QOpenGLShaderProgram *program);
// Graphs
std::list<Graph> m_GraphHistory;
unsigned currentGraphInHistory = 0;
// OpenGL shader, matrix, var-locations
bool shaderCompileSuccess = false;
QString errorMessage;
std::unique_ptr<QOpenGLShaderProgram> m_program;
QMatrix4x4 pmvMatrix; ///< projection, view matrix
int colorLocation;
int vertexLocation;
int matrixLocation;
int selectionLocation;
};