OpenHantek
Loading...
Searching...
No Matches
glscope.h
1// SPDX-License-Identifier: GPL-2.0+
2
3#pragma once
4
5#include <memory>
6#include <list>
7
8#include <QtGlobal>
9#include <QOpenGLBuffer>
10#include <QOpenGLFunctions>
11#include <QOpenGLShaderProgram>
12#include <QOpenGLVertexArrayObject>
13#include <QOpenGLWidget>
14
15#include "glscopegraph.h"
16#include "hantekdso/enums.h"
17#include "hantekprotocol/types.h"
18
19struct DsoSettingsView;
20struct DsoSettingsScope;
22class PPresult;
23
25class GlScope : public QOpenGLWidget {
26 Q_OBJECT
27
28 public:
29 static GlScope *createNormal(DsoSettingsScope *scope, DsoSettingsView *view,
30 QWidget *parent = 0);
31 static GlScope *createZoomed(DsoSettingsScope *scope, DsoSettingsView *view,
32 QWidget *parent = 0);
33
38 static void fixOpenGLversion(QSurfaceFormat::RenderableType t=QSurfaceFormat::DefaultRenderableType);
43 void showData(std::shared_ptr<PPresult> data);
44 void updateCursor(unsigned index = 0);
45 void cursorSelected(unsigned index) { selectedCursor = index; updateCursor(index); }
46
47 protected:
51 GlScope(DsoSettingsScope *scope, DsoSettingsView *view, QWidget *parent = 0);
52 virtual ~GlScope();
53 GlScope(const GlScope&) = delete;
54
56 virtual void initializeGL() override;
57
59 virtual void paintGL() override;
60
64 virtual void resizeGL(int width, int height) override;
65
66 virtual void mousePressEvent(QMouseEvent *event) override;
67 virtual void mouseMoveEvent(QMouseEvent *event) override;
68 virtual void mouseReleaseEvent(QMouseEvent *event) override;
69 virtual void paintEvent(QPaintEvent *event) override;
70
72 void drawGrid();
74 void drawMarkers();
75 void generateVertices(unsigned marker, const DsoSettingsScopeCursor &cursor);
76 void drawVertices(QOpenGLFunctions *gl, unsigned marker, QColor color);
77
78 void drawVoltageChannelGraph(ChannelID channel, Graph &graph, int historyIndex);
79 void drawSpectrumChannelGraph(ChannelID channel, Graph &graph, int historyIndex);
80 QPointF eventToPosition(QMouseEvent *event);
81 signals:
82 void markerMoved(unsigned cursorIndex, unsigned marker);
83
84 private:
85 // User settings
86 DsoSettingsScope *scope;
87 DsoSettingsView *view;
88 bool zoomed = false;
89
90 // Marker
91 const unsigned NO_MARKER = UINT_MAX;
92 #pragma pack(push, 1)
93 struct Vertices {
94 QVector3D a, b, c, d;
95 };
96 #pragma pack(pop)
97 const unsigned VERTICES_ARRAY_SIZE = sizeof(Vertices) / sizeof(QVector3D);
98 std::vector<Vertices> vaMarker;
99 unsigned selectedMarker = NO_MARKER;
100 QOpenGLBuffer m_marker;
101 QOpenGLVertexArrayObject m_vaoMarker;
102
103 // Cursors
104 std::vector<DsoSettingsScopeCursor *> cursorInfo;
105 unsigned selectedCursor = 0;
106
107 // Grid
108 QOpenGLBuffer m_grid;
109 QOpenGLVertexArrayObject m_vaoGrid[3];
110 GLsizei gridDrawCounts[3];
111 void generateGrid(QOpenGLShaderProgram *program);
112
113 // Graphs
114 std::list<Graph> m_GraphHistory;
115 unsigned currentGraphInHistory = 0;
116
117 // OpenGL shader, matrix, var-locations
118 bool shaderCompileSuccess = false;
119 QString errorMessage;
120 std::unique_ptr<QOpenGLShaderProgram> m_program;
121 QMatrix4x4 pmvMatrix;
122 int colorLocation;
123 int vertexLocation;
124 int matrixLocation;
125 int selectionLocation;
126};
OpenGL accelerated widget that displays the oscilloscope screen.
Definition glscope.h:25
void drawGrid()
Draw the grid.
Definition glscope.cpp:513
static void fixOpenGLversion(QSurfaceFormat::RenderableType t=QSurfaceFormat::DefaultRenderableType)
Definition glscope.cpp:37
void drawMarkers()
Draw vertical lines at marker positions.
Definition glscope.cpp:546
GlScope(DsoSettingsScope *scope, DsoSettingsView *view, QWidget *parent=0)
Initializes the scope widget.
Definition glscope.cpp:55
virtual void resizeGL(int width, int height) override
Resize the widget.
Definition glscope.cpp:397
virtual void paintGL() override
Draw the graphs, marker and the grid.
Definition glscope.cpp:358
virtual void initializeGL() override
Initializes OpenGL output.
Definition glscope.cpp:176
void showData(std::shared_ptr< PPresult > data)
Definition glscope.cpp:278
Post processing results.
Definition ppresult.h:31
Holds the cursor parameters.
Definition scopesettings.h:17
Holds the settings for the oscilloscope.
Definition scopesettings.h:77
Holds all view settings.
Definition viewsettings.h:30
Definition glscopegraph.h:14