diff options
author | Miikka Heikkinen <miikka.heikkinen@theqtcompany.com> | 2014-10-28 12:48:17 +0200 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@theqtcompany.com> | 2014-10-29 09:35:29 +0200 |
commit | bf716cfdf0afecccdb1f2eabb2e6a172c620fbff (patch) | |
tree | dd5a8e5d1360defd47599282639e10b3cf3cc90c /src/datavisualization/utils | |
parent | 56d9ec81afc59b1cf6aaae7675ff460a6bc664a8 (diff) |
Support for dynamic opengl builds.
Task-number: QTRD-3392
Change-Id: I786bbf5ee9252b92d43d02d6b88ed9b986b4a5eb
Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src/datavisualization/utils')
-rw-r--r-- | src/datavisualization/utils/abstractobjecthelper.cpp | 1 | ||||
-rw-r--r-- | src/datavisualization/utils/objecthelper.cpp | 1 | ||||
-rw-r--r-- | src/datavisualization/utils/qutils.h | 6 | ||||
-rw-r--r-- | src/datavisualization/utils/scatterobjectbufferhelper.cpp | 2 | ||||
-rw-r--r-- | src/datavisualization/utils/scatterpointbufferhelper.cpp | 2 | ||||
-rw-r--r-- | src/datavisualization/utils/surfaceobject.cpp | 1 | ||||
-rw-r--r-- | src/datavisualization/utils/texturehelper.cpp | 146 | ||||
-rw-r--r-- | src/datavisualization/utils/texturehelper_p.h | 6 | ||||
-rw-r--r-- | src/datavisualization/utils/utils.cpp | 144 | ||||
-rw-r--r-- | src/datavisualization/utils/utils_p.h | 1 |
10 files changed, 167 insertions, 143 deletions
diff --git a/src/datavisualization/utils/abstractobjecthelper.cpp b/src/datavisualization/utils/abstractobjecthelper.cpp index c350d096..40b3a45e 100644 --- a/src/datavisualization/utils/abstractobjecthelper.cpp +++ b/src/datavisualization/utils/abstractobjecthelper.cpp @@ -28,6 +28,7 @@ AbstractObjectHelper::AbstractObjectHelper() m_indexCount(0), m_meshDataLoaded(false) { + initializeOpenGLFunctions(); } AbstractObjectHelper::~AbstractObjectHelper() diff --git a/src/datavisualization/utils/objecthelper.cpp b/src/datavisualization/utils/objecthelper.cpp index b64e8c3f..4240d6f5 100644 --- a/src/datavisualization/utils/objecthelper.cpp +++ b/src/datavisualization/utils/objecthelper.cpp @@ -111,7 +111,6 @@ ObjectHelper *ObjectHelper::getObjectHelper(const Abstract3DRenderer *cacheId, void ObjectHelper::load() { - initializeOpenGLFunctions(); if (m_meshDataLoaded) { // Delete old data glDeleteBuffers(1, &m_vertexbuffer); diff --git a/src/datavisualization/utils/qutils.h b/src/datavisualization/utils/qutils.h index 1e0eb9f9..d4acfc99 100644 --- a/src/datavisualization/utils/qutils.h +++ b/src/datavisualization/utils/qutils.h @@ -30,12 +30,10 @@ inline static QSurfaceFormat qDefaultSurfaceFormat(bool antialias = true) surfaceFormat.setDepthBufferSize(24); surfaceFormat.setStencilBufferSize(8); surfaceFormat.setSwapBehavior(QSurfaceFormat::DoubleBuffer); -#if !defined(QT_OPENGL_ES_2) - surfaceFormat.setRenderableType(QSurfaceFormat::OpenGL); -#else + surfaceFormat.setRenderableType(QSurfaceFormat::DefaultRenderableType); +#if defined(QT_OPENGL_ES_2) // Antialias not supported for ES antialias = false; - surfaceFormat.setRenderableType(QSurfaceFormat::OpenGLES); surfaceFormat.setRedBufferSize(8); surfaceFormat.setBlueBufferSize(8); surfaceFormat.setGreenBufferSize(8); diff --git a/src/datavisualization/utils/scatterobjectbufferhelper.cpp b/src/datavisualization/utils/scatterobjectbufferhelper.cpp index 8925a7a4..44c84ae0 100644 --- a/src/datavisualization/utils/scatterobjectbufferhelper.cpp +++ b/src/datavisualization/utils/scatterobjectbufferhelper.cpp @@ -38,8 +38,6 @@ ScatterObjectBufferHelper::~ScatterObjectBufferHelper() void ScatterObjectBufferHelper::fullLoad(ScatterSeriesRenderCache *cache, qreal dotScale) { - initializeOpenGLFunctions(); - m_meshDataLoaded = false; m_indexCount = 0; diff --git a/src/datavisualization/utils/scatterpointbufferhelper.cpp b/src/datavisualization/utils/scatterpointbufferhelper.cpp index f15ce3ec..22e76f92 100644 --- a/src/datavisualization/utils/scatterpointbufferhelper.cpp +++ b/src/datavisualization/utils/scatterpointbufferhelper.cpp @@ -76,8 +76,6 @@ void ScatterPointBufferHelper::popPoint() void ScatterPointBufferHelper::load(ScatterSeriesRenderCache *cache) { - initializeOpenGLFunctions(); - ScatterRenderItemArray &renderArray = cache->renderArray(); const int renderArraySize = renderArray.size(); m_indexCount = 0; diff --git a/src/datavisualization/utils/surfaceobject.cpp b/src/datavisualization/utils/surfaceobject.cpp index 5498c8b3..b93030b1 100644 --- a/src/datavisualization/utils/surfaceobject.cpp +++ b/src/datavisualization/utils/surfaceobject.cpp @@ -37,7 +37,6 @@ SurfaceObject::SurfaceObject(Surface3DRenderer *renderer) m_oldDataDimension(-1) { m_indicesType = GL_UNSIGNED_INT; - initializeOpenGLFunctions(); glGenBuffers(1, &m_vertexbuffer); glGenBuffers(1, &m_normalbuffer); glGenBuffers(1, &m_uvbuffer); diff --git a/src/datavisualization/utils/texturehelper.cpp b/src/datavisualization/utils/texturehelper.cpp index 939ce901..3944fb0c 100644 --- a/src/datavisualization/utils/texturehelper.cpp +++ b/src/datavisualization/utils/texturehelper.cpp @@ -30,24 +30,24 @@ extern void discardDebugMsgs(QtMsgType type, const QMessageLogContext &context, TextureHelper::TextureHelper() { + initializeOpenGLFunctions(); #if !defined(QT_OPENGL_ES_2) - // Discard warnings about deprecated functions - QtMessageHandler handler = qInstallMessageHandler(discardDebugMsgs); + if (!Utils::isOpenGLES()) { + // Discard warnings about deprecated functions + QtMessageHandler handler = qInstallMessageHandler(discardDebugMsgs); - m_openGlFunctions_2_1 = new QOpenGLFunctions_2_1; - m_openGlFunctions_2_1->initializeOpenGLFunctions(); + m_openGlFunctions_2_1 = + QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_2_1>(); + m_openGlFunctions_2_1->initializeOpenGLFunctions(); - // Restore original message handler - qInstallMessageHandler(handler); + // Restore original message handler + qInstallMessageHandler(handler); + } #endif - initializeOpenGLFunctions(); } TextureHelper::~TextureHelper() { -#if !defined(QT_OPENGL_ES_2) - delete m_openGlFunctions_2_1; -#endif } GLuint TextureHelper::create2DTexture(const QImage &image, bool useTrilinearFiltering, @@ -58,16 +58,16 @@ GLuint TextureHelper::create2DTexture(const QImage &image, bool useTrilinearFilt QImage texImage = image; -#if defined(QT_OPENGL_ES_2) - GLuint imageWidth = Utils::getNearestPowerOfTwo(image.width()); - GLuint imageHeight = Utils::getNearestPowerOfTwo(image.height()); - if (smoothScale) { - texImage = image.scaled(imageWidth, imageHeight, Qt::IgnoreAspectRatio, - Qt::SmoothTransformation); - } else { - texImage = image.scaled(imageWidth, imageHeight, Qt::IgnoreAspectRatio); + if (!Utils::isOpenGLES()) { + GLuint imageWidth = Utils::getNearestPowerOfTwo(image.width()); + GLuint imageHeight = Utils::getNearestPowerOfTwo(image.height()); + if (smoothScale) { + texImage = image.scaled(imageWidth, imageHeight, Qt::IgnoreAspectRatio, + Qt::SmoothTransformation); + } else { + texImage = image.scaled(imageWidth, imageHeight, Qt::IgnoreAspectRatio); + } } -#endif GLuint textureId; glGenTextures(1, &textureId); @@ -93,16 +93,19 @@ GLuint TextureHelper::create2DTexture(const QImage &image, bool useTrilinearFilt return textureId; } -#if !defined(QT_OPENGL_ES_2) GLuint TextureHelper::create3DTexture(const QVector<uchar> *data, int width, int height, int depth, QImage::Format dataFormat) { - if (!width || !height || !depth) + if (Utils::isOpenGLES() || !width || !height || !depth) return 0; + GLuint textureId = 0; +#if defined(QT_OPENGL_ES_2) + Q_UNUSED(dataFormat) + Q_UNUSED(data) +#else glEnable(GL_TEXTURE_3D); - GLuint textureId; glGenTextures(1, &textureId); glBindTexture(GL_TEXTURE_3D, textureId); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -126,17 +129,15 @@ GLuint TextureHelper::create3DTexture(const QVector<uchar> *data, int width, int } m_openGlFunctions_2_1->glTexImage3D(GL_TEXTURE_3D, 0, internalFormat, width, height, depth, 0, format, GL_UNSIGNED_BYTE, data->constData()); - status = glGetError(); if (status) qWarning() << __FUNCTION__ << "3D texture creation failed:" << status; glBindTexture(GL_TEXTURE_3D, 0); glDisable(GL_TEXTURE_3D); - +#endif return textureId; } -#endif GLuint TextureHelper::createCubeMapTexture(const QImage &image, bool useTrilinearFiltering) { @@ -184,11 +185,11 @@ GLuint TextureHelper::createSelectionTexture(const QSize &size, GLuint &frameBuf // glGetError docs advise to call glGetError in loop to clear all error flags while (status) status = glGetError(); -#if !defined(QT_OPENGL_ES_2) - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, size.width(), size.height()); -#else - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, size.width(), size.height()); -#endif + if (Utils::isOpenGLES()) + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, size.width(), size.height()); + else + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, size.width(), size.height()); + status = glGetError(); if (status) { qCritical() << "Selection texture render buffer creation failed:" << status; @@ -271,59 +272,64 @@ GLuint TextureHelper::createGradientTexture(const QLinearGradient &gradient) return create2DTexture(image, false, true, false, true); } -#if !defined(QT_OPENGL_ES_2) GLuint TextureHelper::createDepthTexture(const QSize &size, GLuint textureSize) { - GLuint depthtextureid; - - // Create depth texture for the shadow mapping - glGenTextures(1, &depthtextureid); - glBindTexture(GL_TEXTURE_2D, depthtextureid); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB); - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, size.width() * textureSize, - size.height() * textureSize, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL); - glBindTexture(GL_TEXTURE_2D, 0); - + GLuint depthtextureid = 0; +#if defined(QT_OPENGL_ES_2) + Q_UNUSED(size) + Q_UNUSED(textureSize) +#else + if (!Utils::isOpenGLES()) { + // Create depth texture for the shadow mapping + glGenTextures(1, &depthtextureid); + glBindTexture(GL_TEXTURE_2D, depthtextureid); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, size.width() * textureSize, + size.height() * textureSize, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL); + glBindTexture(GL_TEXTURE_2D, 0); + } +#endif return depthtextureid; } -#endif -#if !defined(QT_OPENGL_ES_2) GLuint TextureHelper::createDepthTextureFrameBuffer(const QSize &size, GLuint &frameBuffer, GLuint textureSize) { GLuint depthtextureid = createDepthTexture(size, textureSize); +#if defined(QT_OPENGL_ES_2) + Q_UNUSED(frameBuffer) +#else + if (!Utils::isOpenGLES()) { + // Create frame buffer + if (!frameBuffer) + glGenFramebuffers(1, &frameBuffer); + glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer); + + // Attach texture to depth attachment + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthtextureid, 0); + + m_openGlFunctions_2_1->glDrawBuffer(GL_NONE); + m_openGlFunctions_2_1->glReadBuffer(GL_NONE); + + // Verify that the frame buffer is complete + GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + if (status != GL_FRAMEBUFFER_COMPLETE) { + qCritical() << "Depth texture frame buffer creation failed" << status; + glDeleteTextures(1, &depthtextureid); + depthtextureid = 0; + } - // Create frame buffer - if (!frameBuffer) - glGenFramebuffers(1, &frameBuffer); - glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer); - - // Attach texture to depth attachment - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthtextureid, 0); - - glDrawBuffer(GL_NONE); - glReadBuffer(GL_NONE); - - // Verify that the frame buffer is complete - GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); - if (status != GL_FRAMEBUFFER_COMPLETE) { - qCritical() << "Depth texture frame buffer creation failed" << status; - glDeleteTextures(1, &depthtextureid); - depthtextureid = 0; + // Restore the default framebuffer + glBindFramebuffer(GL_FRAMEBUFFER, 0); } - - // Restore the default framebuffer - glBindFramebuffer(GL_FRAMEBUFFER, 0); - +#endif return depthtextureid; } -#endif void TextureHelper::deleteTexture(GLuint *texture) { diff --git a/src/datavisualization/utils/texturehelper_p.h b/src/datavisualization/utils/texturehelper_p.h index 03080b2a..6c0aa3de 100644 --- a/src/datavisualization/utils/texturehelper_p.h +++ b/src/datavisualization/utils/texturehelper_p.h @@ -48,21 +48,17 @@ class TextureHelper : protected QOpenGLFunctions // Ownership of created texture is transferred to caller GLuint create2DTexture(const QImage &image, bool useTrilinearFiltering = false, bool convert = true, bool smoothScale = true, bool clampY = false); -#if !defined(QT_OPENGL_ES_2) GLuint create3DTexture(const QVector<uchar> *data, int width, int height, int depth, QImage::Format dataFormat); -#endif GLuint createCubeMapTexture(const QImage &image, bool useTrilinearFiltering = false); // Returns selection texture and inserts generated framebuffers to framebuffer parameters GLuint createSelectionTexture(const QSize &size, GLuint &frameBuffer, GLuint &depthBuffer); GLuint createCursorPositionTexture(const QSize &size, GLuint &frameBuffer); GLuint createUniformTexture(const QColor &color); GLuint createGradientTexture(const QLinearGradient &gradient); -#if !defined(QT_OPENGL_ES_2) GLuint createDepthTexture(const QSize &size, GLuint textureSize); // Returns depth texture and inserts generated framebuffer to parameter GLuint createDepthTextureFrameBuffer(const QSize &size, GLuint &frameBuffer, GLuint textureSize); -#endif void deleteTexture(GLuint *texture); private: @@ -71,7 +67,7 @@ class TextureHelper : protected QOpenGLFunctions QRgb qt_gl_convertToGLFormatHelper(QRgb src_pixel, GLenum texture_format); #if !defined(QT_OPENGL_ES_2) - QOpenGLFunctions_2_1 *m_openGlFunctions_2_1; + QOpenGLFunctions_2_1 *m_openGlFunctions_2_1; // Not owned #endif friend class Bars3DRenderer; friend class Surface3DRenderer; diff --git a/src/datavisualization/utils/utils.cpp b/src/datavisualization/utils/utils.cpp index 534c79f9..cb64eb8f 100644 --- a/src/datavisualization/utils/utils.cpp +++ b/src/datavisualization/utils/utils.cpp @@ -17,6 +17,7 @@ ****************************************************************************/ #include "utils_p.h" +#include "qutils.h" #include <QtGui/QPainter> @@ -55,65 +56,58 @@ QImage Utils::printTextToImage(const QFont &font, const QString &text, const QCo const QColor &txtColor, bool labelBackground, bool borders, int maxLabelWidth) { - if (maxTextureSize == 0) - glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize); - + if (maxTextureSize == 0) { + QOpenGLContext::currentContext()->functions()->glGetIntegerv( + GL_MAX_TEXTURE_SIZE, &maxTextureSize); + } GLuint paddingWidth = 20; -#if !defined(QT_OPENGL_ES_2) // TODO fix ifdef for dynamic OpenGL GLuint paddingHeight = 20; -#endif + GLuint prePadding = 20; + GLint targetWidth = maxTextureSize; + // Calculate text dimensions QFont valueFont = font; valueFont.setPointSize(textureFontSize); QFontMetrics valueFM(valueFont); int valueStrWidth = valueFM.width(text); -#if defined(QT_OPENGL_ES_2) + // ES2 needs to use maxLabelWidth always (when given) because of the power of 2 -issue. - if (maxLabelWidth) -#else - if (maxLabelWidth && labelBackground) -#endif + if (maxLabelWidth && (labelBackground || Utils::isOpenGLES())) valueStrWidth = maxLabelWidth; int valueStrHeight = valueFM.height(); valueStrWidth += paddingWidth / 2; // Fix clipping problem with skewed fonts (italic or italic-style) QSize labelSize; qreal fontRatio = 1.0; -#if defined(QT_OPENGL_ES_2) // TODO fix ifdef for dynamic OpenGL - // Test if text with slighly smaller font would fit into one step smaller texture - // ie. if the text is just exceeded the smaller texture boundary, it would - // make a label with large empty space - GLuint prePadding = 20; - GLint targetWidth = maxTextureSize; - uint testWidth = getNearestPowerOfTwo(valueStrWidth + prePadding) >> 1; - int diffToFit = (valueStrWidth + prePadding) - testWidth; - int maxSqueeze = int((valueStrWidth + prePadding) * 0.1f); - if (diffToFit < maxSqueeze && maxTextureSize > GLint(testWidth)) - targetWidth = testWidth; -#endif + if (Utils::isOpenGLES()) { + // Test if text with slighly smaller font would fit into one step smaller texture + // ie. if the text is just exceeded the smaller texture boundary, it would + // 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); + if (diffToFit < maxSqueeze && maxTextureSize > GLint(testWidth)) + targetWidth = testWidth; + } bool sizeOk = false; int currentFontSize = textureFontSize; do { -#if defined(QT_OPENGL_ES_2) // TODO fix ifdef for dynamic OpenGL - // ES2 can't handle textures with dimensions not in power of 2. Resize labels accordingly. - // Add some padding before converting to power of two to avoid too tight fit - labelSize = QSize(valueStrWidth + prePadding, valueStrHeight + prePadding); - labelSize.setWidth(getNearestPowerOfTwo(labelSize.width())); - labelSize.setHeight(getNearestPowerOfTwo(labelSize.height())); -#else - if (!labelBackground) - labelSize = QSize(valueStrWidth, valueStrHeight); - else - labelSize = QSize(valueStrWidth + paddingWidth * 2, valueStrHeight + paddingHeight * 2); -#endif + if (Utils::isOpenGLES()) { + // ES2 can't handle textures with dimensions not in power of 2. Resize labels accordingly. + // Add some padding before converting to power of two to avoid too tight fit + labelSize = QSize(valueStrWidth + prePadding, valueStrHeight + prePadding); + labelSize.setWidth(getNearestPowerOfTwo(labelSize.width())); + labelSize.setHeight(getNearestPowerOfTwo(labelSize.height())); + } else { + if (!labelBackground) + labelSize = QSize(valueStrWidth, valueStrHeight); + else + labelSize = QSize(valueStrWidth + paddingWidth * 2, valueStrHeight + paddingHeight * 2); + } -#if defined(QT_OPENGL_ES_2) if (!maxTextureSize || (labelSize.width() <= maxTextureSize - && labelSize.width() <= targetWidth)) { -#else - if (!maxTextureSize || labelSize.width() <= maxTextureSize) { -#endif + && (labelSize.width() <= targetWidth || !Utils::isOpenGLES()))) { // Make sure the label is not too wide sizeOk = true; } else if (--currentFontSize == 4) { @@ -124,11 +118,7 @@ QImage Utils::printTextToImage(const QFont &font, const QString &text, const QCo // Reduce font size and try again valueFont.setPointSize(currentFontSize); QFontMetrics currentValueFM(valueFont); -#if defined(QT_OPENGL_ES_2) - if (maxLabelWidth) -#else - if (maxLabelWidth && labelBackground) -#endif + if (maxLabelWidth && (labelBackground || Utils::isOpenGLES())) valueStrWidth = maxLabelWidth * fontRatio; else valueStrWidth = currentValueFM.width(text); @@ -149,18 +139,18 @@ QImage Utils::printTextToImage(const QFont &font, const QString &text, const QCo painter.setFont(valueFont); if (!labelBackground) { painter.setPen(txtColor); -#if defined(QT_OPENGL_ES_2) - painter.drawText((labelSize.width() - valueStrWidth) / 2.0f, - (labelSize.height() - valueStrHeight) / 2.0f, - valueStrWidth, valueStrHeight, - Qt::AlignCenter | Qt::AlignVCenter, - text); -#else - painter.drawText(0, 0, - valueStrWidth, valueStrHeight, - Qt::AlignCenter | Qt::AlignVCenter, - text); -#endif + if (Utils::isOpenGLES()) { + painter.drawText((labelSize.width() - valueStrWidth) / 2.0f, + (labelSize.height() - valueStrHeight) / 2.0f, + valueStrWidth, valueStrHeight, + Qt::AlignCenter | Qt::AlignVCenter, + text); + } else { + painter.drawText(0, 0, + valueStrWidth, valueStrHeight, + Qt::AlignCenter | Qt::AlignVCenter, + text); + } } else { painter.setBrush(QBrush(bgrColor)); qreal radius = 10.0 * fontRatio; @@ -189,8 +179,9 @@ QVector4D Utils::getSelection(QPoint mousepos, int height) // This is the only one that works with OpenGL ES 2.0, so we're forced to use it // Item count will be limited to 256*256*256 GLubyte pixel[4] = {255, 255, 255, 255}; - glReadPixels(mousepos.x(), height - mousepos.y(), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, - (void *)pixel); + QOpenGLContext::currentContext()->functions()->glReadPixels(mousepos.x(), height - mousepos.y(), + 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, + (void *)pixel); QVector4D selectedColor(pixel[0], pixel[1], pixel[2], pixel[3]); return selectedColor; } @@ -322,4 +313,41 @@ QQuaternion Utils::calculateRotation(const QVector3D &xyzRotations) return totalRotation; } +bool Utils::isOpenGLES() +{ +#if defined(QT_OPENGL_ES_2) + return true; +#elif (QT_VERSION < QT_VERSION_CHECK(5, 3, 0)) + return 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(); + resolved = true; + + if (dummySurface) { + ctx->doneCurrent(); + delete ctx; + delete dummySurface; + } + } + return isES; +#endif +} + QT_END_NAMESPACE_DATAVISUALIZATION diff --git a/src/datavisualization/utils/utils_p.h b/src/datavisualization/utils/utils_p.h index fdcb0da0..1a46c731 100644 --- a/src/datavisualization/utils/utils_p.h +++ b/src/datavisualization/utils/utils_p.h @@ -69,6 +69,7 @@ public: static float wrapValue(float value, float min, float max); static QQuaternion calculateRotation(const QVector3D &xyzRotations); + static bool isOpenGLES(); private: static ParamType mapFormatCharToParamType(char formatSpec); |