summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2020-02-11 15:29:55 +0100
committerPaul Lemire <paul.lemire@kdab.com>2020-02-12 16:22:32 +0100
commit26df8a284b745002f067cbde6da40fcdb921c19c (patch)
tree05e8c96cb9f1f37a1aea9c0113de413ccaf0bcb2
parent772d8d3dc775f3e76f0dbb627b4bf96591ca10a4 (diff)
Animations: handle colors as vec3 or vec4
Change-Id: If450816fadce4adad4881938ecaea9c4000afe16 Reviewed-by: Mike Krus <mike.krus@kdab.com>
-rw-r--r--src/animation/backend/animationutils.cpp16
-rw-r--r--tests/auto/animation/animationutils/tst_animationutils.cpp114
2 files changed, 117 insertions, 13 deletions
diff --git a/src/animation/backend/animationutils.cpp b/src/animation/backend/animationutils.cpp
index 80c296a89..3f386d92a 100644
--- a/src/animation/backend/animationutils.cpp
+++ b/src/animation/backend/animationutils.cpp
@@ -158,11 +158,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) {
@@ -170,8 +172,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);
@@ -385,10 +391,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);
}
diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp
index 05558192d..b19d74a25 100644
--- a/tests/auto/animation/animationutils/tst_animationutils.cpp
+++ b/tests/auto/animation/animationutils/tst_animationutils.cpp
@@ -323,9 +323,19 @@ private Q_SLOTS:
qMetaTypeId<QVector<float>>(),
6,
channelMapping->peerId() };
+ ChannelNameAndType rgbColor = { QLatin1String("rgbColor"),
+ static_cast<int>(QVariant::Color),
+ 3,
+ channelMapping->peerId() };
+
+ ChannelNameAndType rgbaColor = { QLatin1String("rgbaColor"),
+ static_cast<int>(QVariant::Color),
+ 4,
+ channelMapping->peerId() };
+
QVector<ChannelNameAndType> channelNamesAndTypes
= { rotation, location, baseColor, metalness, roughness,
- morphTargetWeightsList, morphTargetWeightsVec };
+ morphTargetWeightsList, morphTargetWeightsVec, rgbColor, rgbaColor };
// And the matching indices
ComponentIndices rotationIndices = { 0, 1, 2, 3 };
@@ -335,10 +345,12 @@ private Q_SLOTS:
ComponentIndices roughnessIndices = { 11 };
ComponentIndices morphTargetListIndices = { 12, 13, 14, 15, 16 };
ComponentIndices morphTargetVecIndices = { 17, 18, 19, 20, 21, 22 };
+ ComponentIndices rgbColorIndices = { 23, 24, 25 };
+ ComponentIndices rgbaColorIndices = { 26, 27, 28, 29 };
QVector<ComponentIndices> channelComponentIndices
= { rotationIndices, locationIndices, baseColorIndices,
metalnessIndices, roughnessIndices, morphTargetListIndices,
- morphTargetVecIndices };
+ morphTargetVecIndices, rgbColorIndices, rgbaColorIndices };
QVector<QBitArray> sourceClipMask = { QBitArray(4, true),
QBitArray(3, true),
@@ -346,7 +358,10 @@ private Q_SLOTS:
QBitArray(1, true),
QBitArray(1, true),
QBitArray(5, true),
- QBitArray(6, true) };
+ QBitArray(6, true),
+ QBitArray(3, true),
+ QBitArray(4, true),
+ };
MappingData expectedMapping;
expectedMapping.targetId = channelMapping->targetId();
@@ -969,7 +984,29 @@ private Q_SLOTS:
expectedChanges.normalizedTime = 1.1f; // Invalid
expectedChanges.targetChanges.push_back({mapping.targetId, mapping.propertyName, QVariant::fromValue(QColor::fromRgbF(0.5f, 0.4f, 0.3f))});
- QTest::newRow("QColor color")
+ QTest::newRow("QColor rgb color")
+ << animatorId << mappingData << channelResults << expectedChanges;
+
+ mappingData.clear();
+ channelResults.clear();
+ expectedChanges.targetChanges.clear();
+ }
+
+ // Single property, QColor
+ {
+ animatorId = Qt3DCore::QNodeId::createId();
+ MappingData mapping;
+ mapping.targetId = Qt3DCore::QNodeId::createId();
+ mapping.propertyName = "color";
+ mapping.type = static_cast<int>(QVariant::Color);
+ mapping.channelIndices = QVector<int>() << 0 << 1 << 2 << 3;
+ mappingData.push_back(mapping);
+ channelResults = QVector<float>() << 0.5f << 0.4f << 0.3f << 0.2f;
+ expectedChanges.finalFrame = false;
+ expectedChanges.normalizedTime = 1.1f; // Invalid
+ expectedChanges.targetChanges.push_back({mapping.targetId, mapping.propertyName, QVariant::fromValue(QColor::fromRgbF(0.5f, 0.4f, 0.3f, 0.2f))});
+
+ QTest::newRow("QColor rgba color")
<< animatorId << mappingData << channelResults << expectedChanges;
mappingData.clear();
@@ -1613,7 +1650,7 @@ private Q_SLOTS:
expectedResults.clear();
}
- // color with and without offset
+ // color with and without offset 3 components
{
channel = Channel();
channel.name = QLatin1String("Color");
@@ -1628,7 +1665,7 @@ private Q_SLOTS:
suffixes = (QVector<char>() << 'R' << 'G' << 'B');
expectedResults = (QVector<int>() << 0 << 1 << 2);
- QTest::newRow("QColor Color, offset = 0")
+ QTest::newRow("QColor RGB Color, offset = 0")
<< channel << dataType << expectedChannelComponentCount
<< offset << suffixes << expectedResults;
@@ -1636,7 +1673,39 @@ private Q_SLOTS:
offset = 10;
expectedResults = (QVector<int>() << 10 << 11 << 12);
- QTest::newRow("QColor Color, offset = 10")
+ QTest::newRow("QColor RGB Color, offset = 10")
+ << channel << dataType << expectedChannelComponentCount
+ << offset << suffixes << expectedResults;
+
+ suffixes.clear();
+ expectedResults.clear();
+ }
+
+ // color with and without offset 4 components
+ {
+ channel = Channel();
+ channel.name = QLatin1String("Color");
+ channel.channelComponents.resize(4);
+ channel.channelComponents[0].name = QLatin1String("Color R");
+ channel.channelComponents[1].name = QLatin1String("Color G");
+ channel.channelComponents[2].name = QLatin1String("Color B");
+ channel.channelComponents[3].name = QLatin1String("Color A");
+
+ dataType = static_cast<int>(QVariant::Color);
+ expectedChannelComponentCount = 4;
+ offset = 0;
+ suffixes = (QVector<char>() << 'R' << 'G' << 'B' << 'A');
+ expectedResults = (QVector<int>() << 0 << 1 << 2 << 3);
+
+ QTest::newRow("QColor RGBA Color, offset = 0")
+ << channel << dataType << expectedChannelComponentCount
+ << offset << suffixes << expectedResults;
+
+ expectedResults.clear();
+
+ offset = 10;
+ expectedResults = (QVector<int>() << 10 << 11 << 12 << 13);
+ QTest::newRow("QColor RGBA Color, offset = 10")
<< channel << dataType << expectedChannelComponentCount
<< offset << suffixes << expectedResults;
@@ -1803,14 +1872,41 @@ private Q_SLOTS:
offset = 0;
expectedResults = (QVector<int>() << 0 << 1 << 2);
- QTest::newRow("QColor Color, offset = 0")
+ QTest::newRow("QColor RGB Color, offset = 0")
<< channel << dataType << componentCount << offset << expectedResults;
expectedResults.clear();
offset = 10;
expectedResults = (QVector<int>() << 10 << 11 << 12);
- QTest::newRow("QColor Color, offset = 10")
+ QTest::newRow("QColor RGB Color, offset = 10")
+ << channel << dataType << componentCount << offset << expectedResults;
+
+ expectedResults.clear();
+ }
+
+ {
+ channel = Channel();
+ channel.name = QLatin1String("Color");
+ channel.channelComponents.resize(4);
+ channel.channelComponents[0].name = QLatin1String("Color R");
+ channel.channelComponents[1].name = QLatin1String("Color G");
+ channel.channelComponents[2].name = QLatin1String("Color B");
+ channel.channelComponents[3].name = QLatin1String("Color A");
+
+ dataType = static_cast<int>(QVariant::Color);
+ componentCount = 4;
+ offset = 0;
+ expectedResults = (QVector<int>() << 0 << 1 << 2 << 3);
+
+ QTest::newRow("QColor RGBA Color, offset = 0")
+ << channel << dataType << componentCount << offset << expectedResults;
+
+ expectedResults.clear();
+
+ offset = 10;
+ expectedResults = (QVector<int>() << 10 << 11 << 12 << 13);
+ QTest::newRow("QColor RGBA Color, offset = 10")
<< channel << dataType << componentCount << offset << expectedResults;
expectedResults.clear();