diff options
author | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2016-05-04 17:45:12 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2016-05-06 11:27:24 +0000 |
commit | b1f30239bcb827035c269d722a6b43ec9d9a8bfd (patch) | |
tree | 1fcdc2def9f8673423db892033290263bf236620 /src | |
parent | 2bb63f9e52b4cb025061734c171252564d69c6a9 (diff) |
Fix up openglContext() in QQuickWindow
Return null in all non-OpenGL cases, making it safe to call in
OpenGL-enabled builds even when not running with the OpenGL backend.
Change-Id: I7d8f0e0d177b1447863cc951afdf8d6656a59f9c
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/quick/items/qquickwindow.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index 5d68646681..9355c310fb 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -78,6 +78,7 @@ # include <private/qopenglvertexarrayobject_p.h> # include <private/qsgdefaultrendercontext_p.h> #endif +#include <qsgrendererinterface.h> QT_BEGIN_NAMESPACE @@ -3163,7 +3164,8 @@ void QQuickWindow::setTransientParent_helper(QQuickWindow *window) /*! Returns the opengl context used for rendering. - If the scene graph is not ready, this function will return 0. + If the scene graph is not ready, or the scene graph is not using OpenGL, + this function will return null. \sa sceneGraphInitialized(), sceneGraphInvalidated() */ @@ -3172,17 +3174,15 @@ QOpenGLContext *QQuickWindow::openglContext() const { #ifndef QT_NO_OPENGL Q_D(const QQuickWindow); - if (d->context) { - auto openglRenderContext = static_cast<const QSGDefaultRenderContext *>(d->context); - return openglRenderContext->openglContext(); - } else { - return nullptr; + if (d->context && d->context->isValid()) { + QSGRendererInterface *rif = d->context->sceneGraphContext()->rendererInterface(d->context); + if (rif && rif->graphicsAPI() == QSGRendererInterface::OpenGL) { + auto openglRenderContext = static_cast<const QSGDefaultRenderContext *>(d->context); + return openglRenderContext->openglContext(); + } } - - //return d->context ? d->context->openglContext() : 0; -#else - return nullptr; #endif + return nullptr; } /*! |