summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarc Mutz <[email protected]>2025-11-20 15:46:08 +0100
committerMarc Mutz <[email protected]>2025-12-09 06:03:28 +0000
commit871dcd55566b5080972ed455f7b7fe92ff14d745 (patch)
treed79a16ce4ec4b90e98786bfd0f1ea60c2eeca7e3 /src
parenteae3c8f8a798deb0b4abb78410d08aa626789035 (diff)
QMatrix4x4: restore NRVO in op*(M,M) 4/5: use Qt::Uninitialized ctor
Instead of copying the LHS operand into the result and selectively overwriting fields whose values are not statically known for scaling and translation, write the known values into those fields manually. This allows us to use the Qt::Uninitialized constructor, like in the 3D case, which, in the last step, will allow us to re-enable NRVO in this function. It should also improve numerical stability, because it resets what might have become merely fuzzily-0/1 values to known, clean ones. Amends the start of the public history. Pick-to: 6.11 6.10 6.8 Change-Id: I595498787cebe069c36c1797a9dbe1a94780066d Reviewed-by: Allan Sandfeld Jensen <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/gui/math3d/qmatrix4x4.h14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/gui/math3d/qmatrix4x4.h b/src/gui/math3d/qmatrix4x4.h
index 9872501392d..94f9c12f19b 100644
--- a/src/gui/math3d/qmatrix4x4.h
+++ b/src/gui/math3d/qmatrix4x4.h
@@ -610,14 +610,26 @@ inline QMatrix4x4 operator*(const QMatrix4x4& m1, const QMatrix4x4& m2)
{
QMatrix4x4::Flags flagBits = m1.flagBits | m2.flagBits;
if (flagBits.toInt() < QMatrix4x4::Rotation2D) {
- QMatrix4x4 m = m1;
+ QMatrix4x4 m(Qt::Uninitialized);
m.m[0][0] = m1.m[0][0] * m2.m[0][0];
+ m.m[0][1] = 0.0f;
+ m.m[0][2] = 0.0f;
+ m.m[0][3] = 0.0f;
+
+ m.m[1][0] = 0.0f;
m.m[1][1] = m1.m[1][1] * m2.m[1][1];
+ m.m[1][2] = 0.0f;
+ m.m[1][3] = 0.0f;
+
+ m.m[2][0] = 0.0f;
+ m.m[2][1] = 0.0f;
m.m[2][2] = m1.m[2][2] * m2.m[2][2];
+ m.m[2][3] = 0.0f;
m.m[3][0] = m1.m[3][0] + m1.m[0][0] * m2.m[3][0];
m.m[3][1] = m1.m[3][1] + m1.m[1][1] * m2.m[3][1];
m.m[3][2] = m1.m[3][2] + m1.m[2][2] * m2.m[3][2];
+ m.m[3][3] = 1.0f;
m.flagBits = flagBits;
return m;
}