gles3_builders.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. """Functions used to generate source files during build time
  2. All such functions are invoked in a subprocess on Windows to prevent build flakiness.
  3. """
  4. import os.path
  5. from typing import Optional
  6. from platform_methods import subprocess_main
  7. class GLES3HeaderStruct:
  8. def __init__(self):
  9. self.vertex_lines = []
  10. self.fragment_lines = []
  11. self.uniforms = []
  12. self.fbos = []
  13. self.texunits = []
  14. self.texunit_names = []
  15. self.ubos = []
  16. self.ubo_names = []
  17. self.feedbacks = []
  18. self.vertex_included_files = []
  19. self.fragment_included_files = []
  20. self.reading = ""
  21. self.line_offset = 0
  22. self.vertex_offset = 0
  23. self.fragment_offset = 0
  24. self.variant_defines = []
  25. self.variant_names = []
  26. self.specialization_names = []
  27. self.specialization_values = []
  28. def include_file_in_gles3_header(filename: str, header_data: GLES3HeaderStruct, depth: int):
  29. fs = open(filename, "r")
  30. line = fs.readline()
  31. while line:
  32. if line.find("=") != -1 and header_data.reading == "":
  33. # Mode
  34. eqpos = line.find("=")
  35. defname = line[:eqpos].strip().upper()
  36. define = line[eqpos + 1 :].strip()
  37. header_data.variant_names.append(defname)
  38. header_data.variant_defines.append(define)
  39. line = fs.readline()
  40. header_data.line_offset += 1
  41. header_data.vertex_offset = header_data.line_offset
  42. continue
  43. if line.find("=") != -1 and header_data.reading == "specializations":
  44. # Specialization
  45. eqpos = line.find("=")
  46. specname = line[:eqpos].strip()
  47. specvalue = line[eqpos + 1 :]
  48. header_data.specialization_names.append(specname)
  49. header_data.specialization_values.append(specvalue)
  50. line = fs.readline()
  51. header_data.line_offset += 1
  52. header_data.vertex_offset = header_data.line_offset
  53. continue
  54. if line.find("#[modes]") != -1:
  55. # Nothing really, just skip
  56. line = fs.readline()
  57. header_data.line_offset += 1
  58. header_data.vertex_offset = header_data.line_offset
  59. continue
  60. if line.find("#[specializations]") != -1:
  61. header_data.reading = "specializations"
  62. line = fs.readline()
  63. header_data.line_offset += 1
  64. header_data.vertex_offset = header_data.line_offset
  65. continue
  66. if line.find("#[vertex]") != -1:
  67. header_data.reading = "vertex"
  68. line = fs.readline()
  69. header_data.line_offset += 1
  70. header_data.vertex_offset = header_data.line_offset
  71. continue
  72. if line.find("#[fragment]") != -1:
  73. header_data.reading = "fragment"
  74. line = fs.readline()
  75. header_data.line_offset += 1
  76. header_data.fragment_offset = header_data.line_offset
  77. continue
  78. while line.find("#include ") != -1:
  79. includeline = line.replace("#include ", "").strip()[1:-1]
  80. included_file = os.path.relpath(os.path.dirname(filename) + "/" + includeline)
  81. if not included_file in header_data.vertex_included_files and header_data.reading == "vertex":
  82. header_data.vertex_included_files += [included_file]
  83. if include_file_in_gles3_header(included_file, header_data, depth + 1) is None:
  84. print("Error in file '" + filename + "': #include " + includeline + "could not be found!")
  85. elif not included_file in header_data.fragment_included_files and header_data.reading == "fragment":
  86. header_data.fragment_included_files += [included_file]
  87. if include_file_in_gles3_header(included_file, header_data, depth + 1) is None:
  88. print("Error in file '" + filename + "': #include " + includeline + "could not be found!")
  89. line = fs.readline()
  90. if line.find("uniform") != -1 and line.lower().find("texunit:") != -1:
  91. # texture unit
  92. texunitstr = line[line.find(":") + 1 :].strip()
  93. if texunitstr == "auto":
  94. texunit = "-1"
  95. else:
  96. texunit = str(int(texunitstr))
  97. uline = line[: line.lower().find("//")]
  98. uline = uline.replace("uniform", "")
  99. uline = uline.replace("highp", "")
  100. uline = uline.replace(";", "")
  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 header_data.texunit_names:
  109. header_data.texunits += [(x, texunit)]
  110. header_data.texunit_names += [x]
  111. elif line.find("uniform") != -1 and line.lower().find("ubo:") != -1:
  112. # uniform buffer object
  113. ubostr = line[line.find(":") + 1 :].strip()
  114. ubo = str(int(ubostr))
  115. uline = line[: line.lower().find("//")]
  116. uline = uline[uline.find("uniform") + len("uniform") :]
  117. uline = uline.replace("highp", "")
  118. uline = uline.replace(";", "")
  119. uline = uline.replace("{", "").strip()
  120. lines = uline.split(",")
  121. for x in lines:
  122. x = x.strip()
  123. x = x[x.rfind(" ") + 1 :]
  124. if x.find("[") != -1:
  125. # unfiorm array
  126. x = x[: x.find("[")]
  127. if not x in header_data.ubo_names:
  128. header_data.ubos += [(x, ubo)]
  129. header_data.ubo_names += [x]
  130. elif line.find("uniform") != -1 and line.find("{") == -1 and line.find(";") != -1:
  131. uline = line.replace("uniform", "")
  132. uline = uline.replace(";", "")
  133. lines = uline.split(",")
  134. for x in lines:
  135. x = x.strip()
  136. x = x[x.rfind(" ") + 1 :]
  137. if x.find("[") != -1:
  138. # unfiorm array
  139. x = x[: x.find("[")]
  140. if not x in header_data.uniforms:
  141. header_data.uniforms += [x]
  142. if (line.strip().find("out ") == 0 or line.strip().find("flat ") == 0) and line.find("tfb:") != -1:
  143. uline = line.replace("flat ", "")
  144. uline = uline.replace("out ", "")
  145. uline = uline.replace("highp ", "")
  146. uline = uline.replace(";", "")
  147. uline = uline[uline.find(" ") :].strip()
  148. if uline.find("//") != -1:
  149. name, bind = uline.split("//")
  150. if bind.find("tfb:") != -1:
  151. name = name.strip()
  152. bind = bind.replace("tfb:", "").strip()
  153. header_data.feedbacks += [(name, bind)]
  154. line = line.replace("\r", "")
  155. line = line.replace("\n", "")
  156. if header_data.reading == "vertex":
  157. header_data.vertex_lines += [line]
  158. if header_data.reading == "fragment":
  159. header_data.fragment_lines += [line]
  160. line = fs.readline()
  161. header_data.line_offset += 1
  162. fs.close()
  163. return header_data
  164. def build_gles3_header(
  165. filename: str,
  166. include: str,
  167. class_suffix: str,
  168. optional_output_filename: str = None,
  169. header_data: Optional[GLES3HeaderStruct] = None,
  170. ):
  171. header_data = header_data or GLES3HeaderStruct()
  172. include_file_in_gles3_header(filename, header_data, 0)
  173. if optional_output_filename is None:
  174. out_file = filename + ".gen.h"
  175. else:
  176. out_file = optional_output_filename
  177. fd = open(out_file, "w")
  178. defspec = 0
  179. defvariant = ""
  180. fd.write("/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */\n")
  181. out_file_base = out_file
  182. out_file_base = out_file_base[out_file_base.rfind("/") + 1 :]
  183. out_file_base = out_file_base[out_file_base.rfind("\\") + 1 :]
  184. out_file_ifdef = out_file_base.replace(".", "_").upper()
  185. fd.write("#ifndef " + out_file_ifdef + class_suffix + "_GLES3\n")
  186. fd.write("#define " + out_file_ifdef + class_suffix + "_GLES3\n")
  187. out_file_class = (
  188. out_file_base.replace(".glsl.gen.h", "").title().replace("_", "").replace(".", "") + "Shader" + class_suffix
  189. )
  190. fd.write("\n\n")
  191. fd.write('#include "' + include + '"\n\n\n')
  192. fd.write("class " + out_file_class + " : public Shader" + class_suffix + " {\n\n")
  193. fd.write("public:\n\n")
  194. if header_data.uniforms:
  195. fd.write("\tenum Uniforms {\n")
  196. for x in header_data.uniforms:
  197. fd.write("\t\t" + x.upper() + ",\n")
  198. fd.write("\t};\n\n")
  199. if header_data.variant_names:
  200. fd.write("\tenum ShaderVariant {\n")
  201. for x in header_data.variant_names:
  202. fd.write("\t\t" + x + ",\n")
  203. fd.write("\t};\n\n")
  204. else:
  205. fd.write("\tenum ShaderVariant { DEFAULT };\n\n")
  206. defvariant = "=DEFAULT"
  207. if header_data.specialization_names:
  208. fd.write("\tenum Specializations {\n")
  209. counter = 0
  210. for x in header_data.specialization_names:
  211. fd.write("\t\t" + x.upper() + "=" + str(1 << counter) + ",\n")
  212. counter += 1
  213. fd.write("\t};\n\n")
  214. for i in range(len(header_data.specialization_names)):
  215. defval = header_data.specialization_values[i].strip()
  216. if defval.upper() == "TRUE" or defval == "1":
  217. defspec |= 1 << i
  218. fd.write(
  219. "\t_FORCE_INLINE_ bool version_bind_shader(RID p_version,ShaderVariant p_variant"
  220. + defvariant
  221. + ",uint64_t p_specialization="
  222. + str(defspec)
  223. + ") { return _version_bind_shader(p_version,p_variant,p_specialization); }\n\n"
  224. )
  225. if header_data.uniforms:
  226. fd.write(
  227. "\t_FORCE_INLINE_ int version_get_uniform(Uniforms p_uniform,RID p_version,ShaderVariant p_variant"
  228. + defvariant
  229. + ",uint64_t p_specialization="
  230. + str(defspec)
  231. + ") { return _version_get_uniform(p_uniform,p_version,p_variant,p_specialization); }\n\n"
  232. )
  233. fd.write(
  234. "\t#define _FU if (version_get_uniform(p_uniform,p_version,p_variant,p_specialization)<0) return; \n\n "
  235. )
  236. fd.write(
  237. "\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, float p_value,RID p_version,ShaderVariant p_variant"
  238. + defvariant
  239. + ",uint64_t p_specialization="
  240. + str(defspec)
  241. + ") { _FU glUniform1f(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
  242. )
  243. fd.write(
  244. "\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, double p_value,RID p_version,ShaderVariant p_variant"
  245. + defvariant
  246. + ",uint64_t p_specialization="
  247. + str(defspec)
  248. + ") { _FU glUniform1f(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
  249. )
  250. fd.write(
  251. "\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, uint8_t p_value,RID p_version,ShaderVariant p_variant"
  252. + defvariant
  253. + ",uint64_t p_specialization="
  254. + str(defspec)
  255. + ") { _FU glUniform1ui(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
  256. )
  257. fd.write(
  258. "\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, int8_t p_value,RID p_version,ShaderVariant p_variant"
  259. + defvariant
  260. + ",uint64_t p_specialization="
  261. + str(defspec)
  262. + ") { _FU glUniform1i(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
  263. )
  264. fd.write(
  265. "\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, uint16_t p_value,RID p_version,ShaderVariant p_variant"
  266. + defvariant
  267. + ",uint64_t p_specialization="
  268. + str(defspec)
  269. + ") { _FU glUniform1ui(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
  270. )
  271. fd.write(
  272. "\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, int16_t p_value,RID p_version,ShaderVariant p_variant"
  273. + defvariant
  274. + ",uint64_t p_specialization="
  275. + str(defspec)
  276. + ") { _FU glUniform1i(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
  277. )
  278. fd.write(
  279. "\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, uint32_t p_value,RID p_version,ShaderVariant p_variant"
  280. + defvariant
  281. + ",uint64_t p_specialization="
  282. + str(defspec)
  283. + ") { _FU glUniform1ui(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
  284. )
  285. fd.write(
  286. "\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, int32_t p_value,RID p_version,ShaderVariant p_variant"
  287. + defvariant
  288. + ",uint64_t p_specialization="
  289. + str(defspec)
  290. + ") { _FU glUniform1i(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
  291. )
  292. fd.write(
  293. "\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Color& p_color,RID p_version,ShaderVariant p_variant"
  294. + defvariant
  295. + ",uint64_t p_specialization="
  296. + str(defspec)
  297. + ") { _FU GLfloat col[4]={p_color.r,p_color.g,p_color.b,p_color.a}; glUniform4fv(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),1,col); }\n\n"
  298. )
  299. fd.write(
  300. "\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Vector2& p_vec2,RID p_version,ShaderVariant p_variant"
  301. + defvariant
  302. + ",uint64_t p_specialization="
  303. + str(defspec)
  304. + ") { _FU GLfloat vec2[2]={float(p_vec2.x),float(p_vec2.y)}; glUniform2fv(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),1,vec2); }\n\n"
  305. )
  306. fd.write(
  307. "\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Size2i& p_vec2,RID p_version,ShaderVariant p_variant"
  308. + defvariant
  309. + ",uint64_t p_specialization="
  310. + str(defspec)
  311. + ") { _FU GLint vec2[2]={GLint(p_vec2.x),GLint(p_vec2.y)}; glUniform2iv(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),1,vec2); }\n\n"
  312. )
  313. fd.write(
  314. "\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Vector3& p_vec3,RID p_version,ShaderVariant p_variant"
  315. + defvariant
  316. + ",uint64_t p_specialization="
  317. + str(defspec)
  318. + ") { _FU GLfloat vec3[3]={float(p_vec3.x),float(p_vec3.y),float(p_vec3.z)}; glUniform3fv(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),1,vec3); }\n\n"
  319. )
  320. fd.write(
  321. "\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, float p_a, float p_b,RID p_version,ShaderVariant p_variant"
  322. + defvariant
  323. + ",uint64_t p_specialization="
  324. + str(defspec)
  325. + ") { _FU glUniform2f(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_a,p_b); }\n\n"
  326. )
  327. fd.write(
  328. "\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, float p_a, float p_b, float p_c,RID p_version,ShaderVariant p_variant"
  329. + defvariant
  330. + ",uint64_t p_specialization="
  331. + str(defspec)
  332. + ") { _FU glUniform3f(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_a,p_b,p_c); }\n\n"
  333. )
  334. fd.write(
  335. "\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, float p_a, float p_b, float p_c, float p_d,RID p_version,ShaderVariant p_variant"
  336. + defvariant
  337. + ",uint64_t p_specialization="
  338. + str(defspec)
  339. + ") { _FU glUniform4f(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_a,p_b,p_c,p_d); }\n\n"
  340. )
  341. fd.write(
  342. """\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Transform3D& p_transform,RID p_version,ShaderVariant p_variant"""
  343. + defvariant
  344. + """,uint64_t p_specialization="""
  345. + str(defspec)
  346. + """) { _FU
  347. const Transform3D &tr = p_transform;
  348. GLfloat matrix[16]={ /* build a 16x16 matrix */
  349. (GLfloat)tr.basis.rows[0][0],
  350. (GLfloat)tr.basis.rows[1][0],
  351. (GLfloat)tr.basis.rows[2][0],
  352. (GLfloat)0,
  353. (GLfloat)tr.basis.rows[0][1],
  354. (GLfloat)tr.basis.rows[1][1],
  355. (GLfloat)tr.basis.rows[2][1],
  356. (GLfloat)0,
  357. (GLfloat)tr.basis.rows[0][2],
  358. (GLfloat)tr.basis.rows[1][2],
  359. (GLfloat)tr.basis.rows[2][2],
  360. (GLfloat)0,
  361. (GLfloat)tr.origin.x,
  362. (GLfloat)tr.origin.y,
  363. (GLfloat)tr.origin.z,
  364. (GLfloat)1
  365. };
  366. glUniformMatrix4fv(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),1,false,matrix);
  367. }
  368. """
  369. )
  370. fd.write(
  371. """_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Transform2D& p_transform,RID p_version,ShaderVariant p_variant"""
  372. + defvariant
  373. + """,uint64_t p_specialization="""
  374. + str(defspec)
  375. + """) { _FU
  376. const Transform2D &tr = p_transform;
  377. GLfloat matrix[16]={ /* build a 16x16 matrix */
  378. (GLfloat)tr.columns[0][0],
  379. (GLfloat)tr.columns[0][1],
  380. (GLfloat)0,
  381. (GLfloat)0,
  382. (GLfloat)tr.columns[1][0],
  383. (GLfloat)tr.columns[1][1],
  384. (GLfloat)0,
  385. (GLfloat)0,
  386. (GLfloat)0,
  387. (GLfloat)0,
  388. (GLfloat)1,
  389. (GLfloat)0,
  390. (GLfloat)tr.columns[2][0],
  391. (GLfloat)tr.columns[2][1],
  392. (GLfloat)0,
  393. (GLfloat)1
  394. };
  395. glUniformMatrix4fv(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),1,false,matrix);
  396. }
  397. """
  398. )
  399. fd.write(
  400. """_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Projection& p_matrix, RID p_version, ShaderVariant p_variant"""
  401. + defvariant
  402. + """,uint64_t p_specialization="""
  403. + str(defspec)
  404. + """) { _FU
  405. GLfloat matrix[16];
  406. for (int i = 0; i < 4; i++) {
  407. for (int j = 0; j < 4; j++) {
  408. matrix[i * 4 + j] = p_matrix.columns[i][j];
  409. }
  410. }
  411. glUniformMatrix4fv(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), 1, false, matrix);
  412. }"""
  413. )
  414. fd.write("\n\n#undef _FU\n\n\n")
  415. fd.write("protected:\n\n")
  416. fd.write("\tvirtual void _init() override {\n\n")
  417. if header_data.uniforms:
  418. fd.write("\t\tstatic const char* _uniform_strings[]={\n")
  419. if header_data.uniforms:
  420. for x in header_data.uniforms:
  421. fd.write('\t\t\t"' + x + '",\n')
  422. fd.write("\t\t};\n\n")
  423. else:
  424. fd.write("\t\tstatic const char **_uniform_strings=nullptr;\n")
  425. variant_count = 1
  426. if len(header_data.variant_defines) > 0:
  427. fd.write("\t\tstatic const char* _variant_defines[]={\n")
  428. for x in header_data.variant_defines:
  429. fd.write('\t\t\t"' + x + '",\n')
  430. fd.write("\t\t};\n\n")
  431. variant_count = len(header_data.variant_defines)
  432. else:
  433. fd.write("\t\tstatic const char **_variant_defines[]={" "};\n")
  434. if header_data.texunits:
  435. fd.write("\t\tstatic TexUnitPair _texunit_pairs[]={\n")
  436. for x in header_data.texunits:
  437. fd.write('\t\t\t{"' + x[0] + '",' + x[1] + "},\n")
  438. fd.write("\t\t};\n\n")
  439. else:
  440. fd.write("\t\tstatic TexUnitPair *_texunit_pairs=nullptr;\n")
  441. if header_data.ubos:
  442. fd.write("\t\tstatic UBOPair _ubo_pairs[]={\n")
  443. for x in header_data.ubos:
  444. fd.write('\t\t\t{"' + x[0] + '",' + x[1] + "},\n")
  445. fd.write("\t\t};\n\n")
  446. else:
  447. fd.write("\t\tstatic UBOPair *_ubo_pairs=nullptr;\n")
  448. specializations_found = []
  449. if header_data.specialization_names:
  450. fd.write("\t\tstatic Specialization _spec_pairs[]={\n")
  451. for i in range(len(header_data.specialization_names)):
  452. defval = header_data.specialization_values[i].strip()
  453. if defval.upper() == "TRUE" or defval == "1":
  454. defval = "true"
  455. else:
  456. defval = "false"
  457. fd.write('\t\t\t{"' + header_data.specialization_names[i] + '",' + defval + "},\n")
  458. specializations_found.append(header_data.specialization_names[i])
  459. fd.write("\t\t};\n\n")
  460. else:
  461. fd.write("\t\tstatic Specialization *_spec_pairs=nullptr;\n")
  462. feedback_count = 0
  463. if header_data.feedbacks:
  464. fd.write("\t\tstatic const Feedback _feedbacks[]={\n")
  465. for x in header_data.feedbacks:
  466. name = x[0]
  467. spec = x[1]
  468. if spec in specializations_found:
  469. fd.write('\t\t\t{"' + name + '",' + str(1 << specializations_found.index(spec)) + "},\n")
  470. else:
  471. fd.write('\t\t\t{"' + name + '",0},\n')
  472. feedback_count += 1
  473. fd.write("\t\t};\n\n")
  474. else:
  475. fd.write("\t\tstatic const Feedback* _feedbacks=nullptr;\n")
  476. fd.write("\t\tstatic const char _vertex_code[]={\n")
  477. for x in header_data.vertex_lines:
  478. for c in x:
  479. fd.write(str(ord(c)) + ",")
  480. fd.write(str(ord("\n")) + ",")
  481. fd.write("\t\t0};\n\n")
  482. fd.write("\t\tstatic const char _fragment_code[]={\n")
  483. for x in header_data.fragment_lines:
  484. for c in x:
  485. fd.write(str(ord(c)) + ",")
  486. fd.write(str(ord("\n")) + ",")
  487. fd.write("\t\t0};\n\n")
  488. fd.write(
  489. '\t\t_setup(_vertex_code,_fragment_code,"'
  490. + out_file_class
  491. + '",'
  492. + str(len(header_data.uniforms))
  493. + ",_uniform_strings,"
  494. + str(len(header_data.ubos))
  495. + ",_ubo_pairs,"
  496. + str(feedback_count)
  497. + ",_feedbacks,"
  498. + str(len(header_data.texunits))
  499. + ",_texunit_pairs,"
  500. + str(len(header_data.specialization_names))
  501. + ",_spec_pairs,"
  502. + str(variant_count)
  503. + ",_variant_defines);\n"
  504. )
  505. fd.write("\t}\n\n")
  506. fd.write("};\n\n")
  507. fd.write("#endif\n\n")
  508. fd.close()
  509. def build_gles3_headers(target, source, env):
  510. for x in source:
  511. build_gles3_header(str(x), include="drivers/gles3/shader_gles3.h", class_suffix="GLES3")
  512. if __name__ == "__main__":
  513. subprocess_main(globals())