summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/datavisualization/utils/utils.cpp71
-rw-r--r--src/datavisualization/utils/utils_p.h1
-rw-r--r--tests/barstest/main.cpp22
3 files changed, 49 insertions, 45 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);
diff --git a/tests/barstest/main.cpp b/tests/barstest/main.cpp
index af033990..1305fff9 100644
--- a/tests/barstest/main.cpp
+++ b/tests/barstest/main.cpp
@@ -35,22 +35,19 @@
#include <QLineEdit>
#include <QSpinBox>
#include <QtGui/QOpenGLContext>
-
-static bool isOpenGLES()
-{
-#if defined(QT_OPENGL_ES_2)
- return true;
-#elif (QT_VERSION < QT_VERSION_CHECK(5, 3, 0))
- return false;
-#else
- return QOpenGLContext::currentContext()->isOpenGLES();
-#endif
-}
+#include <QtDataVisualization/QCustom3DItem>
+#include <QtDataVisualization/QCustom3DLabel>
+#include <QtDataVisualization/QCustom3DVolume>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
+ // Test creating custom items before graph is created
+ QCustom3DItem customItem;
+ QCustom3DLabel customLabel;
+ QCustom3DVolume customVolume;
+
QWidget *widget = new QWidget;
QHBoxLayout *hLayout = new QHBoxLayout(widget);
QVBoxLayout *vLayout = new QVBoxLayout();
@@ -60,8 +57,7 @@ int main(int argc, char **argv)
// For testing custom surface format
QSurfaceFormat surfaceFormat;
surfaceFormat.setDepthBufferSize(24);
- if (!isOpenGLES())
- surfaceFormat.setSamples(8);
+ surfaceFormat.setSamples(8);
Q3DBars *widgetchart = new Q3DBars(&surfaceFormat);
QSize screenSize = widgetchart->screen()->size();