diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2016-06-27 17:13:37 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2016-06-29 11:59:54 +0000 |
commit | 5ee02242d72ac9a536584b36ba549480a97303f7 (patch) | |
tree | c898b2eedad203ee0536d7b40cab6c1c08234056 /src/quick/items/qquickopenglshadereffect.cpp | |
parent | 12bff27aa6f1caac9bfacf365c542cf5da6e3148 (diff) |
Unify ShaderEffect property setting
rendererInterface() should not require isSceneGraphInitialized() to be
true - the API and language queries like graphicsApi() have no need for the
scenegraph, they only need the plugin to be loaded, i.e. that the QQuickWindow
is constructed.
This is the key to be able to make GraphicsInfo report graphicsApi and
shaderType with the correct values as early as possible - meaning as soon
as the item is associated with a window. The initialization of the
scenegraph (the exact timing of which varies backend to backend) does not
matter here.
The fragment and vertex shader property setting is now unified in the two
ShaderEffect implementations:
- If the component is complete, the shader is attempted to be processed
right from the setter.
- Otherwise the item will trigger processing once the component is
complete.
- If there is no window when processing is trigerred, it is deferred via
polish.
To implement item polish handling we need a new virtual in
QQuickItemPrivate since we cannot intrdouce virtuals into the public
classes.
This way one can write a condition (and later potentially use file
selectors) like this:
fragmentShader: GraphicsInfo.shaderType == GraphicsInfo.GLSL ? "..." : ...
without having to worry about getting an unintended value processed due to
GraphicsInfo not yet reporting an up-to-date value.
parseLog() forces, for GL at least, shader processing to prevent autotests
from breaking.
Change-Id: If55c69d746c29cd07348ddad2d6b0f2b5dd7f3a2
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src/quick/items/qquickopenglshadereffect.cpp')
-rw-r--r-- | src/quick/items/qquickopenglshadereffect.cpp | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/src/quick/items/qquickopenglshadereffect.cpp b/src/quick/items/qquickopenglshadereffect.cpp index 1e66971fdb..f65062ae38 100644 --- a/src/quick/items/qquickopenglshadereffect.cpp +++ b/src/quick/items/qquickopenglshadereffect.cpp @@ -556,6 +556,8 @@ QQuickOpenGLShaderEffect::QQuickOpenGLShaderEffect(QQuickShaderEffect *item, QOb , m_dirtyGeometry(true) , m_customVertexShader(false) , m_supportsAtlasTextures(false) + , m_vertNeedsUpdate(true) + , m_fragNeedsUpdate(true) { } @@ -573,8 +575,9 @@ void QQuickOpenGLShaderEffect::setFragmentShader(const QByteArray &code) m_dirtyProgram = true; m_dirtyParseLog = true; + m_fragNeedsUpdate = true; if (m_item->isComponentComplete()) - m_common.updateShader(m_item, Key::FragmentShader); + maybeUpdateShaders(); m_item->update(); if (m_status != QQuickShaderEffect::Uncompiled) { @@ -593,8 +596,9 @@ void QQuickOpenGLShaderEffect::setVertexShader(const QByteArray &code) m_dirtyParseLog = true; m_customVertexShader = true; + m_vertNeedsUpdate = true; if (m_item->isComponentComplete()) - m_common.updateShader(m_item, Key::VertexShader); + maybeUpdateShaders(); m_item->update(); if (m_status != QQuickShaderEffect::Uncompiled) { @@ -677,6 +681,8 @@ void QQuickOpenGLShaderEffect::setSupportsAtlasTextures(bool supports) QString QQuickOpenGLShaderEffect::parseLog() { + maybeUpdateShaders(true); + if (m_dirtyParseLog) { m_common.updateParseLog(m_mesh != 0); m_dirtyParseLog = false; @@ -862,10 +868,25 @@ QSGNode *QQuickOpenGLShaderEffect::handleUpdatePaintNode(QSGNode *oldNode, QQuic return node; } -void QQuickOpenGLShaderEffect::handleComponentComplete() +void QQuickOpenGLShaderEffect::maybeUpdateShaders(bool force) { - m_common.updateShader(m_item, Key::VertexShader); - m_common.updateShader(m_item, Key::FragmentShader); + // Defer processing if a window is not yet associated with the item. This + // is because the actual scenegraph backend is not known so conditions + // based on GraphicsInfo.shaderType and similar evaluate to wrong results. + if (!m_item->window() && !force) { + m_item->polish(); + return; + } + + if (m_vertNeedsUpdate) { + m_vertNeedsUpdate = false; + m_common.updateShader(m_item, Key::VertexShader); + } + + if (m_fragNeedsUpdate) { + m_fragNeedsUpdate = false; + m_common.updateShader(m_item, Key::FragmentShader); + } } void QQuickOpenGLShaderEffect::handleItemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value) |