| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | #!/usr/bin/python | 
					
						
							| 
									
										
										
										
											2019-12-27 22:16:57 +08:00
										 |  |  | import sys | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | import os | 
					
						
							| 
									
										
										
										
											2019-12-27 22:16:57 +08:00
										 |  |  | gDefaultPath = sys.argv[1]#"glsl" | 
					
						
							|  |  |  | gOutputHeadFile = sys.argv[2]#"AllShader.hpp" | 
					
						
							|  |  |  | gOutputSourceFile = sys.argv[3]#"AllShader.cpp" | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | def findAllShader(path): | 
					
						
							|  |  |  |     cmd = "find " + path + " -name \"*.glsl\"" | 
					
						
							|  |  |  |     vexs = os.popen(cmd).read().split('\n') | 
					
						
							|  |  |  |     output = [] | 
					
						
							|  |  |  |     for f in vexs: | 
					
						
							|  |  |  |         if len(f)>1: | 
					
						
							|  |  |  |             output.append(f) | 
					
						
							|  |  |  |     return output | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def getName(fileName): | 
					
						
							| 
									
										
										
										
											2020-01-17 10:20:15 +08:00
										 |  |  |     s1 = fileName.replace("/", "_") | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  |     s1 = s1.replace(".", "_") | 
					
						
							|  |  |  |     return s1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def generateFile(headfile, sourcefile, shaders): | 
					
						
							|  |  |  |     h = "#ifndef OPENGL_GLSL_SHADER_AUTO_GENERATE_H\n#define OPENGL_GLSL_SHADER_AUTO_GENERATE_H\n" | 
					
						
							| 
									
										
										
										
											2019-12-27 22:16:57 +08:00
										 |  |  |     cpp = "#include \"AllShader.hpp\"\n" | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  |     for s in shaders: | 
					
						
							|  |  |  |         name = getName(s) | 
					
						
							| 
									
										
										
										
											2020-08-12 16:57:29 +08:00
										 |  |  |         print(name) | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  |         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" | 
					
						
							|  |  |  |     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); |