From ecbc22edf4830f0f1011f3438fc6336c22948fee Mon Sep 17 00:00:00 2001 From: David Graeff Date: Mon, 8 Jan 2018 14:31:58 +0100 Subject: [PATCH] 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 | 48 +++++++++++++++++++++++++++++++----------------- openhantek/src/glscope.h | 9 +-------- openhantek/src/main.cpp | 11 +++++++++++ 3 files changed, 43 insertions(+), 25 deletions(-) diff --git a/openhantek/src/glscope.cpp b/openhantek/src/glscope.cpp index 1ef8a5a..24dacf2 100644 --- a/openhantek/src/glscope.cpp +++ b/openhantek/src/glscope.cpp @@ -5,6 +5,10 @@ #include #include +#include +#include +#include + #include "glscope.h" #include "glgenerator.h" @@ -27,38 +31,48 @@ GlScope *GlScope::createZoomed(DsoSettingsScope *scope, DsoSettingsView *view, c } GlScope::GlScope(DsoSettingsScope *scope, DsoSettingsView *view, const GlGenerator *generator, QWidget *parent) - : GL_WIDGET_CLASS(parent), scope(scope), view(view), generator(generator) { + : QOpenGLWidget(parent), scope(scope), view(view), generator(generator) { connect(generator, &GlGenerator::graphsGenerated, [this]() { update(); }); } void GlScope::initializeGL() { - glDisable(GL_DEPTH_TEST); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + // TODO: Migrate to OpenGL ES2 + // QOpenGLFunctions_ES2 *localFunctions = context()->versionFunctions(); + // QOpenGLFunctions_3_2_Core *localFunctions = context()->versionFunctions(); + QOpenGLFunctions_1_3 *localFunctions = context()->versionFunctions(); + + localFunctions->glDisable(GL_DEPTH_TEST); + localFunctions->glEnable(GL_BLEND); + localFunctions->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glPointSize(1); + localFunctions->glPointSize(1); QColor bg = view->screen.background; - glClearColor((GLfloat)bg.redF(), (GLfloat)bg.greenF(), (GLfloat)bg.blueF(), (GLfloat)bg.alphaF()); + localFunctions->glClearColor((GLfloat)bg.redF(), (GLfloat)bg.greenF(), (GLfloat)bg.blueF(), (GLfloat)bg.alphaF()); - glShadeModel(GL_SMOOTH /*GL_FLAT*/); - glLineStipple(1, 0x3333); + localFunctions->glShadeModel(GL_SMOOTH /*GL_FLAT*/); + localFunctions->glLineStipple(1, 0x3333); - glEnableClientState(GL_VERTEX_ARRAY); + localFunctions->glEnableClientState(GL_VERTEX_ARRAY); } void GlScope::paintGL() { + // TODO: Migrate to OpenGL ES2 + // QOpenGLFunctions_ES2 *localFunctions = context()->versionFunctions(); + // QOpenGLFunctions_3_2_Core *localFunctions = context()->versionFunctions(); + QOpenGLFunctions_1_3 *localFunctions = context()->versionFunctions(); + // Clear OpenGL buffer and configure settings - glClear(GL_COLOR_BUFFER_BIT); - glLineWidth(1); + localFunctions->glClear(GL_COLOR_BUFFER_BIT); + localFunctions->glLineWidth(1); if (generator->isReady()) { drawGraph(view->digitalPhosphorDraws()); } if (!this->zoomed) { // Draw vertical lines at marker positions - glEnable(GL_LINE_STIPPLE); + localFunctions->glEnable(GL_LINE_STIPPLE); QColor trColor = view->screen.markers; - glColor4f((GLfloat)trColor.redF(), (GLfloat)trColor.greenF(), (GLfloat)trColor.blueF(), (GLfloat)trColor.alphaF()); + localFunctions->glColor4f((GLfloat)trColor.redF(), (GLfloat)trColor.greenF(), (GLfloat)trColor.blueF(), (GLfloat)trColor.alphaF()); for (int marker = 0; marker < MARKER_COUNT; ++marker) { if (!scope->horizontal.marker_visible[marker]) continue; @@ -71,12 +85,12 @@ void GlScope::paintGL() { vaMarker[marker][0] = (GLfloat)scope->horizontal.marker[marker]; vaMarker[marker][2] = (GLfloat)scope->horizontal.marker[marker]; - glLineWidth((marker == selectedMarker) ? 3 : 1); - glVertexPointer(2, GL_FLOAT, 0, &vaMarker[marker].front()); - glDrawArrays(GL_LINES, 0, (GLsizei)vaMarker[marker].size() / 2); + localFunctions->glLineWidth((marker == selectedMarker) ? 3 : 1); + localFunctions->glVertexPointer(2, GL_FLOAT, 0, &vaMarker[marker].front()); + localFunctions->glDrawArrays(GL_LINES, 0, (GLsizei)vaMarker[marker].size() / 2); } - glDisable(GL_LINE_STIPPLE); + localFunctions->glDisable(GL_LINE_STIPPLE); } // Draw grid diff --git a/openhantek/src/glscope.h b/openhantek/src/glscope.h index 8e0bdcc..cf6a80e 100644 --- a/openhantek/src/glscope.h +++ b/openhantek/src/glscope.h @@ -6,14 +6,7 @@ #include #include -#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)) #include -using GL_WIDGET_CLASS = QOpenGLWidget; -#else -#include -using GL_WIDGET_CLASS = QGLWidget; -#endif - #include "hantekdso/enums.h" #include "hantekprotocol/definitions.h" @@ -22,7 +15,7 @@ struct DsoSettingsScope; struct DsoSettingsView; /// \brief OpenGL accelerated widget that displays the oscilloscope screen. -class GlScope : public GL_WIDGET_CLASS { +class GlScope : public QOpenGLWidget { Q_OBJECT public: diff --git a/openhantek/src/main.cpp b/openhantek/src/main.cpp index ab9792e..284f911 100644 --- a/openhantek/src/main.cpp +++ b/openhantek/src/main.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -19,6 +20,10 @@ #include "selectdevice/selectsupporteddevice.h" #include "viewconstants.h" +#ifndef VERSION +#error "You need to run the cmake buildsystem!" +#endif + using namespace Hantek; @@ -61,6 +66,12 @@ int main(int argc, char *argv[]) { QCoreApplication::setApplicationName("OpenHantek"); QCoreApplication::setApplicationVersion(VERSION); + QCoreApplication::setAttribute(Qt::AA_UseOpenGLES, true); + QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true); + + QSurfaceFormat format; + format.setProfile(QSurfaceFormat::CoreProfile); + QSurfaceFormat::setDefaultFormat(format); QApplication openHantekApplication(argc, argv); //////// Load translations //////// -- libgit2 0.21.4