summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2018-01-25 16:32:28 +0100
committerLaszlo Agocs <laszlo.agocs@qt.io>2018-01-26 09:17:14 +0000
commit4aaa06a46280c7e9511154ba8535e6a4356174c8 (patch)
tree3eb967e0f998144fc455697a6331e29a3c97f5b7
parent93c27afb0e9caed8e108e454285af771ec5ec895 (diff)
Add support for Enum custom properties
Some effects use this, for example: <Property name="dir" formalName="Grain" list="Both:Horizontal:Vertical" default="Both" ... /> Here the type is implicitly Enum and the actual uniform value is an integer 0, 1, ... Change-Id: I6cfb190e15b6a88e94d9681c370f5ee86d040727 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
-rw-r--r--src/runtime/q3dseffect.cpp3
-rw-r--r--src/runtime/q3dsmaterial.cpp5
-rw-r--r--src/runtime/q3dsmaterial.h1
-rw-r--r--src/runtime/q3dspresentation.cpp15
4 files changed, 19 insertions, 5 deletions
diff --git a/src/runtime/q3dseffect.cpp b/src/runtime/q3dseffect.cpp
index c531e26..8b18eac 100644
--- a/src/runtime/q3dseffect.cpp
+++ b/src/runtime/q3dseffect.cpp
@@ -101,6 +101,9 @@ QString Q3DSEffect::addPropertyUniforms(const QString &shaderSrc) const
addUniform("int", QLatin1String("flag") + prop.name);
s += QString(QLatin1String("vec4 texture2D_%1(vec2 uv) { return GetTextureValue(%1, uv, %1Info.z); }\n")).arg(prop.name);
break;
+ case Q3DS::Enum:
+ addUniform("int", prop.name);
+ break;
// ### there could be more that needs handling here (Buffer?)
diff --git a/src/runtime/q3dsmaterial.cpp b/src/runtime/q3dsmaterial.cpp
index 5c2d9b2..3db317c 100644
--- a/src/runtime/q3dsmaterial.cpp
+++ b/src/runtime/q3dsmaterial.cpp
@@ -319,6 +319,11 @@ PropertyElement parsePropertyElement(QXmlStreamReader *r)
property.align = attribute.value().toString();
} else if (attribute.name() == QStringLiteral("access")) {
property.access = attribute.value().toString();
+ } else if (attribute.name() == QStringLiteral("list")) {
+ // type is not used here. The strings in the list separated by
+ // colons are mapped to integers 0, 1, ...
+ property.type = Q3DS::Enum;
+ property.enumValues = attribute.value().toString().split(QLatin1Char(':'), QString::SkipEmptyParts);
}
}
return property;
diff --git a/src/runtime/q3dsmaterial.h b/src/runtime/q3dsmaterial.h
index 79ca179..4305d16 100644
--- a/src/runtime/q3dsmaterial.h
+++ b/src/runtime/q3dsmaterial.h
@@ -133,6 +133,7 @@ struct Q3DSV_EXPORT PropertyElement
QString name;
QString description;
QString formalName;
+ QStringList enumValues;
Q3DS::PropertyType type;
int componentCount;
float min;
diff --git a/src/runtime/q3dspresentation.cpp b/src/runtime/q3dspresentation.cpp
index a6a9270..c27ea05 100644
--- a/src/runtime/q3dspresentation.cpp
+++ b/src/runtime/q3dspresentation.cpp
@@ -262,9 +262,9 @@ int animatablePropertyTypeToMetaType(Q3DS::PropertyType type)
}
}
-QVariant convertToVariant(const QString &value, Q3DS::PropertyType type)
+QVariant convertToVariant(const QString &value, const Q3DSMaterial::PropertyElement &propMeta)
{
- switch (type) {
+ switch (propMeta.type) {
case StringList:
case Slide:
case Font:
@@ -281,7 +281,6 @@ QVariant convertToVariant(const QString &value, Q3DS::PropertyType type)
case StringListOrInt:
case Renderable:
case PathBuffer:
- case Enum:
return value;
case LongRange:
case Long:
@@ -314,6 +313,12 @@ QVariant convertToVariant(const QString &value, Q3DS::PropertyType type)
return v;
}
break;
+ case Enum:
+ {
+ int idx = propMeta.enumValues.indexOf(value);
+ return idx >= 0 ? idx : 0;
+ }
+ break;
default:
break;
}
@@ -1349,12 +1354,12 @@ static void fillCustomProperties(const QMap<QString, Q3DSMaterial::PropertyEleme
for (auto it = instanceProps.cbegin(), ite = instanceProps.cend(); it != ite; ++it) {
if (it->nameStr() == propMetaIt.key()) {
found = true;
- propTab->insert(it->nameStr(), Q3DS::convertToVariant(it->valueStr(), propMetaIt->type));
+ propTab->insert(it->nameStr(), Q3DS::convertToVariant(it->valueStr(), *propMetaIt));
break;
}
}
if (!found)
- propTab->insert(propMetaIt.key(), Q3DS::convertToVariant(propMetaIt->defaultValue, propMetaIt->type));
+ propTab->insert(propMetaIt.key(), Q3DS::convertToVariant(propMetaIt->defaultValue, *propMetaIt));
}
// Fix up the filenames to that no further adjustment is necessary from this point on.