From f797fb9796adff0eb6adb705709a42320f01f713 Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Sat, 19 Sep 2015 18:24:46 +0200 Subject: RenderShaderData/UBO: improve nested shader data buffer update Although the actual implementation is not optimal when having an array of nested children (as we need to reupload all the children if only one of them as changed), only trigger this update if at least one of the children was updated. Change-Id: I0688323b78a0db70f9f0115e1e8447296506f0c8 Reviewed-by: Andy Nichols --- src/render/materialsystem/shaderdata.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/render/materialsystem') diff --git a/src/render/materialsystem/shaderdata.cpp b/src/render/materialsystem/shaderdata.cpp index 6338df96b..c030225c4 100644 --- a/src/render/materialsystem/shaderdata.cpp +++ b/src/render/materialsystem/shaderdata.cpp @@ -129,25 +129,26 @@ bool ShaderData::needsUpdate(const QMatrix4x4 &viewMatrix) ++transformedIt; } } - const QHash::const_iterator end = m_nestedShaderDataProperties.end(); QHash::const_iterator it = m_nestedShaderDataProperties.begin(); while (it != end) { if (it.value().userType() == QMetaType::QVariantList) { QVariantList updatedNodes; + bool nestedNeedsUpdate = false; Q_FOREACH (const QVariant &v, it.value().value()) { ShaderData *nested = m_manager->lookupResource(v.value()); if (nested != Q_NULLPTR) { - // We need to add the nested nodes the the updated property list - // as if we need to maintain order + // We need to add the nested nodes to the updated property list + // as we need to maintain order // if node[0] doesn't need update but node[1] does, // if we only have a single element, the renderer would update element [0] - nested->needsUpdate(viewMatrix); + nestedNeedsUpdate |= nested->needsUpdate(viewMatrix); updatedNodes << v; } } - if (!updatedNodes.empty()) + // Of course we only add all the nodes if at least one of the nested nodes required and update + if (nestedNeedsUpdate && !updatedNodes.empty()) m_updatedProperties.insert(it.key(), updatedNodes); } else { ShaderData *nested = m_manager->lookupResource(it.value().value()); -- cgit v1.2.3