From c19372354698f6689f50be839fdb27e4e8449e5c Mon Sep 17 00:00:00 2001 From: David Graeff Date: Sat, 13 Jan 2018 18:24:56 +0100 Subject: [PATCH] Use OpenGL 3.2 instead of 3.3 to make it work on MacOSX --- openhantek/src/dsowidget.cpp | 74 +++++++++++++++++++++++++++++++++++--------------------------------------- openhantek/src/dsowidget.h | 1 + openhantek/src/glscope.cpp | 190 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------- openhantek/src/glscope.h | 24 +++++++++++++++++------- openhantek/src/main.cpp | 15 ++++++++------- openhantek/src/scopesettings.h | 1 + openhantek/src/widgets/levelslider.cpp | 22 +++++++--------------- openhantek/src/widgets/levelslider.h | 6 +++--- 8 files changed, 197 insertions(+), 136 deletions(-) diff --git a/openhantek/src/dsowidget.cpp b/openhantek/src/dsowidget.cpp index 3521e3a..62becfd 100644 --- a/openhantek/src/dsowidget.cpp +++ b/openhantek/src/dsowidget.cpp @@ -5,8 +5,8 @@ #include #include #include -#include #include +#include #include "dsowidget.h" @@ -37,11 +37,12 @@ DsoWidget::DsoWidget(DsoSettingsScope *scope, DsoSettingsView *view, const Dso:: setupSliders(mainSliders); setupSliders(zoomSliders); - connect(mainScope, &GlScope::markerMoved, [this] (int marker, double position) { - double step = this->mainSliders.markerSlider->step(marker); + connect(mainScope, &GlScope::markerMoved, [this](int marker, double position) { + double value = std::round(position / MARKER_STEP) * MARKER_STEP; - this->scope->horizontal.marker[marker] = - this->mainSliders.markerSlider->setValue(marker, std::round(position / step) * step); + this->scope->horizontal.marker[marker] = value; + this->mainSliders.markerSlider->setValue(marker, value); + this->mainScope->markerUpdated(); }); // The table for the settings @@ -175,14 +176,6 @@ DsoWidget::DsoWidget(DsoSettingsScope *scope, DsoSettingsView *view, const Dso:: mainLayout->setRowMinimumHeight(row++, 8); mainLayout->addLayout(measurementLayout, row++, 0, 1, 5); - // Apply settings and update measured values - updateTriggerDetails(); - updateRecordLength(scope->horizontal.recordLength); - updateFrequencybase(scope->horizontal.frequencybase); - updateSamplerate(scope->horizontal.samplerate); - updateTimebase(scope->horizontal.timebase); - updateZoom(view->zoom); - // The widget itself setPalette(palette); setBackgroundRole(QPalette::Background); @@ -205,9 +198,6 @@ DsoWidget::DsoWidget(DsoSettingsScope *scope, DsoSettingsView *view, const Dso:: zoomScope->update(); }); zoomSliders.markerSlider->setEnabled(false); - - updateTriggerSource(); - adaptTriggerPositionSlider(); } void DsoWidget::setupSliders(DsoWidget::Sliders &sliders) { @@ -242,11 +232,10 @@ void DsoWidget::setupSliders(DsoWidget::Sliders &sliders) { sliders.triggerLevelSlider = new LevelSlider(Qt::LeftArrow); for (ChannelID channel = 0; channel < spec->channels; ++channel) { sliders.triggerLevelSlider->addSlider((int)channel); - sliders.triggerLevelSlider->setColor( - channel, - (!scope->trigger.special && channel == scope->trigger.source) - ? view->screen.voltage[channel] - : view->screen.voltage[channel].darker()); + sliders.triggerLevelSlider->setColor(channel, + (!scope->trigger.special && channel == scope->trigger.source) + ? view->screen.voltage[channel] + : view->screen.voltage[channel].darker()); adaptTriggerLevelSlider(sliders, channel); sliders.triggerLevelSlider->setValue(channel, scope->voltage[channel].trigger); sliders.triggerLevelSlider->setIndexVisible(channel, scope->voltage[channel].used); @@ -257,7 +246,7 @@ void DsoWidget::setupSliders(DsoWidget::Sliders &sliders) { for (int marker = 0; marker < MARKER_COUNT; ++marker) { sliders.markerSlider->addSlider(QString::number(marker + 1), marker); sliders.markerSlider->setLimits(marker, -DIVS_TIME / 2, DIVS_TIME / 2); - sliders.markerSlider->setStep(marker, DIVS_TIME / 100.0); + sliders.markerSlider->setStep(marker, MARKER_STEP); sliders.markerSlider->setValue(marker, scope->horizontal.marker[marker]); sliders.markerSlider->setIndexVisible(marker, true); } @@ -269,9 +258,9 @@ void DsoWidget::setExporterForNextFrame(std::unique_ptr exporter) { /// \brief Set the trigger level sliders minimum and maximum to the new values. void DsoWidget::adaptTriggerLevelSlider(DsoWidget::Sliders &sliders, ChannelID channel) { - sliders.triggerLevelSlider->setLimits( - (int)channel, (-DIVS_VOLTAGE / 2 - scope->voltage[channel].offset) * scope->gain(channel), - (DIVS_VOLTAGE / 2 - scope->voltage[channel].offset) * scope->gain(channel)); + sliders.triggerLevelSlider->setLimits((int)channel, + (-DIVS_VOLTAGE / 2 - scope->voltage[channel].offset) * scope->gain(channel), + (DIVS_VOLTAGE / 2 - scope->voltage[channel].offset) * scope->gain(channel)); sliders.triggerLevelSlider->setStep((int)channel, scope->gain(channel) * 0.05); } @@ -292,14 +281,10 @@ void DsoWidget::setMeasurementVisible(ChannelID channel) { } measurementGainLabel[channel]->setVisible(scope->voltage[channel].used); - if (!scope->voltage[channel].used) { - measurementGainLabel[channel]->setText(QString()); - } + if (!scope->voltage[channel].used) { measurementGainLabel[channel]->setText(QString()); } measurementMagnitudeLabel[channel]->setVisible(scope->spectrum[channel].used); - if (!scope->spectrum[channel].used) { - measurementMagnitudeLabel[channel]->setText(QString()); - } + if (!scope->spectrum[channel].used) { measurementMagnitudeLabel[channel]->setText(QString()); } } /// \brief Update the label about the marker measurements @@ -411,16 +396,15 @@ void DsoWidget::updateTriggerSource() { if (scope->trigger.special || scope->trigger.source >= spec->channels) { mainSliders.triggerPositionSlider->setColor(0, view->screen.border); zoomSliders.triggerPositionSlider->setColor(0, view->screen.border); - } - else { + } else { mainSliders.triggerPositionSlider->setColor(0, view->screen.voltage[scope->trigger.source]); zoomSliders.triggerPositionSlider->setColor(0, view->screen.voltage[scope->trigger.source]); } for (ChannelID channel = 0; channel < spec->channels; ++channel) { QColor color = (!scope->trigger.special && channel == scope->trigger.source) - ? view->screen.voltage[channel] - : view->screen.voltage[channel].darker(); + ? view->screen.voltage[channel] + : view->screen.voltage[channel].darker(); mainSliders.triggerLevelSlider->setColor(channel, color); zoomSliders.triggerLevelSlider->setColor(channel, color); } @@ -484,8 +468,7 @@ void DsoWidget::updateZoom(bool enabled) { zoomSliders.offsetSlider->show(); zoomSliders.triggerPositionSlider->show(); zoomSliders.triggerLevelSlider->show(); - } - else { + } else { zoomSliders.offsetSlider->hide(); zoomSliders.triggerPositionSlider->hide(); zoomSliders.triggerLevelSlider->hide(); @@ -535,6 +518,20 @@ void DsoWidget::showNew(std::shared_ptr data) { } } +void DsoWidget::showEvent(QShowEvent *event) { + QWidget::showEvent(event); + // Apply settings and update measured values + updateTriggerDetails(); + updateRecordLength(scope->horizontal.recordLength); + updateFrequencybase(scope->horizontal.frequencybase); + updateSamplerate(scope->horizontal.samplerate); + updateTimebase(scope->horizontal.timebase); + updateZoom(view->zoom); + + updateTriggerSource(); + adaptTriggerPositionSlider(); +} + /// \brief Handles valueChanged signal from the offset sliders. /// \param channel The channel whose offset was changed. /// \param value The new offset for the channel. @@ -573,8 +570,7 @@ void DsoWidget::adaptTriggerPositionSlider() { if (m1 != m2 && m1 <= value && value <= m2) { zoomSliders.triggerPositionSlider->setIndexVisible(0, true); zoomSliders.triggerPositionSlider->setValue(0, (value - m1) / (m2 - m1)); - } - else { + } else { zoomSliders.triggerPositionSlider->setIndexVisible(0, false); } } diff --git a/openhantek/src/dsowidget.h b/openhantek/src/dsowidget.h index 982bd22..3f789c5 100644 --- a/openhantek/src/dsowidget.h +++ b/openhantek/src/dsowidget.h @@ -42,6 +42,7 @@ class DsoWidget : public QWidget { void showNew(std::shared_ptr data); protected: + virtual void showEvent(QShowEvent *event); void setupSliders(Sliders &sliders); void adaptTriggerLevelSlider(DsoWidget::Sliders &sliders, ChannelID channel); void adaptTriggerPositionSlider(); diff --git a/openhantek/src/glscope.cpp b/openhantek/src/glscope.cpp index 0f51e5f..82bcded 100644 --- a/openhantek/src/glscope.cpp +++ b/openhantek/src/glscope.cpp @@ -4,12 +4,16 @@ #include #include +#include #include #include +#include #include #include +#include -#include +// We can't be more modern than OpenGL 3.2 or ES2 because of MacOSX. +#include #include #include "glscope.h" @@ -23,7 +27,7 @@ #if defined(QT_OPENGL_ES_2) typedef QOpenGLFunctions_ES2 OPENGL_VER; #else -typedef QOpenGLFunctions_3_3_Core OPENGL_VER; +typedef QOpenGLFunctions_3_2_Core OPENGL_VER; #endif GlScope *GlScope::createNormal(DsoSettingsScope *scope, DsoSettingsView *view, QWidget *parent) { @@ -38,6 +42,25 @@ GlScope *GlScope::createZoomed(DsoSettingsScope *scope, DsoSettingsView *view, Q return s; } +void GlScope::fixOpenGLversion() { + QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true); + + // Prefer full desktop OpenGL without fixed pipeline + QSurfaceFormat format; + format.setSamples(4); // Antia-Aliasing, Multisampling +#if defined(QT_OPENGL_ES_2) + format.setVersion(2, 0); + format.setProfile(QSurfaceFormat::CoreProfile); + format.setRenderableType(QSurfaceFormat::OpenGLES); + QCoreApplication::setAttribute(Qt::AA_UseOpenGLES, true); +#else + format.setVersion(3, 2); + format.setProfile(QSurfaceFormat::CoreProfile); + format.setRenderableType(QSurfaceFormat::OpenGL); +#endif + QSurfaceFormat::setDefaultFormat(format); +} + GlScope::GlScope(DsoSettingsScope *scope, DsoSettingsView *view, QWidget *parent) : QOpenGLWidget(parent), scope(scope), view(view) { vaMarker.resize(MARKER_COUNT); @@ -51,7 +74,7 @@ void GlScope::mousePressEvent(QMouseEvent *event) { double distance = DIVS_TIME; selectedMarker = NO_MARKER; // Capture nearest marker located within snap area (+/- 1% of full scale). - for (int marker = 0; marker < MARKER_COUNT; ++marker) { + for (unsigned marker = 0; marker < MARKER_COUNT; ++marker) { if (!scope->horizontal.marker_visible[marker]) continue; if (fabs(scope->horizontal.marker[marker] - position) < std::min(distance, DIVS_TIME / 100.0)) { distance = fabs(scope->horizontal.marker[marker] - position); @@ -89,13 +112,34 @@ void GlScope::mouseReleaseEvent(QMouseEvent *event) { event->accept(); } +void GlScope::paintEvent(QPaintEvent *event) { + // Draw error message if OpenGL failed + if (!shaderCompileSuccess) { + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing, true); + QFont font = painter.font(); + font.setPointSize(18); + painter.setFont(font); + painter.drawText(rect(), Qt::AlignCenter, errorMessage); + event->accept(); + } else + QOpenGLWidget::paintEvent(event); +} + void GlScope::initializeGL() { - auto *gl = context()->versionFunctions(); + if (!QOpenGLShaderProgram::hasOpenGLShaderPrograms(context())) { + errorMessage = tr("System does not support OpenGL Shading Language (GLSL)"); + return; + } + if (m_program) { + qWarning() << "OpenGL init called twice!"; + return; + } - m_program = std::unique_ptr(new QOpenGLShaderProgram(context())); + auto program = std::unique_ptr(new QOpenGLShaderProgram(context())); const char *vshaderES = R"( - #version 330 + #version 100 attribute highp vec3 vertex; uniform mat4 matrix; void main() @@ -104,9 +148,14 @@ void GlScope::initializeGL() { gl_PointSize = 1.0; } )"; + const char *fshaderES = R"( + #version 100 + uniform highp vec4 colour; + void main() { gl_FragColor = colour; } + )"; const char *vshaderCore = R"( - #version 330 + #version 150 in highp vec3 vertex; uniform mat4 matrix; void main() @@ -116,37 +165,39 @@ void GlScope::initializeGL() { } )"; const char *fshaderCore = R"( - #version 330 + #version 150 uniform highp vec4 colour; - void main() { gl_FragColor = colour; } + out vec4 flatColor; + void main() { flatColor = colour; } )"; qDebug() << "compile shaders"; // Compile vertex shader bool coreShaders = QSurfaceFormat::defaultFormat().profile() == QSurfaceFormat::CoreProfile; - if (!m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, coreShaders ? vshaderCore : vshaderES) || - !m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fshaderCore)) { - qWarning() << "Failed to compile OpenGL shader programs.\n" << m_program->log(); + if (!program->addShaderFromSourceCode(QOpenGLShader::Vertex, coreShaders ? vshaderCore : vshaderES) || + !program->addShaderFromSourceCode(QOpenGLShader::Fragment, coreShaders ? fshaderCore : fshaderES)) { + errorMessage = "Failed to compile OpenGL shader programs.\n" + program->log(); return; } // Link shader pipeline - if (!m_program->link() || !m_program->bind()) { - qWarning() << "Failed to link/bind OpenGL shader programs"; + if (!program->link() || !program->bind()) { + errorMessage = "Failed to link/bind OpenGL shader programs\n" + program->log(); return; } - vertexLocation = m_program->attributeLocation("vertex"); - matrixLocation = m_program->uniformLocation("matrix"); - colorLocation = m_program->uniformLocation("colour"); + vertexLocation = program->attributeLocation("vertex"); + matrixLocation = program->uniformLocation("matrix"); + colorLocation = program->uniformLocation("colour"); if (vertexLocation == -1 || colorLocation == -1 || matrixLocation == -1) { qWarning() << "Failed to locate shader variable"; return; } - m_program->bind(); + program->bind(); + auto *gl = context()->versionFunctions(); gl->glDisable(GL_DEPTH_TEST); gl->glEnable(GL_BLEND); // Enable depth buffer @@ -159,7 +210,7 @@ void GlScope::initializeGL() { QColor bg = view->screen.background; gl->glClearColor((GLfloat)bg.redF(), (GLfloat)bg.greenF(), (GLfloat)bg.blueF(), (GLfloat)bg.alphaF()); - generateGrid(); + generateGrid(program.get()); { m_vaoMarker.create(); @@ -168,15 +219,18 @@ void GlScope::initializeGL() { m_marker.bind(); m_marker.setUsagePattern(QOpenGLBuffer::StaticDraw); m_marker.allocate(int(vaMarker.size() * sizeof(Line))); - m_program->enableAttributeArray(vertexLocation); - m_program->setAttributeBuffer(vertexLocation, GL_FLOAT, 0, 3, 0); + program->enableAttributeArray(vertexLocation); + program->setAttributeBuffer(vertexLocation, GL_FLOAT, 0, 3, 0); } - m_program->release(); + markerUpdated(); + + m_program = std::move(program); + shaderCompileSuccess = true; } void GlScope::showData(PPresult *data) { - if (!m_program || !m_program->isLinked()) return; + if (!shaderCompileSuccess) return; makeCurrent(); // Remove too much entries while (view->digitalPhosphorDraws() < m_GraphHistory.size()) m_GraphHistory.pop_back(); @@ -192,8 +246,23 @@ void GlScope::showData(PPresult *data) { // doneCurrent(); } +void GlScope::markerUpdated() +{ + + for (unsigned marker = 0; marker < vaMarker.size(); ++marker) { + if (!scope->horizontal.marker_visible[marker]) continue; + vaMarker[marker] = {QVector3D((GLfloat)scope->horizontal.marker[marker], -DIVS_VOLTAGE, 0.0f), + QVector3D((GLfloat)scope->horizontal.marker[marker], DIVS_VOLTAGE, 0.0f)}; + } + + // Write coordinates to GPU + makeCurrent(); + m_marker.bind(); + m_marker.write(0, vaMarker.data(), vaMarker.size() * sizeof(Line)); +} + void GlScope::paintGL() { - if (!m_program->isLinked()) return; + if (!shaderCompileSuccess) return; auto *gl = context()->versionFunctions(); @@ -231,6 +300,7 @@ void GlScope::paintGL() { } void GlScope::resizeGL(int width, int height) { + if (!shaderCompileSuccess) return; auto *gl = context()->versionFunctions(); gl->glViewport(0, 0, (GLint)width, (GLint)height); @@ -248,30 +318,7 @@ void GlScope::resizeGL(int width, int height) { m_program->release(); } -void GlScope::drawGrid() { - auto *gl = context()->versionFunctions(); - gl->glLineWidth(1); - - // Grid - m_vaoGrid[0].bind(); - m_program->setUniformValue(colorLocation, view->screen.grid); - gl->glDrawArrays(GL_POINTS, 0, gridDrawCounts[0]); - m_vaoGrid[0].release(); - - // Axes - m_vaoGrid[1].bind(); - m_program->setUniformValue(colorLocation, view->screen.axes); - gl->glDrawArrays(GL_LINES, 0, gridDrawCounts[1]); - m_vaoGrid[1].release(); - - // Border - m_vaoGrid[2].bind(); - m_program->setUniformValue(colorLocation, view->screen.border); - gl->glDrawArrays(GL_LINE_LOOP, 0, gridDrawCounts[2]); - m_vaoGrid[2].release(); -} - -void GlScope::generateGrid() { +void GlScope::generateGrid(QOpenGLShaderProgram *program) { gridDrawCounts[0] = 0; gridDrawCounts[1] = 0; gridDrawCounts[2] = 0; @@ -286,8 +333,8 @@ void GlScope::generateGrid() { m_vaoGrid[0].create(); QOpenGLVertexArrayObject::Binder b(&m_vaoGrid[0]); m_grid.bind(); - m_program->enableAttributeArray(vertexLocation); - m_program->setAttributeBuffer(vertexLocation, GL_FLOAT, 0, 3, 0); + program->enableAttributeArray(vertexLocation); + program->setAttributeBuffer(vertexLocation, GL_FLOAT, 0, 3, 0); } // Draw vertical lines @@ -318,8 +365,8 @@ void GlScope::generateGrid() { m_vaoGrid[1].create(); QOpenGLVertexArrayObject::Binder b(&m_vaoGrid[1]); m_grid.bind(); - m_program->enableAttributeArray(vertexLocation); - m_program->setAttributeBuffer(vertexLocation, GL_FLOAT, int(vaGrid.size() * sizeof(QVector3D)), 3); + program->enableAttributeArray(vertexLocation); + program->setAttributeBuffer(vertexLocation, GL_FLOAT, int(vaGrid.size() * sizeof(QVector3D)), 3); } // Axes @@ -353,8 +400,8 @@ void GlScope::generateGrid() { m_vaoGrid[2].create(); QOpenGLVertexArrayObject::Binder b(&m_vaoGrid[2]); m_grid.bind(); - m_program->enableAttributeArray(vertexLocation); - m_program->setAttributeBuffer(vertexLocation, GL_FLOAT, int(vaGrid.size() * sizeof(QVector3D)), 3); + program->enableAttributeArray(vertexLocation); + program->setAttributeBuffer(vertexLocation, GL_FLOAT, int(vaGrid.size() * sizeof(QVector3D)), 3); } // Border @@ -368,6 +415,29 @@ void GlScope::generateGrid() { m_grid.release(); } +void GlScope::drawGrid() { + auto *gl = context()->versionFunctions(); + gl->glLineWidth(1); + + // Grid + m_vaoGrid[0].bind(); + m_program->setUniformValue(colorLocation, view->screen.grid); + gl->glDrawArrays(GL_POINTS, 0, gridDrawCounts[0]); + m_vaoGrid[0].release(); + + // Axes + m_vaoGrid[1].bind(); + m_program->setUniformValue(colorLocation, view->screen.axes); + gl->glDrawArrays(GL_LINES, 0, gridDrawCounts[1]); + m_vaoGrid[1].release(); + + // Border + m_vaoGrid[2].bind(); + m_program->setUniformValue(colorLocation, view->screen.border); + gl->glDrawArrays(GL_LINE_LOOP, 0, gridDrawCounts[2]); + m_vaoGrid[2].release(); +} + void GlScope::drawMarkers() { auto *gl = context()->versionFunctions(); QColor trColor = view->screen.markers; @@ -375,23 +445,13 @@ void GlScope::drawMarkers() { m_vaoMarker.bind(); - for (unsigned marker = 0; marker < vaMarker.size(); ++marker) { - if (!scope->horizontal.marker_visible[marker]) continue; - vaMarker[marker] = {QVector3D((GLfloat)scope->horizontal.marker[marker], -DIVS_VOLTAGE, 0.0f), - QVector3D((GLfloat)scope->horizontal.marker[marker], DIVS_VOLTAGE, 0.0f)}; - } - - // Write coordinates to GPU - m_marker.bind(); - m_marker.write(0, vaMarker.data(), vaMarker.size() * sizeof(Line)); - // Draw all gl->glLineWidth(1); gl->glDrawArrays(GL_LINES, 0, (GLsizei)vaMarker.size() * 2); - m_marker.release(); // Draw selected if (selectedMarker != NO_MARKER) { + qWarning() << selectedMarker; gl->glLineWidth(3); gl->glDrawArrays(GL_LINES, selectedMarker * 2, (GLsizei)2); } diff --git a/openhantek/src/glscope.h b/openhantek/src/glscope.h index 43d6cc7..62d5dff 100644 --- a/openhantek/src/glscope.h +++ b/openhantek/src/glscope.h @@ -31,10 +31,16 @@ class GlScope : public QOpenGLWidget { 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(); + /** * Show new post processed data * @param data */ void showData(PPresult* data); + void markerUpdated(); protected: /// \brief Initializes the scope widget. @@ -42,21 +48,23 @@ class GlScope : public QOpenGLWidget { /// \param parent The parent widget. GlScope(DsoSettingsScope *scope, DsoSettingsView *view, QWidget *parent = 0); virtual ~GlScope(); + GlScope(const GlScope&) = delete; /// \brief Initializes OpenGL output. - void initializeGL() override; + virtual void initializeGL() override; /// \brief Draw the graphs, marker and the grid. - void paintGL() override; + virtual void paintGL() override; /// \brief Resize the widget. /// \param width The new width of the widget. /// \param height The new height of the widget. - void resizeGL(int width, int height) override; + virtual void resizeGL(int width, int height) override; - void mousePressEvent(QMouseEvent *event) override; - void mouseMoveEvent(QMouseEvent *event) override; - void mouseReleaseEvent(QMouseEvent *event) 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(); @@ -91,13 +99,15 @@ class GlScope : public QOpenGLWidget { QOpenGLBuffer m_grid; QOpenGLVertexArrayObject m_vaoGrid[3]; GLsizei gridDrawCounts[3]; - void generateGrid(); + void generateGrid(QOpenGLShaderProgram *program); // Graphs std::list m_GraphHistory; unsigned currentGraphInHistory = 0; // OpenGL shader, matrix, var-locations + bool shaderCompileSuccess = false; + QString errorMessage; std::unique_ptr m_program; QMatrix4x4 pmvMatrix; ///< projection, view matrix int colorLocation; diff --git a/openhantek/src/main.cpp b/openhantek/src/main.cpp index 572edf1..d5ace2f 100644 --- a/openhantek/src/main.cpp +++ b/openhantek/src/main.cpp @@ -24,6 +24,8 @@ #include "usb/usbdevice.h" #include "viewconstants.h" +#include "glscope.h" + #ifndef VERSION #error "You need to run the cmake buildsystem!" #endif @@ -69,14 +71,8 @@ int main(int argc, char *argv[]) { QCoreApplication::setApplicationName("OpenHantek"); QCoreApplication::setApplicationVersion(VERSION); - QCoreApplication::setAttribute(Qt::AA_UseOpenGLES, true); - QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true); + GlScope::fixOpenGLversion(); - // Prefer full desktop OpenGL without fixed pipeline - QSurfaceFormat format; - format.setProfile(QSurfaceFormat::CoreProfile); - format.setSamples(4); // Antia-Aliasing, Multisampling - QSurfaceFormat::setDefaultFormat(format); QApplication openHantekApplication(argc, argv); //////// Load translations //////// @@ -155,5 +151,10 @@ int main(int argc, char *argv[]) { postProcessingThread.quit(); postProcessingThread.wait(10000); + + if (context && device != nullptr) { + libusb_exit(context); + } + return res; } diff --git a/openhantek/src/scopesettings.h b/openhantek/src/scopesettings.h index 00e844a..b50c5d2 100644 --- a/openhantek/src/scopesettings.h +++ b/openhantek/src/scopesettings.h @@ -11,6 +11,7 @@ #include #define MARKER_COUNT 2 ///< Number of markers +#define MARKER_STEP (DIVS_TIME / 100.0) /// \brief Holds the settings for the horizontal axis. struct DsoSettingsScopeHorizontal { diff --git a/openhantek/src/widgets/levelslider.cpp b/openhantek/src/widgets/levelslider.cpp index 642a0c7..f2890a8 100644 --- a/openhantek/src/widgets/levelslider.cpp +++ b/openhantek/src/widgets/levelslider.cpp @@ -196,17 +196,14 @@ double LevelSlider::maximum(int index) const { /// \param minimum The value a slider has at the bottommost/leftmost position. /// \param maximum The value a slider has at the topmost/rightmost position. /// \return -1 on error, fixValue result on success. -int LevelSlider::setLimits(int index, double minimum, double maximum) { - if (index < 0 || index >= this->slider.count()) return -1; +void LevelSlider::setLimits(int index, double minimum, double maximum) { + if (index < 0 || index >= this->slider.count()) return; this->slider[index]->minimum = minimum; this->slider[index]->maximum = maximum; - int result = this->fixValue(index); - + this->fixValue(index); this->calculateRect(index); this->repaint(); - - return result; } /// \brief Return the step width of the sliders. @@ -243,8 +240,8 @@ double LevelSlider::value(int index) const { /// \param index The index of the slider whose value should be set. /// \param value The new value of the slider. /// \return The new value of the slider. -double LevelSlider::setValue(int index, double value) { - if (index < 0 || index >= this->slider.count()) return -1; +void LevelSlider::setValue(int index, double value) { + if (index < 0 || index >= this->slider.count()) return; // Apply new value this->slider[index]->value = value; @@ -254,8 +251,6 @@ double LevelSlider::setValue(int index, double value) { this->repaint(); if (this->pressedSlider < 0) emit valueChanged(index, value); - - return this->slider[index]->value; } /// \brief Return the direction of the sliders. @@ -563,17 +558,14 @@ int LevelSlider::calculateWidth() { /// \brief Fix the value if it's outside the limits. /// \param index The index of the slider who should be fixed. /// \return 0 when ok, -1 on error, 1 when increased and 2 when decreased. -int LevelSlider::fixValue(int index) { - if (index < 0 || index >= this->slider.count()) return -1; +void LevelSlider::fixValue(int index) { + if (index < 0 || index >= this->slider.count()) return; double lowest = qMin(this->slider[index]->minimum, this->slider[index]->maximum); double highest = qMax(this->slider[index]->minimum, this->slider[index]->maximum); if (this->slider[index]->value < lowest) { this->slider[index]->value = lowest; - return 1; } else if (this->slider[index]->value > highest) { this->slider[index]->value = highest; - return 2; } - return 0; } diff --git a/openhantek/src/widgets/levelslider.h b/openhantek/src/widgets/levelslider.h index e954388..2c6e1d4 100644 --- a/openhantek/src/widgets/levelslider.h +++ b/openhantek/src/widgets/levelslider.h @@ -51,11 +51,11 @@ class LevelSlider : public QWidget { double minimum(int index) const; double maximum(int index) const; - int setLimits(int index, double minimum, double maximum); + void setLimits(int index, double minimum, double maximum); double step(int index) const; double setStep(int index, double step); double value(int index) const; - double setValue(int index, double value); + void setValue(int index, double value); // Parameters for all sliders Qt::ArrowType direction() const; @@ -71,7 +71,7 @@ class LevelSlider : public QWidget { QRect calculateRect(int sliderId); int calculateWidth(); - int fixValue(int index); + void fixValue(int index); QList slider; ///< The parameters for each slider int pressedSlider; ///< The currently pressed (moved) slider -- libgit2 0.21.4