]> git.tdb.fi Git - libs/gl.git/blob - extgen.py
Blender exporter:
[libs/gl.git] / extgen.py
1 #!/usr/bin/python
2 # $Id$
3
4 import sys
5
6 ext=sys.argv[1]
7
8 funcs=[]
9 cur_func=None
10 for line in file("gl.spec"):
11         if line[0]=='#' or line.find(':')>=0:
12                 continue
13         elif line[0]=='\t' and cur_func:
14                 parts=line.split()
15                 if parts[0]=="category" and parts[1]==ext:
16                         funcs.append(cur_func)
17         else:
18                 paren=line.find('(')
19                 if paren>0:
20                         cur_func=line[:paren]
21
22 out=file(ext.lower()+".h", "w")
23 out.write("#ifndef MSP_GL_%s_\n"%ext.upper())
24 out.write("#define MSP_GL_%s_\n"%ext.upper())
25
26 out.write("""
27 #include "gl.h"
28 #include <GL/glext.h>
29
30 namespace Msp {
31 namespace GL {
32
33 """)
34
35 for f in funcs:
36         out.write("extern PFNGL%sPROC gl%s;\n"%(f.upper(), f))
37
38 out.write("\nvoid init_%s();\n"%ext.lower())
39
40 out.write("""
41 } // namespace GL
42 } // namespace Msp
43
44 #endif
45 """)
46
47 out=file(ext.lower()+".cpp", "w")
48 out.write("#include \"extension.h\"\n")
49 out.write("#include \"%s.h\"\n"%ext.lower())
50
51 out.write("""
52 namespace Msp {
53 namespace GL {
54
55 """)
56
57 for f in funcs:
58         out.write("PFNGL%sPROC gl%s=0;\n"%(f.upper(), f))
59
60 out.write("\nvoid init_%s()\n{\n"%ext.lower())
61 for f in funcs:
62         out.write("\tgl%s=reinterpret_cast<PFNGL%sPROC>(get_proc_address(\"gl%s\"));\n"%(f, f.upper(), f))
63 out.write("}\n")
64
65 out.write("""
66 } // namespace GL
67 } // namespace Msp
68 """)