From 3cce585f3c05ea4dffa324f10bd99dfbc2577cfe Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 29 Jul 2015 13:16:14 +0200 Subject: [PATCH] Avoid multisampled contexts in QQuickWidget Like with QOpenGLWidget, not requesting a multisampled context unnecessarily avoids crashing with Mesa/Intel/EGL (f.ex. in the qquickviewcomparison example when enabling multisampling). Task-number: QTBUG-47509 Change-Id: Ia22110332f639a238cfb3b2c36916f65c00a7bbc Reviewed-by: Andy Nichols --- src/quickwidgets/qquickwidget.cpp | 11 ++++++++++- src/quickwidgets/qquickwidget_p.h | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp index 26dd4e5b3..553dba37f 100644 --- a/src/quickwidgets/qquickwidget.cpp +++ b/src/quickwidgets/qquickwidget.cpp @@ -143,6 +143,7 @@ QQuickWidgetPrivate::QQuickWidgetPrivate() , eventPending(false) , updatePending(false) , fakeHidden(false) + , requestedSamples(0) { } @@ -772,7 +773,7 @@ void QQuickWidget::createFramebufferObject() context->makeCurrent(d->offscreenSurface); - int samples = d->offscreenWindow->requestedFormat().samples(); + int samples = d->requestedSamples; if (!QOpenGLExtensions(context).hasOpenGLExtension(QOpenGLExtensions::FramebufferMultisample)) samples = 0; @@ -1248,6 +1249,14 @@ void QQuickWidget::setFormat(const QSurfaceFormat &format) newFormat.setDepthBufferSize(qMax(newFormat.depthBufferSize(), currentFormat.depthBufferSize())); newFormat.setStencilBufferSize(qMax(newFormat.stencilBufferSize(), currentFormat.stencilBufferSize())); newFormat.setAlphaBufferSize(qMax(newFormat.alphaBufferSize(), currentFormat.alphaBufferSize())); + + // Do not include the sample count. Requesting a multisampled context is not necessary + // since we render into an FBO, never to an actual surface. What's more, attempting to + // create a pbuffer with a multisampled config crashes certain implementations. Just + // avoid the entire hassle, the result is the same. + d->requestedSamples = newFormat.samples(); + newFormat.setSamples(0); + d->offscreenWindow->setFormat(newFormat); } diff --git a/src/quickwidgets/qquickwidget_p.h b/src/quickwidgets/qquickwidget_p.h index dd0da96c3..9249fa138 100644 --- a/src/quickwidgets/qquickwidget_p.h +++ b/src/quickwidgets/qquickwidget_p.h @@ -115,6 +115,8 @@ public: bool eventPending; bool updatePending; bool fakeHidden; + + int requestedSamples; }; QT_END_NAMESPACE -- 2.34.1