summaryrefslogtreecommitdiffstats
path: root/src/datavisualization/engine/qabstract3dgraph.cpp
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@theqtcompany.com>2015-12-29 12:27:48 +0200
committerMiikka Heikkinen <miikka.heikkinen@theqtcompany.com>2015-12-30 08:45:14 +0000
commit64f0d4fb353ae2e447483897839d4df8b5b32f54 (patch)
treefeb89a4253b05c20377b980773edc7619bbae0b9 /src/datavisualization/engine/qabstract3dgraph.cpp
parent104c12823b1cbccb2a25593b0af319c0a42abbb5 (diff)
Add a method for checking if context was successfully created
Now it is possible to check after graph construction if the graph is actually usable in environments where the OpenGL support might not be sufficient. Task-number: QTRD-3748 Change-Id: Ia68b4e51386859f6d0c7b09cb44e50a74730ca55 Reviewed-by: Titta Heikkala <titta.heikkala@theqtcompany.com>
Diffstat (limited to 'src/datavisualization/engine/qabstract3dgraph.cpp')
-rw-r--r--src/datavisualization/engine/qabstract3dgraph.cpp33
1 files changed, 28 insertions, 5 deletions
diff --git a/src/datavisualization/engine/qabstract3dgraph.cpp b/src/datavisualization/engine/qabstract3dgraph.cpp
index 2f3caccd..bc40fbf9 100644
--- a/src/datavisualization/engine/qabstract3dgraph.cpp
+++ b/src/datavisualization/engine/qabstract3dgraph.cpp
@@ -189,7 +189,11 @@ QAbstract3DGraph::QAbstract3DGraph(QAbstract3DGraphPrivate *d, const QSurfaceFor
d_ptr->m_context->setFormat(requestedFormat());
d_ptr->m_context->create();
- d_ptr->m_context->makeCurrent(this);
+ bool makeSuccess = d_ptr->m_context->makeCurrent(this);
+
+ // If we fail to get context, just abort
+ if (!makeSuccess || !QOpenGLContext::currentContext())
+ return;
initializeOpenGLFunctions();
@@ -208,6 +212,8 @@ QAbstract3DGraph::QAbstract3DGraph(QAbstract3DGraphPrivate *d, const QSurfaceFor
qFatal("GLSL version must be 1.20 or higher. Try installing latest display drivers.");
}
+ d_ptr->m_initialized = true;
+
d_ptr->renderLater();
#if defined(Q_OS_OSX)
@@ -872,6 +878,20 @@ qreal QAbstract3DGraph::margin() const
}
/*!
+ * \return \c{true} if the OpenGL context of the graph has been successfully initialized.
+ * Trying to use a graph when the context initialization has failed typically results in a crash.
+ * A common reason for a context initialization failure is lack of sufficient platform support
+ * for OpenGL.
+ */
+bool QAbstract3DGraph::hasContext() const
+{
+ if (d_ptr->m_initialized)
+ return true;
+ else
+ return false;
+}
+
+/*!
* \internal
*/
bool QAbstract3DGraph::event(QEvent *event)
@@ -898,9 +918,11 @@ void QAbstract3DGraph::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event);
- Q3DScene *scene = d_ptr->m_visualController->scene();
- scene->d_ptr->setWindowSize(QSize(width(), height()));
- scene->d_ptr->setViewport(QRect(0, 0, width(), height()));
+ if (d_ptr->m_visualController) {
+ Q3DScene *scene = d_ptr->m_visualController->scene();
+ scene->d_ptr->setWindowSize(QSize(width(), height()));
+ scene->d_ptr->setViewport(QRect(0, 0, width(), height()));
+ }
}
/*!
@@ -968,7 +990,8 @@ QAbstract3DGraphPrivate::QAbstract3DGraphPrivate(QAbstract3DGraph *q)
m_updatePending(false),
m_visualController(0),
m_devicePixelRatio(1.f),
- m_offscreenSurface(0)
+ m_offscreenSurface(0),
+ m_initialized(false)
{
}