Avoid rebuiding batches during a material animation
authorJocelyn Turcotte <jturcotte@woboq.com>
Sun, 2 Aug 2015 17:43:23 +0000 (19:43 +0200)
committerJocelyn Turcotte (Woboq GmbH) <jturcotte@woboq.com>
Thu, 13 Aug 2015 11:42:35 +0000 (11:42 +0000)
Animating a complete batch of geometries bound by property
bindings will cause an unnecessary rebuild of the batch on
each animation step even though it will end up with the
same batch as in the previous frame.

Since the invalidation happens in nodeChanged, any node
change in an updatePaintNode might trigger an invalitation
if it is compared with a material that hasn't been updated yet.

Delay the verification of the DirtyMaterial flag until all
materials have been updated, later on in visitNode, to
make sure that we call compare only on up-to-date materials.

Change-Id: I03c095efc20817813508d959c74b41eae57beedc
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp

index f49fedb..6d0ed4c 100644 (file)
@@ -487,6 +487,11 @@ void Updater::visitGeometryNode(Node *n)
             if (e->batch)
                 renderer->invalidateBatchAndOverlappingRenderOrders(e->batch);
         }
+        if (n->dirtyState & QSGNode::DirtyMaterial) {
+            Element *e = n->element();
+            if (e->batch && e->batch->isMaterialCompatible(e) == BatchBreaksOnCompare)
+                renderer->invalidateBatchAndOverlappingRenderOrders(e->batch);
+        }
     }
 
     SHADOWNODE_TRAVERSE(n) visitNode(*child);
@@ -1216,10 +1221,7 @@ void Renderer::nodeChanged(QSGNode *node, QSGNode::DirtyState state)
             if (e->isMaterialBlended != blended) {
                 m_rebuild |= Renderer::FullRebuild;
                 e->isMaterialBlended = blended;
-            } else if (e->batch) {
-                if (e->batch->isMaterialCompatible(e) == BatchBreaksOnCompare)
-                    invalidateBatchAndOverlappingRenderOrders(e->batch);
-            } else {
+            } else if (!e->batch) {
                 m_rebuild |= Renderer::BuildBatches;
             }
         }