/// <inheritdoc/> public virtual EffectParameterDescription GetDescription(Effect effect, EffectParameter parameter) { if (parameter == null) { throw new ArgumentNullException("parameter"); } EffectParameterDescription description = null; // First, try to get usage from annotation string. var annotation = parameter.Annotations["Semantic"]; if (annotation != null && annotation.ParameterType == EffectParameterType.String) { description = GetDescriptionFromString(parameter, annotation.GetValueString()); } if (description == null) { // No annotation. // --> Try to get usage from semantic. description = GetDescriptionFromString(parameter, parameter.Semantic); } if (description == null) { // No annotation, no semantic. // --> Try to get usage from parameter name. // Check whether string matches entry in dictionary. description = GetDescriptionFromString(parameter, parameter.Name); } if (description == null) { // Too bad, better luck next time. return(null); } // Get the effect parameter hint from annotations. var hint = EffectHelper.GetHintFromAnnotations(parameter); if (hint.HasValue) { // User-defined hint found in effect file. // --> Override default. description.Hint = hint.Value; } return(description); }
/// <summary> /// Interprets the specified effect parameter and adds an /// <see cref="EffectParameterDescription"/> to the collection. /// </summary> /// <param name="effect">The effect.</param> /// <param name="parameter">The effect parameter.</param> /// <param name="interpreters">The effect interpreters.</param> private void InterpretParameter(Effect effect, EffectParameter parameter, EffectInterpreterCollection interpreters) { Debug.Assert(!Contains(parameter), "Effect binding already contains a description for the given effect parameter."); // Try all interpreters to find a description. foreach (var interpreter in interpreters) { var description = interpreter.GetDescription(effect, parameter); if (description != null) { Add(description); return; } } // No description found. If the parameter is a struct or array of structs // we check the structure members. if (parameter.ParameterClass == EffectParameterClass.Struct) { if (parameter.Elements.Count > 0) { // Effect parameter is an array of structs. foreach (EffectParameter element in parameter.Elements) { foreach (EffectParameter member in element.StructureMembers) { InterpretParameter(effect, member, interpreters); } } } else { // Effect parameter is a struct. foreach (EffectParameter member in parameter.StructureMembers) { InterpretParameter(effect, member, interpreters); } } } else { // No description found and this parameter is no struct. // Try to get hint from annotations and create default description (= "Unknown usage"). var hint = EffectHelper.GetHintFromAnnotations(parameter) ?? EffectParameterHint.Material; Add(new EffectParameterDescription(parameter, null, 0, hint)); } }