Exemple #1
0
        private string CSharpToShaderTypeCore(string fullType, bool packed)
        {
            string mapped = packed
                ? MetalKnownTypes.GetPackedName(fullType)
                : MetalKnownTypes.GetMappedName(fullType);

            return(mapped
                   .Replace(".", "_")
                   .Replace("+", "_"));
        }
        private static string TranslateCore(string typeName, string methodName, InvocationParameterInfo[] parameters)
        {
            string        target  = parameters[0].Identifier;
            StringBuilder swizzle = new StringBuilder();

            foreach (char c in methodName)
            {
                swizzle.Append(char.ToLowerInvariant(c));
            }

            bool result = MetalKnownTypes.GetUnpackedType(parameters[0].FullTypeName, out string unpackedType);

            Debug.Assert(result);

            return($"{unpackedType}({target}).{swizzle.ToString()}");
        }
        protected void WriteStructure(StringBuilder sb, StructureDefinition sd)
        {
            sb.AppendLine($"struct {CSharpToShaderType(sd.Name)}");
            sb.AppendLine("{");
            StringBuilder fb          = new StringBuilder();
            uint          attribute   = 0;
            uint          colorTarget = 0;

            foreach (FieldDefinition field in sd.Fields)
            {
                string typeName = CSharpToShaderType(field.Type);
                if (field.SemanticType == SemanticType.None)
                {
                    typeName = MetalKnownTypes.GetPackedName(typeName);
                }

                fb.Append(typeName);
                fb.Append(' ');
                fb.Append(CorrectIdentifier(field.Name.Trim()));
                int arrayCount = field.ArrayElementCount;
                if (arrayCount > 0)
                {
                    fb.Append('['); fb.Append(arrayCount); fb.Append(']');
                }

                if (field.SemanticType == SemanticType.SystemPosition)
                {
                    fb.Append($" [[ position ]]");
                }
                else if (field.SemanticType == SemanticType.ColorTarget)
                {
                    fb.Append($" [[ color({colorTarget++}) ]]");
                }
                else if (field.SemanticType != SemanticType.None)
                {
                    fb.Append($" [[ attribute({attribute++}) ]]");
                }
                fb.Append(';');
                sb.Append("    ");
                sb.AppendLine(fb.ToString());
                fb.Clear();
            }
            sb.AppendLine("};");
            sb.AppendLine();
        }
 protected override string CSharpToShaderTypeCore(string fullType)
 {
     return(MetalKnownTypes.GetMappedName(fullType)
            .Replace(".", "_")
            .Replace("+", "_"));
 }