forked from lavavu/LavaVu
-
Notifications
You must be signed in to change notification settings - Fork 1
/
extensions.py
executable file
·164 lines (143 loc) · 4 KB
/
extensions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/python
#This script generates Extensions.h/cpp for handling OpenGL extensions
#Define the functions required in the lists below,
#second list is for functions requiring retrieval by pointer on windows only
#We don't use glew because it doesn't work with OSMesa
functions = [
"glBlendFuncSeparate",
"glPointParameterfv",
"glPointParameterf",
"glBindBuffer",
"glGenBuffers",
"glIsBuffer",
"glBufferData",
"glBufferSubData",
"glDeleteBuffers",
"glCreateShader",
"glDeleteShader",
"glShaderSource",
"glCompileShader",
"glAttachShader",
"glIsShader",
"glGetShaderiv",
"glGetShaderInfoLog",
"glCreateProgram",
"glDeleteProgram",
"glLinkProgram",
"glGetProgramiv",
"glUseProgram",
"glGetProgramInfoLog",
"glGenRenderbuffers",
"glBindRenderbuffer",
"glRenderbufferStorage",
"glRenderbufferStorageMultisample",
"glTexImage2DMultisample",
"glGenFramebuffers",
"glFramebufferRenderbuffer",
"glFramebufferTexture2D",
"glCheckFramebufferStatus",
"glBindFramebuffer",
"glDeleteRenderbuffers",
"glDeleteFramebuffers",
"glBlitFramebuffer",
"glGenerateMipmap",
"glGetUniformLocation",
"glUniform1f",
"glUniform1i",
"glUniform2f",
"glUniform1fv",
"glUniform2fv",
"glUniform3fv",
"glUniform4fv",
"glUniform1iv",
"glUniform2iv",
"glUniform3iv",
"glUniform4iv",
"glUniformMatrix4fv",
"glGetActiveUniform",
"glGetActiveAttrib",
"glGetAttribLocation",
"glEnableVertexAttribArray",
"glVertexAttribPointer",
"glDisableVertexAttribArray",
"glGenVertexArrays",
"glDeleteVertexArrays",
"glBindVertexArray",
"glDrawElementsBaseVertex",
"glIsProgram",
"glVertexAttrib1f",
"glVertexAttrib2f",
#"glUniform1d",
#"glUniform1dv",
#"glUniform2d",
#"glUniform2dv",
]
win_functions = [
"glActiveTexture",
"glDrawRangeElements",
"glTexImage3D",
"glTexSubImage3D",
]
#Write the header
header = open("src/Extensions.h", "w")
header.write("//AUTOGENERATED: Global includes header for LavaVu\n")
header.write("#ifndef Extensions__\n")
header.write("#define Extensions__\n")
header.write("\n")
header.write("//Define pointers to required gl 2.0+ functions\n")
header.write("\n")
header.write("typedef void* (*getProcAddressFN)(const char* procName);\n")
header.write("\n")
header.write("#if defined _WIN32\n")
header.write('#include "Include.h"\n')
for fn in win_functions:
header.write("extern PFN" + fn.upper() + "PROC " + fn + ";\n")
header.write("#define EXTENSION_POINTERS\n")
header.write("#else\n")
header.write("extern getProcAddressFN GetProcAddress;\n")
header.write("#endif\n")
header.write("\n")
header.write("#ifdef EXTENSION_POINTERS\n")
for fn in functions:
header.write("extern PFN" + fn.upper() + "PROC " + fn + ";\n")
header.write("#endif\n")
header.write("\n")
header.write("void OpenGL_Extensions_Init();\n")
header.write("\n")
header.write("#endif //Extensions__\n")
header.write("\n")
header.close()
#Write the source
source = open("src/Extensions.cpp", "w")
source.write("//AUTOGENERATED: Global extension handler for LavaVu\n")
source.write("#include \"Extensions.h\"\n")
source.write("\n")
source.write("//Define pointers to required gl 2.0+ functions\n")
source.write("\n")
source.write("#if defined _WIN32\n")
source.write("#define GetProcAddress(arg) wglGetProcAddress((LPCSTR)arg)\n")
for fn in win_functions:
source.write("PFN" + fn.upper() + "PROC " + fn + ";\n")
source.write("#else\n")
source.write("getProcAddressFN GetProcAddress;\n")
source.write("#endif\n")
source.write("\n")
source.write("#ifdef EXTENSION_POINTERS\n")
for fn in functions:
source.write("PFN" + fn.upper() + "PROC " + fn + ";\n")
source.write("#endif\n")
source.write("\n")
source.write("void OpenGL_Extensions_Init()\n")
source.write("{\n")
source.write("#ifdef EXTENSION_POINTERS\n")
source.write("#if defined _WIN32\n")
for fn in win_functions:
source.write(" " + fn + " = (PFN" + fn.upper() + "PROC) GetProcAddress(\"" + fn + "\");\n")
source.write("#endif\n")
for fn in functions:
source.write(" " + fn + " = (PFN" + fn.upper() + "PROC) GetProcAddress(\"" + fn + "\");\n")
source.write("#endif\n")
source.write("}\n")
source.write("\n")
source.write("\n")
source.close()