summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Bumberger <fbumberger@rim.com>2012-08-27 17:58:55 -0400
committerQt by Nokia <qt-info@nokia.com>2012-08-28 02:03:22 +0200
commit5a14306a84a07d305b5d6fb8cc1e78400ded75d6 (patch)
tree8a294d69bed4477bf87d6cb0512835e0426c4e2b
parentff8b10d436c3590a651c0cf91ef9ba6c95f1cb15 (diff)
Changed the BackToFront sorting of QQuickItem3Dv5.0.0-beta1
I changed the sort algorithm to qSort, because the implemented bubble sort seems not to be the best choice especially when dealing with a huge amount of children. Change-Id: Ib28dae6e1718bb8c9801277a65194fc10098a1e8 Reviewed-by: Julian de Bhal <julian.debhal@nokia.com>
-rw-r--r--src/quick3d/qquickitem3d.cpp23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/quick3d/qquickitem3d.cpp b/src/quick3d/qquickitem3d.cpp
index 5e4792648..e8ff72afd 100644
--- a/src/quick3d/qquickitem3d.cpp
+++ b/src/quick3d/qquickitem3d.cpp
@@ -1236,25 +1236,22 @@ void QQuickItem3D::drawChildren(QGLPainter *painter)
if (d->sortChildren == QQuickItem3D::BackToFront) {
// Collect up the transformed z positions of all children.
- QList<qreal> zlist;
+ QList<QPair<qreal, QQuickItem3D*> > zlist;
QMatrix4x4 mv = painter->modelViewMatrix();
for (int index = 0; index < list.size(); ++index) {
QVector3D position = list.at(index)->position();
- zlist.append(mv.map(position).z());
+ zlist.append(QPair<qreal, QQuickItem3D*> (mv.map(position).z(), list.at(index)));
}
- // Sort the item list (Caution: really dumb sort algorithm).
- for (int i = 0; i < list.size() - 1; ++i) {
- for (int j = i + 1; j < list.size(); ++j) {
- if (zlist.at(i) > zlist.at(j)) {
- qSwap(list[i], list[j]);
- qSwap(zlist[i], zlist[j]);
- }
- }
- }
+ qSort(zlist);
+ for (int index = 0; index < zlist.size(); ++index)
+ zlist.at(index).second->draw(painter);
+
+ }
+ else {
+ for (int index = 0; index < list.size(); ++index)
+ list.at(index)->draw(painter);
}
- for (int index = 0; index < list.size(); ++index)
- list.at(index)->draw(painter);
}
/*!