7 extgen.py <extension> [<version>] [<secondary> ...]"
9 Reads gl.spec and generates files to use <extension>. Any promoted functions
10 are exposed with their promoted names. If <secondary> extensions are given,
11 any promoted functions from those are pulled in as well. <version> can be
12 given to override the version where <extension> was promoted to core."""
16 exttype = ext.split('_')[0]
17 secondary = sys.argv[2:]
19 if secondary and secondary[0][0].isdigit():
20 ver = secondary.pop(0)
24 def __init__(self, name):
29 self.vectorequiv = None
38 if line[0]=='#' or line.find(':')>=0:
43 if parts[0]=="category":
44 cur_func.category = parts[1]
45 elif parts[0]=="vectorequiv":
46 cur_func.vectorequiv = parts[1]
47 elif parts[0]=="alias":
48 cur_func.aliases.append(parts[1])
49 elif parts[0]=="version":
50 cur_func.version = parts[1]
51 elif parts[0]=="delete":
52 del funcs[cur_func.name]
55 paren = line.find('(')
59 cur_func = funcs[name]
61 cur_func = Function(name)
62 funcs[name] = cur_func
65 parse_file("gl.spec.fixes")
67 for f in funcs.itervalues():
68 if f.category==ext or f.category in secondary:
69 if not f.aliases and f.vectorequiv:
70 for g in funcs.itervalues():
71 if g!=f and g.vectorequiv==f.vectorequiv and f.name.startswith(g.name):
72 f.aliases.append(g.name)
80 if f.category==ext and not f.aliases:
84 if e.category==ext or e.category in secondary:
88 funcs = [f for f in funcs.itervalues() if is_relevant(f)]
89 funcs.sort(key=(lambda f: f.name))
93 f.typedef = "PFNGL%sPROC"%f.extfunc.name.upper()
96 if not f.category.startswith("VERSION_"):
99 f.typedef = "PFNGL%sPROC"%f.name.upper()
100 if not f.name.endswith(exttype):
104 ver = map(int, ver.split('.'))
106 out = file(ext.lower()+".h", "w")
107 out.write("#ifndef MSP_GL_%s_\n"%ext.upper())
108 out.write("#define MSP_GL_%s_\n"%ext.upper())
111 #include "extension.h"
113 #include <GL/glext.h>
122 out.write("extern %s gl%s;\n"%(f.typedef, f.name))
124 out.write("\nextern Extension %s;\n"%ext)
133 out = file(ext.lower()+".cpp", "w")
134 out.write("#include \"%s.h\"\n"%ext.lower())
144 out.write("%s gl%s = 0;\n"%(f.typedef, f.name))
146 out.write("\nExtension::SupportLevel init_%s()\n{\n"%ext.lower())
148 out.write("\tif(is_version_at_least(%d, %d)"%tuple(ver))
150 out.write(" || is_supported(\"GL_%s\")"%bp_ext)
151 out.write(")\n\t{\n")
153 out.write("\t\tgl%s = reinterpret_cast<%s>(get_proc_address(\"gl%s\"));\n"%(f.name, f.typedef, f.name))
154 out.write("\t\treturn Extension::CORE;\n")
157 out.write("\tif(is_supported(\"GL_%s\"))\n\t{\n"%(ext))
162 out.write("\t\tgl%s = reinterpret_cast<%s>(get_proc_address(\"gl%s\"));\n"%(f.name, f.typedef, n))
163 out.write("\t\treturn Extension::EXTENSION;\n")
165 out.write("\treturn Extension::UNSUPPORTED;\n")
168 out.write("\nExtension %s(\"GL_%s\", init_%s);\n"%(ext, ext, ext.lower()))