-
Notifications
You must be signed in to change notification settings - Fork 94
/
read_glsl_spec.py
275 lines (215 loc) · 8.65 KB
/
read_glsl_spec.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# Read the glsl xhtml files and spit out some python code with all of the supported functions in a big list.
# make sure find_glsl.py has created the glsl doc directories
import os
import xml.etree.ElementTree as ET
import shared_glsl
import ntpath
path = os.path.dirname(os.path.abspath(__file__))
sl_extensions =[
'1', '2', '3', '4', 'Coarse', 'Fine', 'Snorm2x16', 'Snorm4x8', '2x16', '4x8', 'Offset', '2x16', '4x8',
]
#versions displayed in tables
version_check = ['','sl1.10' , 'sl1.20' , 'sl1.30' , 'sl1.40' , 'sl1.50' , 'sl3.30' , 'sl4.00' , 'sl4.10' ,'sl4.20' ,'sl4.30' ,'sl4.40' ,'sl4.50' ]
version_check_el = ['','el1.10' , 'el3.00' , 'el3.10' ]
#Get versions for GLSL
def get_versions( path_file ):
xtree = ET.parse(path_file)
element = xtree.find('.//div[@id="versions"]')
table = element[1][0][2]
test = '\u2714'; #this is the check symbol
versions = []
for x in range(1, 13):
text = table[0][x].text
if text == test:
versions.append(version_check[x])
return versions
#Get version for GLSL ES
def get_el_versions( path_file ):
xtree = ET.parse(path_file)
element = xtree.find('.//div[@id="versions"]')
table = element[1][0][2]
test = '\u2714'; #this is the check symbol
versions = []
for x in range(1, 4):
text = table[0][x].text
if text == test:
versions.append(version_check_el[x])
#print "got it in version " + version_check[x]
return versions
def test_extensions(gldir, command):
# See if removing an extension gives us a real entry
for extension in sl_extensions:
if command[-len(extension):] == extension:
command_file = shared_glsl.find_command_file(gldir, command[0:-len(extension)])
if not command_file == False:
return command[0:-len(extension)]
return ""
def test_replacements(gldir, command):
command_docs = test_extensions(gldir, command)
if (len(command_docs)):
return command_docs
#GLSL ES tests
#dfdx
command_test = command.replace("", "x")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test
#GLSL tests
#dfdx
command_test = command.replace("y", "x")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test
#dfdy
for ext in sl_extensions:
command_test = command.replace("y", "x")
command_test = command_test.replace(ext, "")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test
command_test = command.replace("U", "")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test
command_test = command.replace("u", "")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test
command_test = command.replace("imul", "umul")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test
for ext in sl_extensions:
command_test = command.replace("S", "U")
command_test = command_test.replace(ext, "")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test
#I don't think we need anything under this part for GLSL
# Some commands need just a single letter removed
command_test = command.replace("I", "")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test
command_test = command.replace("L", "")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test
command_test = command.replace("Getn", "Get")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test
if command_test != command:
test = test_extensions(gldir, command_test)
if len(test):
return test
command_test = command.replace("Readn", "Read")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test
# Named commands are stored under their non-named equivalents
command_test = command.replace("NamedFramebuffer", "")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test
command_test = command.replace("NamedFramebuffer", "Buffer")
if command_test != command:
test = test_extensions(gldir, command_test)
if len(test):
return test
command_test = command.replace("Named", "")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test
if command_test != command:
test = test_extensions(gldir, command_test)
if len(test):
return test
command_test = command.replace("Named", "").replace("Data", "")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test
command_test = command.replace("Named", "").replace("SubData", "")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test
command_test = command.replace("Texture", "")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test
command_test = command.replace("ArrayAttrib", "AttribArray")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test
command_test = command.replace("VertexArray", "Bind")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test
command_test = command.replace("Array", "")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test
command_test = command.replace("ArrayAttribI", "Attrib")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test
command_test = command.replace("ArrayAttribL", "Attrib")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test
# For glTextureBuffer -> glTexBuffer and glTextureBufferRange -> glTexBufferRange
command_test = command.replace("ture", "")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test
if command_test != command:
return test_extensions(gldir, command_test)
command_test = command.replace("ByRegion", "")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test
return command
#glsl.xml contains only the list of commands
gltree = ET.parse('specs/glsl.xml')
glroot = gltree.getroot()
current_command_list = []
commads = glroot[1];
stored_version_commands = { '' : [ {'':''} ,] }
#load version keys
for x in version_check:
stored_version_commands[x] = [ {'':''} ,];
for x in version_check_el:
stored_version_commands[x] = [ {'':''} ,];
for command in commads:
if command.tag != 'command':
continue
current_command_list.append(command[0][0].text);
support_API = {'el3' , 'sl4' }
# go over all supported API
for api in support_API:
for command_name in current_command_list:
path_file = path+"/"+api+"/"+command_name+".xhtml"
if(os.path.isfile(path_file)):
versions = []
if api[0:2] == 'sl':
versions = get_versions(path_file)
if api[0:2] == 'el':
versions = get_el_versions(path_file)
for x in range(len(versions)):
print(command_name)
stored_version_commands[versions[x]].append({command_name : command_name})
else:
if os.path.exists(api):
test_extensions(api , command_name )
command_file = shared_glsl.find_command_file(api, command_name)
if command_file == False:
command_docs = test_replacements(api, command_name)
command_file = shared_glsl.find_command_file(api, command_docs)
if command_file == False:
print("No command docs file found for " + command_name + " (" + api + ")")
print(command_name + " does not exist")
#Todo: Skip ES errors for now
if api[0:2] != 'el':
assert(False)
else:
versions = []
if api[0:2] == 'sl':
versions = get_versions(path+"/"+api+"/"+command_docs+".xhtml")
if api[0:2] == 'el':
versions = get_el_versions(path+"/"+api+"/"+command_docs+".xhtml")
for x in range(len(versions)):
stored_version_commands[versions[x]].append({command_name : command_docs})
output = open("glsl_spec.py", "w")
output.write("version_commands = {\n")
for version in stored_version_commands:
if version == "":
continue
#print version
output.write(" '" + version[0:5] + "': {\n")
for x in stored_version_commands[version]:
mstring = str(x)
mstring = mstring.replace("{" , "")
mstring = mstring.replace("}" , "")
if mstring == "'': ''":
continue
output.write(" " +mstring+ ",\n")
output.write(" },\n")
output.write("}\n")
output.close()