-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexport_shaders.py
67 lines (48 loc) · 1.69 KB
/
export_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
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
import os
SHADER_FILE = 'include/Zenderer/CoreGraphics/ShaderFiles.hpp'
SHADER_PATH = 'data/shaders/'
def shader(path):
data = open(path, 'r').readlines()
return data, len(data)
def main():
header = open(SHADER_FILE, 'r')
data = header.readlines()
header.close()
index = 0
for i in xrange(len(data)):
if data[i].find('// Begin shader data.') != -1:
index = i
break
data = data[:index+1] + ['\n']
for i in os.listdir(SHADER_PATH):
fn = i.split('.')
const = '_'.join([x.upper() for x in fn])
print "Creating shader constant for %s ... " % i,
data.append('%s/// Created from %s.\n' % ((' ' * 4), SHADER_PATH + i))
data.append('%sstatic const string_t %s = string_t(\n' % (' ' * 4, const))
lines, count = shader(SHADER_PATH + i)
for x in xrange(len(lines)):
line = lines[x]
string = ''
if line.strip() != '':
string = '%s"%s\\n"' % ((' ' * 8), line[:-1])
data.append(string + '\n')
data.append('%s);\n\n' % (' ' * 4))
print "Done."
print "Writing %d bytes to %s ... " % (sum([len(x) for x in data]), SHADER_FILE),
header = open(SHADER_FILE, 'w')
header.write(''.join(data))
# Close the namespaces / preprocessor stuff
header.write('''}
}
#endif // ZENDERER__CORE_GRAPHICS__SHADER_FILES_HPP
/** @} **/
''')
header.close()
print "Done."
if __name__ == "__main__":
try:
main()
raw_input("Done.")
except Exception, e:
print "An unhandled exception occured:", repr(e)