From 6a8e0f4d39c8677119eda2f37879ed0ee2dab72b Mon Sep 17 00:00:00 2001 From: Martin Reboredo Date: Sun, 30 Jan 2022 18:15:49 -0300 Subject: [PATCH 1/4] QOpenGL classes instead of QGL --- Gui/CurveGui.cpp | 6 ++- Gui/CurveWidget.cpp | 34 ++++++++++----- Gui/CurveWidget.h | 11 +++-- Gui/CurveWidgetPrivate.cpp | 14 ++++--- Gui/CustomParamInteract.cpp | 16 ++++++-- Gui/CustomParamInteract.h | 12 +++--- Gui/DopeSheetView.cpp | 26 ++++++++---- Gui/DopeSheetView.h | 15 +++---- Gui/GuiFwd.h | 2 +- Gui/Histogram.cpp | 78 ++++++++++++++++++++--------------- Gui/Histogram.h | 13 +++--- Gui/HostOverlay.cpp | 9 ++-- Gui/QGLExtrasCompat.h | 30 ++++++++++++++ Gui/QGLWidgetCompat.h | 28 +++++++++++++ Gui/TextRenderer.cpp | 36 +++++++++++++--- Gui/TimeLineGui.cpp | 14 ++++--- Gui/TimeLineGui.h | 9 +++- Gui/ViewerGL.cpp | 82 +++++++++++++++++++++++-------------- Gui/ViewerGL.h | 17 ++++---- Gui/ViewerGLPrivate.cpp | 17 ++++++-- Gui/ViewerGLPrivate.h | 4 +- 21 files changed, 326 insertions(+), 147 deletions(-) create mode 100644 Gui/QGLExtrasCompat.h create mode 100644 Gui/QGLWidgetCompat.h diff --git a/Gui/CurveGui.cpp b/Gui/CurveGui.cpp index bdf381fa87..e864729a1b 100644 --- a/Gui/CurveGui.cpp +++ b/Gui/CurveGui.cpp @@ -45,6 +45,10 @@ #include "Gui/CurveWidgetPrivate.h" #include "Gui/KnobGui.h" +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) +#include +#endif + NATRON_NAMESPACE_ENTER CurveGui::CurveGui(CurveWidget *curveWidget, @@ -299,7 +303,7 @@ CurveGui::drawCurve(int curveIndex, return; } - assert( QGLContext::currentContext() == _curveWidget->context() ); + assert( QOpenGLContext::currentContext() == _curveWidget->context() ); std::vector vertices, exprVertices; double x1 = 0; diff --git a/Gui/CurveWidget.cpp b/Gui/CurveWidget.cpp index c4a5b0b8c2..b12e7f0f31 100644 --- a/Gui/CurveWidget.cpp +++ b/Gui/CurveWidget.cpp @@ -70,6 +70,10 @@ GCC_DIAG_UNUSED_PRIVATE_FIELD_ON #include "Gui/TabWidget.h" #include "Gui/ViewerGL.h" +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) +#include +#endif + NATRON_NAMESPACE_ENTER /*****************************CURVE WIDGET***********************************************/ @@ -116,8 +120,12 @@ CurveWidget::CurveWidget(Gui* gui, CurveSelection* selection, TimeLinePtr timeline, QWidget* parent, - const QGLWidget* shareWidget) - : QGLWidget(parent, shareWidget) + const QOpenGLWidget* shareWidget) +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) + : QOpenGLWidget(parent) +#else + : QOpenGLWidget(parent, shareWidget) +#endif , _imp( new CurveWidgetPrivate(gui, selection, timeline, this) ) { // always running in the main thread @@ -435,7 +443,11 @@ CurveWidget::swapOpenGLBuffers() // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) + update(); +#else swapBuffers(); +#endif } /** @@ -486,7 +498,7 @@ CurveWidget::getScreenPixelRatio() const assert( qApp && qApp->thread() == QThread::currentThread() ); #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - return windowHandle()->devicePixelRatio(); + return devicePixelRatio(); #else return _imp->_gui ? _imp->_gui->devicePixelRatio() : 1.; #endif @@ -579,7 +591,7 @@ CurveWidget::resizeGL(int width, { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == context() ); + assert( QOpenGLContext::currentContext() == context() ); if ( !appPTR->isOpenGLLoaded() ) { return; @@ -620,7 +632,7 @@ CurveWidget::paintGL() { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == context() ); + assert( QOpenGLContext::currentContext() == context() ); if ( !appPTR->isOpenGLLoaded() ) { return; @@ -735,7 +747,7 @@ CurveWidget::renderText(double x, { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == context() ); + assert( QOpenGLContext::currentContext() == context() ); if ( text.isEmpty() ) { return; @@ -1241,7 +1253,7 @@ CurveWidget::mouseMoveEvent(QMouseEvent* e) if (_imp->_state == eEventStateNone) { // nothing else to do - QGLWidget::mouseMoveEvent(e); + QOpenGLWidget::mouseMoveEvent(e); return; } @@ -1364,7 +1376,7 @@ CurveWidget::mouseMoveEvent(QMouseEvent* e) if (mustUpdate) { update(); } - QGLWidget::mouseMoveEvent(e); + QOpenGLWidget::mouseMoveEvent(e); } // mouseMoveEvent void @@ -1622,7 +1634,7 @@ CurveWidget::keyPressEvent(QKeyEvent* e) if (ce) { ce->handleUnCaughtKeyPressEvent(e); } - QGLWidget::keyPressEvent(e); + QOpenGLWidget::keyPressEvent(e); } } // keyPressEvent @@ -1630,7 +1642,7 @@ void CurveWidget::enterEvent(QEvent* e) { setFocus(); - QGLWidget::enterEvent(e); + QOpenGLWidget::enterEvent(e); } void @@ -2128,7 +2140,7 @@ CurveWidget::onUpdateOnPenUpActionTriggered() void CurveWidget::focusInEvent(QFocusEvent* e) { - QGLWidget::focusInEvent(e); + QOpenGLWidget::focusInEvent(e); } void diff --git a/Gui/CurveWidget.h b/Gui/CurveWidget.h index 06d8c612f6..a45d13c299 100644 --- a/Gui/CurveWidget.h +++ b/Gui/CurveWidget.h @@ -39,7 +39,6 @@ CLANG_DIAG_OFF(deprecated) CLANG_DIAG_OFF(uninitialized) -#include #include #include #include @@ -47,6 +46,12 @@ CLANG_DIAG_OFF(uninitialized) CLANG_DIAG_ON(deprecated) CLANG_DIAG_ON(uninitialized) +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) +#include +#else +#include "Gui/QGLWidgetCompat.h" +#endif + #include "Global/GlobalDefines.h" #include "Engine/OverlaySupport.h" @@ -60,7 +65,7 @@ NATRON_NAMESPACE_ENTER class CurveWidgetPrivate; class CurveWidget - : public QGLWidget, public OverlaySupport + : public QOpenGLWidget, public OverlaySupport { friend class CurveGui; friend class CurveWidgetPrivate; @@ -76,7 +81,7 @@ GCC_DIAG_SUGGEST_OVERRIDE_ON CurveSelection* selection, TimeLinePtr timeline = TimeLinePtr(), QWidget* parent = NULL, - const QGLWidget* shareWidget = NULL); + const QOpenGLWidget* shareWidget = NULL); virtual ~CurveWidget() OVERRIDE; diff --git a/Gui/CurveWidgetPrivate.cpp b/Gui/CurveWidgetPrivate.cpp index c95c902f41..800d2c86e3 100644 --- a/Gui/CurveWidgetPrivate.cpp +++ b/Gui/CurveWidgetPrivate.cpp @@ -51,6 +51,10 @@ #include "Gui/Menu.h" #include "Gui/ticks.h" +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) +#include +#endif + #define CLICK_DISTANCE_FROM_CURVE_ACCEPTANCE 5 //maximum distance from a curve that accepts a mouse click // (in widget pixels) #define CURSOR_WIDTH 15 @@ -289,7 +293,7 @@ CurveWidgetPrivate::drawSelectionRectangle(double screenPixelRatio) { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == _widget->context() ); + assert( QOpenGLContext::currentContext() == _widget->context() ); { GLProtectAttrib a(GL_HINT_BIT | GL_ENABLE_BIT | GL_LINE_BIT | GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT); @@ -363,7 +367,7 @@ CurveWidgetPrivate::drawTimelineMarkers(double screenPixelRatio) { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == _widget->context() ); + assert( QOpenGLContext::currentContext() == _widget->context() ); glCheckError(); refreshTimelinePositions(); @@ -426,7 +430,7 @@ CurveWidgetPrivate::drawCurves(double screenPixelRatio) { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == _widget->context() ); + assert( QOpenGLContext::currentContext() == _widget->context() ); //now draw each curve std::vector visibleCurves; @@ -444,7 +448,7 @@ CurveWidgetPrivate::drawScale(double screenPixelRatio) glCheckError(); // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == _widget->context() ); + assert( QOpenGLContext::currentContext() == _widget->context() ); QPointF btmLeft = zoomCtx.toZoomCoordinates(0, _widget->height() - 1); QPointF topRight = zoomCtx.toZoomCoordinates(_widget->width() - 1, 0); @@ -568,7 +572,7 @@ CurveWidgetPrivate::drawSelectedKeyFramesBbox(double screenPixelRatio) { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == _widget->context() ); + assert( QOpenGLContext::currentContext() == _widget->context() ); { GLProtectAttrib a(GL_HINT_BIT | GL_ENABLE_BIT | GL_LINE_BIT | GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT); diff --git a/Gui/CustomParamInteract.cpp b/Gui/CustomParamInteract.cpp index 1c0abb234e..085e17d0dd 100644 --- a/Gui/CustomParamInteract.cpp +++ b/Gui/CustomParamInteract.cpp @@ -47,6 +47,10 @@ #include "Engine/AppInstance.h" #include "Engine/TimeLine.h" +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) +#include +#endif + NATRON_NAMESPACE_ENTER @@ -85,7 +89,7 @@ CustomParamInteract::CustomParamInteract(const KnobGuiPtr& knob, void* ofxParamHandle, const OfxParamOverlayInteractPtr & entryPoint, QWidget* parent) - : QGLWidget(parent) + : QOpenGLWidget(parent) , _imp( new CustomParamInteractPrivate(knob, ofxParamHandle, entryPoint) ) { double minW, minH; @@ -103,7 +107,7 @@ CustomParamInteract::paintGL() { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == context() ); + assert( QOpenGLContext::currentContext() == context() ); if ( !appPTR->isOpenGLLoaded() ) { return; @@ -149,7 +153,7 @@ CustomParamInteract::resizeGL(int w, { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == context() ); + assert( QOpenGLContext::currentContext() == context() ); if ( !appPTR->isOpenGLLoaded() ) { return; @@ -171,7 +175,11 @@ CustomParamInteract::sizeHint() const void CustomParamInteract::swapOpenGLBuffers() { +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) + update(); +#else swapBuffers(); +#endif } void @@ -201,7 +209,7 @@ double CustomParamInteract::getScreenPixelRatio() const { #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - return windowHandle()->devicePixelRatio(); + return devicePixelRatio(); #else KnobGuiPtr k = _imp->knob.lock(); return (k && k->getGui()) ? k->getGui()->devicePixelRatio() : 1.; diff --git a/Gui/CustomParamInteract.h b/Gui/CustomParamInteract.h index fc7e62ce21..27220aadbb 100644 --- a/Gui/CustomParamInteract.h +++ b/Gui/CustomParamInteract.h @@ -36,11 +36,11 @@ #include "Global/GLIncludes.h" //! -CLANG_DIAG_ON(deprecated) -CLANG_DIAG_ON(uninitialized) +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) +#include +#else +#include "Gui/QGLWidgetCompat.h" +#endif #include "Engine/OverlaySupport.h" @@ -50,7 +50,7 @@ NATRON_NAMESPACE_ENTER struct CustomParamInteractPrivate; class CustomParamInteract - : public QGLWidget, public OverlaySupport + : public QOpenGLWidget, public OverlaySupport { public: CustomParamInteract(const KnobGuiPtr& knob, diff --git a/Gui/DopeSheetView.cpp b/Gui/DopeSheetView.cpp index a3dd9a4da8..3f8a884c81 100644 --- a/Gui/DopeSheetView.cpp +++ b/Gui/DopeSheetView.cpp @@ -76,6 +76,10 @@ #include "Gui/ZoomContext.h" #include "Gui/TabWidget.h" +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) +#include +#endif + #define NATRON_DOPESHEET_MIN_RANGE_FIT 10 NATRON_NAMESPACE_ENTER @@ -110,14 +114,14 @@ running_in_main_thread() } void -running_in_main_context(const QGLWidget *glWidget) +running_in_main_context(const QOpenGLWidget *glWidget) { - assert( glWidget->context() == QGLContext::currentContext() ); + assert( glWidget->context() == QOpenGLContext::currentContext() ); Q_UNUSED(glWidget); } void -running_in_main_thread_and_context(const QGLWidget *glWidget) +running_in_main_thread_and_context(const QOpenGLWidget *glWidget) { running_in_main_thread(); running_in_main_context(glWidget); @@ -809,7 +813,10 @@ DopeSheetViewPrivate::generateKeyframeTextures() if (std::max( kfTexturesImages[i].width(), kfTexturesImages[i].height() ) != KF_PIXMAP_SIZE) { kfTexturesImages[i] = kfTexturesImages[i].scaled(KF_PIXMAP_SIZE, KF_PIXMAP_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation); } - kfTexturesImages[i] = QGLWidget::convertToGLFormat(kfTexturesImages[i]); + +#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0) + kfTexturesImages[i] = QOpenGLWidget::convertToGLFormat(kfTexturesImages[i]); +#endif glBindTexture(GL_TEXTURE_2D, kfTexturesIDs[i]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); @@ -2562,7 +2569,7 @@ DopeSheetView::DopeSheetView(DopeSheet *model, Gui *gui, const TimeLinePtr &timeline, QWidget *parent) - : QGLWidget(parent) + : QOpenGLWidget(parent) , _imp( new DopeSheetViewPrivate(this) ) { _imp->model = model; @@ -2683,7 +2690,12 @@ DopeSheetView::swapOpenGLBuffers() { running_in_main_thread(); + +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) + update(); +#else swapBuffers(); +#endif } /** @@ -2734,7 +2746,7 @@ double DopeSheetView::getScreenPixelRatio() const { #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - return windowHandle()->devicePixelRatio(); + return devicePixelRatio(); #else return _imp->gui ? _imp->gui->devicePixelRatio() : 1.; #endif @@ -3707,7 +3719,7 @@ DopeSheetView::wheelEvent(QWheelEvent *e) void DopeSheetView::focusInEvent(QFocusEvent *e) { - QGLWidget::focusInEvent(e); + QOpenGLWidget::focusInEvent(e); } NATRON_NAMESPACE_EXIT diff --git a/Gui/DopeSheetView.h b/Gui/DopeSheetView.h index c636441d1e..20d65fc97f 100644 --- a/Gui/DopeSheetView.h +++ b/Gui/DopeSheetView.h @@ -36,19 +36,14 @@ #include "Global/GLIncludes.h" //! -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) -#include +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) +#include #else -#include +#include "Gui/QGLWidgetCompat.h" #endif -#include -CLANG_DIAG_ON(deprecated) -CLANG_DIAG_ON(uninitialized) - #include "Engine/OverlaySupport.h" #include "Engine/ViewIdx.h" @@ -81,7 +76,7 @@ class DopeSheetViewPrivate; * /!\ This class should depends less of the hierarchy view. */ class DopeSheetView - : public QGLWidget, public OverlaySupport + : public QOpenGLWidget, public OverlaySupport { GCC_DIAG_SUGGEST_OVERRIDE_OFF Q_OBJECT diff --git a/Gui/GuiFwd.h b/Gui/GuiFwd.h index a2e224b95e..511c16f9aa 100644 --- a/Gui/GuiFwd.h +++ b/Gui/GuiFwd.h @@ -49,7 +49,7 @@ class QFont; class QFontComboBox; class QFontMetrics; class QFrame; -class QGLShaderProgram; +class QOpenGLShaderProgram; class QGraphicsLineItem; class QGraphicsPolygonItem; class QGraphicsScene; diff --git a/Gui/Histogram.cpp b/Gui/Histogram.cpp index 585a185ad9..c5782fde85 100644 --- a/Gui/Histogram.cpp +++ b/Gui/Histogram.cpp @@ -33,7 +33,6 @@ #include #include #include -#include GCC_DIAG_UNUSED_PRIVATE_FIELD_OFF // /opt/local/include/QtGui/qmime.h:119:10: warning: private field 'type' is not used [-Wunused-private-field] #include @@ -45,6 +44,9 @@ GCC_DIAG_UNUSED_PRIVATE_FIELD_ON #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) #include +#include +#else +#include "Gui/QGLExtrasCompat.h" #endif #include "Engine/HistogramCPU.h" @@ -70,6 +72,10 @@ GCC_DIAG_UNUSED_PRIVATE_FIELD_ON #include "Gui/ZoomContext.h" #include "Gui/ticks.h" +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) +#include +#endif + NATRON_NAMESPACE_ENTER @@ -212,18 +218,18 @@ struct HistogramPrivate /*The shader that computes the histogram: Takes in input the image, and writes to the 256x1 texture*/ - QGLShaderProgramPtr histogramComputingShader; + QOpenGLShaderProgramPtr histogramComputingShader; /*The shader that computes the maximum of the histogram. Takes in input the reduction I and writes to the reduction I+1 the local maximas of the reduction I. Each pixel of the texture I+1 holds the maximum of 4 pixels in the texture I.*/ - QGLShaderProgramPtr histogramMaximumShader; + QOpenGLShaderProgramPtr histogramMaximumShader; /*The shader that renders the histogram. Takes in input the image and the histogram texture and produces the 256x256 image of the histogram.*/ - QGLShaderProgramPtr histogramRenderingShader; + QOpenGLShaderProgramPtr histogramRenderingShader; /*vbo ID, This vbo holds the texture coordinates to fetch to compute the histogram. It changes when the @@ -283,8 +289,12 @@ struct HistogramPrivate }; Histogram::Histogram(Gui* gui, - const QGLWidget* shareWidget) - : QGLWidget(gui, shareWidget) + const QOpenGLWidget* shareWidget) +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) + : QOpenGLWidget(gui) +#else + : QOpenGLWidget(gui, shareWidget) +#endif , PanelWidget(this, gui) , _imp( new HistogramPrivate(this) ) { @@ -685,34 +695,34 @@ Histogram::initializeGL() return; } - assert( QGLContext::currentContext() == context() ); + assert( QOpenGLContext::currentContext() == context() ); #ifdef NATRON_HISTOGRAM_USING_OPENGL - _imp->histogramComputingShader.reset( new QGLShaderProgram( context() ) ); - if ( !_imp->histogramComputingShader->addShaderFromSourceCode(QGLShader::Vertex, histogramComputationVertex_vert) ) { + _imp->histogramComputingShader.reset( new QOpenGLShaderProgram( context() ) ); + if ( !_imp->histogramComputingShader->addShaderFromSourceCode(QOpenGLShader::Vertex, histogramComputationVertex_vert) ) { qDebug() << _imp->histogramComputingShader->log(); } - if ( !_imp->histogramComputingShader->addShaderFromSourceCode(QGLShader::Fragment, histogramComputation_frag) ) { + if ( !_imp->histogramComputingShader->addShaderFromSourceCode(QOpenGLShader::Fragment, histogramComputation_frag) ) { qDebug() << _imp->histogramComputingShader->log(); } if ( !_imp->histogramComputingShader->link() ) { qDebug() << _imp->histogramComputingShader->log(); } - _imp->histogramMaximumShader.reset( new QGLShaderProgram( context() ) ); - if ( !_imp->histogramMaximumShader->addShaderFromSourceCode(QGLShader::Fragment, histogramMaximum_frag) ) { + _imp->histogramMaximumShader.reset( new QOpenGLShaderProgram( context() ) ); + if ( !_imp->histogramMaximumShader->addShaderFromSourceCode(QOpenGLShader::Fragment, histogramMaximum_frag) ) { qDebug() << _imp->histogramMaximumShader->log(); } if ( !_imp->histogramMaximumShader->link() ) { qDebug() << _imp->histogramMaximumShader->log(); } - _imp->histogramRenderingShader.reset( new QGLShaderProgram( context() ) ); - if ( !_imp->histogramRenderingShader->addShaderFromSourceCode(QGLShader::Vertex, histogramRenderingVertex_vert) ) { + _imp->histogramRenderingShader.reset( new QOpenGLShaderProgram( context() ) ); + if ( !_imp->histogramRenderingShader->addShaderFromSourceCode(QOpenGLShader::Vertex, histogramRenderingVertex_vert) ) { qDebug() << _imp->histogramRenderingShader->log(); } - if ( !_imp->histogramRenderingShader->addShaderFromSourceCode(QGLShader::Fragment, histogramRendering_frag) ) { + if ( !_imp->histogramRenderingShader->addShaderFromSourceCode(QOpenGLShader::Fragment, histogramRendering_frag) ) { qDebug() << _imp->histogramRenderingShader->log(); } if ( !_imp->histogramRenderingShader->link() ) { @@ -822,7 +832,7 @@ HistogramPrivate::resizeComputingVBO(int w, { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == context() ); + assert( QOpenGLContext::currentContext() == context() ); glBindBuffer(GL_ARRAY_BUFFER, vboID); int vertexCount = w * h; @@ -942,7 +952,7 @@ HistogramPrivate::activateHistogramRenderingShader(Histogram::DisplayModeEnum ch { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == context() ); + assert( QOpenGLContext::currentContext() == context() ); histogramRenderingShader->bind(); glActiveTexture(GL_TEXTURE0); @@ -998,7 +1008,7 @@ HistogramPrivate::computeHistogram(Histogram::DisplayModeEnum channel) { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == context() ); + assert( QOpenGLContext::currentContext() == context() ); GLenum attachment = colorAttachmentFromDisplayMode(channel); @@ -1092,7 +1102,7 @@ HistogramPrivate::renderHistogram(Histogram::DisplayModeEnum channel) { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == context() ); + assert( QOpenGLContext::currentContext() == context() ); GLenum attachment = colorAttachmentFromDisplayMode(channel); @@ -1141,7 +1151,7 @@ Histogram::paintGL() { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == context() ); + assert( QOpenGLContext::currentContext() == context() ); if ( !appPTR->isOpenGLLoaded() ) { return; @@ -1226,7 +1236,7 @@ Histogram::resizeGL(int width, { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == context() ); + assert( QOpenGLContext::currentContext() == context() ); if ( !appPTR->isOpenGLLoaded() ) { return; @@ -1333,7 +1343,7 @@ Histogram::mouseMoveEvent(QMouseEvent* e) update(); break; } - QGLWidget::mouseMoveEvent(e); + QOpenGLWidget::mouseMoveEvent(e); } // Histogram::mouseMoveEvent void @@ -1482,7 +1492,7 @@ Histogram::keyPressEvent(QKeyEvent* e) e->accept(); } else { handleUnCaughtKeyPressEvent(e); - QGLWidget::keyPressEvent(e); + QOpenGLWidget::keyPressEvent(e); } } @@ -1490,14 +1500,14 @@ void Histogram::keyReleaseEvent(QKeyEvent* e) { handleUnCaughtKeyUpEvent(e); - QGLWidget::keyReleaseEvent(e); + QOpenGLWidget::keyReleaseEvent(e); } void Histogram::enterEvent(QEvent* e) { enterEventBase(); - QGLWidget::enterEvent(e); + QOpenGLWidget::enterEvent(e); } void @@ -1507,7 +1517,7 @@ Histogram::leaveEvent(QEvent* e) assert( qApp && qApp->thread() == QThread::currentThread() ); leaveEventBase(); _imp->drawCoordinates = false; - QGLWidget::leaveEvent(e); + QOpenGLWidget::leaveEvent(e); } void @@ -1516,7 +1526,7 @@ Histogram::showEvent(QShowEvent* e) // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - QGLWidget::showEvent(e); + QOpenGLWidget::showEvent(e); if ( (width() != 0) && (height() != 0) ) { computeHistogramAndRefresh(true); } @@ -1579,7 +1589,7 @@ double Histogram::getScreenPixelRatio() const { #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - return windowHandle()->devicePixelRatio(); + return devicePixelRatio(); #else return getGui() ? getGui()->devicePixelRatio() : 1.; #endif @@ -1590,7 +1600,7 @@ HistogramPrivate::drawScale() { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == widget->context() ); + assert( QOpenGLContext::currentContext() == widget->context() ); glCheckError(); @@ -1692,7 +1702,7 @@ HistogramPrivate::drawWarnings() { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == widget->context() ); + assert( QOpenGLContext::currentContext() == widget->context() ); if (mipMapLevel > 0) { QFontMetrics fm(*_textFont); QString str( tr("Image downscaled") ); @@ -1750,7 +1760,7 @@ HistogramPrivate::drawViewerPicker() // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == widget->context() ); + assert( QOpenGLContext::currentContext() == widget->context() ); double wHeight = widget->height(); QPointF topLeft = zoomCtx.toZoomCoordinates(0, 0); @@ -1830,7 +1840,7 @@ HistogramPrivate::drawPicker() { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == widget->context() ); + assert( QOpenGLContext::currentContext() == widget->context() ); glCheckError(); QFontMetrics fm(*_textFont, 0); @@ -1973,7 +1983,7 @@ HistogramPrivate::drawHistogramCPU() { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == widget->context() ); + assert( QOpenGLContext::currentContext() == widget->context() ); glCheckError(); { @@ -2069,7 +2079,7 @@ Histogram::renderText(double x, { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == context() ); + assert( QOpenGLContext::currentContext() == context() ); if ( text.isEmpty() ) { return; diff --git a/Gui/Histogram.h b/Gui/Histogram.h index 7f9c3439b6..57ae983780 100644 --- a/Gui/Histogram.h +++ b/Gui/Histogram.h @@ -35,13 +35,16 @@ #include "Global/GLIncludes.h" //! -#include -CLANG_DIAG_ON(deprecated) CLANG_DIAG_ON(uninitialized) +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) +#include +#else +#include "Gui/QGLWidgetCompat.h" +#endif + #include "Gui/PanelWidget.h" #include "Gui/GuiFwd.h" @@ -52,7 +55,7 @@ NATRON_NAMESPACE_ENTER **/ struct HistogramPrivate; class Histogram - : public QGLWidget + : public QOpenGLWidget , public PanelWidget { GCC_DIAG_SUGGEST_OVERRIDE_OFF @@ -72,7 +75,7 @@ GCC_DIAG_SUGGEST_OVERRIDE_ON }; Histogram(Gui* gui, - const QGLWidget* shareWidget = NULL); + const QOpenGLWidget* shareWidget = NULL); virtual ~Histogram(); diff --git a/Gui/HostOverlay.cpp b/Gui/HostOverlay.cpp index 4de860b89c..20f90c5145 100644 --- a/Gui/HostOverlay.cpp +++ b/Gui/HostOverlay.cpp @@ -49,9 +49,6 @@ #include "Global/KeySymbols.h" #include "Global/GLIncludes.h" //! -CLANG_DIAG_ON(deprecated) #include #include #include @@ -59,6 +56,12 @@ CLANG_DIAG_ON(deprecated) #include #include +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) +#include +#else +#include "Gui/QGLWidgetCompat.h" +#endif + #ifndef M_PI #define M_PI 3.14159265358979323846264338327950288419717 diff --git a/Gui/QGLExtrasCompat.h b/Gui/QGLExtrasCompat.h new file mode 100644 index 0000000000..a518129b38 --- /dev/null +++ b/Gui/QGLExtrasCompat.h @@ -0,0 +1,30 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * This file is part of Natron , + * (C) 2018-2022 The Natron developers + * (C) 2013-2018 INRIA and Alexandre Gauthier-Foichat + * + * Natron is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Natron is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Natron. If not, see + * ***** END LICENSE BLOCK ***** */ + +#ifndef NATRON_GUI_QGLEXTRASCOMPAT_H +#define NATRON_GUI_QGLEXTRASCOMPAT_H + +#include +#include + +typedef QGLShaderProgram QOpenGLShaderProgram; +typedef QSharedPointer QOpenGLShaderProgramPtr; +typedef QGLShader QOpenGLShader; + +#endif // NATRON_GUI_QGLEXTRASCOMPAT_H diff --git a/Gui/QGLWidgetCompat.h b/Gui/QGLWidgetCompat.h new file mode 100644 index 0000000000..0861759e59 --- /dev/null +++ b/Gui/QGLWidgetCompat.h @@ -0,0 +1,28 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * This file is part of Natron , + * (C) 2018-2022 The Natron developers + * (C) 2013-2018 INRIA and Alexandre Gauthier-Foichat + * + * Natron is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Natron is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Natron. If not, see + * ***** END LICENSE BLOCK ***** */ + +#ifndef NATRON_GUI_QGLWIDGETCOMPAT_H +#define NATRON_GUI_QGLWIDGETCOMPAT_H + +#include + +typedef QGLWidget QOpenGLWidget; +typedef QGLContext QOpenGLContext; + +#endif // NATRON_GUI_QGLWIDGETCOMPAT_H diff --git a/Gui/TextRenderer.cpp b/Gui/TextRenderer.cpp index 0caecb3d14..8560537937 100644 --- a/Gui/TextRenderer.cpp +++ b/Gui/TextRenderer.cpp @@ -39,9 +39,13 @@ CLANG_DIAG_ON(deprecated) CLANG_DIAG_ON(uninitialized) #include "Global/GLIncludes.h" //! -CLANG_DIAG_ON(deprecated) + +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) +#include +#include +#else +#include "Gui/QGLWidgetCompat.h" +#endif NATRON_NAMESPACE_ENTER @@ -148,7 +152,9 @@ TextRendererPrivate::newTransparentTexture() QImage image(TEXTURE_SIZE, TEXTURE_SIZE, QImage::Format_ARGB32); image.fill(Qt::transparent); - image = QGLWidget::convertToGLFormat(image); +#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0) + image = QOpenGLWidget::convertToGLFormat(image); +#endif glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, TEXTURE_SIZE, TEXTURE_SIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, image.bits() ); @@ -196,7 +202,9 @@ TextRendererPrivate::createCharacter(QChar c) // fill the texture with the QImage - image = QGLWidget::convertToGLFormat(image); +#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0) + image = QOpenGLWidget::convertToGLFormat(image); +#endif glCheckError(); GLuint savedTexture; @@ -278,7 +286,7 @@ TextRenderer::renderText(float x, TextRendererPrivatePtr p; FontRenderers::iterator it = _imp->renderers.find(font); if ( it != _imp->renderers.end() ) { - p = (*it).second; + p = it->second; } else { p = TextRendererPrivatePtr( new TextRendererPrivate(font) ); _imp->renderers[font] = p; @@ -336,6 +344,21 @@ TextRenderer::renderText(float x, assert( glIsTexture(texture) ); } glCheckError(); +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) + glBegin(GL_TRIANGLES); + glTexCoord2f(c->xTexCoords[0], c->yTexCoords[1]); + glVertex2f(0, 0); + glTexCoord2f(c->xTexCoords[1], c->yTexCoords[1]); + glVertex2f(c->w * scalex, 0); + glTexCoord2f(c->xTexCoords[1], c->yTexCoords[0]); + glVertex2f(c->w * scalex, c->h * scaley); + glTexCoord2f(c->xTexCoords[1], c->yTexCoords[0]); + glVertex2f(c->w * scalex, c->h * scaley); + glTexCoord2f(c->xTexCoords[0], c->yTexCoords[0]); + glVertex2f(0, c->h * scaley); + glTexCoord2f(c->xTexCoords[0], c->yTexCoords[1]); + glVertex2f(0, 0); +#else glBegin(GL_QUADS); glTexCoord2f(c->xTexCoords[0], c->yTexCoords[0]); glVertex2f(0, 0); @@ -345,6 +368,7 @@ TextRenderer::renderText(float x, glVertex2f(c->w * scalex, c->h * scaley); glTexCoord2f(c->xTexCoords[0], c->yTexCoords[1]); glVertex2f(0, c->h * scaley); +#endif glEnd(); glCheckErrorIgnoreOSXBug(); glTranslatef(c->w * scalex, 0, 0); diff --git a/Gui/TimeLineGui.cpp b/Gui/TimeLineGui.cpp index 85050b40d0..757fbeeb04 100644 --- a/Gui/TimeLineGui.cpp +++ b/Gui/TimeLineGui.cpp @@ -62,6 +62,10 @@ GCC_DIAG_UNUSED_PRIVATE_FIELD_ON #include "Gui/ViewerTab.h" #include "Gui/ticks.h" +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) +#include +#endif + NATRON_NAMESPACE_ENTER #define TICK_HEIGHT 7 @@ -235,7 +239,7 @@ TimeLineGui::TimeLineGui(ViewerInstance* viewer, TimeLinePtr timeline, Gui* gui, ViewerTab* viewerTab) - : QGLWidget(viewerTab) + : QOpenGLWidget(viewerTab) , _imp( new TimelineGuiPrivate(this, viewer, gui, viewerTab) ) { setTimeline(timeline); @@ -856,7 +860,7 @@ TimeLineGui::renderText(double x, const QFont & font, int flags) const { - assert( QGLContext::currentContext() == context() ); + assert( QOpenGLContext::currentContext() == context() ); glCheckError(); if ( text.isEmpty() ) { @@ -1017,7 +1021,7 @@ TimeLineGui::enterEvent(QEvent* e) { _imp->alphaCursor = true; update(); - QGLWidget::enterEvent(e); + QOpenGLWidget::enterEvent(e); } void @@ -1025,7 +1029,7 @@ TimeLineGui::leaveEvent(QEvent* e) { _imp->alphaCursor = false; update(); - QGLWidget::leaveEvent(e); + QOpenGLWidget::leaveEvent(e); } void @@ -1083,7 +1087,7 @@ TimeLineGui::mouseReleaseEvent(QMouseEvent* e) } _imp->state = eTimelineStateIdle; - QGLWidget::mouseReleaseEvent(e); + QOpenGLWidget::mouseReleaseEvent(e); } // TimeLineGui::mouseReleaseEvent void diff --git a/Gui/TimeLineGui.h b/Gui/TimeLineGui.h index f7b61a51bd..a65e5322f1 100644 --- a/Gui/TimeLineGui.h +++ b/Gui/TimeLineGui.h @@ -38,13 +38,18 @@ CLANG_DIAG_OFF(deprecated) CLANG_DIAG_OFF(uninitialized) #include "Global/GLIncludes.h" //! #include #include #include CLANG_DIAG_ON(deprecated) CLANG_DIAG_ON(uninitialized) +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) +#include +#else +#include "Gui/QGLWidgetCompat.h" +#endif + #include "Global/GlobalDefines.h" #include "Gui/GuiFwd.h" @@ -54,7 +59,7 @@ NATRON_NAMESPACE_ENTER struct TimelineGuiPrivate; class TimeLineGui - : public QGLWidget + : public QOpenGLWidget { GCC_DIAG_SUGGEST_OVERRIDE_OFF Q_OBJECT diff --git a/Gui/ViewerGL.cpp b/Gui/ViewerGL.cpp index 32283b4070..b828d4145d 100644 --- a/Gui/ViewerGL.cpp +++ b/Gui/ViewerGL.cpp @@ -37,6 +37,7 @@ #include #include #include // qApp +#include #include #else #include @@ -49,10 +50,15 @@ GCC_DIAG_UNUSED_PRIVATE_FIELD_OFF #include #include GCC_DIAG_UNUSED_PRIVATE_FIELD_ON -#include #include #include +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) +#include +#else +#include "Gui/QGLExtrasCompat.h" +#endif + #include "Engine/Lut.h" #include "Engine/Node.h" #include "Engine/NodeGuiI.h" @@ -84,6 +90,10 @@ GCC_DIAG_UNUSED_PRIVATE_FIELD_ON #include "Gui/TabWidget.h" #include "Gui/ViewerTab.h" +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) +#include +#endif + #define USER_ROI_BORDER_TICK_SIZE 15.f #define USER_ROI_CROSS_RADIUS 15.f @@ -114,8 +124,12 @@ NATRON_NAMESPACE_ENTER ViewerGL::ViewerGL(ViewerTab* parent, - const QGLWidget* shareWidget) - : QGLWidget(parent, shareWidget) + const QOpenGLWidget* shareWidget) +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) + : QOpenGLWidget(parent) +#else + : QOpenGLWidget(parent, shareWidget) +#endif , _imp( new Implementation(this, parent) ) { // always running in the main thread @@ -524,7 +538,7 @@ ViewerGL::clearColorBuffer(double r, { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == context() ); + assert( QOpenGLContext::currentContext() == context() ); glCheckError(); { GLProtectAttrib att(GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT); @@ -585,7 +599,7 @@ ViewerGL::drawOverlay(unsigned int mipMapLevel) { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == context() ); + assert( QOpenGLContext::currentContext() == context() ); glCheckError(); @@ -1175,7 +1189,7 @@ ViewerGL::drawPersistentMessage() { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == context() ); + assert( QOpenGLContext::currentContext() == context() ); assert(_imp->_textFont); int offset = 10; @@ -1238,7 +1252,7 @@ ViewerGL::getPboID(int index) { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == context() ); + assert( QOpenGLContext::currentContext() == context() ); if ( index >= (int)_imp->pboIds.size() ) { GLuint handle; @@ -1453,25 +1467,25 @@ ViewerGL::initShaderGLSL() { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == context() ); + assert( QOpenGLContext::currentContext() == context() ); if (!_imp->shaderLoaded) { - _imp->shaderBlack.reset( new QGLShaderProgram( context() ) ); - if ( !_imp->shaderBlack->addShaderFromSourceCode(QGLShader::Vertex, vertRGB) ) { + _imp->shaderBlack.reset( new QOpenGLShaderProgram( context() ) ); + if ( !_imp->shaderBlack->addShaderFromSourceCode(QOpenGLShader::Vertex, vertRGB) ) { qDebug() << qPrintable( _imp->shaderBlack->log() ); } - if ( !_imp->shaderBlack->addShaderFromSourceCode(QGLShader::Fragment, blackFrag) ) { + if ( !_imp->shaderBlack->addShaderFromSourceCode(QOpenGLShader::Fragment, blackFrag) ) { qDebug() << qPrintable( _imp->shaderBlack->log() ); } if ( !_imp->shaderBlack->link() ) { qDebug() << qPrintable( _imp->shaderBlack->log() ); } - _imp->shaderRGB.reset( new QGLShaderProgram( context() ) ); - if ( !_imp->shaderRGB->addShaderFromSourceCode(QGLShader::Vertex, vertRGB) ) { + _imp->shaderRGB.reset( new QOpenGLShaderProgram( context() ) ); + if ( !_imp->shaderRGB->addShaderFromSourceCode(QOpenGLShader::Vertex, vertRGB) ) { qDebug() << qPrintable( _imp->shaderRGB->log() ); } - if ( !_imp->shaderRGB->addShaderFromSourceCode(QGLShader::Fragment, fragRGB) ) { + if ( !_imp->shaderRGB->addShaderFromSourceCode(QOpenGLShader::Fragment, fragRGB) ) { qDebug() << qPrintable( _imp->shaderRGB->log() ); } @@ -1599,7 +1613,7 @@ ViewerGL::transferBufferFromRAMtoGPU(const unsigned char* ramBuffer, { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == context() ); + assert( QOpenGLContext::currentContext() == context() ); GLenum e = glGetError(); Q_UNUSED(e); @@ -2107,7 +2121,7 @@ void ViewerGL::mouseMoveEvent(QMouseEvent* e) { if ( !penMotionInternal(e->x(), e->y(), /*pressure=*/ 1., currentTimeForEvent(e), e) ) { - QGLWidget::mouseMoveEvent(e); + QOpenGLWidget::mouseMoveEvent(e); } } // mouseMoveEvent @@ -2135,17 +2149,17 @@ ViewerGL::tabletEvent(QTabletEvent* e) break; } _imp->pressureOnPress = pressure; - QGLWidget::tabletEvent(e); + QOpenGLWidget::tabletEvent(e); break; } case QEvent::TabletRelease: { _imp->pressureOnRelease = pressure; - QGLWidget::tabletEvent(e); + QOpenGLWidget::tabletEvent(e); break; } case QEvent::TabletMove: { if ( !penMotionInternal(e->x(), e->y(), pressure, currentTimeForEvent(e), e) ) { - QGLWidget::tabletEvent(e); + QOpenGLWidget::tabletEvent(e); } else { e->accept(); } @@ -2555,7 +2569,7 @@ ViewerGL::mouseDoubleClickEvent(QMouseEvent* e) if ( _imp->viewerTab->notifyOverlaysPenDoubleClick(RenderScale(scale), QMouseEventLocalPos(e), pos_opengl) ) { update(); } - QGLWidget::mouseDoubleClickEvent(e); + QOpenGLWidget::mouseDoubleClickEvent(e); } QPointF @@ -2768,7 +2782,7 @@ ViewerGL::wheelEvent(QWheelEvent* e) assert( qApp && qApp->thread() == QThread::currentThread() ); if (!_imp->viewerTab) { - return QGLWidget::wheelEvent(e); + return QOpenGLWidget::wheelEvent(e); } // delta=120 is a standard wheel mouse click, but mice may be more accurate @@ -2806,13 +2820,13 @@ ViewerGL::wheelEvent(QWheelEvent* e) if (e->orientation() != Qt::Vertical) { #endif // we only handle vertical motion for zooming - return QGLWidget::wheelEvent(e); + return QOpenGLWidget::wheelEvent(e); } Gui* gui = _imp->viewerTab->getGui(); if (!gui) { - return QGLWidget::wheelEvent(e); + return QOpenGLWidget::wheelEvent(e); } NodeGuiIPtr nodeGui_i = _imp->viewerTab->getInternalNode()->getNode()->getNodeGui(); @@ -3150,7 +3164,7 @@ ViewerGL::focusInEvent(QFocusEvent* e) if ( _imp->viewerTab->notifyOverlaysFocusGained( RenderScale(scale) ) ) { update(); } - QGLWidget::focusInEvent(e); + QOpenGLWidget::focusInEvent(e); } void @@ -3167,7 +3181,7 @@ ViewerGL::focusOutEvent(QFocusEvent* e) if ( _imp->viewerTab->notifyOverlaysFocusLost( RenderScale(scale) ) ) { update(); } - QGLWidget::focusOutEvent(e); + QOpenGLWidget::focusOutEvent(e); } void @@ -3177,7 +3191,7 @@ ViewerGL::enterEvent(QEvent* e) assert( qApp && qApp->thread() == QThread::currentThread() ); _imp->infoViewer[0]->showMouseInfo(); _imp->infoViewer[1]->showMouseInfo(); - QGLWidget::enterEvent(e); + QOpenGLWidget::enterEvent(e); } void @@ -3192,7 +3206,7 @@ ViewerGL::leaveEvent(QEvent* e) } _imp->infoViewer[0]->hideMouseInfo(); _imp->infoViewer[1]->hideMouseInfo(); - QGLWidget::leaveEvent(e); + QOpenGLWidget::leaveEvent(e); } void @@ -3200,7 +3214,7 @@ ViewerGL::resizeEvent(QResizeEvent* e) { // public to hack the protected field // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - QGLWidget::resizeEvent(e); + QOpenGLWidget::resizeEvent(e); } ImageBitDepthEnum @@ -3319,7 +3333,7 @@ ViewerGL::renderText(double x, { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == context() ); + assert( QOpenGLContext::currentContext() == context() ); if ( text.isEmpty() ) { return; @@ -3617,7 +3631,11 @@ ViewerGL::swapOpenGLBuffers() { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) + update(); +#else swapBuffers(); +#endif } /** @@ -3636,7 +3654,11 @@ ViewerGL::redrawNow() { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) + update(); +#else updateGL(); +#endif } /** @@ -3672,7 +3694,7 @@ double ViewerGL::getScreenPixelRatio() const { #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - return windowHandle()->devicePixelRatio(); + return devicePixelRatio(); #else return (_imp->viewerTab && _imp->viewerTab->getGui()) ? _imp->viewerTab->getGui()->devicePixelRatio() : 1.; #endif diff --git a/Gui/ViewerGL.h b/Gui/ViewerGL.h index 571c854700..0fc27560dd 100644 --- a/Gui/ViewerGL.h +++ b/Gui/ViewerGL.h @@ -37,11 +37,12 @@ #include "Global/GLIncludes.h" //! -CLANG_DIAG_OFF(deprecated) -CLANG_DIAG_OFF(uninitialized) -#include -CLANG_DIAG_ON(deprecated) -CLANG_DIAG_ON(uninitialized) + +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) +#include +#else +#include "Gui/QGLWidgetCompat.h" +#endif #include "Engine/OpenGLViewerI.h" #include "Engine/ViewIdx.h" @@ -58,7 +59,7 @@ NATRON_NAMESPACE_ENTER * OpenGL related code as well as user events. **/ class ViewerGL - : public QGLWidget, public OpenGLViewerI + : public QOpenGLWidget, public OpenGLViewerI { GCC_DIAG_SUGGEST_OVERRIDE_OFF Q_OBJECT @@ -72,7 +73,7 @@ GCC_DIAG_SUGGEST_OVERRIDE_ON can pass a pointer to the 1st viewer you created. It allows the viewers to share the same OpenGL context. */ explicit ViewerGL(ViewerTab* parent, - const QGLWidget* shareWidget = NULL); + const QOpenGLWidget* shareWidget = NULL); virtual ~ViewerGL() OVERRIDE; @@ -107,7 +108,7 @@ GCC_DIAG_SUGGEST_OVERRIDE_ON /** *@brief Hack to allow the resizeEvent to be publicly used elsewhere. - * It calls QGLWidget::resizeEvent(QResizeEvent*). + * It calls QOpenGLWidget::resizeEvent(QResizeEvent*). **/ virtual void resizeEvent(QResizeEvent* e) OVERRIDE FINAL; diff --git a/Gui/ViewerGLPrivate.cpp b/Gui/ViewerGLPrivate.cpp index 7ac783d6a7..ec9089bb62 100644 --- a/Gui/ViewerGLPrivate.cpp +++ b/Gui/ViewerGLPrivate.cpp @@ -33,7 +33,12 @@ #include "Global/GLIncludes.h" //! // qApp -#include + +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) +#include +#else +#include "Gui/QGLExtrasCompat.h" +#endif #include "Engine/Lut.h" // Color #include "Engine/Settings.h" @@ -44,6 +49,10 @@ #include "Gui/Menu.h" #include "Gui/ViewerTab.h" +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) +#include +#endif + #ifndef M_PI #define M_PI 3.14159265358979323846264338327950288 /* pi */ #endif @@ -228,7 +237,7 @@ ViewerGL::Implementation::drawRenderingVAO(unsigned int mipMapLevel, { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == _this->context() ); + assert( QOpenGLContext::currentContext() == _this->context() ); bool useShader = _this->getBitDepth() != eImageBitDepthByte; @@ -472,8 +481,8 @@ ViewerGL::Implementation::initAndCheckGlExtensions() { // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); - assert( QGLContext::currentContext() == _this->context() ); - assert( QGLShaderProgram::hasOpenGLShaderPrograms( _this->context() ) ); + assert( QOpenGLContext::currentContext() == _this->context() ); + assert( QOpenGLShaderProgram::hasOpenGLShaderPrograms( _this->context() ) ); return true; } diff --git a/Gui/ViewerGLPrivate.h b/Gui/ViewerGLPrivate.h index 928916a06b..d89cf0ccb9 100644 --- a/Gui/ViewerGLPrivate.h +++ b/Gui/ViewerGLPrivate.h @@ -159,8 +159,8 @@ struct ViewerGL::Implementation GLuint iboTriangleStripId; /*!< IBOs holding vertices indexes for triangle strip sets*/ TextureInfo displayTextures[2]; /*!< A pointer to the textures that would be used if A and B are displayed*/ std::vector partialUpdateTextures; /*!< Pointer to the partial rectangle textures overlayed onto the displayed texture when tracking*/ - boost::scoped_ptr shaderRGB; /*!< The shader program used to render RGB data*/ - boost::scoped_ptr shaderBlack; /*!< The shader program used when the viewer is disconnected.*/ + boost::scoped_ptr shaderRGB; /*!< The shader program used to render RGB data*/ + boost::scoped_ptr shaderBlack; /*!< The shader program used when the viewer is disconnected.*/ bool shaderLoaded; /*!< Flag to check whether the shaders have already been loaded.*/ InfoViewerWidget* infoViewer[2]; /*!< Pointer to the info bar below the viewer holding pixel/mouse/format related info*/ ViewerTab* const viewerTab; /*!< Pointer to the viewer tab GUI*/ From ee02d5b20818ab86b6805dde172dc21c8626b691 Mon Sep 17 00:00:00 2001 From: Martin Reboredo Date: Sun, 30 Jan 2022 20:08:03 -0300 Subject: [PATCH 2/4] Fix build failure in #764 --- Gui/Gui.pro | 9 +++++++-- Gui/GuiFwd.h | 5 ++++- Gui/ViewerGLPrivate.h | 4 ++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Gui/Gui.pro b/Gui/Gui.pro index bda80d9691..0d27bb0b80 100644 --- a/Gui/Gui.pro +++ b/Gui/Gui.pro @@ -22,8 +22,13 @@ TEMPLATE = lib CONFIG += staticlib CONFIG += moc rcc CONFIG += boost opengl qt cairo python shiboken pyside -QT += gui core opengl network -greaterThan(QT_MAJOR_VERSION, 4): QT += concurrent +QT += gui core network + +greaterThan(QT_MAJOR_VERSION, 4) { + QT += concurrent +} else { + QT += opengl +} GUI_WRAPPER_DIR = Qt$${QT_MAJOR_VERSION}/NatronGui ENGINE_WRAPPER_DIR = Qt$${QT_MAJOR_VERSION}/NatronEngine diff --git a/Gui/GuiFwd.h b/Gui/GuiFwd.h index 511c16f9aa..d9e127abad 100644 --- a/Gui/GuiFwd.h +++ b/Gui/GuiFwd.h @@ -49,7 +49,6 @@ class QFont; class QFontComboBox; class QFontMetrics; class QFrame; -class QOpenGLShaderProgram; class QGraphicsLineItem; class QGraphicsPolygonItem; class QGraphicsScene; @@ -95,6 +94,10 @@ class QWheelEvent; class QWidget; typedef boost::shared_ptr QUndoStackPtr; +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) +class QOpenGLShaderProgram; +#endif + // Natron Gui NATRON_NAMESPACE_ENTER class AboutWindow; diff --git a/Gui/ViewerGLPrivate.h b/Gui/ViewerGLPrivate.h index d89cf0ccb9..78eca6b118 100644 --- a/Gui/ViewerGLPrivate.h +++ b/Gui/ViewerGLPrivate.h @@ -42,6 +42,10 @@ CLANG_DIAG_ON(uninitialized) #include "Gui/ZoomContext.h" #include "Gui/GuiFwd.h" +#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0) +#include "Gui/QGLExtrasCompat.h" +#endif + #define WIPE_MIX_HANDLE_LENGTH 50. #define WIPE_ROTATE_HANDLE_LENGTH 100. From 7cbdc2d5f8b507f465294158c40efb1112fb415e Mon Sep 17 00:00:00 2001 From: Martin Reboredo Date: Tue, 1 Feb 2022 17:39:36 -0300 Subject: [PATCH 3/4] Document QGLCompat headers and ViewerGL update --- Gui/QGLExtrasCompat.h | 16 ++++++++++++++-- Gui/QGLWidgetCompat.h | 13 ++++++++++++- Gui/ViewerGL.cpp | 1 + 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Gui/QGLExtrasCompat.h b/Gui/QGLExtrasCompat.h index a518129b38..ba73d576ee 100644 --- a/Gui/QGLExtrasCompat.h +++ b/Gui/QGLExtrasCompat.h @@ -17,11 +17,23 @@ * along with Natron. If not, see * ***** END LICENSE BLOCK ***** */ +// This is a header that provides type declarations that map a subset of the newer QOpenGL +// classes used by Natron with their older QGL counterparts + #ifndef NATRON_GUI_QGLEXTRASCOMPAT_H #define NATRON_GUI_QGLEXTRASCOMPAT_H -#include -#include +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) +#error "This file must not be included while using Qt >= 5.4.0" +#endif + +#include "Global/Macros.h" + +// QGL was deprecated in macOS +CLANG_DIAG_OFF(deprecated) +#include +#include +CLANG_DIAG_ON(deprecated) typedef QGLShaderProgram QOpenGLShaderProgram; typedef QSharedPointer QOpenGLShaderProgramPtr; diff --git a/Gui/QGLWidgetCompat.h b/Gui/QGLWidgetCompat.h index 0861759e59..e3f7f108ea 100644 --- a/Gui/QGLWidgetCompat.h +++ b/Gui/QGLWidgetCompat.h @@ -17,10 +17,21 @@ * along with Natron. If not, see * ***** END LICENSE BLOCK ***** */ +// This is a header that provides type declarations that map a subset of the newer QOpenGL +// classes used by Natron with their older QGL counterparts + #ifndef NATRON_GUI_QGLWIDGETCOMPAT_H #define NATRON_GUI_QGLWIDGETCOMPAT_H -#include +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) +#error "This file must not be included while using Qt >= 5.4.0" +#endif + +#include "Global/Macros.h" + +CLANG_DIAG_OFF(deprecated) +#include +CLANG_DIAG_ON(deprecated) typedef QGLWidget QOpenGLWidget; typedef QGLContext QOpenGLContext; diff --git a/Gui/ViewerGL.cpp b/Gui/ViewerGL.cpp index b828d4145d..33db819367 100644 --- a/Gui/ViewerGL.cpp +++ b/Gui/ViewerGL.cpp @@ -3632,6 +3632,7 @@ ViewerGL::swapOpenGLBuffers() // always running in the main thread assert( qApp && qApp->thread() == QThread::currentThread() ); #if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) + // calls glSwapBuffers in the widget stack as described in https://doc.qt.io/qt-5/qopenglwidget.html#threading update(); #else swapBuffers(); From ccb937e87bc67bb8e4cc1450742ea3059719f652 Mon Sep 17 00:00:00 2001 From: Martin Reboredo Date: Sat, 5 Feb 2022 23:46:52 -0300 Subject: [PATCH 4/4] Fix build with KDE Qt5 git --- Gui/Gui.pro | 2 +- Gui/TextRenderer.cpp | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Gui/Gui.pro b/Gui/Gui.pro index 0d27bb0b80..b7cefc518e 100644 --- a/Gui/Gui.pro +++ b/Gui/Gui.pro @@ -25,7 +25,7 @@ CONFIG += boost opengl qt cairo python shiboken pyside QT += gui core network greaterThan(QT_MAJOR_VERSION, 4) { - QT += concurrent + QT += concurrent widgets } else { QT += opengl } diff --git a/Gui/TextRenderer.cpp b/Gui/TextRenderer.cpp index 8560537937..e4fe851c9a 100644 --- a/Gui/TextRenderer.cpp +++ b/Gui/TextRenderer.cpp @@ -345,19 +345,15 @@ TextRenderer::renderText(float x, } glCheckError(); #if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) - glBegin(GL_TRIANGLES); + glBegin(GL_QUADS); glTexCoord2f(c->xTexCoords[0], c->yTexCoords[1]); glVertex2f(0, 0); glTexCoord2f(c->xTexCoords[1], c->yTexCoords[1]); glVertex2f(c->w * scalex, 0); glTexCoord2f(c->xTexCoords[1], c->yTexCoords[0]); glVertex2f(c->w * scalex, c->h * scaley); - glTexCoord2f(c->xTexCoords[1], c->yTexCoords[0]); - glVertex2f(c->w * scalex, c->h * scaley); glTexCoord2f(c->xTexCoords[0], c->yTexCoords[0]); glVertex2f(0, c->h * scaley); - glTexCoord2f(c->xTexCoords[0], c->yTexCoords[1]); - glVertex2f(0, 0); #else glBegin(GL_QUADS); glTexCoord2f(c->xTexCoords[0], c->yTexCoords[0]);