]> git.tdb.fi Git - libs/gl.git/blob - extgen.py
Blender exporter: Add support for texture coordinates
[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/gl.h>
28
29 namespace Msp {
30 namespace GL {
31
32 """)
33
34 for f in funcs:
35         out.write("extern PFNGL%sPROC gl%s;\n"%(f.upper(), f))
36
37 out.write("\nvoid init_%s();\n"%ext.lower())
38
39 out.write("""
40 } // namespace GL
41 } // namespace Msp
42
43 #endif
44 """)
45
46 out=file(ext.lower()+".cpp", "w")
47 out.write("#include \"extension.h\"\n")
48 out.write("#include \"%s.h\"\n"%ext.lower())
49
50 out.write("""
51 namespace Msp {
52 namespace GL {
53
54 """)
55
56 for f in funcs:
57         out.write("PFNGL%sPROC gl%s=0;\n"%(f.upper(), f))
58
59 out.write("\nvoid init_%s()\n{\n"%ext.lower())
60 for f in funcs:
61         out.write("\tgl%s=reinterpret_cast<PFNGL%sPROC>(get_proc_address(\"gl%s\"));\n"%(f, f.upper(), f))
62 out.write("}\n")
63
64 out.write("""
65 } // namespace GL
66 } // namespace Msp
67 """)