public virtual void Write(ShaderGenerationContext context) { AddPassRequiredAttributes(GetRequiredPassAttributes(context)); AddPassKeywords(GetRequiredPassKeywords(context)); context.LogShaderSection($"Generated Data Struct {AttributeStructName}"); context.WriteLine($"struct {AttributeStructName}"); context.WriteLine("{"); context.WriteIndented((c) => { for (int i = 0; i < _attributes.Count; i++) { AttributeConfig config = _attributes[i]; if (config.AttributeType != AttributeType.Anonymous) { c.WriteLine($"#define __{AttributeStructName.ToUpper()}{config.AttributeType.ToString().ToUpper()} {config.Name}"); } config.WriteAttributeDefinition(c, i, this is KeywordFragmentInput); } }); foreach (string keyword in _keywords) { context.WriteLine(keyword); } context.WriteLine("};"); context.Newine(); }
private void AddPassRequiredAttributes(List <AttributeConfig> requiredAttributes) { foreach (AttributeConfig requiredAttribute in requiredAttributes) { bool needsToBeAdded = false; if (requiredAttribute.AttributeType == AttributeType.Anonymous) { needsToBeAdded = true; } else { if (_attributes.All(config => config.AttributeType != requiredAttribute.AttributeType)) { needsToBeAdded = true; } else { AttributeConfig existingAttribute = _attributes.First(config => config.AttributeType == requiredAttribute.AttributeType); if (existingAttribute.DataType != requiredAttribute.DataType || existingAttribute.Dimensions != requiredAttribute.Dimensions) { throw new KeywordMap.ShaderGenerationException($"Attribute {existingAttribute.Name} of type {existingAttribute.AttributeType} needs to be a {requiredAttribute.DataType} ({requiredAttribute.Dimensions}) in this shader model"); } } } if (needsToBeAdded) { _attributes.Add(requiredAttribute); } } }