aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorJiDe Zhang <zhangjide@uniontech.com>2021-10-28 11:45:52 +0800
committerJiDe Zhang <zhangjide@uniontech.com>2021-10-29 18:59:48 +0800
commit85b5413dc43e20951a3f27b2940961b1c998df95 (patch)
treeb131e0f53937f0db19f1d4a06e86d7810d5ade5c /examples
parent004e90b15569ab204e8302df853ef66eba918131 (diff)
Avoid unnecessary color format conversion
If a color is not the rgb format, when QColor::red() QColor::blue() QColor::green() is used continuously to obtain the values of different channels, three times color conversions will occur. Therefore, use QColor::toRgb() before that to ensure that only one conversion is performed at most. Not only rgb, the conversion of other formats is the same. Change-Id: Ia969e1ca6f1524ad5d7e8dec915bcbc407875c66 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'examples')
-rw-r--r--examples/quick/scenegraph/graph/linenode.cpp6
-rw-r--r--examples/quick/scenegraph/graph/noisynode.cpp6
2 files changed, 4 insertions, 8 deletions
diff --git a/examples/quick/scenegraph/graph/linenode.cpp b/examples/quick/scenegraph/graph/linenode.cpp
index 74161c8040..c567218f74 100644
--- a/examples/quick/scenegraph/graph/linenode.cpp
+++ b/examples/quick/scenegraph/graph/linenode.cpp
@@ -123,10 +123,8 @@ bool LineShader::updateUniformData(RenderState &state, QSGMaterial *newMaterial,
}
LineMaterial *mat = static_cast<LineMaterial *>(newMaterial);
- float c[4] = { float(mat->state.color.redF()),
- float(mat->state.color.greenF()),
- float(mat->state.color.blueF()),
- float(mat->state.color.alphaF()) };
+ float c[4];
+ mat->state.color.getRgbF(&c[0], &c[1], &c[2], &c[3]);
memcpy(buf->data() + 64, c, 16);
memcpy(buf->data() + 84, &mat->state.size, 4);
memcpy(buf->data() + 88, &mat->state.spread, 4);
diff --git a/examples/quick/scenegraph/graph/noisynode.cpp b/examples/quick/scenegraph/graph/noisynode.cpp
index f8b72bfe67..474d75058c 100644
--- a/examples/quick/scenegraph/graph/noisynode.cpp
+++ b/examples/quick/scenegraph/graph/noisynode.cpp
@@ -131,10 +131,8 @@ bool NoisyShader::updateUniformData(RenderState &state, QSGMaterial *newMaterial
}
NoisyMaterial *mat = static_cast<NoisyMaterial *>(newMaterial);
- float c[4] = { float(mat->state.color.redF()),
- float(mat->state.color.greenF()),
- float(mat->state.color.blueF()),
- float(mat->state.color.alphaF()) };
+ float c[4];
+ mat->state.color.getRgbF(&c[0], &c[1], &c[2], &c[3]);
memcpy(buf->data() + 64, c, 16);
const QSize s = mat->state.texture->textureSize();