From 48e32cfabed8527ac788142393226ad931d29420 Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Mon, 7 Oct 2013 10:17:56 +0200 Subject: [PATCH] All matrices in a batch need to be 2D safe when merging. 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 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp | 19 +++++++++++++++++-- src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp index ab67dc5..f25e144 100644 --- a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp +++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp @@ -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; diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h index 6e9bd75..94e8ba5 100644 --- a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h +++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h @@ -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() { -- 2.7.4