summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2021-01-27 07:24:55 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-02-03 08:27:55 +0000
commitb72eca26017ee5b30c1dbfec558e11274b372e01 (patch)
treecf0756d7578e179c7489768d18209f6180d2ac3b
parent03e5f60e585701608c1181365faee484d7a1f14c (diff)
Fix light uniforms not properly being updated
- We cache commands and only rebuild them when really needed. When we rebuild then, we also store the mapping between uniform location and parameter name - When reusing a command, we only update the uniform values but expect the mapping between to remain the same. - When dealing with lights however, we can end up in a case where the light type changes, and therefore so does the shader data associated. The command remains cached as nothing really requires a rebuid. Yet, this means we could have more or less parameters than the number of mappings we have stored previously if the shader data defines more or less properties. To account for this, we now rebuild the mapping when building the command or if the number of parameters in the parameter pack is different than at the previous frame. Change-Id: I9400fc7e5bcb4b97ac9da69cdf794010cf81103b Reviewed-by: Mike Krus <mike.krus@kdab.com> (cherry picked from commit a7f627b29b2792154bc2a45f31bd32b74fd508b4) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/plugins/renderers/opengl/renderer/renderview.cpp4
-rw-r--r--src/plugins/renderers/opengl/renderer/shaderparameterpack_p.h5
2 files changed, 8 insertions, 1 deletions
diff --git a/src/plugins/renderers/opengl/renderer/renderview.cpp b/src/plugins/renderers/opengl/renderer/renderview.cpp
index c26e1bb09..fbc1cd841 100644
--- a/src/plugins/renderers/opengl/renderer/renderview.cpp
+++ b/src/plugins/renderers/opengl/renderer/renderview.cpp
@@ -1080,6 +1080,7 @@ void RenderView::setShaderAndUniforms(RenderCommand *command,
command->m_parameterPack.reserve(shader->parameterPackSize());
}
+ const size_t previousUniformCount = command->m_parameterPack.uniforms().size();
if (shader->hasActiveVariables()) {
const QVector<int> &standardUniformNamesIds = shader->standardUniformNameIds();
@@ -1104,8 +1105,9 @@ void RenderView::setShaderAndUniforms(RenderCommand *command,
updateLightUniforms(command, entity);
}
+ const size_t actualUniformCount = command->m_parameterPack.uniforms().size();
// Prepare the ShaderParameterPack based on the active uniforms of the shader
- if (!updateUniformsOnly)
+ if (!updateUniformsOnly || previousUniformCount != actualUniformCount)
shader->prepareUniforms(command->m_parameterPack);
}
diff --git a/src/plugins/renderers/opengl/renderer/shaderparameterpack_p.h b/src/plugins/renderers/opengl/renderer/shaderparameterpack_p.h
index 4fa96f51d..4e678e567 100644
--- a/src/plugins/renderers/opengl/renderer/shaderparameterpack_p.h
+++ b/src/plugins/renderers/opengl/renderer/shaderparameterpack_p.h
@@ -105,6 +105,11 @@ struct PackUniformHash
values.reserve(count);
}
+ size_t size() const
+ {
+ return keys.size();
+ }
+
inline int indexForKey(int key) const
{
const auto b = keys.cbegin();