Beispiel #1
0
        private void GenerateEnum(IndentedTextWriter writer, GLEnum glEnum, GLFeature feature, HashSet <GLChangeReference> collected)
        {
            bool any = false;

            using (var sb = new StringBuilderTextWriter(new StringBuilder()))
                using (var tempWriter = new IndentedTextWriter(sb))
                {
                    tempWriter.Indent = writer.Indent;
                    tempWriter.WriteLine("enum " + glEnum.Name + " : uint");
                    tempWriter.WriteLine("{");

                    using (tempWriter.Indentation())
                    {
                        foreach (var entry in glEnum.Entries)
                        {
                            var reference = new GLChangeReference("enum", entry.Value.Name);

                            if (!collected.Contains(reference))
                            {
                                continue;
                            }
                            any = true;

                            tempWriter.WriteLine(entry.Value.Name + " = " + entry.Value.Value + ",");
                        }
                    }

                    tempWriter.WriteLine("}");

                    if (any)
                    {
                        writer.WriteLine(sb.StringBuilder.ToString());
                    }
                }
        }
Beispiel #2
0
        public void Generate(string outputFileName, IGenerator generator, IGLSpecification spec, GLFeature feature, GLFeature.GLProfile profile, string namesapceName)
        {
            string outputDir = feature.Name;

            if (!Directory.Exists(outputDir))
            {
                Directory.CreateDirectory(outputDir);
            }
            using (var fs = new FileStream(Path.Combine(outputDir, outputFileName), FileMode.Create))
                using (var streamWriter = new StreamWriter(fs))
                    using (var indentedTextWriter = new IndentedTextWriter(streamWriter))
                    {
                        indentedTextWriter.WriteLine("using System;");
                        indentedTextWriter.WriteLine("using System.Runtime.InteropServices;");


                        indentedTextWriter.WriteLine("namespace OpenTK.Graphics" + (string.IsNullOrWhiteSpace(namesapceName) ? string.Empty : "." + namesapceName));
                        indentedTextWriter.WriteLine("{");
                        using (indentedTextWriter.Indentation())
                        {
                            generator.Generate(indentedTextWriter, spec, feature, profile);
                        }

                        indentedTextWriter.WriteLine("}");
                    }
        }
Beispiel #3
0
        private void GenerateSpecialNumbers(IndentedTextWriter writer, GLEnum glEnum, GLFeature feature, HashSet <GLChangeReference> collected)
        {
            bool any = false;

            using (var sb = new StringBuilderTextWriter(new StringBuilder()))
                using (var tempWriter = new IndentedTextWriter(sb))
                {
                    tempWriter.Indent = writer.Indent;
                    tempWriter.WriteLine("public static class " + glEnum.Name + "");
                    tempWriter.WriteLine("{");

                    using (tempWriter.Indentation())
                    {
                        foreach (var entry in glEnum.Entries)
                        {
                            var reference = new GLChangeReference("enum", entry.Value.Name);

                            if (!collected.Contains(reference))
                            {
                                continue;
                            }
                            any = true;
                            string dataType = entry.Value.Value <= byte.MaxValue ? "byte" :
                                              entry.Value.Value <= ushort.MaxValue ? "ushort" :
                                              entry.Value.Value <= uint.MaxValue ? "uint" : "ulong";
                            tempWriter.WriteLine($"public static {dataType} {entry.Value.Name} = {entry.Value.Value};");
                        }
                    }

                    tempWriter.WriteLine("}");

                    if (any)
                    {
                        writer.WriteLine(sb.StringBuilder.ToString());
                    }
                }
        }
Beispiel #4
0
        public void Generate(IndentedTextWriter indentedTextWriter, IGLSpecification spec, GLFeature feature, GLFeature.GLProfile profile)
        {
            var collected = feature.CollectFeatures(profile.Name);
            List <(GLMethod m, string name)> delegates = new List <(GLMethod m, string name)>();

            foreach (var t in spec.Types.Values.OfType <GLTypeDef>())
            {
                var resolved = t.OriginalType.Resolved();
                if (resolved.IsMethod)
                {
                    var methodType = (GLMethod)resolved;
                    if (string.IsNullOrEmpty(profile.Name)) // Only add delegates in base profile
                    {
                        delegates.Add((methodType, t.Name));
                    }
                    continue;
                }

                while (resolved.IsTypeDef)
                {
                    resolved = ((GLTypeDef)resolved).OriginalType.Resolved();
                }
                indentedTextWriter.WriteLine("using " + t.Name + " = " + resolved + ";");
            }
            indentedTextWriter.WriteLine("public static unsafe partial class GL");
            indentedTextWriter.WriteLine("{");
            using (indentedTextWriter.Indentation())
            {
                foreach (var(del, delName) in delegates)
                {
                    indentedTextWriter.Write("public delegate " + del.ReturnTypeBase + " " + delName + "(");
                    bool first = true;
                    foreach (var p in del.Parameters)
                    {
                        if (!first)
                        {
                            indentedTextWriter.Write(", ");
                        }
                        var pType = p.Type;
                        if (pType.IsConst)
                        {
                            indentedTextWriter.Write("[Const]");
                            pType = ((GLConstType)pType).ElementType;
                        }
                        indentedTextWriter.Write(pType + " " + p.Name);
                        first = false;
                    }
                    indentedTextWriter.WriteLine(");");
                }

                if (!string.IsNullOrEmpty(profile.Name))
                {
                    indentedTextWriter.WriteLine("public static class " + profile.Name);
                    indentedTextWriter.WriteLine("{");
                    indentedTextWriter.Indent++;
                }



                foreach (var e in spec.Methods.Values)
                {
                    GenerateMethod(indentedTextWriter, e, feature, collected);
                }

                if (!string.IsNullOrEmpty(profile.Name))
                {
                    indentedTextWriter.Indent--;
                    indentedTextWriter.WriteLine("}");
                }
            }
            indentedTextWriter.WriteLine("}");
        }