Example #1
0
 private void EmitVertexInputsGetter(ShaderSetProcessorInput input, CsCodeWriter ccw)
 {
     using (ccw.PushBlock($"public static VertexInputDescription[] GetVertexInputs()"))
     {
         ccw.WriteLine($"return new VertexInputDescription[]");
         using (ccw.PushBlock(null, ";"))
         {
             ccw.WriteLine("new VertexInputDescription(");
             ccw.IncreaseIndentation();
             ParameterDefinition[] vsParams = input.VertexFunction.Parameters;
             foreach (ParameterDefinition param in vsParams)
             {
                 StructureDefinition sd = input.Model.GetStructureDefinition(param.Type);
                 foreach (FieldDefinition fd in sd.Fields)
                 {
                     string              name     = fd.Name;
                     VertexSemanticType  semantic = GetSemantic(fd.SemanticType);
                     VertexElementFormat format   = GetFormat(fd.Type);
                     ccw.Write($"new VertexInputElement(\"{name}\", VertexSemanticType.{semantic}, VertexElementFormat.{format})");
                     if (fd == sd.Fields.Last())
                     {
                         ccw.WriteLine(")");
                     }
                     else
                     {
                         ccw.WriteLine(",");
                     }
                 }
             }
             ccw.DecreaseIndentation();
         }
     }
 }
Example #2
0
        public void ProcessShaderSet(ShaderSetProcessorInput input)
        {
            if (input.VertexFunction == null || input.FragmentFunction == null)
            {
                throw new InvalidOperationException("Veldrid.ShaderGen failed -- incomplete shader set.");
            }

            string outputPath = Path.Combine(UserArgs, input.SetName + ".SetInfo.cs");

            using (StreamWriter fs = File.CreateText(outputPath))
            {
                CsCodeWriter ccw = new CsCodeWriter(fs);

                ccw.WriteLine("// This file is generated.");
                ccw.Using("Veldrid");
                ccw.Using("Veldrid.Graphics");

                using (ccw.PushBlock($"public static class {input.SetName}SetInfo"))
                {
                    EmitVertexInputsGetter(input, ccw);
                    EmitResourceDescsGetter(input, ccw);
                    EmitCreateAll(input, ccw);
                }
            }
        }
Example #3
0
        private void EmitResourceDescsGetter(ShaderSetProcessorInput input, CsCodeWriter ccw)
        {
            using (ccw.PushBlock("public static ShaderResourceDescription[] GetResources()"))
            {
                ccw.WriteLine("return new ShaderResourceDescription[]");
                using (ccw.PushBlock(null, ";"))
                {
                    foreach (ResourceDefinition rd in input.Model.Resources)
                    {
                        string name        = rd.Name;
                        string secondParam =
                            rd.ResourceKind == ShaderResourceKind.Texture2D || rd.ResourceKind == ShaderResourceKind.TextureCube
                            ? "ShaderResourceType.Texture"
                            : rd.ResourceKind == ShaderResourceKind.Sampler
                                ? "ShaderResourceType.Sampler"
                                : GetConstantSecondParam(rd.ValueType, input.Model);

                        ccw.WriteLine($"new ShaderResourceDescription(\"{name}\", {secondParam}),");
                    }
                }
            }
        }