Commit 40e9b2885476afcee11833b2da0cafa7f3cc2afd

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

Command line switch to change between OpenGL and OpenGL ES. Add necessary depend…

…encies to build.md doc
docs/build.md
... ... @@ -3,10 +3,10 @@ layout: default
3 3 ---
4 4 ### [Linux](#linux)
5 5 For debian (stretch and newer), Ubuntu 17.04+ and Mint 17+ and other deb based distributions install named requirements like this:
6   -> apt install g++ cmake qttools5-dev qttools5-dev-tools libfftw3-dev binutils-dev libusb-1.0-0-dev libqt5opengl5-dev mesa-common-dev libgl1-mesa-dev
  6 +> apt install g++ cmake qttools5-dev qttools5-dev-tools libfftw3-dev binutils-dev libusb-1.0-0-dev libqt5opengl5-dev mesa-common-dev libgl1-mesa-dev libgles2-mesa-dev
7 7  
8 8 For rpm based distributions (Fedora 21+, OpenSuse) use this command:
9   -> dnf install cmake gcc-c++ qt5-qtbase-gui qt5-qttools-devel qt5-qttranslations fftw-devel binutils-devel libusb-devel
  9 +> dnf install cmake gcc-c++ qt5-qtbase-gui qt5-qttools-devel qt5-qttranslations fftw-devel binutils-devel libusb-devel mesa-libGL-devel mesa-libGLES-devel
10 10  
11 11 After you've installed the requirements run the following commands inside the directory of this package:
12 12 > mkdir build <br>
... ...
openhantek/src/glscope.cpp
... ... @@ -12,9 +12,7 @@
12 12 #include <QOpenGLShaderProgram>
13 13 #include <QPainter>
14 14  
15   -// We can't be more modern than OpenGL 3.2 or ES2 because of MacOSX.
16   -#include <QOpenGLFunctions_3_2_Core>
17   -#include <QOpenGLFunctions_ES2>
  15 +#include <QOpenGLFunctions>
