gles3_builders.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  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(filename: str, include: str, class_suffix: str, header_data: Optional[GLES3HeaderStruct] = None):
  165. header_data = header_data or GLES3HeaderStruct()
  166. include_file_in_gles3_header(filename, header_data, 0)
  167. out_file = filename + ".gen.h"
  168. fd = open(out_file, "w")
  169. defspec = 0
  170. defvariant = ""
  171. fd.write("/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */\n")
  172. out_file_base = out_file
  173. out_file_base = out_file_base[out_file_base.rfind("/") + 1 :]
  174. out_file_base = out_file_base[out_file_base.rfind("\\") + 1 :]
  175. out_file_ifdef = out_file_base.replace(".", "_").upper()
  176. fd.write("#ifndef " + out_file_ifdef + class_suffix + "_GLES3\n")
  177. fd.write("#define " + out_file_ifdef + class_suffix + "_GLES3\n")
  178. out_file_class = (
  179. out_file_base.replace(".glsl.gen.h", "").title().replace("_", "").replace(".", "") + "Shader" + class_suffix
  180. )
  181. fd.write("\n\n")
  182. fd.write('#include "' + include + '"\n\n\n')
  183. fd.write("class " + out_file_class + " : public Shader" + class_suffix + " {\n\n")
  184. fd.write("public:\n\n")
  185. if header_data.uniforms:
  186. fd.write("\tenum Uniforms {\n")
  187. for x in header_data.uniforms:
  188. fd.write("\t\t" + x.upper() + ",\n")
  189. fd.write("\t};\n\n")
  190. if header_data.variant_names:
  191. fd.write("\tenum ShaderVariant {\n")
  192. for x in header_data.variant_names:
  193. fd.write("\t\t" + x + ",\n")
  194. fd.write("\t};\n\n")
  195. else:
  196. fd.write("\tenum ShaderVariant { DEFAULT };\n\n")
  197. defvariant = "=DEFAULT"
  198. if header_data.specialization_names:
  199. fd.write("\tenum Specializations {\n")
  200. counter = 0
  201. for x in header_data.specialization_names:
  202. fd.write("\t\t" + x.upper() + "=" + str(1 << counter) + ",\n")
  203. counter += 1
  204. fd.write("\t};\n\n")
  205. for i in range(len(header_data.specialization_names)):
  206. defval = header_data.specialization_values[i].strip()
  207. if defval.upper() == "TRUE" or defval == "1":
  208. defspec |= 1 << i
  209. fd.write(
  210. "\t_FORCE_INLINE_ bool version_bind_shader(RID p_version,ShaderVariant p_variant"
  211. + defvariant
  212. + ",uint64_t p_specialization="
  213. + str(defspec)
  214. + ") { return _version_bind_shader(p_version,p_variant,p_specialization); }\n\n"
  215. )
  216. if header_data.uniforms:
  217. fd.write(
  218. "\t_FORCE_INLINE_ int version_get_uniform(Uniforms p_uniform,RID p_version,ShaderVariant p_variant"
  219. + defvariant
  220. + ",uint64_t p_specialization="
  221. + str(defspec)
  222. + ") { return _version_get_uniform(p_uniform,p_version,p_variant,p_specialization); }\n\n"
  223. )
  224. fd.write(
  225. "\t#define _FU if (version_get_uniform(p_uniform,p_version,p_variant,p_specialization)<0) return; \n\n "
  226. )
  227. fd.write(
  228. "\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, float p_value,RID p_version,ShaderVariant p_variant"
  229. + defvariant
  230. + ",uint64_t p_specialization="
  231. + str(defspec)
  232. + ") { _FU glUniform1f(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
  233. )
  234. fd.write(
  235. "\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, double p_value,RID p_version,ShaderVariant p_variant"
  236. + defvariant
  237. + ",uint64_t p_specialization="
  238. + str(defspec)
  239. + ") { _FU glUniform1f(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
  240. )
  241. fd.write(
  242. "\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, uint8_t p_value,RID p_version,ShaderVariant p_variant"
  243. + defvariant
  244. + ",uint64_t p_specialization="
  245. + str(defspec)
  246. + ") { _FU glUniform1ui(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
  247. )
  248. fd.write(
  249. "\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, int8_t p_value,RID p_version,ShaderVariant p_variant"
  250. + defvariant
  251. + ",uint64_t p_specialization="
  252. + str(defspec)
  253. + ") { _FU glUniform1i(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
  254. )
  255. fd.write(
  256. "\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, uint16_t p_value,RID p_version,ShaderVariant p_variant"
  257. + defvariant
  258. + ",uint64_t p_specialization="
  259. + str(defspec)
  260. + ") { _FU glUniform1ui(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
  261. )
  262. fd.write(
  263. "\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, int16_t p_value,RID p_version,ShaderVariant p_variant"
  264. + defvariant
  265. + ",uint64_t p_specialization="
  266. + str(defspec)
  267. + ") { _FU glUniform1i(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
  268. )
  269. fd.write(
  270. "\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, uint32_t p_value,RID p_version,ShaderVariant p_variant"
  271. + defvariant
  272. + ",uint64_t p_specialization="
  273. + str(defspec)
  274. + ") { _FU glUniform1ui(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
  275. )
  276. fd.write(
  277. "\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, int32_t p_value,RID p_version,ShaderVariant p_variant"
  278. + defvariant
  279. + ",uint64_t p_specialization="
  280. + str(defspec)
  281. + ") { _FU glUniform1i(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_value); }\n\n"
  282. )
  283. fd.write(
  284. "\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Color& p_color,RID p_version,ShaderVariant p_variant"
  285. + defvariant
  286. + ",uint64_t p_specialization="
  287. + str(defspec)
  288. + ") { _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"
  289. )
  290. fd.write(
  291. "\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Vector2& p_vec2,RID p_version,ShaderVariant p_variant"
  292. + defvariant
  293. + ",uint64_t p_specialization="
  294. + str(defspec)
  295. + ") { _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"
  296. )
  297. fd.write(
  298. "\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Size2i& p_vec2,RID p_version,ShaderVariant p_variant"
  299. + defvariant
  300. + ",uint64_t p_specialization="
  301. + str(defspec)
  302. + ") { _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"
  303. )
  304. fd.write(
  305. "\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Vector3& p_vec3,RID p_version,ShaderVariant p_variant"
  306. + defvariant
  307. + ",uint64_t p_specialization="
  308. + str(defspec)
  309. + ") { _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"
  310. )
  311. fd.write(
  312. "\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, float p_a, float p_b,RID p_version,ShaderVariant p_variant"
  313. + defvariant
  314. + ",uint64_t p_specialization="
  315. + str(defspec)
  316. + ") { _FU glUniform2f(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_a,p_b); }\n\n"
  317. )
  318. fd.write(
  319. "\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"
  320. + defvariant
  321. + ",uint64_t p_specialization="
  322. + str(defspec)
  323. + ") { _FU glUniform3f(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_a,p_b,p_c); }\n\n"
  324. )
  325. fd.write(
  326. "\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"
  327. + defvariant
  328. + ",uint64_t p_specialization="
  329. + str(defspec)
  330. + ") { _FU glUniform4f(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),p_a,p_b,p_c,p_d); }\n\n"
  331. )
  332. fd.write(
  333. """\t_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Transform3D& p_transform,RID p_version,ShaderVariant p_variant"""
  334. + defvariant
  335. + """,uint64_t p_specialization="""
  336. + str(defspec)
  337. + """) { _FU
  338. const Transform3D &tr = p_transform;
  339. GLfloat matrix[16]={ /* build a 16x16 matrix */
  340. (GLfloat)tr.basis.rows[0][0],
  341. (GLfloat)tr.basis.rows[1][0],
  342. (GLfloat)tr.basis.rows[2][0],
  343. (GLfloat)0,
  344. (GLfloat)tr.basis.rows[0][1],
  345. (GLfloat)tr.basis.rows[1][1],
  346. (GLfloat)tr.basis.rows[2][1],
  347. (GLfloat)0,
  348. (GLfloat)tr.basis.rows[0][2],
  349. (GLfloat)tr.basis.rows[1][2],
  350. (GLfloat)tr.basis.rows[2][2],
  351. (GLfloat)0,
  352. (GLfloat)tr.origin.x,
  353. (GLfloat)tr.origin.y,
  354. (GLfloat)tr.origin.z,
  355. (GLfloat)1
  356. };
  357. glUniformMatrix4fv(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),1,false,matrix);
  358. }
  359. """
  360. )
  361. fd.write(
  362. """_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Transform2D& p_transform,RID p_version,ShaderVariant p_variant"""
  363. + defvariant
  364. + """,uint64_t p_specialization="""
  365. + str(defspec)
  366. + """) { _FU
  367. const Transform2D &tr = p_transform;
  368. GLfloat matrix[16]={ /* build a 16x16 matrix */
  369. (GLfloat)tr.columns[0][0],
  370. (GLfloat)tr.columns[0][1],
  371. (GLfloat)0,
  372. (GLfloat)0,
  373. (GLfloat)tr.columns[1][0],
  374. (GLfloat)tr.columns[1][1],
  375. (GLfloat)0,
  376. (GLfloat)0,
  377. (GLfloat)0,
  378. (GLfloat)0,
  379. (GLfloat)1,
  380. (GLfloat)0,
  381. (GLfloat)tr.columns[2][0],
  382. (GLfloat)tr.columns[2][1],
  383. (GLfloat)0,
  384. (GLfloat)1
  385. };
  386. glUniformMatrix4fv(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),1,false,matrix);
  387. }
  388. """
  389. )
  390. fd.write(
  391. """_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Projection& p_matrix, RID p_version, ShaderVariant p_variant"""
  392. + defvariant
  393. + """,uint64_t p_specialization="""
  394. + str(defspec)
  395. + """) { _FU
  396. GLfloat matrix[16];
  397. for (int i = 0; i < 4; i++) {
  398. for (int j = 0; j < 4; j++) {
  399. matrix[i * 4 + j] = p_matrix.columns[i][j];
  400. }
  401. }
  402. glUniformMatrix4fv(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), 1, false, matrix);
  403. }"""
  404. )
  405. fd.write("\n\n#undef _FU\n\n\n")
  406. fd.write("protected:\n\n")
  407. fd.write("\tvirtual void _init() override {\n\n")
  408. if header_data.uniforms:
  409. fd.write("\t\tstatic const char* _uniform_strings[]={\n")
  410. if header_data.uniforms:
  411. for x in header_data.uniforms:
  412. fd.write('\t\t\t"' + x + '",\n')
  413. fd.write("\t\t};\n\n")
  414. else:
  415. fd.write("\t\tstatic const char **_uniform_strings=nullptr;\n")
  416. variant_count = 1
  417. if len(header_data.variant_defines) > 0:
  418. fd.write("\t\tstatic const char* _variant_defines[]={\n")
  419. for x in header_data.variant_defines:
  420. fd.write('\t\t\t"' + x + '",\n')
  421. fd.write("\t\t};\n\n")
  422. variant_count = len(header_data.variant_defines)
  423. else:
  424. fd.write("\t\tstatic const char **_variant_defines[]={" "};\n")
  425. if header_data.texunits:
  426. fd.write("\t\tstatic TexUnitPair _texunit_pairs[]={\n")
  427. for x in header_data.texunits:
  428. fd.write('\t\t\t{"' + x[0] + '",' + x[1] + "},\n")
  429. fd.write("\t\t};\n\n")
  430. else:
  431. fd.write("\t\tstatic TexUnitPair *_texunit_pairs=nullptr;\n")
  432. if header_data.ubos:
  433. fd.write("\t\tstatic UBOPair _ubo_pairs[]={\n")
  434. for x in header_data.ubos:
  435. fd.write('\t\t\t{"' + x[0] + '",' + x[1] + "},\n")
  436. fd.write("\t\t};\n\n")
  437. else:
  438. fd.write("\t\tstatic UBOPair *_ubo_pairs=nullptr;\n")
  439. specializations_found = []
  440. if header_data.specialization_names:
  441. fd.write("\t\tstatic Specialization _spec_pairs[]={\n")
  442. for i in range(len(header_data.specialization_names)):
  443. defval = header_data.specialization_values[i].strip()
  444. if defval.upper() == "TRUE" or defval == "1":
  445. defval = "true"
  446. else:
  447. defval = "false"
  448. fd.write('\t\t\t{"' + header_data.specialization_names[i] + '",' + defval + "},\n")
  449. specializations_found.append(header_data.specialization_names[i])
  450. fd.write("\t\t};\n\n")
  451. else:
  452. fd.write("\t\tstatic Specialization *_spec_pairs=nullptr;\n")
  453. feedback_count = 0
  454. if header_data.feedbacks:
  455. fd.write("\t\tstatic const Feedback _feedbacks[]={\n")
  456. for x in header_data.feedbacks:
  457. name = x[0]
  458. spec = x[1]
  459. if spec in specializations_found:
  460. fd.write('\t\t\t{"' + name + '",' + str(1 << specializations_found.index(spec)) + "},\n")
  461. else:
  462. fd.write('\t\t\t{"' + name + '",0},\n')
  463. feedback_count += 1
  464. fd.write("\t\t};\n\n")
  465. else:
  466. fd.write("\t\tstatic const Feedback* _feedbacks=nullptr;\n")
  467. fd.write("\t\tstatic const char _vertex_code[]={\n")
  468. for x in header_data.vertex_lines:
  469. for c in x:
  470. fd.write(str(ord(c)) + ",")
  471. fd.write(str(ord("\n")) + ",")
  472. fd.write("\t\t0};\n\n")
  473. fd.write("\t\tstatic const char _fragment_code[]={\n")
  474. for x in header_data.fragment_lines:
  475. for c in x:
  476. fd.write(str(ord(c)) + ",")
  477. fd.write(str(ord("\n")) + ",")
  478. fd.write("\t\t0};\n\n")
  479. fd.write(
  480. '\t\t_setup(_vertex_code,_fragment_code,"'
  481. + out_file_class
  482. + '",'
  483. + str(len(header_data.uniforms))
  484. + ",_uniform_strings,"
  485. + str(len(header_data.ubos))
  486. + ",_ubo_pairs,"
  487. + str(feedback_count)
  488. + ",_feedbacks,"
  489. + str(len(header_data.texunits))
  490. + ",_texunit_pairs,"
  491. + str(len(header_data.specialization_names))
  492. + ",_spec_pairs,"
  493. + str(variant_count)
  494. + ",_variant_defines);\n"
  495. )
  496. fd.write("\t}\n\n")
  497. fd.write("};\n\n")
  498. fd.write("#endif\n\n")
  499. fd.close()
  500. def build_gles3_headers(target, source, env):
  501. for x in source:
  502. build_gles3_header(str(x), include="drivers/gles3/shader_gles3.h", class_suffix="GLES3")
  503. if __name__ == "__main__":
  504. subprocess_main(globals())