Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Substitute QGL classes with QOpenGL #764

Merged
merged 4 commits into from Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion Gui/CurveGui.cpp
Expand Up @@ -45,6 +45,10 @@
#include "Gui/CurveWidgetPrivate.h"
#include "Gui/KnobGui.h"

#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
#include <QOpenGLContext>
#endif

NATRON_NAMESPACE_ENTER

CurveGui::CurveGui(CurveWidget *curveWidget,
Expand Down Expand Up @@ -299,7 +303,7 @@ CurveGui::drawCurve(int curveIndex,
return;
}

assert( QGLContext::currentContext() == _curveWidget->context() );
assert( QOpenGLContext::currentContext() == _curveWidget->context() );

std::vector<float> vertices, exprVertices;
double x1 = 0;
Expand Down
34 changes: 23 additions & 11 deletions Gui/CurveWidget.cpp
Expand Up @@ -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 <QOpenGLContext>
#endif

NATRON_NAMESPACE_ENTER

/*****************************CURVE WIDGET***********************************************/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1241,7 +1253,7 @@ CurveWidget::mouseMoveEvent(QMouseEvent* e)

if (_imp->_state == eEventStateNone) {
// nothing else to do
QGLWidget::mouseMoveEvent(e);
QOpenGLWidget::mouseMoveEvent(e);

return;
}
Expand Down Expand Up @@ -1364,7 +1376,7 @@ CurveWidget::mouseMoveEvent(QMouseEvent* e)
if (mustUpdate) {
update();
}
QGLWidget::mouseMoveEvent(e);
QOpenGLWidget::mouseMoveEvent(e);
} // mouseMoveEvent

void
Expand Down Expand Up @@ -1622,15 +1634,15 @@ CurveWidget::keyPressEvent(QKeyEvent* e)
if (ce) {
ce->handleUnCaughtKeyPressEvent(e);
}
QGLWidget::keyPressEvent(e);
QOpenGLWidget::keyPressEvent(e);
}
} // keyPressEvent

void
CurveWidget::enterEvent(QEvent* e)
{
setFocus();
QGLWidget::enterEvent(e);
QOpenGLWidget::enterEvent(e);
}

void
Expand Down Expand Up @@ -2128,7 +2140,7 @@ CurveWidget::onUpdateOnPenUpActionTriggered()
void
CurveWidget::focusInEvent(QFocusEvent* e)
{
QGLWidget::focusInEvent(e);
QOpenGLWidget::focusInEvent(e);
}

void
Expand Down
11 changes: 8 additions & 3 deletions Gui/CurveWidget.h
Expand Up @@ -39,14 +39,19 @@

CLANG_DIAG_OFF(deprecated)
CLANG_DIAG_OFF(uninitialized)
#include <QtOpenGL/QGLWidget>
#include <QtCore/QMetaType>
#include <QtCore/QSize>
#include <QDialog>
#include <QtCore/QByteArray>
CLANG_DIAG_ON(deprecated)
CLANG_DIAG_ON(uninitialized)

#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
#include <QOpenGLWidget>
#else
#include "Gui/QGLWidgetCompat.h"
#endif

#include "Global/GlobalDefines.h"

#include "Engine/OverlaySupport.h"
Expand All @@ -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;
Expand All @@ -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;

Expand Down
14 changes: 9 additions & 5 deletions Gui/CurveWidgetPrivate.cpp
Expand Up @@ -51,6 +51,10 @@
#include "Gui/Menu.h"
#include "Gui/ticks.h"

#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
#include <QOpenGLContext>
#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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<CurveGuiPtr> visibleCurves;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 12 additions & 4 deletions Gui/CustomParamInteract.cpp
Expand Up @@ -47,6 +47,10 @@
#include "Engine/AppInstance.h"
#include "Engine/TimeLine.h"

#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
#include <QOpenGLContext>
#endif


NATRON_NAMESPACE_ENTER

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -171,7 +175,11 @@ CustomParamInteract::sizeHint() const
void
CustomParamInteract::swapOpenGLBuffers()
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
update();
#else
swapBuffers();
#endif
}

void
Expand Down Expand Up @@ -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.;
Expand Down
12 changes: 6 additions & 6 deletions Gui/CustomParamInteract.h
Expand Up @@ -36,11 +36,11 @@
#include "Global/GLIncludes.h" //!<must be included before QGlWidget because of gl.h and glew.h
#include "Global/GlobalDefines.h"

CLANG_DIAG_OFF(deprecated)
CLANG_DIAG_OFF(uninitialized)
#include <QGLWidget>
CLANG_DIAG_ON(deprecated)
CLANG_DIAG_ON(uninitialized)
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
#include <QOpenGLWidget>
#else
#include "Gui/QGLWidgetCompat.h"
#endif

#include "Engine/OverlaySupport.h"

Expand All @@ -50,7 +50,7 @@ NATRON_NAMESPACE_ENTER

struct CustomParamInteractPrivate;
class CustomParamInteract
: public QGLWidget, public OverlaySupport
: public QOpenGLWidget, public OverlaySupport
{
public:
CustomParamInteract(const KnobGuiPtr& knob,
Expand Down
26 changes: 19 additions & 7 deletions Gui/DopeSheetView.cpp
Expand Up @@ -76,6 +76,10 @@
#include "Gui/ZoomContext.h"
#include "Gui/TabWidget.h"

#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
#include <QOpenGLContext>
#endif

#define NATRON_DOPESHEET_MIN_RANGE_FIT 10

NATRON_NAMESPACE_ENTER
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2683,7 +2690,12 @@ DopeSheetView::swapOpenGLBuffers()
{
running_in_main_thread();


#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
update();
#else
swapBuffers();
#endif
}

/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -3707,7 +3719,7 @@ DopeSheetView::wheelEvent(QWheelEvent *e)
void
DopeSheetView::focusInEvent(QFocusEvent *e)
{
QGLWidget::focusInEvent(e);
QOpenGLWidget::focusInEvent(e);
}

NATRON_NAMESPACE_EXIT
Expand Down