summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2020-02-11 15:29:55 +0100
committerMike Krus <mike.krus@kdab.com>2020-03-19 06:11:17 +0000
commit5007e6e09db2262d28567ad276771e8fb823b069 (patch)
treee21d052c93dfc756cb39a8471b823e45a430353e /src
parent292481b0c0f87e43579acd6d26c6bc9e1a399a93 (diff)
Animations: handle colors as vec3 or vec4
Change-Id: If450816fadce4adad4881938ecaea9c4000afe16 Reviewed-by: Mike Krus <mike.krus@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/animation/backend/animationutils.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/animation/backend/animationutils.cpp b/src/animation/backend/animationutils.cpp
index 92e614236..a7a2e0036 100644
--- a/src/animation/backend/animationutils.cpp
+++ b/src/animation/backend/animationutils.cpp
@@ -160,11 +160,13 @@ ComponentIndices channelComponentsToIndices(const Channel &channel,
#if defined Q_COMPILER_UNIFORM_INIT
static const QVector<char> standardSuffixes = { 'X', 'Y', 'Z', 'W' };
static const QVector<char> quaternionSuffixes = { 'W', 'X', 'Y', 'Z' };
- static const QVector<char> colorSuffixes = { 'R', 'G', 'B' };
+ static const QVector<char> colorSuffixesRGB = { 'R', 'G', 'B' };
+ static const QVector<char> colorSuffixesRGBA = { 'R', 'G', 'B', 'A' };
#else
static const QVector<char> standardSuffixes = (QVector<char>() << 'X' << 'Y' << 'Z' << 'W');
static const QVector<char> quaternionSuffixes = (QVector<char>() << 'W' << 'X' << 'Y' << 'Z');
- static const QVector<char> colorSuffixes = (QVector<char>() << 'R' << 'G' << 'B');
+ static const QVector<char> colorSuffixesRGB = (QVector<char>() << 'R' << 'G' << 'B');
+ static const QVector<char> colorSuffixesRGBA = (QVector<char>() << 'R' << 'G' << 'B' << 'A');
#endif
switch (dataType) {
@@ -172,8 +174,12 @@ ComponentIndices channelComponentsToIndices(const Channel &channel,
return channelComponentsToIndicesHelper(channel, expectedComponentCount,
offset, quaternionSuffixes);
case QVariant::Color:
+ if (expectedComponentCount == 3)
+ return channelComponentsToIndicesHelper(channel, expectedComponentCount,
+ offset, colorSuffixesRGB);
+ Q_ASSERT(expectedComponentCount == 4);
return channelComponentsToIndicesHelper(channel, expectedComponentCount,
- offset, colorSuffixes);
+ offset, colorSuffixesRGBA);
default:
return channelComponentsToIndicesHelper(channel, expectedComponentCount,
offset, standardSuffixes);
@@ -387,10 +393,12 @@ QVariant buildPropertyValue(const MappingData &mappingData, const QVector<float>
}
case QVariant::Color: {
+ // A color can either be a vec3 or a vec4
const QColor color =
QColor::fromRgbF(channelResults[mappingData.channelIndices[0]],
channelResults[mappingData.channelIndices[1]],
- channelResults[mappingData.channelIndices[2]]);
+ channelResults[mappingData.channelIndices[2]],
+ mappingData.channelIndices.size() > 3 ? channelResults[mappingData.channelIndices[3]] : 1.0f);
return QVariant::fromValue(color);
}