From add7c0aadd5b4195f39a7a547f2f5b2fa36636f0 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Fri, 12 Sep 2014 13:30:20 +0200 Subject: [PATCH] Propagate swap interval from QOpenGLWidget to the tlw Otherwise it is impossible to set a swap interval different than the one set by QSurfaceFormat::setDefaultFormat(). Both windows and xcb will pick up the updated interval from the window on the next frame. Change-Id: I55a59f83a62d3adcea687adf28639646b576ed58 Reviewed-by: Paul Olav Tvete --- src/widgets/kernel/qopenglwidget.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/widgets/kernel/qopenglwidget.cpp b/src/widgets/kernel/qopenglwidget.cpp index 22ea852d99c..2abddd8941f 100644 --- a/src/widgets/kernel/qopenglwidget.cpp +++ b/src/widgets/kernel/qopenglwidget.cpp @@ -587,7 +587,8 @@ void QOpenGLWidgetPrivate::initialize() // Get our toplevel's context with which we will share in order to make the // texture usable by the underlying window's backingstore. - QOpenGLContext *shareContext = get(q->window())->shareContext(); + QWidget *tlw = q->window(); + QOpenGLContext *shareContext = get(tlw)->shareContext(); if (!shareContext) { qWarning("QOpenGLWidget: Cannot be used without a context shared with the toplevel."); return; @@ -601,6 +602,19 @@ void QOpenGLWidgetPrivate::initialize() return; } + // Propagate settings that make sense only for the tlw. + QSurfaceFormat tlwFormat = tlw->windowHandle()->format(); + if (requestedFormat.swapInterval() != tlwFormat.swapInterval()) { + // Most platforms will pick up the changed swap interval on the next + // makeCurrent or swapBuffers. + tlwFormat.setSwapInterval(requestedFormat.swapInterval()); + tlw->windowHandle()->setFormat(tlwFormat); + } + if (requestedFormat.swapBehavior() != tlwFormat.swapBehavior()) { + tlwFormat.setSwapBehavior(requestedFormat.swapBehavior()); + tlw->windowHandle()->setFormat(tlwFormat); + } + // The top-level window's surface is not good enough since it causes way too // much trouble with regards to the QSurfaceFormat for example. So just like // in QQuickWidget, use a dedicated QOffscreenSurface.