From 07cd34e7380a425947f7a2912666595e797116d7 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 1 Jun 2015 17:04:07 +0200 Subject: Redirect the default FBO correctly with QQuickWidget Similarly to QOpenGLWidget, functions like QOpenGLFramebufferObject::bindDefault() should bind the QQuickWidget's FBO, not 0, while rendering the scene graph. This becomes particularly important on platforms with surfaceless context support. Here offscreen surfaces are not backed by any surface. Therefore any OpenGL operation accessing the current draw framebuffer with FBO 0 bound may potentially crash, as there is no draw framebuffer at all. The distance field glyph cache exhibits this issue when running with EGL on Mesa: glViewport crashes when we render via QQuickWidget and the current framebuffer is reset to 0. The problem goes away when the code changed is to use bindDefault() - as it should have anyhow - and QQuickWidget is enhanced to communicate the "default" framebuffer to QOpenGLContext, just like QOpenGLWidget does. Task-number: QTBUG-46415 Task-number: QTBUG-43269 Change-Id: I35fe375a0870dadecc4a074dfdec122c6a4c92ab Reviewed-by: Eskil Abrahamsen Blomfeldt Reviewed-by: Paul Olav Tvete --- src/quickwidgets/qquickwidget.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/quickwidgets/qquickwidget.cpp') diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp index 608c5f93f5..a848774ae9 100644 --- a/src/quickwidgets/qquickwidget.cpp +++ b/src/quickwidgets/qquickwidget.cpp @@ -202,7 +202,12 @@ void QQuickWidgetPrivate::itemGeometryChanged(QQuickItem *resizeItem, const QRec void QQuickWidgetPrivate::render(bool needsSync) { - context->makeCurrent(offscreenSurface); + if (!context->makeCurrent(offscreenSurface)) { + qWarning("QQuickWidget: Cannot render due to failing makeCurrent()"); + return; + } + + QOpenGLContextPrivate::get(context)->defaultFboRedirect = fbo->handle(); if (needsSync) { renderControl->polishItems(); @@ -217,6 +222,8 @@ void QQuickWidgetPrivate::render(bool needsSync) } static_cast(context->functions())->flushShared(); + + QOpenGLContextPrivate::get(context)->defaultFboRedirect = 0; } void QQuickWidgetPrivate::renderSceneGraph() -- cgit v1.2.3