-
Notifications
You must be signed in to change notification settings - Fork 4
/
makeshader.py
executable file
·48 lines (45 loc) · 1.42 KB
/
makeshader.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
#!/usr/bin/python
gDefaultPath = "glsl"
gOutputHeadFile = "AllShader.h"
gOutputSourceFile = "glsl/AllShader.cpp"
import os
def findAllShader(path):
cmd = "find " + path + " -name \"*.vex\""
vexs = os.popen(cmd).read().split('\n')
cmd = "find " + path + " -name \"*.fra\""
fras = os.popen(cmd).read().split('\n')
output = []
for f in vexs:
if len(f)>1:
output.append(f)
for f in fras:
if len(f)>1:
output.append(f)
return output
def getName(fileName):
s1 = fileName.replace("/", "_")
s1 = s1.replace(".", "_")
return s1
def generateFile(headfile, sourcefile, shaders):
h = "#ifndef GLSL_SHADER_AUTO_GENERATE_H\n#define GLSL_SHADER_AUTO_GENERATE_H\n"
cpp = "#include \"" + headfile +"\"\n"
for s in shaders:
name = getName(s)
h += "extern const char* " + name + ";\n";
cpp += "const char* " + name + " = \n";
with open(s) as f:
lines = f.read().split("\n")
for l in lines:
if (len(l) < 1):
continue
cpp += "\""+l+"\\n\"\n"
cpp += ";\n"
h+= "#endif"
headfile = "include/" + headfile;
with open(headfile, "w") as f:
f.write(h);
with open(sourcefile, "w") as f:
f.write(cpp);
if __name__ == '__main__':
shaders = findAllShader(gDefaultPath)
generateFile(gOutputHeadFile, gOutputSourceFile, shaders);