diff options
author | Liang Qi <liang.qi@qt.io> | 2018-10-25 07:21:05 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2018-10-25 07:21:53 +0200 |
commit | e28e91ae99b8c3859899e04cc9370534c7c7b86d (patch) | |
tree | cca81b1e745be4f25aab78e8e917c2324594e539 /src/gui/opengl | |
parent | 5ea233ca6782eb27adf596515cb66ef3dadc1d5e (diff) | |
parent | ebfad73b4e44fe6db8059200da105b4b87888718 (diff) |
Merge remote-tracking branch 'origin/5.12' into dev
Conflicts:
src/corelib/animation/qpropertyanimation.cpp
src/gui/image/qicon.cpp
tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
Change-Id: I3698172b7b44ebb487cb38f50fd2c4a9f8a35b21
Diffstat (limited to 'src/gui/opengl')
-rw-r--r-- | src/gui/opengl/qopenglbuffer.cpp | 11 | ||||
-rw-r--r-- | src/gui/opengl/qopengldebug.cpp | 65 | ||||
-rw-r--r-- | src/gui/opengl/qopenglengineshadermanager.cpp | 12 | ||||
-rw-r--r-- | src/gui/opengl/qopenglfunctions.cpp | 63 | ||||
-rw-r--r-- | src/gui/opengl/qopenglprogrambinarycache.cpp | 9 | ||||
-rw-r--r-- | src/gui/opengl/qopengltextureglyphcache.cpp | 10 |
6 files changed, 41 insertions, 129 deletions
diff --git a/src/gui/opengl/qopenglbuffer.cpp b/src/gui/opengl/qopenglbuffer.cpp index 000494244d..537097c09f 100644 --- a/src/gui/opengl/qopenglbuffer.cpp +++ b/src/gui/opengl/qopenglbuffer.cpp @@ -63,12 +63,7 @@ QT_BEGIN_NAMESPACE QOpenGLBuffer objects can be copied around as a reference to the underlying OpenGL buffer object: - \code - QOpenGLBuffer buffer1(QOpenGLBuffer::IndexBuffer); - buffer1.create(); - - QOpenGLBuffer buffer2 = buffer1; - \endcode + \snippet code/src_gui_opengl_qopenglbuffer.cpp 0 QOpenGLBuffer performs a shallow copy when objects are copied in this manner, but does not implement copy-on-write semantics. The original @@ -484,9 +479,7 @@ void QOpenGLBuffer::release() been bound to the context but wants to make sure that it is released. - \code - QOpenGLBuffer::release(QOpenGLBuffer::VertexBuffer); - \endcode + \snippet code/src_gui_opengl_qopenglbuffer.cpp 1 */ void QOpenGLBuffer::release(QOpenGLBuffer::Type type) { diff --git a/src/gui/opengl/qopengldebug.cpp b/src/gui/opengl/qopengldebug.cpp index 7072db5af4..2e628a2bd5 100644 --- a/src/gui/opengl/qopengldebug.cpp +++ b/src/gui/opengl/qopengldebug.cpp @@ -89,16 +89,7 @@ QT_BEGIN_NAMESPACE call. Moreover, OpenGL errors stack up, therefore glGetError should always be used in a loop like this: - \code - - GLenum error = GL_NO_ERROR; - do { - error = glGetError(); - if (error != GL_NO_ERROR) - // handle the error - } while (error != GL_NO_ERROR); - - \endcode + \snippet code/src_gui_opengl_qopengldebug.cpp 0 If you try to clear the error stack, make sure not just keep going until GL_NO_ERROR is returned but also break on GL_CONTEXT_LOST as that error @@ -125,20 +116,7 @@ QT_BEGIN_NAMESPACE to create a debug context from Qt, you must set the QSurfaceFormat::DebugContext format option on the QSurfaceFormat used to create the QOpenGLContext object: - \code - - QSurfaceFormat format; - // asks for a OpenGL 3.2 debug context using the Core profile - format.setMajorVersion(3); - format.setMinorVersion(2); - format.setProfile(QSurfaceFormat::CoreProfile); - format.setOption(QSurfaceFormat::DebugContext); - - QOpenGLContext *context = new QOpenGLContext; - context->setFormat(format); - context->create(); - - \endcode + \snippet code/src_gui_opengl_qopengldebug.cpp 1 Note that requesting a 3.2 OpenGL Core Profile is just for the example's purposes; this class is not tied to any specific OpenGL or OpenGL ES @@ -152,24 +130,13 @@ QT_BEGIN_NAMESPACE object), and like the other OpenGL functions in Qt you \e{must} initialize it before usage by calling initialize() whilst there is a current OpenGL context: - \code - - QOpenGLContext *ctx = QOpenGLContext::currentContext(); - QOpenGLDebugLogger *logger = new QOpenGLDebugLogger(this); - - logger->initialize(); // initializes in the current context, i.e. ctx - - \endcode + \snippet code/src_gui_opengl_qopengldebug.cpp 2 Note that the \c{GL_KHR_debug} extension \e{must} be available in the context in order to access the messages logged by OpenGL. You can check the presence of this extension by calling: - \code - - ctx->hasExtension(QByteArrayLiteral("GL_KHR_debug")) - - \endcode + \snippet code/src_gui_opengl_qopengldebug.cpp 3 where \c{ctx} is a valid QOpenGLContext. If the extension is not available, initialize() will return false. @@ -179,13 +146,7 @@ QT_BEGIN_NAMESPACE OpenGL implementations keep an internal log of debug messages. Messages stored in this log can be retrieved by using the loggedMessages() function: - \code - - const QList<QOpenGLDebugMessage> messages = logger->loggedMessages(); - for (const QOpenGLDebugMessage &message : messages) - qDebug() << message; - - \endcode + \snippet code/src_gui_opengl_qopengldebug.cpp 4 The internal log has a limited size; when it fills up, older messages will get discarded to make room for the new incoming messages. When you call @@ -203,12 +164,7 @@ QT_BEGIN_NAMESPACE you need to connect a suitable slot to the messageLogged() signal, and start logging by calling startLogging(): - \code - - connect(logger, &QOpenGLDebugLogger::messageLogged, receiver, &LogHandler::handleLoggedMessage); - logger->startLogging(); - - \endcode + \snippet code/src_gui_opengl_qopengldebug.cpp 5 Similarly, logging can be disabled at any time by calling the stopLogging() function. @@ -259,14 +215,7 @@ QT_BEGIN_NAMESPACE \l{QOpenGLDebugMessage::}{createThirdPartyMessage()}, and then inserting it into the log by calling logMessage(): - \code - - QOpenGLDebugMessage message = - QOpenGLDebugMessage::createApplicationMessage(QStringLiteral("Custom message")); - - logger->logMessage(message); - - \endcode + \snippet code/src_gui_opengl_qopengldebug.cpp 6 Note that OpenGL implementations have a vendor-specific limit to the length of the messages that can be inserted in the debug log. You can retrieve diff --git a/src/gui/opengl/qopenglengineshadermanager.cpp b/src/gui/opengl/qopenglengineshadermanager.cpp index b7bac2728a..1e5a10c99c 100644 --- a/src/gui/opengl/qopenglengineshadermanager.cpp +++ b/src/gui/opengl/qopenglengineshadermanager.cpp @@ -256,9 +256,13 @@ QOpenGLEngineSharedShaders::QOpenGLEngineSharedShaders(QOpenGLContext* context) QByteArray fragSource; // Compile up the simple shader: +#ifdef Q_OS_WASM + vertexSource.append(qShaderSnippets[PositionOnlyVertexShader]); + vertexSource.append(qShaderSnippets[MainVertexShader]); +#else vertexSource.append(qShaderSnippets[MainVertexShader]); vertexSource.append(qShaderSnippets[PositionOnlyVertexShader]); - +#endif fragSource.append(qShaderSnippets[MainFragmentShader]); fragSource.append(qShaderSnippets[ShockingPinkSrcFragmentShader]); @@ -384,9 +388,13 @@ QOpenGLEngineShaderProg *QOpenGLEngineSharedShaders::findProgramInCache(const QO fragSource.append(qShaderSnippets[prog.maskFragShader]); QByteArray vertexSource; +#ifdef Q_OS_WASM + vertexSource.append(qShaderSnippets[prog.positionVertexShader]); + vertexSource.append(qShaderSnippets[prog.mainVertexShader]); +#else vertexSource.append(qShaderSnippets[prog.mainVertexShader]); vertexSource.append(qShaderSnippets[prog.positionVertexShader]); - +#endif QScopedPointer<QOpenGLShaderProgram> shaderProgram(new QOpenGLShaderProgram); CachedShader shaderCache(fragSource, vertexSource); diff --git a/src/gui/opengl/qopenglfunctions.cpp b/src/gui/opengl/qopenglfunctions.cpp index 4f48604a88..b4ff21f3fd 100644 --- a/src/gui/opengl/qopenglfunctions.cpp +++ b/src/gui/opengl/qopenglfunctions.cpp @@ -90,65 +90,18 @@ void CLASS::init(QOpenGLContext *context) \ that need it. The recommended way to use QOpenGLFunctions is by direct inheritance: - \code - class MyGLWindow : public QWindow, protected QOpenGLFunctions - { - Q_OBJECT - public: - MyGLWindow(QScreen *screen = 0); - - protected: - void initializeGL(); - void paintGL(); - - QOpenGLContext *m_context; - }; - - MyGLWindow(QScreen *screen) - : QWindow(screen), QOpenGLWidget(parent) - { - setSurfaceType(OpenGLSurface); - create(); - - // Create an OpenGL context - m_context = new QOpenGLContext; - m_context->create(); - - // Setup scene and render it - initializeGL(); - paintGL(); - } - - void MyGLWindow::initializeGL() - { - m_context->makeCurrent(this); - initializeOpenGLFunctions(); - } - \endcode + \snippet code/src_gui_opengl_qopenglfunctions.cpp 0 The \c{paintGL()} function can then use any of the OpenGL ES 2.0 functions without explicit resolution, such as glActiveTexture() in the following example: - \code - void MyGLWindow::paintGL() - { - m_context->makeCurrent(this); - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, textureId); - ... - m_context->swapBuffers(this); - m_context->doneCurrent(); - } - \endcode + \snippet code/src_gui_opengl_qopenglfunctions.cpp 1 QOpenGLFunctions can also be used directly for ad-hoc invocation of OpenGL ES 2.0 functions on all platforms: - \code - QOpenGLFunctions glFuncs(QOpenGLContext::currentContext()); - glFuncs.glActiveTexture(GL_TEXTURE1); - \endcode + \snippet code/src_gui_opengl_qopenglfunctions.cpp 2 An alternative approach is to query the context's associated QOpenGLFunctions instance. This is somewhat faster than the previous @@ -157,10 +110,7 @@ void CLASS::init(QOpenGLContext *context) \ resolving happens only once for a given context, regardless of the number of QOpenGLFunctions instances initialized for it. - \code - QOpenGLFunctions *glFuncs = QOpenGLContext::currentContext()->functions(); - glFuncs->glActiveTexture(GL_TEXTURE1); - \endcode + \snippet code/src_gui_opengl_qopenglfunctions.cpp 3 QOpenGLFunctions provides wrappers for all OpenGL ES 2.0 functions, including the common subset of OpenGL 1.x and ES @@ -175,10 +125,7 @@ void CLASS::init(QOpenGLContext *context) \ feature. For example, the following checks if non power of two textures are available: - \code - QOpenGLFunctions funcs(QOpenGLContext::currentContext()); - bool npot = funcs.hasOpenGLFeature(QOpenGLFunctions::NPOTTextures); - \endcode + \snippet code/src_gui_opengl_qopenglfunctions.cpp 4 \sa QOpenGLContext, QSurfaceFormat */ diff --git a/src/gui/opengl/qopenglprogrambinarycache.cpp b/src/gui/opengl/qopenglprogrambinarycache.cpp index 0f03101329..c96021a969 100644 --- a/src/gui/opengl/qopenglprogrambinarycache.cpp +++ b/src/gui/opengl/qopenglprogrambinarycache.cpp @@ -63,7 +63,7 @@ Q_DECLARE_LOGGING_CATEGORY(DBG_SHADER_CACHE) #endif const quint32 BINSHADER_MAGIC = 0x5174; -const quint32 BINSHADER_VERSION = 0x2; +const quint32 BINSHADER_VERSION = 0x3; const quint32 BINSHADER_QTVERSION = QT_VERSION; namespace { @@ -120,7 +120,7 @@ QString QOpenGLProgramBinaryCache::cacheFileName(const QByteArray &cacheKey) con return m_cacheDir + QString::fromUtf8(cacheKey); } -#define BASE_HEADER_SIZE (int(3 * sizeof(quint32))) +#define BASE_HEADER_SIZE (int(4 * sizeof(quint32))) #define FULL_HEADER_SIZE(stringsSize) (BASE_HEADER_SIZE + 12 + stringsSize + 8) #define PADDING_SIZE(fullHeaderSize) (((fullHeaderSize + 3) & ~3) - fullHeaderSize) @@ -159,6 +159,10 @@ bool QOpenGLProgramBinaryCache::verifyHeader(const QByteArray &buf) const qCDebug(DBG_SHADER_CACHE, "Qt version does not match"); return false; } + if (readUInt(&p) != sizeof(quintptr)) { + qCDebug(DBG_SHADER_CACHE, "Architecture does not match"); + return false; + } return true; } @@ -371,6 +375,7 @@ void QOpenGLProgramBinaryCache::save(const QByteArray &cacheKey, uint programId) writeUInt(&p, BINSHADER_MAGIC); writeUInt(&p, BINSHADER_VERSION); writeUInt(&p, BINSHADER_QTVERSION); + writeUInt(&p, sizeof(quintptr)); writeStr(&p, info.glvendor); writeStr(&p, info.glrenderer); diff --git a/src/gui/opengl/qopengltextureglyphcache.cpp b/src/gui/opengl/qopengltextureglyphcache.cpp index 556d52ef99..e3cbba955d 100644 --- a/src/gui/opengl/qopengltextureglyphcache.cpp +++ b/src/gui/opengl/qopengltextureglyphcache.cpp @@ -344,15 +344,25 @@ void QOpenGLTextureGlyphCache::resizeTextureData(int width, int height) { QString source; +#ifdef Q_OS_WASM + source.append(QLatin1String(isCoreProfile ? qopenglslUntransformedPositionVertexShader_core : qopenglslUntransformedPositionVertexShader)); + source.append(QLatin1String(isCoreProfile ? qopenglslMainWithTexCoordsVertexShader_core : qopenglslMainWithTexCoordsVertexShader)); +#else source.append(QLatin1String(isCoreProfile ? qopenglslMainWithTexCoordsVertexShader_core : qopenglslMainWithTexCoordsVertexShader)); source.append(QLatin1String(isCoreProfile ? qopenglslUntransformedPositionVertexShader_core : qopenglslUntransformedPositionVertexShader)); +#endif m_blitProgram->addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, source); } { QString source; +#ifdef Q_OS_WASM + source.append(QLatin1String(isCoreProfile ? qopenglslImageSrcFragmentShader_core : qopenglslImageSrcFragmentShader)); + source.append(QLatin1String(isCoreProfile ? qopenglslMainFragmentShader_core : qopenglslMainFragmentShader)); +#else source.append(QLatin1String(isCoreProfile ? qopenglslMainFragmentShader_core : qopenglslMainFragmentShader)); source.append(QLatin1String(isCoreProfile ? qopenglslImageSrcFragmentShader_core : qopenglslImageSrcFragmentShader)); +#endif m_blitProgram->addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, source); } |