aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquickshadereffect.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quick/items/qquickshadereffect.cpp')
-rw-r--r--src/quick/items/qquickshadereffect.cpp48
1 files changed, 34 insertions, 14 deletions
diff --git a/src/quick/items/qquickshadereffect.cpp b/src/quick/items/qquickshadereffect.cpp
index d47203057f..7dea334785 100644
--- a/src/quick/items/qquickshadereffect.cpp
+++ b/src/quick/items/qquickshadereffect.cpp
@@ -486,6 +486,15 @@ QT_BEGIN_NAMESPACE
\li Samplers must use binding points starting from 1.
+ \li When Qt Quick is rendering with \c multiview enabled, e.g. because it is
+ part of a 3D scene rendering in a VR/AR environment where the left and right
+ eye content are generated in a single pass, the ShaderEffect's shaders have
+ to be written with this in mind. With a view count of 2 for example, there
+ will be \c 2 matrices (qt_Matrix is an array of mat4 with two elements). The
+ vertex shader is expected to take \c gl_ViewIndex into account. See the \c
+ Multiview section in the \l{QSB Manual} for general information on creating
+ multiview-capable shaders.
+
\endlist
\sa {Item Layers}, {QSB Manual}, {Qt Shader Tools Build System Integration}
@@ -641,11 +650,9 @@ void QQuickShaderEffect::setMesh(const QVariant &mesh)
This property defines which sides of the item should be visible.
- \list
- \li ShaderEffect.NoCulling - Both sides are visible
- \li ShaderEffect.BackFaceCulling - only front side is visible
- \li ShaderEffect.FrontFaceCulling - only back side is visible
- \endlist
+ \value ShaderEffect.NoCulling Both sides are visible
+ \value ShaderEffect.BackFaceCulling only the front side is visible
+ \value ShaderEffect.FrontFaceCulling only the back side is visible
The default is NoCulling.
*/
@@ -700,11 +707,9 @@ void QQuickShaderEffect::setSupportsAtlasTextures(bool supports)
This property tells the current status of the shaders.
- \list
- \li ShaderEffect.Compiled - the shader program was successfully compiled and linked.
- \li ShaderEffect.Uncompiled - the shader program has not yet been compiled.
- \li ShaderEffect.Error - the shader program failed to compile or link.
- \endlist
+ \value ShaderEffect.Compiled the shader program was successfully compiled and linked.
+ \value ShaderEffect.Uncompiled the shader program has not yet been compiled.
+ \value ShaderEffect.Error the shader program failed to compile or link.
When setting the fragment or vertex shader source code, the status will
become Uncompiled. The first time the ShaderEffect is rendered with new
@@ -985,9 +990,11 @@ void QQuickShaderEffectPrivate::handleEvent(QEvent *event)
{
if (event->type() == QEvent::DynamicPropertyChange) {
const auto propertyName = static_cast<QDynamicPropertyChangeEvent *>(event)->propertyName();
- const auto mappedId = findMappedShaderVariableId(propertyName);
- if (mappedId)
- propertyChanged(*mappedId);
+ for (int i = 0; i < NShader; ++i) {
+ const auto mappedId = findMappedShaderVariableId(propertyName, Shader(i));
+ if (mappedId)
+ propertyChanged(*mappedId);
+ }
}
}
@@ -1039,6 +1046,7 @@ QSGNode *QQuickShaderEffectPrivate::handleUpdatePaintNode(QSGNode *oldNode, QQui
sd.fragment.dirtyConstants = &m_dirtyConstants[Fragment];
sd.fragment.dirtyTextures = &m_dirtyTextures[Fragment];
sd.materialTypeCacheKey = q->window();
+ sd.viewCount = QQuickWindowPrivate::get(q->window())->multiViewCount();
node->syncMaterial(&sd);
@@ -1121,6 +1129,7 @@ bool QQuickShaderEffectPrivate::updateUniformValue(const QByteArray &name, const
sd.fragment.dirtyConstants = &dirtyConstants[Fragment];
sd.fragment.dirtyTextures = {};
sd.materialTypeCacheKey = q->window();
+ sd.viewCount = QQuickWindowPrivate::get(q->window())->multiViewCount();
node->syncMaterial(&sd);
@@ -1274,7 +1283,7 @@ bool QQuickShaderEffectPrivate::updateShader(Shader shaderType, const QUrl &file
// provided and monitored like with an application-provided shader.
QSGGuiThreadShaderEffectManager::ShaderInfo::Variable v;
v.name = QByteArrayLiteral("source");
- v.bindPoint = 0; // fake
+ v.bindPoint = 1; // fake, must match the default source bindPoint in qquickshadereffectnode.cpp
v.type = texturesSeparate ? QSGGuiThreadShaderEffectManager::ShaderInfo::Texture
: QSGGuiThreadShaderEffectManager::ShaderInfo::Sampler;
m_shaders[shaderType].shaderInfo.variables.append(v);
@@ -1442,6 +1451,17 @@ std::optional<int> QQuickShaderEffectPrivate::findMappedShaderVariableId(const Q
return {};
}
+std::optional<int> QQuickShaderEffectPrivate::findMappedShaderVariableId(const QByteArray &name, Shader shaderType) const
+{
+ const auto &vars = m_shaders[shaderType].shaderInfo.variables;
+ for (int idx = 0; idx < vars.size(); ++idx) {
+ if (vars[idx].name == name)
+ return indexToMappedId(shaderType, idx);
+ }
+
+ return {};
+}
+
bool QQuickShaderEffectPrivate::sourceIsUnique(QQuickItem *source, Shader typeToSkip, int indexToSkip) const
{
for (int shaderType = 0; shaderType < NShader; ++shaderType) {