Commit ecbc22edf4830f0f1011f3438fc6336c22948fee

Authored by David Graeff
Committed by David Gräff
1 parent e8ac975c

OpenGL: Don't use OpenGL functions directly, but use the Qt variants. We need to…

… migrate to the OpenGL ES profile soon. Embedded systems like the Raspberry or Android devices do not support the OpenGL desktop profile at all and desktops may deprecate those as well.
openhantek/src/glscope.cpp
... ... @@ -5,6 +5,10 @@
5 5 #include <QColor>
6 6 #include <QMouseEvent>
7 7  
  8 +#include <QOpenGLFunctions_ES2>
  9 +#include <QOpenGLFunctions_3_2_Core>
  10 +#include <QOpenGLFunctions_1_3>
  11 +
8 12 #include "glscope.h"
9 13  
10 14 #include "glgenerator.h"
... ... @@ -27,38 +31,48 @@ GlScope *GlScope::createZoomed(DsoSettingsScope *scope, DsoSettingsView *view, c
27 31 }
28 32  
29 33 GlScope::GlScope(DsoSettingsScope *scope, DsoSettingsView *view, const GlGenerator *generator, QWidget *parent)
30   - : GL_WIDGET_CLASS(parent), scope(scope), view(view), generator(generator) {
  34 + : QOpenGLWidget(parent), scope(scope), view(view), generator(generator) {
31 35 connect(generator, &GlGenerator::graphsGenerated, [this]() { update(); });
32 36 }
33 37  
34 38 void GlScope::initializeGL() {
35   - glDisable(GL_DEPTH_TEST);
36   - glEnable(GL_BLEND);
37   - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  39 + // TODO: Migrate to OpenGL ES2
  40 + // QOpenGLFunctions_ES2 *localFunctions = context()->versionFunctions<QOpenGLFunctions_ES2>();
  41 + // QOpenGLFunctions_3_2_Core *localFunctions = context()->versionFunctions<QOpenGLFunctions_3_2_Core>();
  42 + QOpenGLFunctions_1_3 *localFunctions = context()->versionFunctions<QOpenGLFunctions_1_3>();
  43 +
  44 + localFunctions->glDisable(GL_DEPTH_TEST);
  45 + localFunctions->glEnable(GL_BLEND);
  46 + localFunctions->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
38 47  
39   - glPointSize(1);
  48 + localFunctions->glPointSize(1);
40 49  
41 50 QColor bg = view->screen.background;
42   - glClearColor((GLfloat)bg.redF(), (GLfloat)bg.greenF(), (GLfloat)bg.blueF(), (GLfloat)bg.alphaF());
  51 + localFunctions->glClearColor((GLfloat)bg.redF(), (GLfloat)bg.greenF(), (GLfloat)bg.blueF(), (GLfloat)bg.alphaF());
43 52  
44   - glShadeModel(GL_SMOOTH /*GL_FLAT*/);
45   - glLineStipple(1, 0x3333);
  53 + localFunctions->glShadeModel(GL_SMOOTH /*GL_FLAT*/);
  54 + localFunctions->glLineStipple(1, 0x3333);
46 55  
47   - glEnableClientState(GL_VERTEX_ARRAY);
  56 + localFunctions->glEnableClientState(GL_VERTEX_ARRAY);
48 57 }
49 58  
50 59 void GlScope::paintGL() {
  60 + // TODO: Migrate to OpenGL ES2
  61 + // QOpenGLFunctions_ES2 *localFunctions = context()->versionFunctions<QOpenGLFunctions_ES2>();
  62 + // QOpenGLFunctions_3_2_Core *localFunctions = context()->versionFunctions<QOpenGLFunctions_3_2_Core>();
  63 + QOpenGLFunctions_1_3 *localFunctions = context()->versionFunctions<QOpenGLFunctions_1_3>();
  64 +
51 65 // Clear OpenGL buffer and configure settings
52   - glClear(GL_COLOR_BUFFER_BIT);
53   - glLineWidth(1);
  66 + localFunctions->glClear(GL_COLOR_BUFFER_BIT);
  67 + localFunctions->glLineWidth(1);
54 68  
55 69 if (generator->isReady()) { drawGraph(view->digitalPhosphorDraws()); }
56 70  
57 71 if (!this->zoomed) {
58 72 // Draw vertical lines at marker positions
59   - glEnable(GL_LINE_STIPPLE);
  73 + localFunctions->glEnable(GL_LINE_STIPPLE);
60 74 QColor trColor = view->screen.markers;
61   - glColor4f((GLfloat)trColor.redF(), (GLfloat)trColor.greenF(), (GLfloat)trColor.blueF(), (GLfloat)trColor.alphaF());
  75 + localFunctions->glColor4f((GLfloat)trColor.redF(), (GLfloat)trColor.greenF(), (GLfloat)trColor.blueF(), (GLfloat)trColor.alphaF());
62 76  
63 77 for (int marker = 0; marker < MARKER_COUNT; ++marker) {
64 78 if (!scope->horizontal.marker_visible[marker]) continue;
... ... @@ -71,12 +85,12 @@ void GlScope::paintGL() {
71 85 vaMarker[marker][0] = (GLfloat)scope->horizontal.marker[marker];
72 86 vaMarker[marker][2] = (GLfloat)scope->horizontal.marker[marker];
73 87  
74   - glLineWidth((marker == selectedMarker) ? 3 : 1);
75   - glVertexPointer(2, GL_FLOAT, 0, &vaMarker[marker].front());
76   - glDrawArrays(GL_LINES, 0, (GLsizei)vaMarker[marker].size() / 2);
  88 + localFunctions->glLineWidth((marker == selectedMarker) ? 3 : 1);
  89 + localFunctions->glVertexPointer(2, GL_FLOAT, 0, &vaMarker[marker].front());
  90 + localFunctions->glDrawArrays(GL_LINES, 0, (GLsizei)vaMarker[marker].size() / 2);
77 91 }
78 92  
79   - glDisable(GL_LINE_STIPPLE);
  93 + localFunctions->glDisable(GL_LINE_STIPPLE);
80 94 }
81 95  
82 96 // Draw grid
... ...
openhantek/src/glscope.h
... ... @@ -6,14 +6,7 @@
6 6 #include <QtGlobal>
7 7 #include <array>
8 8  
9   -#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
10 9 #include <QOpenGLWidget>
11   -using GL_WIDGET_CLASS = QOpenGLWidget;
12   -#else
13   -#include <QGLWidget>
14   -using GL_WIDGET_CLASS = QGLWidget;
15   -#endif
16   -
17 10 #include "hantekdso/enums.h"
18 11 #include "hantekprotocol/definitions.h"
19 12  
... ... @@ -22,7 +15,7 @@ struct DsoSettingsScope;
22 15 struct DsoSettingsView;
23 16  
24 17 /// \brief OpenGL accelerated widget that displays the oscilloscope screen.
25   -class GlScope : public GL_WIDGET_CLASS {
  18 +class GlScope : public QOpenGLWidget {
26 19 Q_OBJECT
27 20  
28 21 public:
... ...
openhantek/src/main.cpp
... ... @@ -5,6 +5,7 @@
5 5 #include <QLibraryInfo>
6 6 #include <QLocale>
7 7 #include <QTranslator>
  8 +#include <QSurfaceFormat>
8 9  
9 10 #include <iostream>
10 11 #include <memory>
... ... @@ -19,6 +20,10 @@
19 20 #include "selectdevice/selectsupporteddevice.h"
20 21 #include "viewconstants.h"
21 22  
  23 +#ifndef VERSION
  24 +#error "You need to run the cmake buildsystem!"
  25 +#endif
  26 +
22 27 using namespace Hantek;
23 28  
24 29  
... ... @@ -61,6 +66,12 @@ int main(int argc, char *argv[]) {
61 66 QCoreApplication::setApplicationName("OpenHantek");
62 67 QCoreApplication::setApplicationVersion(VERSION);
63 68  
  69 + QCoreApplication::setAttribute(Qt::AA_UseOpenGLES, true);
  70 + QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true);
  71 +
  72 + QSurfaceFormat format;
  73 + format.setProfile(QSurfaceFormat::CoreProfile);
  74 + QSurfaceFormat::setDefaultFormat(format);
64 75 QApplication openHantekApplication(argc, argv);
65 76  
66 77 //////// Load translations ////////
... ...