18 16  
19 17 #include "glscope.h"
20 18  
... ... @@ -24,12 +22,6 @@
24 22 #include "viewconstants.h"
25 23 #include "viewsettings.h"
26 24  
27   -#if defined(QT_OPENGL_ES_2)
28   -typedef QOpenGLFunctions_ES2 OPENGL_VER;
29   -#else
30   -typedef QOpenGLFunctions_3_2_Core OPENGL_VER;
31   -#endif
32   -
33 25 GlScope *GlScope::createNormal(DsoSettingsScope *scope, DsoSettingsView *view, QWidget *parent) {
34 26 GlScope *s = new GlScope(scope, view, parent);
35 27 s->zoomed = false;
... ... @@ -42,22 +34,21 @@ GlScope *GlScope::createZoomed(DsoSettingsScope *scope, DsoSettingsView *view, Q
42 34 return s;
43 35 }
44 36  
45   -void GlScope::fixOpenGLversion() {
  37 +void GlScope::fixOpenGLversion(QSurfaceFormat::RenderableType t) {
46 38 QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true);
47 39  
48 40 // Prefer full desktop OpenGL without fixed pipeline
49 41 QSurfaceFormat format;
50 42 format.setSamples(4); // Antia-Aliasing, Multisampling
51   -#if defined(QT_OPENGL_ES_2)
52   - format.setVersion(2, 0);
53   - format.setProfile(QSurfaceFormat::CoreProfile);
54   - format.setRenderableType(QSurfaceFormat::OpenGLES);
55   - QCoreApplication::setAttribute(Qt::AA_UseOpenGLES, true);
56   -#else
57   - format.setVersion(3, 2);
58 43 format.setProfile(QSurfaceFormat::CoreProfile);
59   - format.setRenderableType(QSurfaceFormat::OpenGL);
60   -#endif
  44 + if (t==QSurfaceFormat::OpenGLES) {
  45 + format.setVersion(2, 0);
  46 + format.setRenderableType(QSurfaceFormat::OpenGLES);
  47 + QCoreApplication::setAttribute(Qt::AA_UseOpenGLES, true);
  48 + } else {
  49 + format.setVersion(3, 2);
  50 + format.setRenderableType(QSurfaceFormat::OpenGL);
  51 + }
61 52 QSurfaceFormat::setDefaultFormat(format);
62 53 }
63 54  
... ... @@ -66,7 +57,7 @@ GlScope::GlScope(DsoSettingsScope *scope, DsoSettingsView *view, QWidget *parent
66 57 vaMarker.resize(MARKER_COUNT);
67 58 }
68 59  
69   -GlScope::~GlScope() {}
  60 +GlScope::~GlScope() {/* virtual destructor necessary */}
70 61  
71 62 void GlScope::mousePressEvent(QMouseEvent *event) {
72 63 if (!zoomed && event->button() == Qt::LeftButton) {
... ... @@ -154,7 +145,7 @@ void GlScope::initializeGL() {
154 145 void main() { gl_FragColor = colour; }
155 146 )";
156 147  
157   - const char *vshaderCore = R"(
  148 + const char *vshaderDesktop = R"(
158 149 #version 150
159 150 in highp vec3 vertex;
160 151 uniform mat4 matrix;
... ... @@ -164,7 +155,7 @@ void GlScope::initializeGL() {
164 155 gl_PointSize = 1.0;
165 156 }
166 157 )";
167   - const char *fshaderCore = R"(
  158 + const char *fshaderDesktop = R"(
168 159 #version 150
169 160 uniform highp vec4 colour;
170 161 out vec4 flatColor;
... ... @@ -173,9 +164,9 @@ void GlScope::initializeGL() {
173 164  
174 165 qDebug() << "compile shaders";
175 166 // Compile vertex shader
176   - bool coreShaders = QSurfaceFormat::defaultFormat().profile() == QSurfaceFormat::CoreProfile;
177   - if (!program->addShaderFromSourceCode(QOpenGLShader::Vertex, coreShaders ? vshaderCore : vshaderES) ||
178   - !program->addShaderFromSourceCode(QOpenGLShader::Fragment, coreShaders ? fshaderCore : fshaderES)) {
  167 + bool usesOpenGL = QSurfaceFormat::defaultFormat().renderableType()==QSurfaceFormat::OpenGL;
  168 + if (!program->addShaderFromSourceCode(QOpenGLShader::Vertex, usesOpenGL ? vshaderDesktop : vshaderES) ||
  169 + !program->addShaderFromSourceCode(QOpenGLShader::Fragment, usesOpenGL ? fshaderDesktop : fshaderES)) {
179 170 errorMessage = "Failed to compile OpenGL shader programs.\n" + program->log();
180 171 return;
181 172 }
... ... @@ -197,7 +188,7 @@ void GlScope::initializeGL() {
197 188  
198 189 program->bind();
199 190  
200   - auto *gl = context()->versionFunctions<OPENGL_VER>();
  191 + auto *gl = context()->functions();
201 192 gl->glDisable(GL_DEPTH_TEST);
202 193 gl->glEnable(GL_BLEND);
203 194 // Enable depth buffer
... ... @@ -246,8 +237,7 @@ void GlScope::showData(PPresult *data) {
246 237 // doneCurrent();
247 238 }
248 239  
249   -void GlScope::markerUpdated()
250   -{
  240 +void GlScope::markerUpdated() {
251 241  
252 242 for (unsigned marker = 0; marker < vaMarker.size(); ++marker) {
253 243 if (!scope->horizontal.marker_visible[marker]) continue;
... ... @@ -264,7 +254,7 @@ void GlScope::markerUpdated()
264 254 void GlScope::paintGL() {
265 255 if (!shaderCompileSuccess) return;
266 256  
267   - auto *gl = context()->versionFunctions<OPENGL_VER>();
  257 + auto *gl = context()->functions();
268 258  
269 259 // Clear OpenGL buffer and configure settings
270 260 // TODO Don't clear if view->digitalPhosphorDraws()>1
... ... @@ -301,7 +291,7 @@ void GlScope::paintGL() {
301 291  
302 292 void GlScope::resizeGL(int width, int height) {
303 293 if (!shaderCompileSuccess) return;
304   - auto *gl = context()->versionFunctions<OPENGL_VER>();
  294 + auto *gl = context()->functions();
305 295 gl->glViewport(0, 0, (GLint)width, (GLint)height);
306 296  
307 297 // Set axes to div-scale and apply correction for exact pixelization
... ... @@ -416,7 +406,7 @@ void GlScope::generateGrid(QOpenGLShaderProgram *program) {
416 406 }
417 407  
418 408 void GlScope::drawGrid() {
419   - auto *gl = context()->versionFunctions<OPENGL_VER>();
  409 + auto *gl = context()->functions();
420 410 gl->glLineWidth(1);
421 411  
422 412 // Grid
... ... @@ -439,7 +429,7 @@ void GlScope::drawGrid() {
439 429 }
440 430  
441 431 void GlScope::drawMarkers() {
442   - auto *gl = context()->versionFunctions<OPENGL_VER>();
  432 + auto *gl = context()->functions();
443 433 QColor trColor = view->screen.markers;
444 434 m_program->setUniformValue(colorLocation, trColor);
445 435  
... ... @@ -451,7 +441,6 @@ void GlScope::drawMarkers() {
451 441  
452 442 // Draw selected
453 443 if (selectedMarker != NO_MARKER) {
454   - qWarning() << selectedMarker;
455 444 gl->glLineWidth(3);
456 445 gl->glDrawArrays(GL_LINES, selectedMarker * 2, (GLsizei)2);
457 446 }
... ... @@ -467,7 +456,7 @@ void GlScope::drawVoltageChannelGraph(ChannelID channel, Graph &amp;graph, int histo
467 456  
468 457 QOpenGLVertexArrayObject::Binder b(v.first);
469 458 const GLenum dMode = (view->interpolation == Dso::INTERPOLATION_OFF) ? GL_POINTS : GL_LINE_STRIP;
470   - context()->versionFunctions<OPENGL_VER>()->glDrawArrays(dMode, 0, v.second);
  459 + context()->functions()->glDrawArrays(dMode, 0, v.second);
471 460 }
472 461  
473 462 void GlScope::drawSpectrumChannelGraph(ChannelID channel, Graph &graph, int historyIndex) {
... ... @@ -478,5 +467,5 @@ void GlScope::drawSpectrumChannelGraph(ChannelID channel, Graph &amp;graph, int hist
478 467  
479 468 QOpenGLVertexArrayObject::Binder b(v.first);
480 469 const GLenum dMode = (view->interpolation == Dso::INTERPOLATION_OFF) ? GL_POINTS : GL_LINE_STRIP;
481   - context()->versionFunctions<OPENGL_VER>()->glDrawArrays(dMode, 0, v.second);
  470 + context()->functions()->glDrawArrays(dMode, 0, v.second);
482 471 }
... ...
openhantek/src/glscope.h
... ... @@ -34,7 +34,7 @@ class GlScope : public QOpenGLWidget {
34 34 * We need at least OpenGL 3.2 with shader version 150 or
35 35 * OpenGL ES 2.0 with shader version 100.
36 36 */
37   - static void fixOpenGLversion();
  37 + static void fixOpenGLversion(QSurfaceFormat::RenderableType t=QSurfaceFormat::DefaultRenderableType);
38 38 /**
39 39 * Show new post processed data
40 40 * @param data
... ...
openhantek/src/glscopegraph.cpp
... ... @@ -21,8 +21,6 @@ void Graph::writeData(PPresult *data, QOpenGLShaderProgram *program, int vertexL
21 21 allocatedMem = neededMemory;
22 22 }
23 23  
24   - qDebug() << data->data(0)->frequency;
25   -
26 24 // Write data to buffer
27 25 int offset = 0;
28 26 vaoVoltage.resize(data->vaChannelVoltage.size());
... ...
openhantek/src/main.cpp
1 1 // SPDX-License-Identifier: GPL-2.0+
2 2  
3 3 #include <QApplication>
  4 +#include <QCommandLineParser>
4 5 #include <QDebug>
5 6 #include <QLibraryInfo>
6 7 #include <QLocale>
... ... @@ -71,7 +72,19 @@ int main(int argc, char *argv[]) {
71 72 QCoreApplication::setApplicationName("OpenHantek");
72 73 QCoreApplication::setApplicationVersion(VERSION);
73 74  
74   - GlScope::fixOpenGLversion();
  75 + bool useGles = false;
  76 + {
  77 + QCoreApplication parserApp(argc, argv);
  78 + QCommandLineParser p;
  79 + p.addHelpOption();
  80 + p.addVersionOption();
  81 + QCommandLineOption useGlesOption("useGLES", QCoreApplication::tr("Use OpenGL ES instead of OpenGL"));
  82 + p.addOption(useGlesOption);
  83 + p.process(parserApp);
  84 + useGles = p.isSet(useGlesOption);
  85 + }
  86 +
  87 + GlScope::fixOpenGLversion(useGles ? QSurfaceFormat::OpenGLES : QSurfaceFormat::OpenGL);
75 88  
76 89 QApplication openHantekApplication(argc, argv);
77 90  
... ... @@ -152,9 +165,7 @@ int main(int argc, char *argv[]) {
152 165 postProcessingThread.quit();
153 166 postProcessingThread.wait(10000);
154 167  
155   - if (context && device != nullptr) {
156   - libusb_exit(context);
157   - }
  168 + if (context && device != nullptr) { libusb_exit(context); }
158 169  
159 170 return res;
160 171 }
... ...