methods.py 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636
  1. import os
  2. def add_source_files(self, sources, filetype, lib_env=None, shared=False):
  3. import glob
  4. import string
  5. # if not lib_objects:
  6. if not lib_env:
  7. lib_env = self
  8. if type(filetype) == type(""):
  9. dir = self.Dir('.').abspath
  10. list = glob.glob(dir + "/" + filetype)
  11. for f in list:
  12. sources.append(self.Object(f))
  13. else:
  14. for f in filetype:
  15. sources.append(self.Object(f))
  16. def build_shader_header(target, source, env):
  17. for x in source:
  18. print x
  19. name = str(x)
  20. name = name[name.rfind("/") + 1:]
  21. name = name[name.rfind("\\") + 1:]
  22. name = name.replace(".", "_")
  23. fs = open(str(x), "r")
  24. fd = open(str(x) + ".h", "w")
  25. fd.write("/* this file has been generated by SCons, do not edit! */\n")
  26. fd.write("static const char *" + name + "=\n")
  27. line = fs.readline()
  28. while(line):
  29. line = line.replace("\r", "")
  30. line = line.replace("\n", "")
  31. line = line.replace("\\", "\\\\")
  32. line = line.replace("\"", "\\\"")
  33. fd.write("\"" + line + "\\n\"\n")
  34. line = fs.readline()
  35. fd.write(";\n")
  36. return 0
  37. def build_glsl_header(filename):
  38. fs = open(filename, "r")
  39. line = fs.readline()
  40. vertex_lines = []
  41. fragment_lines = []
  42. uniforms = []
  43. attributes = []
  44. fbos = []
  45. conditionals = []
  46. texunits = []
  47. texunit_names = []
  48. ubos = []
  49. ubo_names = []
  50. reading = ""
  51. line_offset = 0
  52. vertex_offset = 0
  53. fragment_offset = 0
  54. while(line):
  55. if (line.find("[vertex]") != -1):
  56. reading = "vertex"
  57. line = fs.readline()
  58. line_offset += 1
  59. vertex_offset = line_offset
  60. continue
  61. if (line.find("[fragment]") != -1):
  62. reading = "fragment"
  63. line = fs.readline()
  64. line_offset += 1
  65. fragment_offset = line_offset
  66. continue
  67. if (line.find("#ifdef ") != -1):
  68. ifdefline = line.replace("#ifdef ", "").strip()
  69. if (not ifdefline in conditionals):
  70. conditionals += [ifdefline]
  71. if (line.find("#elif defined(") != -1):
  72. ifdefline = line.replace("#elif defined(", "").strip()
  73. ifdefline = ifdefline.replace(")", "").strip()
  74. if (not ifdefline in conditionals):
  75. conditionals += [ifdefline]
  76. import re
  77. if re.search(r"^\s*uniform", line):
  78. if (line.lower().find("texunit:") != -1):
  79. # texture unit
  80. texunit = str(int(line[line.find(":") + 1:].strip()))
  81. uline = line[:line.lower().find("//")]
  82. uline = uline.replace("uniform", "")
  83. uline = uline.replace(";", "")
  84. lines = uline.split(",")
  85. for x in lines:
  86. x = x.strip()
  87. x = x[x.rfind(" ") + 1:]
  88. if (x.find("[") != -1):
  89. # unfiorm array
  90. x = x[:x.find("[")]
  91. if (not x in texunit_names):
  92. texunits += [(x, texunit)]
  93. texunit_names += [x]
  94. elif (line.lower().find("ubo:") != -1):
  95. # ubo
  96. uboidx = str(int(line[line.find(":") + 1:].strip()))
  97. uline = line[:line.lower().find("//")]
  98. uline = uline[uline.find("uniform") + len("uniform"):]
  99. uline = uline.replace(";", "")
  100. uline = uline.replace("{", "").strip()
  101. lines = uline.split(",")
  102. for x in lines:
  103. x = x.strip()
  104. x = x[x.rfind(" ") + 1:]
  105. if (x.find("[") != -1):
  106. # unfiorm array
  107. x = x[:x.find("[")]
  108. if (not x in ubo_names):
  109. ubos += [(x, uboidx)]
  110. ubo_names += [x]
  111. else:
  112. uline = line.replace("uniform", "")
  113. uline = uline.replace(";", "")
  114. lines = uline.split(",")
  115. for x in lines:
  116. x = x.strip()
  117. x = x[x.rfind(" ") + 1:]
  118. if (x.find("[") != -1):
  119. # unfiorm array
  120. x = x[:x.find("[")]
  121. if (not x in uniforms):
  122. uniforms += [x]
  123. if ((line.strip().find("in ") == 0 or line.strip().find("attribute ") == 0) and line.find("attrib:") != -1):
  124. uline = line.replace("in ", "")
  125. uline = uline.replace("attribute ", "")
  126. uline = uline.replace(";", "")
  127. uline = uline[uline.find(" "):].strip()
  128. if (uline.find("//") != -1):
  129. name, bind = uline.split("//")
  130. if (bind.find("attrib:") != -1):
  131. name = name.strip()
  132. bind = bind.replace("attrib:", "").strip()
  133. attributes += [(name, bind)]
  134. if (line.strip().find("out ") == 0):
  135. uline = line.replace("out", "").strip()
  136. uline = uline.replace(";", "")
  137. uline = uline[uline.find(" "):].strip()
  138. if (uline.find("//") != -1):
  139. name, bind = uline.split("//")
  140. if (bind.find("drawbuffer:") != -1):
  141. name = name.strip()
  142. bind = bind.replace("drawbuffer:", "").strip()
  143. fbos += [(name, bind)]
  144. line = line.replace("\r", "")
  145. line = line.replace("\n", "")
  146. line = line.replace("\\", "\\\\")
  147. line = line.replace("\"", "\\\"")
  148. # line=line+"\\n\\" no need to anymore
  149. if (reading == "vertex"):
  150. vertex_lines += [line]
  151. if (reading == "fragment"):
  152. fragment_lines += [line]
  153. line = fs.readline()
  154. line_offset += 1
  155. fs.close()
  156. out_file = filename + ".h"
  157. fd = open(out_file, "w")
  158. fd.write("/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */\n")
  159. out_file_base = out_file
  160. out_file_base = out_file_base[out_file_base.rfind("/") + 1:]
  161. out_file_base = out_file_base[out_file_base.rfind("\\") + 1:]
  162. # print("out file "+out_file+" base " +out_file_base)
  163. out_file_ifdef = out_file_base.replace(".", "_").upper()
  164. fd.write("#ifndef " + out_file_ifdef + "\n")
  165. fd.write("#define " + out_file_ifdef + "\n")
  166. out_file_class = out_file_base.replace(".glsl.h", "").title().replace("_", "").replace(".", "") + "ShaderGL"
  167. fd.write("\n\n")
  168. fd.write("#include \"drivers/opengl/shader_gl.h\"\n\n\n")
  169. fd.write("class " + out_file_class + " : public ShaderGL {\n\n")
  170. fd.write("\t virtual String get_shader_name() const { return \"" + out_file_class + "\"; }\n")
  171. fd.write("public:\n\n")
  172. if (len(conditionals)):
  173. fd.write("\tenum Conditionals {\n")
  174. for x in conditionals:
  175. fd.write("\t\t" + x + ",\n")
  176. fd.write("\t};\n\n")
  177. if (len(uniforms)):
  178. fd.write("\tenum Uniforms {\n")
  179. for x in uniforms:
  180. fd.write("\t\t" + x.upper() + ",\n")
  181. fd.write("\t};\n\n")
  182. fd.write("\t_FORCE_INLINE_ int get_uniform(Uniforms p_uniform) const { return _get_uniform(p_uniform); }\n\n")
  183. if (len(conditionals)):
  184. fd.write("\t_FORCE_INLINE_ void set_conditional(Conditionals p_conditional,bool p_enable) { _set_conditional(p_conditional,p_enable); }\n\n")
  185. fd.write("\t#define _FU if (get_uniform(p_uniform)<0) return; ERR_FAIL_COND( get_active()!=this );\n\n ")
  186. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, bool p_value) { _FU glUniform1i(get_uniform(p_uniform),p_value?1:0); }\n\n")
  187. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, float p_value) { _FU glUniform1f(get_uniform(p_uniform),p_value); }\n\n")
  188. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, double p_value) { _FU glUniform1f(get_uniform(p_uniform),p_value); }\n\n")
  189. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, uint8_t p_value) { _FU glUniform1i(get_uniform(p_uniform),p_value); }\n\n")
  190. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, int8_t p_value) { _FU glUniform1i(get_uniform(p_uniform),p_value); }\n\n")
  191. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, uint16_t p_value) { _FU glUniform1i(get_uniform(p_uniform),p_value); }\n\n")
  192. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, int16_t p_value) { _FU glUniform1i(get_uniform(p_uniform),p_value); }\n\n")
  193. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, uint32_t p_value) { _FU glUniform1i(get_uniform(p_uniform),p_value); }\n\n")
  194. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, int32_t p_value) { _FU glUniform1i(get_uniform(p_uniform),p_value); }\n\n")
  195. #fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, uint64_t p_value) { _FU glUniform1i(get_uniform(p_uniform),p_value); }\n\n");
  196. #fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, int64_t p_value) { _FU glUniform1i(get_uniform(p_uniform),p_value); }\n\n");
  197. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, unsigned long p_value) { _FU glUniform1i(get_uniform(p_uniform),p_value); }\n\n")
  198. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, long p_value) { _FU glUniform1i(get_uniform(p_uniform),p_value); }\n\n")
  199. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, const Color& p_color) { _FU GLfloat col[4]={p_color.r,p_color.g,p_color.b,p_color.a}; glUniform4fv(get_uniform(p_uniform),1,col); }\n\n")
  200. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, const Vector2& p_vec2) { _FU GLfloat vec2[2]={p_vec2.x,p_vec2.y}; glUniform2fv(get_uniform(p_uniform),1,vec2); }\n\n")
  201. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, const Vector3& p_vec3) { _FU GLfloat vec3[3]={p_vec3.x,p_vec3.y,p_vec3.z}; glUniform3fv(get_uniform(p_uniform),1,vec3); }\n\n")
  202. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, float p_a, float p_b) { _FU glUniform2f(get_uniform(p_uniform),p_a,p_b); }\n\n")
  203. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, float p_a, float p_b, float p_c) { _FU glUniform3f(get_uniform(p_uniform),p_a,p_b,p_c); }\n\n")
  204. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, float p_a, float p_b, float p_c, float p_d) { _FU glUniform4f(get_uniform(p_uniform),p_a,p_b,p_c,p_d); }\n\n")
  205. fd.write("""\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, const Transform& p_transform) { _FU
  206. const Transform &tr = p_transform;
  207. GLfloat matrix[16]={ /* build a 16x16 matrix */
  208. tr.basis.elements[0][0],
  209. tr.basis.elements[1][0],
  210. tr.basis.elements[2][0],
  211. 0,
  212. tr.basis.elements[0][1],
  213. tr.basis.elements[1][1],
  214. tr.basis.elements[2][1],
  215. 0,
  216. tr.basis.elements[0][2],
  217. tr.basis.elements[1][2],
  218. tr.basis.elements[2][2],
  219. 0,
  220. tr.origin.x,
  221. tr.origin.y,
  222. tr.origin.z,
  223. 1
  224. };
  225. glUniformMatrix4fv(get_uniform(p_uniform),1,false,matrix);
  226. }
  227. """)
  228. fd.write("""\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, const Transform2D& p_transform) { _FU
  229. const Transform2D &tr = p_transform;
  230. GLfloat matrix[16]={ /* build a 16x16 matrix */
  231. tr.elements[0][0],
  232. tr.elements[0][1],
  233. 0,
  234. 0,
  235. tr.elements[1][0],
  236. tr.elements[1][1],
  237. 0,
  238. 0,
  239. 0,
  240. 0,
  241. 1,
  242. 0,
  243. tr.elements[2][0],
  244. tr.elements[2][1],
  245. 0,
  246. 1
  247. };
  248. glUniformMatrix4fv(get_uniform(p_uniform),1,false,matrix);
  249. }
  250. """)
  251. fd.write("""\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, const CameraMatrix& p_matrix) { _FU
  252. GLfloat matrix[16];
  253. for (int i=0;i<4;i++) {
  254. for (int j=0;j<4;j++) {
  255. matrix[i*4+j]=p_matrix.matrix[i][j];
  256. }
  257. }
  258. glUniformMatrix4fv(get_uniform(p_uniform),1,false,matrix);
  259. }; """)
  260. fd.write("\n\n#undef _FU\n\n\n")
  261. fd.write("\tvirtual void init() {\n\n")
  262. if (len(conditionals)):
  263. fd.write("\t\tstatic const char* _conditional_strings[]={\n")
  264. if (len(conditionals)):
  265. for x in conditionals:
  266. fd.write("\t\t\t\"#define " + x + "\\n\",\n")
  267. fd.write("\t\t};\n\n")
  268. else:
  269. fd.write("\t\tstatic const char **_conditional_strings=NULL;\n")
  270. if (len(uniforms)):
  271. fd.write("\t\tstatic const char* _uniform_strings[]={\n")
  272. if (len(uniforms)):
  273. for x in uniforms:
  274. fd.write("\t\t\t\"" + x + "\",\n")
  275. fd.write("\t\t};\n\n")
  276. else:
  277. fd.write("\t\tstatic const char **_uniform_strings=NULL;\n")
  278. if (len(attributes)):
  279. fd.write("\t\tstatic AttributePair _attribute_pairs[]={\n")
  280. for x in attributes:
  281. fd.write("\t\t\t{\"" + x[0] + "\"," + x[1] + "},\n")
  282. fd.write("\t\t};\n\n")
  283. else:
  284. fd.write("\t\tstatic AttributePair *_attribute_pairs=NULL;\n")
  285. if (len(fbos)):
  286. fd.write("\t\tstatic FBOPair _fbo_pairs[]={\n")
  287. for x in fbos:
  288. fd.write("\t\t\t{\"" + x[0] + "\"," + x[1] + "},\n")
  289. fd.write("\t\t};\n\n")
  290. else:
  291. fd.write("\t\tstatic FBOPair *_fbo_pairs=NULL;\n")
  292. if (len(ubos)):
  293. fd.write("\t\tstatic UBOPair _ubo_pairs[]={\n")
  294. for x in ubos:
  295. fd.write("\t\t\t{\"" + x[0] + "\"," + x[1] + "},\n")
  296. fd.write("\t\t};\n\n")
  297. else:
  298. fd.write("\t\tstatic UBOPair *_ubo_pairs=NULL;\n")
  299. if (len(texunits)):
  300. fd.write("\t\tstatic TexUnitPair _texunit_pairs[]={\n")
  301. for x in texunits:
  302. fd.write("\t\t\t{\"" + x[0] + "\"," + x[1] + "},\n")
  303. fd.write("\t\t};\n\n")
  304. else:
  305. fd.write("\t\tstatic TexUnitPair *_texunit_pairs=NULL;\n")
  306. fd.write("\t\tstatic const char* _vertex_code=\"\\\n")
  307. for x in vertex_lines:
  308. fd.write("\t\t\t" + x + "\n")
  309. fd.write("\t\t\";\n\n")
  310. fd.write("\t\tstatic const int _vertex_code_start=" + str(vertex_offset) + ";\n")
  311. fd.write("\t\tstatic const char* _fragment_code=\"\\\n")
  312. for x in fragment_lines:
  313. fd.write("\t\t\t" + x + "\n")
  314. fd.write("\t\t\";\n\n")
  315. fd.write("\t\tstatic const int _fragment_code_start=" + str(fragment_offset) + ";\n")
  316. fd.write("\t\tsetup(_conditional_strings," + str(len(conditionals)) + ",_uniform_strings," + str(len(uniforms)) + ",_attribute_pairs," + str(len(attributes)) + ",_fbo_pairs," + str(len(fbos)) + ",_ubo_pairs," + str(len(ubos)) + ",_texunit_pairs," + str(len(texunits)) + ",_vertex_code,_fragment_code,_vertex_code_start,_fragment_code_start);\n")
  317. fd.write("\t};\n\n")
  318. fd.write("};\n\n")
  319. fd.write("#endif\n\n")
  320. fd.close()
  321. def build_glsl_headers(target, source, env):
  322. for x in source:
  323. build_glsl_header(str(x))
  324. return 0
  325. def build_hlsl_dx9_header(filename):
  326. fs = open(filename, "r")
  327. line = fs.readline()
  328. vertex_lines = []
  329. fragment_lines = []
  330. uniforms = []
  331. fragment_uniforms = []
  332. attributes = []
  333. fbos = []
  334. conditionals = []
  335. reading = ""
  336. line_offset = 0
  337. vertex_offset = 0
  338. fragment_offset = 0
  339. while(line):
  340. if (line.find("[vertex]") != -1):
  341. reading = "vertex"
  342. line = fs.readline()
  343. line_offset += 1
  344. vertex_offset = line_offset
  345. continue
  346. if (line.find("[fragment]") != -1):
  347. reading = "fragment"
  348. line = fs.readline()
  349. line_offset += 1
  350. fragment_offset = line_offset
  351. continue
  352. if (line.find("#ifdef ") != -1):
  353. ifdefline = line.replace("#ifdef ", "").strip()
  354. if (not ifdefline in conditionals):
  355. conditionals += [ifdefline]
  356. if (line.find("#elif defined(") != -1):
  357. ifdefline = line.replace("#elif defined(", "").strip()
  358. ifdefline = ifdefline.replace(")", "").strip()
  359. if (not ifdefline in conditionals):
  360. conditionals += [ifdefline]
  361. if (line.find("uniform") != -1):
  362. uline = line.replace("uniform", "")
  363. uline = uline.replace(";", "")
  364. lines = uline.split(",")
  365. for x in lines:
  366. x = x.strip()
  367. x = x[x.rfind(" ") + 1:]
  368. if (x.find("[") != -1):
  369. # unfiorm array
  370. x = x[:x.find("[")]
  371. if (not x in uniforms):
  372. uniforms += [x]
  373. fragment_uniforms += [reading == "fragment"]
  374. line = line.replace("\r", "")
  375. line = line.replace("\n", "")
  376. line = line.replace("\\", "\\\\")
  377. line = line.replace("\"", "\\\"")
  378. line = line + "\\n\\"
  379. if (reading == "vertex"):
  380. vertex_lines += [line]
  381. if (reading == "fragment"):
  382. fragment_lines += [line]
  383. line = fs.readline()
  384. line_offset += 1
  385. fs.close()
  386. out_file = filename + ".h"
  387. fd = open(out_file, "w")
  388. fd.write("/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */\n")
  389. out_file_base = out_file
  390. out_file_base = out_file_base[out_file_base.rfind("/") + 1:]
  391. out_file_base = out_file_base[out_file_base.rfind("\\") + 1:]
  392. # print("out file "+out_file+" base " +out_file_base)
  393. out_file_ifdef = out_file_base.replace(".", "_").upper()
  394. fd.write("#ifndef " + out_file_ifdef + "\n")
  395. fd.write("#define " + out_file_ifdef + "\n")
  396. out_file_class = out_file_base.replace(".hlsl.h", "").title().replace("_", "").replace(".", "") + "ShaderDX9"
  397. fd.write("\n\n")
  398. fd.write("#include \"drivers/directx9/shader_dx9.h\"\n\n\n")
  399. fd.write("class " + out_file_class + " : public ShaderDX9 {\n\n")
  400. fd.write("\t virtual String get_shader_name() const { return \"" + out_file_class + "\"; }\n")
  401. fd.write("public:\n\n")
  402. if (len(conditionals)):
  403. fd.write("\tenum Conditionals {\n")
  404. for x in conditionals:
  405. fd.write("\t\t" + x + ",\n")
  406. fd.write("\t};\n\n")
  407. if (len(uniforms)):
  408. fd.write("\tenum Uniforms {\n")
  409. for x in uniforms:
  410. fd.write("\t\t" + x.upper() + ",\n")
  411. fd.write("\t};\n\n")
  412. if (len(conditionals)):
  413. fd.write("\t_FORCE_INLINE_ void set_conditional(Conditionals p_conditional,bool p_enable) { _set_conditional(p_conditional,p_enable); }\n\n")
  414. fd.write("\t#define _FU if (!_uniform_valid(p_uniform)) return; ERR_FAIL_COND( get_active()!=this );\n\n ")
  415. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, bool p_value) { _FU set_uniformb(p_uniform,p_value); }\n\n")
  416. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, float p_value) { _FU set_uniformf(p_uniform,p_value); }\n\n")
  417. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, double p_value) { _FU set_uniformf(p_uniform,p_value); }\n\n")
  418. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, uint8_t p_value) { _FU set_uniformi(p_uniform,p_value); }\n\n")
  419. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, int8_t p_value) { _FU set_uniformi(p_uniform,p_value); }\n\n")
  420. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, uint16_t p_value) { _FU set_uniformi(p_uniform,p_value); }\n\n")
  421. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, int16_t p_value) { _FU set_uniformi(p_uniform,p_value); }\n\n")
  422. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, uint32_t p_value) { _FU set_uniformi(p_uniform,p_value); }\n\n")
  423. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, int32_t p_value) { _FU set_uniformi(p_uniform,p_value); }\n\n")
  424. #fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, uint64_t p_value) { _FU set_uniformi(p_uniform,p_value); }\n\n");
  425. #fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, int64_t p_value) { _FU set_uniformi(p_uniform,p_value); }\n\n");
  426. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, unsigned long p_value) { _FU set_uniformi(p_uniform,p_value); }\n\n")
  427. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, long p_value) { _FU set_uniformi(p_uniform,p_value); }\n\n")
  428. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, const Color& p_color) { _FU float col[4]={p_color.r,p_color.g,p_color.b,p_color.a}; set_uniformfv(p_uniform,col); }\n\n")
  429. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, const Vector2& p_vec2) { _FU float vec2[4]={p_vec2.x,p_vec2.y,0,0}; set_uniformfv(p_uniform,vec2); }\n\n")
  430. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, const Vector3& p_vec3) { _FU float vec3[4]={p_vec3.x,p_vec3.y,p_vec3.z,0}; set_uniformfv(p_uniform,vec3); }\n\n")
  431. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, float p_a, float p_b) { _FU float vec2[4]={p_a,p_b,0,0}; set_uniformfv(p_uniform,vec2); }\n\n")
  432. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, float p_a, float p_b, float p_c) { _FU float vec3[4]={p_a,p_b,p_c,0}; set_uniformfv(p_uniform,vec3); }\n\n")
  433. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, float p_a, float p_b, float p_c, float p_d) { _FU float vec4[4]={p_a,p_b,p_c,p_d}; set_uniformfv(p_uniform,vec4); }\n\n")
  434. fd.write("""\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, const Transform& p_transform) { _FU
  435. const Transform &tr = p_transform;
  436. float matrix[16]={ /* build a 16x16 matrix */
  437. tr.basis.elements[0][0],
  438. tr.basis.elements[0][1],
  439. tr.basis.elements[0][2],
  440. tr.origin.x,
  441. tr.basis.elements[1][0],
  442. tr.basis.elements[1][1],
  443. tr.basis.elements[1][2],
  444. tr.origin.y,
  445. tr.basis.elements[2][0],
  446. tr.basis.elements[2][1],
  447. tr.basis.elements[2][2],
  448. tr.origin.z,
  449. 0,
  450. 0,
  451. 0,
  452. 1
  453. };
  454. set_uniformfv(p_uniform,&matrix[0],4);
  455. }
  456. """)
  457. fd.write("""\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, const CameraMatrix& p_matrix) { _FU
  458. float matrix[16];
  459. for (int i=0;i<4;i++) {
  460. for (int j=0;j<4;j++) {
  461. matrix[i*4+j]=p_matrix.matrix[j][i];
  462. }
  463. }
  464. set_uniformfv(p_uniform,&matrix[0],4);
  465. }; """)
  466. fd.write("\n\n#undef _FU\n\n\n")
  467. fd.write("\tvirtual void init(IDirect3DDevice9 *p_device,ShaderSupport p_version) {\n\n")
  468. if (len(conditionals)):
  469. fd.write("\t\tstatic const char* _conditional_strings[]={\n")
  470. if (len(conditionals)):
  471. for x in conditionals:
  472. fd.write("\t\t\t\"" + x + "\",\n")
  473. fd.write("\t\t};\n\n")
  474. else:
  475. fd.write("\t\tstatic const char **_conditional_strings=NULL;\n")
  476. if (len(uniforms)):
  477. fd.write("\t\tstatic const char* _uniform_strings[]={\n")
  478. if (len(uniforms)):
  479. for x in uniforms:
  480. fd.write("\t\t\t\"" + x + "\",\n")
  481. fd.write("\t\t};\n\n")
  482. fd.write("\t\tstatic const bool _fragment_uniforms[]={\n")
  483. if (len(uniforms)):
  484. for x in fragment_uniforms:
  485. if (x):
  486. fd.write("\t\t\ttrue,\n")
  487. else:
  488. fd.write("\t\t\tfalse,\n")
  489. fd.write("\t\t};\n\n")
  490. else:
  491. fd.write("\t\tstatic const char **_uniform_strings=NULL;\n")
  492. fd.write("\t\tstatic const bool *_fragment_uniforms=NULL;\n")
  493. fd.write("\t\tstatic const char* _vertex_code=\"\\\n")
  494. for x in vertex_lines:
  495. fd.write("\t\t\t" + x + "\n")
  496. fd.write("\t\t\";\n\n")
  497. fd.write("\t\tstatic const int _vertex_code_start=" + str(vertex_offset) + ";\n")
  498. fd.write("\t\tstatic const char* _fragment_code=\"\\\n")
  499. for x in fragment_lines:
  500. fd.write("\t\t\t" + x + "\n")
  501. fd.write("\t\t\";\n\n")
  502. fd.write("\t\tstatic const int _fragment_code_start=" + str(fragment_offset) + ";\n")
  503. fd.write("\t\tsetup(p_device,p_version,_conditional_strings," + str(len(conditionals)) + ",_uniform_strings," + str(len(uniforms)) + ",_fragment_uniforms,_vertex_code,_fragment_code,_vertex_code_start,_fragment_code_start);\n")
  504. fd.write("\t};\n\n")
  505. fd.write("};\n\n")
  506. fd.write("#endif\n\n")
  507. fd.close()
  508. def build_hlsl_dx9_headers(target, source, env):
  509. for x in source:
  510. build_hlsl_dx9_header(str(x))
  511. return 0
  512. class LegacyGLHeaderStruct:
  513. def __init__(self):
  514. self.vertex_lines = []
  515. self.fragment_lines = []
  516. self.uniforms = []
  517. self.attributes = []
  518. self.feedbacks = []
  519. self.fbos = []
  520. self.conditionals = []
  521. self.enums = {}
  522. self.texunits = []
  523. self.texunit_names = []
  524. self.ubos = []
  525. self.ubo_names = []
  526. self.vertex_included_files = []
  527. self.fragment_included_files = []
  528. self.reading = ""
  529. self.line_offset = 0
  530. self.vertex_offset = 0
  531. self.fragment_offset = 0
  532. def include_file_in_legacygl_header(filename, header_data, depth):
  533. fs = open(filename, "r")
  534. line = fs.readline()
  535. while(line):
  536. if (line.find("[vertex]") != -1):
  537. header_data.reading = "vertex"
  538. line = fs.readline()
  539. header_data.line_offset += 1
  540. header_data.vertex_offset = header_data.line_offset
  541. continue
  542. if (line.find("[fragment]") != -1):
  543. header_data.reading = "fragment"
  544. line = fs.readline()
  545. header_data.line_offset += 1
  546. header_data.fragment_offset = header_data.line_offset
  547. continue
  548. while(line.find("#include ") != -1):
  549. includeline = line.replace("#include ", "").strip()[1:-1]
  550. import os.path
  551. included_file = os.path.relpath(os.path.dirname(filename) + "/" + includeline)
  552. if (not included_file in header_data.vertex_included_files and header_data.reading == "vertex"):
  553. header_data.vertex_included_files += [included_file]
  554. if(include_file_in_legacygl_header(included_file, header_data, depth + 1) == None):
  555. print "Error in file '" + filename + "': #include " + includeline + "could not be found!"
  556. elif (not included_file in header_data.fragment_included_files and header_data.reading == "fragment"):
  557. header_data.fragment_included_files += [included_file]
  558. if(include_file_in_legacygl_header(included_file, header_data, depth + 1) == None):
  559. print "Error in file '" + filename + "': #include " + includeline + "could not be found!"
  560. line = fs.readline()
  561. if (line.find("#ifdef ") != -1 or line.find("#elif defined(") != -1):
  562. if (line.find("#ifdef ") != -1):
  563. ifdefline = line.replace("#ifdef ", "").strip()
  564. else:
  565. ifdefline = line.replace("#elif defined(", "").strip()
  566. ifdefline = ifdefline.replace(")", "").strip()
  567. if (line.find("_EN_") != -1):
  568. enumbase = ifdefline[:ifdefline.find("_EN_")]
  569. ifdefline = ifdefline.replace("_EN_", "_")
  570. line = line.replace("_EN_", "_")
  571. # print(enumbase+":"+ifdefline);
  572. if (enumbase not in header_data.enums):
  573. header_data.enums[enumbase] = []
  574. if (ifdefline not in header_data.enums[enumbase]):
  575. header_data.enums[enumbase].append(ifdefline)
  576. elif (not ifdefline in header_data.conditionals):
  577. header_data.conditionals += [ifdefline]
  578. if (line.find("uniform") != -1 and line.lower().find("texunit:") != -1):
  579. # texture unit
  580. texunitstr = line[line.find(":") + 1:].strip()
  581. if (texunitstr == "auto"):
  582. texunit = "-1"
  583. else:
  584. texunit = str(int(texunitstr))
  585. uline = line[:line.lower().find("//")]
  586. uline = uline.replace("uniform", "")
  587. uline = uline.replace("highp", "")
  588. uline = uline.replace(";", "")
  589. lines = uline.split(",")
  590. for x in lines:
  591. x = x.strip()
  592. x = x[x.rfind(" ") + 1:]
  593. if (x.find("[") != -1):
  594. # unfiorm array
  595. x = x[:x.find("[")]
  596. if (not x in header_data.texunit_names):
  597. header_data.texunits += [(x, texunit)]
  598. header_data.texunit_names += [x]
  599. elif (line.find("uniform") != -1 and line.lower().find("ubo:") != -1):
  600. # uniform buffer object
  601. ubostr = line[line.find(":") + 1:].strip()
  602. ubo = str(int(ubostr))
  603. uline = line[:line.lower().find("//")]
  604. uline = uline[uline.find("uniform") + len("uniform"):]
  605. uline = uline.replace("highp", "")
  606. uline = uline.replace(";", "")
  607. uline = uline.replace("{", "").strip()
  608. lines = uline.split(",")
  609. for x in lines:
  610. x = x.strip()
  611. x = x[x.rfind(" ") + 1:]
  612. if (x.find("[") != -1):
  613. # unfiorm array
  614. x = x[:x.find("[")]
  615. if (not x in header_data.ubo_names):
  616. header_data.ubos += [(x, ubo)]
  617. header_data.ubo_names += [x]
  618. elif (line.find("uniform") != -1 and line.find("{") == -1 and line.find(";") != -1):
  619. uline = line.replace("uniform", "")
  620. uline = uline.replace(";", "")
  621. lines = uline.split(",")
  622. for x in lines:
  623. x = x.strip()
  624. x = x[x.rfind(" ") + 1:]
  625. if (x.find("[") != -1):
  626. # unfiorm array
  627. x = x[:x.find("[")]
  628. if (not x in header_data.uniforms):
  629. header_data.uniforms += [x]
  630. if (line.strip().find("attribute ") == 0 and line.find("attrib:") != -1):
  631. uline = line.replace("in ", "")
  632. uline = uline.replace("attribute ", "")
  633. uline = uline.replace("highp ", "")
  634. uline = uline.replace(";", "")
  635. uline = uline[uline.find(" "):].strip()
  636. if (uline.find("//") != -1):
  637. name, bind = uline.split("//")
  638. if (bind.find("attrib:") != -1):
  639. name = name.strip()
  640. bind = bind.replace("attrib:", "").strip()
  641. header_data.attributes += [(name, bind)]
  642. if (line.strip().find("out ") == 0 and line.find("tfb:") != -1):
  643. uline = line.replace("out ", "")
  644. uline = uline.replace("highp ", "")
  645. uline = uline.replace(";", "")
  646. uline = uline[uline.find(" "):].strip()
  647. if (uline.find("//") != -1):
  648. name, bind = uline.split("//")
  649. if (bind.find("tfb:") != -1):
  650. name = name.strip()
  651. bind = bind.replace("tfb:", "").strip()
  652. header_data.feedbacks += [(name, bind)]
  653. line = line.replace("\r", "")
  654. line = line.replace("\n", "")
  655. # line=line.replace("\\","\\\\")
  656. # line=line.replace("\"","\\\"")
  657. # line=line+"\\n\\"
  658. if (header_data.reading == "vertex"):
  659. header_data.vertex_lines += [line]
  660. if (header_data.reading == "fragment"):
  661. header_data.fragment_lines += [line]
  662. line = fs.readline()
  663. header_data.line_offset += 1
  664. fs.close()
  665. return header_data
  666. def build_legacygl_header(filename, include, class_suffix, output_attribs):
  667. header_data = LegacyGLHeaderStruct()
  668. include_file_in_legacygl_header(filename, header_data, 0)
  669. out_file = filename + ".h"
  670. fd = open(out_file, "w")
  671. enum_constants = []
  672. fd.write("/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */\n")
  673. out_file_base = out_file
  674. out_file_base = out_file_base[out_file_base.rfind("/") + 1:]
  675. out_file_base = out_file_base[out_file_base.rfind("\\") + 1:]
  676. # print("out file "+out_file+" base " +out_file_base)
  677. out_file_ifdef = out_file_base.replace(".", "_").upper()
  678. fd.write("#ifndef " + out_file_ifdef + class_suffix + "_120\n")
  679. fd.write("#define " + out_file_ifdef + class_suffix + "_120\n")
  680. out_file_class = out_file_base.replace(".glsl.h", "").title().replace("_", "").replace(".", "") + "Shader" + class_suffix
  681. fd.write("\n\n")
  682. fd.write("#include \"" + include + "\"\n\n\n")
  683. fd.write("class " + out_file_class + " : public Shader" + class_suffix + " {\n\n")
  684. fd.write("\t virtual String get_shader_name() const { return \"" + out_file_class + "\"; }\n")
  685. fd.write("public:\n\n")
  686. if (len(header_data.conditionals)):
  687. fd.write("\tenum Conditionals {\n")
  688. for x in header_data.conditionals:
  689. fd.write("\t\t" + x.upper() + ",\n")
  690. fd.write("\t};\n\n")
  691. if (len(header_data.uniforms)):
  692. fd.write("\tenum Uniforms {\n")
  693. for x in header_data.uniforms:
  694. fd.write("\t\t" + x.upper() + ",\n")
  695. fd.write("\t};\n\n")
  696. fd.write("\t_FORCE_INLINE_ int get_uniform(Uniforms p_uniform) const { return _get_uniform(p_uniform); }\n\n")
  697. if (len(header_data.conditionals)):
  698. fd.write("\t_FORCE_INLINE_ void set_conditional(Conditionals p_conditional,bool p_enable) { _set_conditional(p_conditional,p_enable); }\n\n")
  699. fd.write("\t#define _FU if (get_uniform(p_uniform)<0) return; ERR_FAIL_COND( get_active()!=this );\n\n ")
  700. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, float p_value) { _FU glUniform1f(get_uniform(p_uniform),p_value); }\n\n")
  701. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, double p_value) { _FU glUniform1f(get_uniform(p_uniform),p_value); }\n\n")
  702. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, uint8_t p_value) { _FU glUniform1i(get_uniform(p_uniform),p_value); }\n\n")
  703. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, int8_t p_value) { _FU glUniform1i(get_uniform(p_uniform),p_value); }\n\n")
  704. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, uint16_t p_value) { _FU glUniform1i(get_uniform(p_uniform),p_value); }\n\n")
  705. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, int16_t p_value) { _FU glUniform1i(get_uniform(p_uniform),p_value); }\n\n")
  706. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, uint32_t p_value) { _FU glUniform1i(get_uniform(p_uniform),p_value); }\n\n")
  707. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, int32_t p_value) { _FU glUniform1i(get_uniform(p_uniform),p_value); }\n\n")
  708. #fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, uint64_t p_value) { _FU glUniform1i(get_uniform(p_uniform),p_value); }\n\n");
  709. #fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, int64_t p_value) { _FU glUniform1i(get_uniform(p_uniform),p_value); }\n\n");
  710. #fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, unsigned long p_value) { _FU glUniform1i(get_uniform(p_uniform),p_value); }\n\n");
  711. #fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, long p_value) { _FU glUniform1i(get_uniform(p_uniform),p_value); }\n\n");
  712. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, const Color& p_color) { _FU GLfloat col[4]={p_color.r,p_color.g,p_color.b,p_color.a}; glUniform4fv(get_uniform(p_uniform),1,col); }\n\n")
  713. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, const Vector2& p_vec2) { _FU GLfloat vec2[2]={p_vec2.x,p_vec2.y}; glUniform2fv(get_uniform(p_uniform),1,vec2); }\n\n")
  714. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, const Vector3& p_vec3) { _FU GLfloat vec3[3]={p_vec3.x,p_vec3.y,p_vec3.z}; glUniform3fv(get_uniform(p_uniform),1,vec3); }\n\n")
  715. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, float p_a, float p_b) { _FU glUniform2f(get_uniform(p_uniform),p_a,p_b); }\n\n")
  716. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, float p_a, float p_b, float p_c) { _FU glUniform3f(get_uniform(p_uniform),p_a,p_b,p_c); }\n\n")
  717. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, float p_a, float p_b, float p_c, float p_d) { _FU glUniform4f(get_uniform(p_uniform),p_a,p_b,p_c,p_d); }\n\n")
  718. fd.write("""\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, const Transform& p_transform) { _FU
  719. const Transform &tr = p_transform;
  720. GLfloat matrix[16]={ /* build a 16x16 matrix */
  721. tr.basis.elements[0][0],
  722. tr.basis.elements[1][0],
  723. tr.basis.elements[2][0],
  724. 0,
  725. tr.basis.elements[0][1],
  726. tr.basis.elements[1][1],
  727. tr.basis.elements[2][1],
  728. 0,
  729. tr.basis.elements[0][2],
  730. tr.basis.elements[1][2],
  731. tr.basis.elements[2][2],
  732. 0,
  733. tr.origin.x,
  734. tr.origin.y,
  735. tr.origin.z,
  736. 1
  737. };
  738. glUniformMatrix4fv(get_uniform(p_uniform),1,false,matrix);
  739. }
  740. """)
  741. fd.write("""\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, const Transform2D& p_transform) { _FU
  742. const Transform2D &tr = p_transform;
  743. GLfloat matrix[16]={ /* build a 16x16 matrix */
  744. tr.elements[0][0],
  745. tr.elements[0][1],
  746. 0,
  747. 0,
  748. tr.elements[1][0],
  749. tr.elements[1][1],
  750. 0,
  751. 0,
  752. 0,
  753. 0,
  754. 1,
  755. 0,
  756. tr.elements[2][0],
  757. tr.elements[2][1],
  758. 0,
  759. 1
  760. };
  761. glUniformMatrix4fv(get_uniform(p_uniform),1,false,matrix);
  762. }
  763. """)
  764. fd.write("""\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, const CameraMatrix& p_matrix) { _FU
  765. GLfloat matrix[16];
  766. for (int i=0;i<4;i++) {
  767. for (int j=0;j<4;j++) {
  768. matrix[i*4+j]=p_matrix.matrix[i][j];
  769. }
  770. }
  771. glUniformMatrix4fv(get_uniform(p_uniform),1,false,matrix);
  772. }; """)
  773. fd.write("\n\n#undef _FU\n\n\n")
  774. fd.write("\tvirtual void init() {\n\n")
  775. enum_value_count = 0
  776. if (len(header_data.enums)):
  777. fd.write("\t\t//Written using math, given nonstandarity of 64 bits integer constants..\n")
  778. fd.write("\t\tstatic const Enum _enums[]={\n")
  779. bitofs = len(header_data.conditionals)
  780. enum_vals = []
  781. for xv in header_data.enums:
  782. x = header_data.enums[xv]
  783. bits = 1
  784. amt = len(x)
  785. # print(x)
  786. while(2**bits < amt):
  787. bits += 1
  788. # print("amount: "+str(amt)+" bits "+str(bits));
  789. strs = "{"
  790. for i in range(amt):
  791. strs += "\"#define " + x[i] + "\\n\","
  792. v = {}
  793. v["set_mask"] = "uint64_t(" + str(i) + ")<<" + str(bitofs)
  794. v["clear_mask"] = "((uint64_t(1)<<40)-1) ^ (((uint64_t(1)<<" + str(bits) + ") - 1)<<" + str(bitofs) + ")"
  795. enum_vals.append(v)
  796. enum_constants.append(x[i])
  797. strs += "NULL}"
  798. fd.write("\t\t\t{(uint64_t(1<<" + str(bits) + ")-1)<<" + str(bitofs) + "," + str(bitofs) + "," + strs + "},\n")
  799. bitofs += bits
  800. fd.write("\t\t};\n\n")
  801. fd.write("\t\tstatic const EnumValue _enum_values[]={\n")
  802. enum_value_count = len(enum_vals)
  803. for x in enum_vals:
  804. fd.write("\t\t\t{" + x["set_mask"] + "," + x["clear_mask"] + "},\n")
  805. fd.write("\t\t};\n\n")
  806. else:
  807. fd.write("\t\tstatic const Enum *_enums=NULL;\n")
  808. fd.write("\t\tstatic const EnumValue *_enum_values=NULL;\n")
  809. conditionals_found = []
  810. if (len(header_data.conditionals)):
  811. fd.write("\t\tstatic const char* _conditional_strings[]={\n")
  812. if (len(header_data.conditionals)):
  813. for x in header_data.conditionals:
  814. fd.write("\t\t\t\"#define " + x + "\\n\",\n")
  815. conditionals_found.append(x)
  816. fd.write("\t\t};\n\n")
  817. else:
  818. fd.write("\t\tstatic const char **_conditional_strings=NULL;\n")
  819. if (len(header_data.uniforms)):
  820. fd.write("\t\tstatic const char* _uniform_strings[]={\n")
  821. if (len(header_data.uniforms)):
  822. for x in header_data.uniforms:
  823. fd.write("\t\t\t\"" + x + "\",\n")
  824. fd.write("\t\t};\n\n")
  825. else:
  826. fd.write("\t\tstatic const char **_uniform_strings=NULL;\n")
  827. if output_attribs:
  828. if (len(header_data.attributes)):
  829. fd.write("\t\tstatic AttributePair _attribute_pairs[]={\n")
  830. for x in header_data.attributes:
  831. fd.write("\t\t\t{\"" + x[0] + "\"," + x[1] + "},\n")
  832. fd.write("\t\t};\n\n")
  833. else:
  834. fd.write("\t\tstatic AttributePair *_attribute_pairs=NULL;\n")
  835. feedback_count = 0
  836. if (len(header_data.feedbacks)):
  837. fd.write("\t\tstatic const Feedback _feedbacks[]={\n")
  838. for x in header_data.feedbacks:
  839. name = x[0]
  840. cond = x[1]
  841. if (cond in conditionals_found):
  842. fd.write("\t\t\t{\"" + name + "\"," + str(conditionals_found.index(cond)) + "},\n")
  843. else:
  844. fd.write("\t\t\t{\"" + name + "\",-1},\n")
  845. feedback_count += 1
  846. fd.write("\t\t};\n\n")
  847. else:
  848. fd.write("\t\tstatic const Feedback* _feedbacks=NULL;\n")
  849. if (len(header_data.texunits)):
  850. fd.write("\t\tstatic TexUnitPair _texunit_pairs[]={\n")
  851. for x in header_data.texunits:
  852. fd.write("\t\t\t{\"" + x[0] + "\"," + x[1] + "},\n")
  853. fd.write("\t\t};\n\n")
  854. else:
  855. fd.write("\t\tstatic TexUnitPair *_texunit_pairs=NULL;\n")
  856. if (len(header_data.ubos)):
  857. fd.write("\t\tstatic UBOPair _ubo_pairs[]={\n")
  858. for x in header_data.ubos:
  859. fd.write("\t\t\t{\"" + x[0] + "\"," + x[1] + "},\n")
  860. fd.write("\t\t};\n\n")
  861. else:
  862. fd.write("\t\tstatic UBOPair *_ubo_pairs=NULL;\n")
  863. fd.write("\t\tstatic const char _vertex_code[]={\n")
  864. for x in header_data.vertex_lines:
  865. for i in range(len(x)):
  866. fd.write(str(ord(x[i])) + ",")
  867. fd.write(str(ord('\n')) + ",")
  868. fd.write("\t\t0};\n\n")
  869. fd.write("\t\tstatic const int _vertex_code_start=" + str(header_data.vertex_offset) + ";\n")
  870. fd.write("\t\tstatic const char _fragment_code[]={\n")
  871. for x in header_data.fragment_lines:
  872. for i in range(len(x)):
  873. fd.write(str(ord(x[i])) + ",")
  874. fd.write(str(ord('\n')) + ",")
  875. fd.write("\t\t0};\n\n")
  876. fd.write("\t\tstatic const int _fragment_code_start=" + str(header_data.fragment_offset) + ";\n")
  877. if output_attribs:
  878. fd.write("\t\tsetup(_conditional_strings," + str(len(header_data.conditionals)) + ",_uniform_strings," + str(len(header_data.uniforms)) + ",_attribute_pairs," + str(len(header_data.attributes)) + ", _texunit_pairs," + str(len(header_data.texunits)) + ",_ubo_pairs," + str(len(header_data.ubos)) + ",_feedbacks," + str(feedback_count) + ",_vertex_code,_fragment_code,_vertex_code_start,_fragment_code_start);\n")
  879. else:
  880. fd.write("\t\tsetup(_conditional_strings," + str(len(header_data.conditionals)) + ",_uniform_strings," + str(len(header_data.uniforms)) + ",_texunit_pairs," + str(len(header_data.texunits)) + ",_enums," + str(len(header_data.enums)) + ",_enum_values," + str(enum_value_count) + ",_ubo_pairs," + str(len(header_data.ubos)) + ",_feedbacks," + str(feedback_count) + ",_vertex_code,_fragment_code,_vertex_code_start,_fragment_code_start);\n")
  881. fd.write("\t};\n\n")
  882. if (len(enum_constants)):
  883. fd.write("\tenum EnumConditionals {\n")
  884. for x in enum_constants:
  885. fd.write("\t\t" + x.upper() + ",\n")
  886. fd.write("\t};\n\n")
  887. fd.write("\tvoid set_enum_conditional(EnumConditionals p_cond) { _set_enum_conditional(p_cond); }\n")
  888. fd.write("};\n\n")
  889. fd.write("#endif\n\n")
  890. fd.close()
  891. def build_legacygl_headers(target, source, env):
  892. for x in source:
  893. build_legacygl_header(str(x), include="drivers/legacygl/shader_lgl.h", class_suffix="LGL", output_attribs=False)
  894. return 0
  895. def build_gles2_headers(target, source, env):
  896. for x in source:
  897. build_legacygl_header(str(x), include="drivers/gles2/shader_gles2.h", class_suffix="GLES2", output_attribs=True)
  898. def build_gles3_headers(target, source, env):
  899. for x in source:
  900. build_legacygl_header(str(x), include="drivers/gles3/shader_gles3.h", class_suffix="GLES3", output_attribs=True)
  901. def update_version():
  902. rev = "custom_build"
  903. if (os.getenv("BUILD_REVISION") != None):
  904. rev = os.getenv("BUILD_REVISION")
  905. print("Using custom revision: " + rev)
  906. import version
  907. f = open("core/version.h", "wb")
  908. f.write("#define VERSION_SHORT_NAME " + str(version.short_name) + "\n")
  909. f.write("#define VERSION_NAME " + str(version.name) + "\n")
  910. f.write("#define VERSION_MAJOR " + str(version.major) + "\n")
  911. f.write("#define VERSION_MINOR " + str(version.minor) + "\n")
  912. if (hasattr(version, 'patch')):
  913. f.write("#define VERSION_PATCH " + str(version.patch) + "\n")
  914. f.write("#define VERSION_REVISION " + str(rev) + "\n")
  915. f.write("#define VERSION_STATUS " + str(version.status) + "\n")
  916. import datetime
  917. f.write("#define VERSION_YEAR " + str(datetime.datetime.now().year) + "\n")
  918. def parse_cg_file(fname, uniforms, sizes, conditionals):
  919. import re
  920. fs = open(fname, "r")
  921. line = fs.readline()
  922. while line:
  923. if re.match(r"^\s*uniform", line):
  924. res = re.match(r"uniform ([\d\w]*) ([\d\w]*)")
  925. type = res.groups(1)
  926. name = res.groups(2)
  927. uniforms.append(name)
  928. if (type.find("texobj") != -1):
  929. sizes.append(1)
  930. else:
  931. t = re.match(r"float(\d)x(\d)", type)
  932. if t:
  933. sizes.append(int(t.groups(1)) * int(t.groups(2)))
  934. else:
  935. t = re.match(r"float(\d)", type)
  936. sizes.append(int(t.groups(1)))
  937. if line.find("[branch]") != -1:
  938. conditionals.append(name)
  939. line = fs.readline()
  940. def build_cg_shader(sname):
  941. vp_uniforms = []
  942. vp_uniform_sizes = []
  943. vp_conditionals = []
  944. parse_cg_file("vp_" + sname + ".cg", vp_uniforms, vp_uniform_sizes, vp_conditionals)
  945. fp_uniforms = []
  946. fp_uniform_sizes = []
  947. fp_conditionals = []
  948. parse_cg_file("fp_" + sname + ".cg", fp_uniforms, fp_uniform_sizes, fp_conditionals)
  949. fd = open("shader_" + sname + ".cg.h", "w")
  950. fd.write('\n#include "shader_cell.h"\n')
  951. fd.write("\nclass Shader_" + sname + " : public ShaderCell {\n")
  952. fd.write("\n\tstatic struct VertexUniforms[] = {\n")
  953. offset = 0
  954. for i in range(0, len(vp_uniforms)):
  955. fd.write('\t\t{ "%s", %d, %d },\n' % (vp_uniforms[i], offset, vp_uniform_sizes[i]))
  956. offset = offset + vp_uniform_sizes[i]
  957. fd.write("\t};\n\n")
  958. fd.write("public:\n\n")
  959. fd.write("\tenum {\n")
  960. for i in range(0, len(vp_uniforms)):
  961. fd.write('\t\tVP_%s,\n' % vp_uniforms[i].upper())
  962. fd.write("\t};\n")
  963. import glob
  964. def detect_modules():
  965. module_list = []
  966. includes_cpp = ""
  967. register_cpp = ""
  968. unregister_cpp = ""
  969. files = glob.glob("modules/*")
  970. files.sort() # so register_module_types does not change that often, and also plugins are registered in alphabetic order
  971. for x in files:
  972. if (not os.path.isdir(x)):
  973. continue
  974. x = x.replace("modules/", "") # rest of world
  975. x = x.replace("modules\\", "") # win32
  976. module_list.append(x)
  977. try:
  978. with open("modules/" + x + "/register_types.h"):
  979. includes_cpp += '#include "modules/' + x + '/register_types.h"\n'
  980. register_cpp += '#ifdef MODULE_' + x.upper() + '_ENABLED\n'
  981. register_cpp += '\tregister_' + x + '_types();\n'
  982. register_cpp += '#endif\n'
  983. unregister_cpp += '#ifdef MODULE_' + x.upper() + '_ENABLED\n'
  984. unregister_cpp += '\tunregister_' + x + '_types();\n'
  985. unregister_cpp += '#endif\n'
  986. except IOError:
  987. pass
  988. modules_cpp = """
  989. // modules.cpp - THIS FILE IS GENERATED, DO NOT EDIT!!!!!!!
  990. #include "register_module_types.h"
  991. """ + includes_cpp + """
  992. void register_module_types() {
  993. """ + register_cpp + """
  994. }
  995. void unregister_module_types() {
  996. """ + unregister_cpp + """
  997. }
  998. """
  999. f = open("modules/register_module_types.cpp", "wb")
  1000. f.write(modules_cpp)
  1001. return module_list
  1002. def win32_spawn(sh, escape, cmd, args, env):
  1003. import subprocess
  1004. newargs = ' '.join(args[1:])
  1005. cmdline = cmd + " " + newargs
  1006. startupinfo = subprocess.STARTUPINFO()
  1007. #startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
  1008. for e in env:
  1009. if type(env[e]) != type(""):
  1010. env[e] = str(env[e])
  1011. proc = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
  1012. stderr=subprocess.PIPE, startupinfo=startupinfo, shell=False, env=env)
  1013. data, err = proc.communicate()
  1014. rv = proc.wait()
  1015. if rv:
  1016. print "====="
  1017. print err
  1018. print "====="
  1019. return rv
  1020. """
  1021. def win32_spawn(sh, escape, cmd, args, spawnenv):
  1022. import win32file
  1023. import win32event
  1024. import win32process
  1025. import win32security
  1026. for var in spawnenv:
  1027. spawnenv[var] = spawnenv[var].encode('ascii', 'replace')
  1028. sAttrs = win32security.SECURITY_ATTRIBUTES()
  1029. StartupInfo = win32process.STARTUPINFO()
  1030. newargs = ' '.join(map(escape, args[1:]))
  1031. cmdline = cmd + " " + newargs
  1032. # check for any special operating system commands
  1033. if cmd == 'del':
  1034. for arg in args[1:]:
  1035. win32file.DeleteFile(arg)
  1036. exit_code = 0
  1037. else:
  1038. # otherwise execute the command.
  1039. hProcess, hThread, dwPid, dwTid = win32process.CreateProcess(None, cmdline, None, None, 1, 0, spawnenv, None, StartupInfo)
  1040. win32event.WaitForSingleObject(hProcess, win32event.INFINITE)
  1041. exit_code = win32process.GetExitCodeProcess(hProcess)
  1042. win32file.CloseHandle(hProcess);
  1043. win32file.CloseHandle(hThread);
  1044. return exit_code
  1045. """
  1046. def android_add_maven_repository(self, url):
  1047. self.android_maven_repos.append(url)
  1048. def android_add_dependency(self, depline):
  1049. self.android_dependencies.append(depline)
  1050. def android_add_java_dir(self, subpath):
  1051. base_path = self.Dir(".").abspath + "/modules/" + self.current_module + "/" + subpath
  1052. self.android_java_dirs.append(base_path)
  1053. def android_add_res_dir(self, subpath):
  1054. base_path = self.Dir(".").abspath + "/modules/" + self.current_module + "/" + subpath
  1055. self.android_res_dirs.append(base_path)
  1056. def android_add_aidl_dir(self, subpath):
  1057. base_path = self.Dir(".").abspath + "/modules/" + self.current_module + "/" + subpath
  1058. self.android_aidl_dirs.append(base_path)
  1059. def android_add_jni_dir(self, subpath):
  1060. base_path = self.Dir(".").abspath + "/modules/" + self.current_module + "/" + subpath
  1061. self.android_jni_dirs.append(base_path)
  1062. def android_add_default_config(self, config):
  1063. self.android_default_config.append(config)
  1064. def android_add_to_manifest(self, file):
  1065. base_path = self.Dir(".").abspath + "/modules/" + self.current_module + "/" + file
  1066. f = open(base_path, "rb")
  1067. self.android_manifest_chunk += f.read()
  1068. def android_add_to_permissions(self, file):
  1069. base_path = self.Dir(".").abspath + "/modules/" + self.current_module + "/" + file
  1070. f = open(base_path, "rb")
  1071. self.android_permission_chunk += f.read()
  1072. def android_add_to_attributes(self, file):
  1073. base_path = self.Dir(".").abspath + "/modules/" + self.current_module + "/" + file
  1074. f = open(base_path, "rb")
  1075. self.android_appattributes_chunk += f.read()
  1076. def disable_module(self):
  1077. self.disabled_modules.append(self.current_module)
  1078. def use_windows_spawn_fix(self, platform=None):
  1079. if (os.name != "nt"):
  1080. return # not needed, only for windows
  1081. # On Windows, due to the limited command line length, when creating a static library
  1082. # from a very high number of objects SCons will invoke "ar" once per object file;
  1083. # that makes object files with same names to be overwritten so the last wins and
  1084. # the library looses symbols defined by overwritten objects.
  1085. # By enabling quick append instead of the default mode (replacing), libraries will
  1086. # got built correctly regardless the invokation strategy.
  1087. # Furthermore, since SCons will rebuild the library from scratch when an object file
  1088. # changes, no multiple versions of the same object file will be present.
  1089. self.Replace(ARFLAGS='q')
  1090. import subprocess
  1091. def mySubProcess(cmdline, env):
  1092. prefix = ""
  1093. if(platform == 'javascript'):
  1094. prefix = "python.exe "
  1095. startupinfo = subprocess.STARTUPINFO()
  1096. startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
  1097. proc = subprocess.Popen(prefix + cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
  1098. stderr=subprocess.PIPE, startupinfo=startupinfo, shell=False, env=env)
  1099. data, err = proc.communicate()
  1100. rv = proc.wait()
  1101. if rv:
  1102. print "====="
  1103. print err
  1104. print "====="
  1105. return rv
  1106. def mySpawn(sh, escape, cmd, args, env):
  1107. newargs = ' '.join(args[1:])
  1108. cmdline = cmd + " " + newargs
  1109. rv = 0
  1110. env = {str(key): str(value) for key, value in env.iteritems()}
  1111. if len(cmdline) > 32000 and cmd.endswith("ar"):
  1112. cmdline = cmd + " " + args[1] + " " + args[2] + " "
  1113. for i in range(3, len(args)):
  1114. rv = mySubProcess(cmdline + args[i], env)
  1115. if rv:
  1116. break
  1117. else:
  1118. rv = mySubProcess(cmdline, env)
  1119. return rv
  1120. self['SPAWN'] = mySpawn
  1121. def split_lib(self, libname):
  1122. import string
  1123. env = self
  1124. num = 0
  1125. cur_base = ""
  1126. max_src = 64
  1127. list = []
  1128. lib_list = []
  1129. for f in getattr(env, libname + "_sources"):
  1130. fname = ""
  1131. if type(f) == type(""):
  1132. fname = env.File(f).path
  1133. else:
  1134. fname = env.File(f)[0].path
  1135. fname = fname.replace("\\", "/")
  1136. base = string.join(fname.split("/")[:2], "/")
  1137. if base != cur_base and len(list) > max_src:
  1138. if num > 0:
  1139. lib = env.Library(libname + str(num), list)
  1140. lib_list.append(lib)
  1141. list = []
  1142. num = num + 1
  1143. cur_base = base
  1144. list.append(f)
  1145. lib = env.Library(libname + str(num), list)
  1146. lib_list.append(lib)
  1147. if len(lib_list) > 0:
  1148. import os, sys
  1149. if os.name == 'posix' and sys.platform == 'msys':
  1150. env.Replace(ARFLAGS=['rcsT'])
  1151. lib = env.Library(libname + "_collated", lib_list)
  1152. lib_list = [lib]
  1153. lib_base = []
  1154. env.add_source_files(lib_base, "*.cpp")
  1155. lib_list.insert(0, env.Library(libname, lib_base))
  1156. env.Prepend(LIBS=lib_list)
  1157. def save_active_platforms(apnames, ap):
  1158. for x in ap:
  1159. pth = x + "/logo.png"
  1160. # print("open path: "+pth)
  1161. pngf = open(pth, "rb")
  1162. b = pngf.read(1)
  1163. str = " /* AUTOGENERATED FILE, DO NOT EDIT */ \n"
  1164. str += " static const unsigned char _" + x[9:] + "_logo[]={"
  1165. while(len(b) == 1):
  1166. str += hex(ord(b))
  1167. b = pngf.read(1)
  1168. if (len(b) == 1):
  1169. str += ","
  1170. str += "};\n"
  1171. wf = x + "/logo.h"
  1172. logow = open(wf, "wb")
  1173. logow.write(str)
  1174. def no_verbose(sys, env):
  1175. # If the output is not a terminal, do nothing
  1176. if not sys.stdout.isatty():
  1177. return
  1178. colors = {}
  1179. colors['cyan'] = '\033[96m'
  1180. colors['purple'] = '\033[95m'
  1181. colors['blue'] = '\033[94m'
  1182. colors['green'] = '\033[92m'
  1183. colors['yellow'] = '\033[93m'
  1184. colors['red'] = '\033[91m'
  1185. colors['end'] = '\033[0m'
  1186. compile_source_message = '%sCompiling %s==> %s$SOURCE%s' % (colors['blue'], colors['purple'], colors['yellow'], colors['end'])
  1187. java_compile_source_message = '%sCompiling %s==> %s$SOURCE%s' % (colors['blue'], colors['purple'], colors['yellow'], colors['end'])
  1188. compile_shared_source_message = '%sCompiling shared %s==> %s$SOURCE%s' % (colors['blue'], colors['purple'], colors['yellow'], colors['end'])
  1189. link_program_message = '%sLinking Program %s==> %s$TARGET%s' % (colors['red'], colors['purple'], colors['yellow'], colors['end'])
  1190. link_library_message = '%sLinking Static Library %s==> %s$TARGET%s' % (colors['red'], colors['purple'], colors['yellow'], colors['end'])
  1191. ranlib_library_message = '%sRanlib Library %s==> %s$TARGET%s' % (colors['red'], colors['purple'], colors['yellow'], colors['end'])
  1192. link_shared_library_message = '%sLinking Shared Library %s==> %s$TARGET%s' % (colors['red'], colors['purple'], colors['yellow'], colors['end'])
  1193. java_library_message = '%sCreating Java Archive %s==> %s$TARGET%s' % (colors['red'], colors['purple'], colors['yellow'], colors['end'])
  1194. env.Append(CXXCOMSTR=[compile_source_message])
  1195. env.Append(CCCOMSTR=[compile_source_message])
  1196. env.Append(SHCCCOMSTR=[compile_shared_source_message])
  1197. env.Append(SHCXXCOMSTR=[compile_shared_source_message])
  1198. env.Append(ARCOMSTR=[link_library_message])
  1199. env.Append(RANLIBCOMSTR=[ranlib_library_message])
  1200. env.Append(SHLINKCOMSTR=[link_shared_library_message])
  1201. env.Append(LINKCOMSTR=[link_program_message])
  1202. env.Append(JARCOMSTR=[java_library_message])
  1203. env.Append(JAVACCOMSTR=[java_compile_source_message])
  1204. def detect_visual_c_compiler_version(tools_env):
  1205. # tools_env is the variable scons uses to call tools that execute tasks, SCons's env['ENV'] that executes tasks...
  1206. # (see the SCons documentation for more information on what it does)...
  1207. # in order for this function to be well encapsulated i choose to force it to recieve SCons's TOOLS env (env['ENV']
  1208. # and not scons setup environment (env)... so make sure you call the right environment on it or it will fail to detect
  1209. # the propper vc version that will be called
  1210. # These is no flag to give to visual c compilers to set the architecture, ie scons bits argument (32,64,ARM etc)
  1211. # There are many different cl.exe files that are run, and each one compiles & links to a different architecture
  1212. # As far as I know, the only way to figure out what compiler will be run when Scons calls cl.exe via Program()
  1213. # is to check the PATH varaible and figure out which one will be called first. Code bellow does that and returns:
  1214. # the following string values:
  1215. # "" Compiler not detected
  1216. # "amd64" Native 64 bit compiler
  1217. # "amd64_x86" 64 bit Cross Compiler for 32 bit
  1218. # "x86" Native 32 bit compiler
  1219. # "x86_amd64" 32 bit Cross Compiler for 64 bit
  1220. # There are other architectures, but Godot does not support them currently, so this function does not detect arm/amd64_arm
  1221. # and similar architectures/compilers
  1222. # Set chosen compiler to "not detected"
  1223. vc_chosen_compiler_index = -1
  1224. vc_chosen_compiler_str = ""
  1225. # find() works with -1 so big ifs bellow are needed... the simplest solution, in fact
  1226. # First test if amd64 and amd64_x86 compilers are present in the path
  1227. vc_amd64_compiler_detection_index = tools_env["PATH"].find(tools_env["VCINSTALLDIR"] + "BIN\\amd64;")
  1228. if(vc_amd64_compiler_detection_index > -1):
  1229. vc_chosen_compiler_index = vc_amd64_compiler_detection_index
  1230. vc_chosen_compiler_str = "amd64"
  1231. vc_amd64_x86_compiler_detection_index = tools_env["PATH"].find(tools_env["VCINSTALLDIR"] + "BIN\\amd64_x86;")
  1232. if(vc_amd64_x86_compiler_detection_index > -1
  1233. and (vc_chosen_compiler_index == -1
  1234. or vc_chosen_compiler_index > vc_amd64_x86_compiler_detection_index)):
  1235. vc_chosen_compiler_index = vc_amd64_x86_compiler_detection_index
  1236. vc_chosen_compiler_str = "amd64_x86"
  1237. # Now check the 32 bit compilers
  1238. vc_x86_compiler_detection_index = tools_env["PATH"].find(tools_env["VCINSTALLDIR"] + "BIN;")
  1239. if(vc_x86_compiler_detection_index > -1
  1240. and (vc_chosen_compiler_index == -1
  1241. or vc_chosen_compiler_index > vc_x86_compiler_detection_index)):
  1242. vc_chosen_compiler_index = vc_x86_compiler_detection_index
  1243. vc_chosen_compiler_str = "x86"
  1244. vc_x86_amd64_compiler_detection_index = tools_env["PATH"].find(tools_env['VCINSTALLDIR'] + "BIN\\x86_amd64;")
  1245. if(vc_x86_amd64_compiler_detection_index > -1
  1246. and (vc_chosen_compiler_index == -1
  1247. or vc_chosen_compiler_index > vc_x86_amd64_compiler_detection_index)):
  1248. vc_chosen_compiler_index = vc_x86_amd64_compiler_detection_index
  1249. vc_chosen_compiler_str = "x86_amd64"
  1250. # debug help
  1251. # print vc_amd64_compiler_detection_index
  1252. # print vc_amd64_x86_compiler_detection_index
  1253. # print vc_x86_compiler_detection_index
  1254. # print vc_x86_amd64_compiler_detection_index
  1255. # print "chosen "+str(vc_chosen_compiler_index)+ " | "+str(vc_chosen_compiler_str)
  1256. return vc_chosen_compiler_str
  1257. def precious_program(env, program, sources, **args):
  1258. program = env.ProgramOriginal(program, sources, **args)
  1259. env.Precious(program)
  1260. return program