summaryrefslogtreecommitdiffstats
path: root/src/datavisualization/utils/utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/datavisualization/utils/utils.cpp')
-rw-r--r--src/datavisualization/utils/utils.cpp80
1 files changed, 47 insertions, 33 deletions
diff --git a/src/datavisualization/utils/utils.cpp b/src/datavisualization/utils/utils.cpp
index 42a1e532..7f10bac7 100644
--- a/src/datavisualization/utils/utils.cpp
+++ b/src/datavisualization/utils/utils.cpp
@@ -21,14 +21,17 @@
#include <QtGui/QPainter>
#include <QtGui/QOpenGLContext>
-#include <QtGui/QWindow>
+#include <QtGui/QOffscreenSurface>
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;
@@ -87,7 +89,7 @@ QImage Utils::printTextToImage(const QFont &font, const QString &text, const QCo
// make a label with large empty space
uint testWidth = getNearestPowerOfTwo(valueStrWidth + prePadding) >> 1;
int diffToFit = (valueStrWidth + prePadding) - testWidth;
- int maxSqueeze = int((valueStrWidth + prePadding) * 0.1f);
+ int maxSqueeze = int((valueStrWidth + prePadding) * 0.25f);
if (diffToFit < maxSqueeze && maxTextureSize > GLint(testWidth))
targetWidth = testWidth;
}
@@ -317,39 +319,51 @@ QQuaternion Utils::calculateRotation(const QVector3D &xyzRotations)
bool Utils::isOpenGLES()
{
+ if (!staticsResolved)
+ resolveStatics();
+ return isES;
+}
+
+void Utils::resolveStatics()
+{
+ QOpenGLContext *ctx = QOpenGLContext::currentContext();
+ QOffscreenSurface *dummySurface = 0;
+ if (!ctx) {
+ QSurfaceFormat surfaceFormat;
+ dummySurface = new QOffscreenSurface();
+ 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;
+ }
+
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
+ // We support only ES2 emulation with software renderer for now
+ if (QCoreApplication::testAttribute(Qt::AA_UseSoftwareOpenGL)) {
+ qWarning("Only OpenGL ES2 emulation is available for software rendering.");
+ isES = true;
}
- return isES;
#endif
+
+ staticsResolved = true;
}
QT_END_NAMESPACE_DATAVISUALIZATION