summaryrefslogtreecommitdiffstats
path: root/src/datavisualization/engine/qabstract3dgraph.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/datavisualization/engine/qabstract3dgraph.cpp')
-rw-r--r--src/datavisualization/engine/qabstract3dgraph.cpp59
1 files changed, 45 insertions, 14 deletions
diff --git a/src/datavisualization/engine/qabstract3dgraph.cpp b/src/datavisualization/engine/qabstract3dgraph.cpp
index 2f3caccd..50ccef00 100644
--- a/src/datavisualization/engine/qabstract3dgraph.cpp
+++ b/src/datavisualization/engine/qabstract3dgraph.cpp
@@ -1,23 +1,31 @@
-/******************************************************************************
+/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
-** This file is part of the Qt Data Visualization module.
-**
-** $QT_BEGIN_LICENSE:COMM$
+** This file is part of the Qt Data Visualization module of the Qt Toolkit.
**
+** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
-******************************************************************************/
+****************************************************************************/
#include "qabstract3dgraph.h"
#include "qabstract3dgraph_p.h"
@@ -189,7 +197,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 +220,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 +886,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 +926,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 +998,8 @@ QAbstract3DGraphPrivate::QAbstract3DGraphPrivate(QAbstract3DGraph *q)
m_updatePending(false),
m_visualController(0),
m_devicePixelRatio(1.f),
- m_offscreenSurface(0)
+ m_offscreenSurface(0),
+ m_initialized(false)
{
}