4 using System.Collections.Generic;
7 using SiliconStudio.Paradox.Shaders.Parser.Ast;
8 using SiliconStudio.Shaders.Ast;
9 using SiliconStudio.Shaders.Ast.Hlsl;
10 using SiliconStudio.Shaders.Visitor;
11 using SiliconStudio.Shaders.Writer;
15 namespace SiliconStudio.Paradox.Shaders.Parser.Mixins
22 protected bool IsColorStatus =
false;
27 protected bool IsArrayStatus =
false;
32 protected bool ProcessInitialValueStatus =
false;
37 protected bool VariableAsParameterKey =
true;
42 public virtual bool Run()
51 if (VariableAsParameterKey)
53 WriteVariableAsParameterKey(variable);
68 WriteLinkLine(namespaceBlock);
69 Write(
"namespace ").Write(namespaceBlock.Name);
71 foreach (
Node node
in namespaceBlock.Body)
78 internal bool IsParameterKey(
Variable variable)
81 if (variable.
Qualifiers.
Contains(SiliconStudio.Shaders.Ast.Hlsl.StorageQualifier.Extern)
82 || variable.Qualifiers.Contains(StorageQualifier.Const)
84 || variable.Qualifiers.Contains(ParadoxStorageQualifier.PatchStream)
97 if (!IsParameterKey(variable))
103 ProcessInitialValueStatus =
false;
104 IsArrayStatus =
false;
106 var variableType = variable.Attributes.OfType<AttributeDeclaration>().Where(x => x.Name ==
"Type").Select(x => (string)x.Parameters[0].Value).FirstOrDefault();
107 var variableMap = variable.Attributes.OfType<AttributeDeclaration>().Where(x => x.Name ==
"Map").Select(x => (string)x.Parameters[0].Value).FirstOrDefault();
109 Write(
"public static readonly ParameterKey<");
110 if (variableType == null)
111 VisitDynamic(variable.
Type);
115 Write(variable.
Name);
117 if (variableMap == null)
119 Write(
"ParameterKeys.New<");
120 if (variableType == null)
121 VisitDynamic(variable.
Type);
125 if (ProcessInitialValueStatus && variable.
InitialValue != null)
127 var initialValueString = variable.InitialValue.ToString();
129 if (initialValueString !=
"null")
133 initialValueString = variable.Type.ToString() + initialValueString;
137 if (initialValueString.StartsWith(
"float2")
138 || initialValueString.StartsWith(
"float3")
139 || initialValueString.StartsWith(
"float4"))
140 initialValueString = initialValueString.Replace(
"float",
"new Vector");
141 else if (IsArrayStatus)
143 initialValueString =
"new " + initialValueString;
148 initialValueString = initialValueString.Replace(
"Vector3",
"Color3");
149 initialValueString = initialValueString.Replace(
"Vector4",
"Color4");
152 Write(initialValueString);
162 IsColorStatus =
false;
163 IsArrayStatus =
false;
164 ProcessInitialValueStatus =
false;
174 var type = typeName.ResolveType();
175 if (ReferenceEquals(typeName, type))
177 base.Visit(typeName);
178 ProcessInitialValueStatus =
true;
190 base.Visit(scalarType);
191 ProcessInitialValueStatus =
true;
201 var finalTypeName =
"Vector" + type.Dimension;
205 finalTypeName =
"Color3";
207 finalTypeName =
"Color4";
209 throw new NotSupportedException(
"Color attribute is only valid for float3/float4.");
211 Write(finalTypeName);
212 ProcessInitialValueStatus =
true;
223 ProcessInitialValueStatus =
true;
243 Write(
"SamplerState");
253 var dimensions = type.Dimensions;
254 if (dimensions.Count != 1)
255 throw new NotSupportedException();
266 VisitDynamic(type.
Type);
268 ProcessInitialValueStatus =
true;
269 IsArrayStatus =
true;
280 ProcessInitialValueStatus =
true;
285 return list.Any(str => string.Compare(value, str, StringComparison.InvariantCultureIgnoreCase) == 0);
static readonly SiliconStudio.Shaders.Ast.StorageQualifier Compose
Compose keyword (compose).
Base class for all vector types
Identifier Name
Gets or sets the name.
virtual bool Run()
Runs the code generation. Results is accessible from ShaderWriter.Text property.
TypeBase Type
Gets or sets the type.
override void Visit(TypeName typeName)
Visits the specified type.
virtual void Visit(StateType type)
Visits the specified type.
virtual void Visit(TextureType type)
Visits the specified type.
static readonly SiliconStudio.Shaders.Ast.StorageQualifier Stream
Stream keyword (stream).
virtual void Visit(NamespaceBlock namespaceBlock)
Visits the specified namespace block.
Qualifier Qualifiers
Gets or sets the qualifiers.
int Dimension
Gets or sets the dimension.
override void Visit(ArrayType type)
Visits the specified type.
void WriteVariableAsParameterKey(Variable variable)
virtual void Visit(VectorType type)
Visits the specified type.
SiliconStudio.Shaders.Ast.StorageQualifier StorageQualifier
virtual void Visit(TypeBase type)
Visits the specified type.
override void Visit(ScalarType scalarType)
List< AttributeBase > Attributes
bool Contains(CompositeEnum enumValue)
Determines whether [contains] [the specified enum value].
Expression InitialValue
Gets or sets the initial value.
static bool IsStringInList(string value, params string[] list)
TypeBase Type
Gets or sets the type.
virtual void Visit(MatrixType type)
Visits the specified type.
Identifier Name
Gets or sets the type name.
override void Visit(Variable variable)