gles3_builders.py 25 KB

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