From 4a552d95f69b1319caacc5d36bcf428b06f32e1c Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 29 Jul 2015 13:10:06 +0200 Subject: [PATCH] Avoid multisampled contexts in QOpenGLWidget as it is not needed at all. Multisampled FBOs do not need multisampled configs. What's more, this fixes crashing Mesa with Intel and EGL, where creating a pbuffer for a config with multisampling simply crashes. (and due to other issues we disable surfaceless QOffscreenSurface for Intel so the pbuffer cannot be avoided) Task-number: QTBUG-47509 Change-Id: I3ae3fae8513a6dc64ca4ab11c61d4777c6c09cec Reviewed-by: Andy Nichols --- src/widgets/kernel/qopenglwidget.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/widgets/kernel/qopenglwidget.cpp b/src/widgets/kernel/qopenglwidget.cpp index ea7a761bf1..b98e8a6a66 100644 --- a/src/widgets/kernel/qopenglwidget.cpp +++ b/src/widgets/kernel/qopenglwidget.cpp @@ -553,7 +553,8 @@ public: hasBeenComposed(false), flushPending(false), paintDevice(0), - updateBehavior(QOpenGLWidget::NoPartialUpdate) + updateBehavior(QOpenGLWidget::NoPartialUpdate), + requestedSamples(0) { requestedFormat = QSurfaceFormat::defaultFormat(); } @@ -595,6 +596,7 @@ public: QOpenGLPaintDevice *paintDevice; QSurfaceFormat requestedFormat; QOpenGLWidget::UpdateBehavior updateBehavior; + int requestedSamples; }; void QOpenGLWidgetPaintDevicePrivate::beginPaint() @@ -686,7 +688,7 @@ void QOpenGLWidgetPrivate::recreateFbo() delete resolvedFbo; resolvedFbo = 0; - int samples = context->format().samples(); + int samples = requestedSamples; QOpenGLExtensions *extfuncs = static_cast(context->functions()); if (!extfuncs->hasOpenGLExtension(QOpenGLExtensions::FramebufferMultisample)) samples = 0; @@ -742,6 +744,13 @@ void QOpenGLWidgetPrivate::initialize() return; } + // 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. + requestedSamples = requestedFormat.samples(); + requestedFormat.setSamples(0); + QScopedPointer ctx(new QOpenGLContext); ctx->setShareContext(shareContext); ctx->setFormat(requestedFormat);