summaryrefslogtreecommitdiffstats
path: root/src/datavisualization
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@theqtcompany.com>2014-10-29 12:22:26 +0200
committerTomi Korpipää <tomi.korpipaa@digia.com>2014-10-29 13:08:40 +0200
commita96cf650b967d88757bc4e550dbdbbd24dfe55cc (patch)
treecc86ec0760c6f588db12d9682bd35d64f90eaa0b /src/datavisualization
parent1797a7697d975545dd5b5b0d280c3a054dab39c5 (diff)
Fix crash when initializing QCustom3DLabel out of context.
Task-number: QTRD-3391 Change-Id: I5c2f2b674e50e7d39bc9355ebc9bcf05f22d5a39 Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src/datavisualization')
-rw-r--r--src/datavisualization/utils/utils.cpp71
-rw-r--r--src/datavisualization/utils/utils_p.h1
2 files changed, 40 insertions, 32 deletions
diff --git a/src/datavisualization/utils/utils.cpp b/src/datavisualization/utils/utils.cpp
index 42a1e532..685e0707 100644
--- a/src/datavisualization/utils/utils.cpp
+++ b/src/datavisualization/utils/utils.cpp
@@ -28,7 +28,10 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION
#define NUM_IN_POWER(y, x) for (;y<x;y<<=1)
#define MIN_POWER 2
-static GLint maxTextureSize = 0; // Safe, as all instances have the same texture size
+// Some values that only need to be resolved once
+static bool staticsResolved = false;
+static GLint maxTextureSize = 0;
+static bool isES = false;
GLuint Utils::getNearestPowerOfTwo(GLuint value)
{
@@ -58,10 +61,9 @@ QImage Utils::printTextToImage(const QFont &font, const QString &text, const QCo
const QColor &txtColor, bool labelBackground,
bool borders, int maxLabelWidth)
{
- if (maxTextureSize == 0) {
- QOpenGLContext::currentContext()->functions()->glGetIntegerv(
- GL_MAX_TEXTURE_SIZE, &maxTextureSize);
- }
+ if (!staticsResolved)
+ resolveStatics();
+
GLuint paddingWidth = 20;
GLuint paddingHeight = 20;
GLuint prePadding = 20;
@@ -317,39 +319,44 @@ QQuaternion Utils::calculateRotation(const QVector3D &xyzRotations)
bool Utils::isOpenGLES()
{
+ if (!staticsResolved)
+ resolveStatics();
+ return isES;
+}
+
+void Utils::resolveStatics()
+{
+ QOpenGLContext *ctx = QOpenGLContext::currentContext();
+ QWindow *dummySurface = 0;
+ if (!ctx) {
+ QSurfaceFormat surfaceFormat = qDefaultSurfaceFormat();
+ dummySurface = new QWindow();
+ dummySurface->setSurfaceType(QWindow::OpenGLSurface);
+ dummySurface->setFormat(surfaceFormat);
+ dummySurface->create();
+ ctx = new QOpenGLContext;
+ ctx->setFormat(surfaceFormat);
+ ctx->create();
+ ctx->makeCurrent(dummySurface);
+ }
+
#if defined(QT_OPENGL_ES_2)
- return true;
+ isES = true;
#elif (QT_VERSION < QT_VERSION_CHECK(5, 3, 0))
- return false;
+ isES = false;
#else
- static bool resolved = false;
- static bool isES = false;
- if (!resolved) {
- QOpenGLContext *ctx = QOpenGLContext::currentContext();
- QWindow *dummySurface = 0;
- if (!ctx) {
- QSurfaceFormat surfaceFormat = qDefaultSurfaceFormat();
- dummySurface = new QWindow();
- dummySurface->setSurfaceType(QWindow::OpenGLSurface);
- dummySurface->setFormat(surfaceFormat);
- dummySurface->create();
- ctx = new QOpenGLContext;
- ctx->setFormat(surfaceFormat);
- ctx->create();
- ctx->makeCurrent(dummySurface);
- }
+ isES = ctx->isOpenGLES();
+#endif
- isES = ctx->isOpenGLES();
- resolved = true;
+ ctx->functions()->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
- if (dummySurface) {
- ctx->doneCurrent();
- delete ctx;
- delete dummySurface;
- }
+ if (dummySurface) {
+ ctx->doneCurrent();
+ delete ctx;
+ delete dummySurface;
}
- return isES;
-#endif
+
+ staticsResolved = true;
}
QT_END_NAMESPACE_DATAVISUALIZATION
diff --git a/src/datavisualization/utils/utils_p.h b/src/datavisualization/utils/utils_p.h
index 1a46c731..06895bcf 100644
--- a/src/datavisualization/utils/utils_p.h
+++ b/src/datavisualization/utils/utils_p.h
@@ -70,6 +70,7 @@ public:
static float wrapValue(float value, float min, float max);
static QQuaternion calculateRotation(const QVector3D &xyzRotations);
static bool isOpenGLES();
+ static void resolveStatics();
private:
static ParamType mapFormatCharToParamType(char formatSpec);