/// <summary> /// Super special OpenGL 1 version handler /// </summary> private static void AddVersion1(GLSpec spec, XElement versionElem) { var version = new GLVersion { Api = "GL", Number = "1.0", Profile = string.Empty, Name = "GL10" }; // First we process commands like any other version foreach (var require in versionElem.Elements("require")) { foreach (var commandElem in require.Elements("command")) { var command = new GLCommand { Name = commandElem.Attribute("name").Value }; command.Initialize(commandElem.Document); version.Commands.Add(command); } } // Then we go through all included commands and use all the groups on any parameters // to include all the enums we need from the groups section foreach (var group in (from c in version.Commands from p in c.Parameters select p.Group).Distinct()) { if (string.IsNullOrEmpty(group)) { continue; } foreach (var enumElem in versionElem.Document.Root.Element("groups").Elements("group").Where(e => e.Attribute("name").Value == group).Elements("enum")) { if (!version.Enums.ContainsKey(enumElem.Attribute("name").Value)) { string enumName = enumElem.Attribute("name").Value; version.Enums.Add(enumName, GetEnumValue(versionElem, enumName)); } } } spec.Versions.Add(version); }
/// <summary> /// Creates a given version. /// </summary> private static void AddVersion(GLSpec spec, XElement versionElem, string profile) { var version = new GLVersion { Api = versionElem.Attribute("api").Value.ToUpper(), Number = versionElem.Attribute("number").Value, Profile = profile }; if (version.Api != "GL") { version.Api = "GLES"; } version.Name = version.Api + version.Number.Replace(".", ""); if (!string.IsNullOrEmpty(profile)) { version.Name += "" + profile; } // Add all enums and commands from previous version for (int i = spec.Versions.Count - 1; i >= 0; i--) { var previousVersion = spec.Versions[i]; if (previousVersion.Api == version.Api && (previousVersion.Profile == string.Empty || previousVersion.Profile == version.Profile)) { foreach (var pair in previousVersion.Enums) { version.Enums.Add(pair.Key, pair.Value); } foreach (var command in previousVersion.Commands) { version.Commands.Add(command.Clone()); } // only handle previous one version of same API and profile since it will have folded // all enums/commands in turn break; } } // Include all new enums and commands foreach (var require in versionElem.Elements("require")) { foreach (var enumElem in require.Elements("enum")) { if (!version.Enums.ContainsKey(enumElem.Attribute("name").Value)) { string enumName = enumElem.Attribute("name").Value; version.Enums.Add(enumName, GetEnumValue(versionElem, enumName)); } } foreach (var commandElem in require.Elements("command")) { var command = new GLCommand { Name = commandElem.Attribute("name").Value }; if (version.Commands.Find(c => c.Name == command.Name) != null) { continue; } command.Initialize(commandElem.Document); version.Commands.Add(command); } } // Remove any enums and commands foreach (var remove in versionElem.Elements("remove")) { if (remove.Attribute("profile") == null || remove.Attribute("profile").Value.ToLower() == profile.ToLower()) { foreach (var en in remove.Elements("enum")) { version.Enums.Remove(en.Attribute("name").Value); } foreach (var en in remove.Elements("command")) { version.Commands.RemoveAll(c => c.Name == en.Attribute("name").Value); } } } spec.Versions.Add(version); }