-
Notifications
You must be signed in to change notification settings - Fork 0
/
assemble_shaders.py
41 lines (32 loc) · 1.42 KB
/
assemble_shaders.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
# dict of name, filename pairs. The 'name' will be the name of the variable in javascript.
source_config = {
'shader_fs_text': ('x-shader/x-fragment', 'shader_sources/shader_fs.txt'),
'shader_vs_text': ('x-shader/x-vertex', 'shader_sources/shader_vs.txt'),
'trails_shader_fs_text': ('x-shader/x-fragment', 'shader_sources/trails_shader_fs.txt'),
'trails_shader_vs_text': ('x-shader/x-vertex', 'shader_sources/trails_shader_vs.txt'),
'tex_trails_shader_fs_text': ('x-shader/x-fragment', 'shader_sources/tex_trails_shader_fs.txt'),
'tex_trails_shader_vs_text': ('x-shader/x-vertex', 'shader_sources/tex_trails_shader_vs.txt'),
}
def read():
sources = {}
for name, (ty, fname) in source_config.iteritems():
with open(fname, 'r') as f:
sources[name] = (ty, f.read())
return sources
def write(destname, sources):
def iter_contents():
for name, (ty, data) in sources.iteritems():
##data = data.replace('"', '\\"')
assert '"' not in data
lines = data.splitlines()
yield '{0}: {{ type: "{1}", data: "{2}" }}'.format(name, ty, '\\n\\\n'.join(lines))
with open(destname, 'w') as f:
f.write('gravity.shaders = {\n')
f.write(',\n'.join(iter_contents()))
f.write('\n}\n')
def main():
destname = 'gravity/shaders.js'
sources = read()
write(destname, sources)
if __name__ == '__main__':
main()