All matrices in a batch need to be 2D safe when merging.
authorGunnar Sletta <gunnar.sletta@digia.com>
Mon, 7 Oct 2013 08:17:56 +0000 (10:17 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 8 Oct 2013 06:47:47 +0000 (08:47 +0200)
If we merge geometry nodes that make actual use of the
z-coordinate, this information becomes lost when merging
and the result is that we end up with an arbitrary
wrongfully applied transformation to the merged element.

Task-number: QTBUG-33897
Change-Id: I6129243e9bb890949023c35dc6b7bce30d31709a
Reviewed-by: Andrew Knight <andrew.knight@digia.com>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp
src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h

index ab67dc5..f25e144 100644 (file)
@@ -648,6 +648,21 @@ bool Batch::isTranslateOnlyToRoot() const {
     return only;
 }
 
+/*
+ * Iterates through all the nodes in the batch and returns true if the
+ * nodes are all "2D safe" meaning that they can be merged and that
+ * the value in the z coordinate is of no consequence.
+ */
+bool Batch::allMatricesAre2DSafe() const {
+    Element *e = first;
+    while (e) {
+        if (!QMatrix4x4_Accessor::is2DSafe(*e->node->matrix()))
+            return false;
+        e = e->nextInBatch;
+    }
+    return true;
+}
+
 static int qsg_countNodesInBatch(const Batch *batch)
 {
     int sum = 0;
@@ -1597,11 +1612,11 @@ void Renderer::uploadBatch(Batch *b)
         bool canMerge = (g->drawingMode() == GL_TRIANGLES || g->drawingMode() == GL_TRIANGLE_STRIP)
                         && b->positionAttribute >= 0
                         && g->indexType() == GL_UNSIGNED_SHORT
-                        && QMatrix4x4_Accessor::is2DSafe(*gn->matrix())
                         && (gn->activeMaterial()->flags() & QSGMaterial::CustomCompileStep) == 0
                         && (((gn->activeMaterial()->flags() & QSGMaterial::RequiresDeterminant) == 0)
                             || (((gn->activeMaterial()->flags() & QSGMaterial_RequiresFullMatrixBit) == 0) && b->isTranslateOnlyToRoot())
-                            );
+                            )
+                        && b->allMatricesAre2DSafe();
 
         b->merged = canMerge;
 
index 6e9bd75..94e8ba5 100644 (file)
@@ -57,7 +57,6 @@ struct Vec;
 struct Rect;
 struct Buffer;
 struct Chunk;
-struct AlphaChunk;
 struct Batch;
 struct Node;
 class Updater;
@@ -243,6 +242,7 @@ struct Batch
     void cleanupRemovedElements();
 
     bool isTranslateOnlyToRoot() const;
+    bool allMatricesAre2DSafe() const;
 
     // pseudo-constructor...
     void init() {