Shader: Attribute can now have expressions as values and struct fields can be conditionally supported

This commit is contained in:
Jérôme Leclercq
2021-07-07 11:41:58 +02:00
parent 749b40cb31
commit f9af35b489
36 changed files with 945 additions and 600 deletions

View File

@@ -7,6 +7,73 @@
namespace Nz::ShaderAst
{
template<typename T>
void AstSerializerBase::Attribute(AttributeValue<T>& attribute)
{
UInt32 valueType;
if (IsWriting())
{
if (!attribute.HasValue())
valueType = 0;
else if (attribute.IsExpression())
valueType = 1;
else if (attribute.IsResultingValue())
valueType = 2;
else
throw std::runtime_error("unexpected attribute");
}
Value(valueType);
switch (valueType)
{
case 0:
if (!IsWriting())
attribute = {};
break;
case 1:
{
if (!IsWriting())
{
ExpressionPtr expr;
Node(expr);
attribute = std::move(expr);
}
else
Node(const_cast<ExpressionPtr&>(attribute.GetExpression())); //< not used for writing
break;
}
case 2:
{
if (!IsWriting())
{
T value;
if constexpr (std::is_enum_v<T>)
Enum(value);
else
Value(value);
attribute = std::move(value);
}
else
{
T& value = const_cast<T&>(attribute.GetResultingValue()); //< not used for writing
if constexpr (std::is_enum_v<T>)
Enum(value);
else
Value(value);
}
break;
}
}
}
template<typename T>
void AstSerializerBase::Container(T& container)
{