@null3d/engine 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1357) hide show
  1. package/LICENSE-APACHE +176 -0
  2. package/LICENSE-MIT +21 -0
  3. package/README.md +108 -2
  4. package/THIRD-PARTY-NOTICES.txt +637 -0
  5. package/dist/wasm/single/null3d.js +3972 -0
  6. package/dist/wasm/single/null3d_bg.wasm +0 -0
  7. package/dist/wasm/threaded/null3d.js +3988 -0
  8. package/dist/wasm/threaded/null3d_bg.wasm +0 -0
  9. package/docs/api/animation.md +492 -0
  10. package/docs/api/assets.md +400 -0
  11. package/docs/api/cameras.md +161 -0
  12. package/docs/api/controls.md +319 -0
  13. package/docs/api/debug.md +450 -0
  14. package/docs/api/engine.md +254 -0
  15. package/docs/api/feature-draws.md +172 -0
  16. package/docs/api/feature-effects.md +137 -0
  17. package/docs/api/feature-instances.md +154 -0
  18. package/docs/api/features.md +323 -0
  19. package/docs/api/geometry.md +307 -0
  20. package/docs/api/grass.md +114 -0
  21. package/docs/api/impostors.md +274 -0
  22. package/docs/api/input.md +238 -0
  23. package/docs/api/lights.md +266 -0
  24. package/docs/api/lines.md +163 -0
  25. package/docs/api/materials.md +875 -0
  26. package/docs/api/math.md +129 -0
  27. package/docs/api/objects.md +155 -0
  28. package/docs/api/page.md +97 -0
  29. package/docs/api/particles.md +205 -0
  30. package/docs/api/points.md +130 -0
  31. package/docs/api/post.md +494 -0
  32. package/docs/api/quality.md +200 -0
  33. package/docs/api/raycast.md +269 -0
  34. package/docs/api/reference/animation.md +158 -0
  35. package/docs/api/reference/assets.md +335 -0
  36. package/docs/api/reference/cameras.md +138 -0
  37. package/docs/api/reference/controls.md +463 -0
  38. package/docs/api/reference/debug.md +586 -0
  39. package/docs/api/reference/engine.md +647 -0
  40. package/docs/api/reference/feature-draws.md +94 -0
  41. package/docs/api/reference/feature-effects.md +32 -0
  42. package/docs/api/reference/feature-instances.md +63 -0
  43. package/docs/api/reference/features.md +361 -0
  44. package/docs/api/reference/geometry.md +856 -0
  45. package/docs/api/reference/grass.md +131 -0
  46. package/docs/api/reference/impostors.md +368 -0
  47. package/docs/api/reference/input.md +121 -0
  48. package/docs/api/reference/lights.md +257 -0
  49. package/docs/api/reference/lines.md +84 -0
  50. package/docs/api/reference/materials.md +375 -0
  51. package/docs/api/reference/math.md +229 -0
  52. package/docs/api/reference/objects.md +103 -0
  53. package/docs/api/reference/particles.md +336 -0
  54. package/docs/api/reference/points.md +57 -0
  55. package/docs/api/reference/post.md +244 -0
  56. package/docs/api/reference/quality.md +213 -0
  57. package/docs/api/reference/raycast.md +94 -0
  58. package/docs/api/reference/render.md +238 -0
  59. package/docs/api/reference/scene.md +543 -0
  60. package/docs/api/reference/sketch.md +125 -0
  61. package/docs/api/reference/sound.md +203 -0
  62. package/docs/api/reference/splats.md +214 -0
  63. package/docs/api/reference/sprites.md +71 -0
  64. package/docs/api/reference/tasks.md +92 -0
  65. package/docs/api/reference/terrain.md +161 -0
  66. package/docs/api/reference/textures.md +153 -0
  67. package/docs/api/reference/three-compat.md +60 -0
  68. package/docs/api/reference/time.md +25 -0
  69. package/docs/api/reference/ui.md +52 -0
  70. package/docs/api/reference/vertex-draws.md +55 -0
  71. package/docs/api/reference/water.md +430 -0
  72. package/docs/api/reference/wind.md +106 -0
  73. package/docs/api/render.md +499 -0
  74. package/docs/api/scene.md +606 -0
  75. package/docs/api/sketch.md +231 -0
  76. package/docs/api/sound.md +169 -0
  77. package/docs/api/splats.md +264 -0
  78. package/docs/api/sprites.md +169 -0
  79. package/docs/api/tasks.md +106 -0
  80. package/docs/api/terrain.md +118 -0
  81. package/docs/api/textures.md +272 -0
  82. package/docs/api/three-compat.md +102 -0
  83. package/docs/api/time.md +134 -0
  84. package/docs/api/ui.md +134 -0
  85. package/docs/api/vertex-draws.md +171 -0
  86. package/docs/api/water.md +486 -0
  87. package/docs/api/wind.md +375 -0
  88. package/docs/cli/null3d.md +603 -0
  89. package/docs/concepts/architecture.md +174 -0
  90. package/docs/concepts/assets.md +128 -0
  91. package/docs/concepts/backends.md +197 -0
  92. package/docs/concepts/color-management.md +134 -0
  93. package/docs/concepts/culling.md +227 -0
  94. package/docs/concepts/handles.md +93 -0
  95. package/docs/concepts/instances.md +285 -0
  96. package/docs/concepts/large-worlds.md +126 -0
  97. package/docs/concepts/lighting.md +587 -0
  98. package/docs/concepts/lod.md +241 -0
  99. package/docs/concepts/materials.md +128 -0
  100. package/docs/concepts/particle-buffer.md +201 -0
  101. package/docs/concepts/post-processing.md +420 -0
  102. package/docs/concepts/quality-preset-tables.md +94 -0
  103. package/docs/concepts/quality-presets.md +341 -0
  104. package/docs/concepts/render-graph.md +222 -0
  105. package/docs/concepts/render-layers.md +111 -0
  106. package/docs/concepts/shadows.md +448 -0
  107. package/docs/concepts/static-dynamic.md +113 -0
  108. package/docs/cookbook/index.md +664 -0
  109. package/docs/data/threejs-mapping.json +2152 -0
  110. package/docs/errors/E1101.md +23 -0
  111. package/docs/errors/E1102.md +23 -0
  112. package/docs/errors/E1103.md +23 -0
  113. package/docs/errors/E1104.md +23 -0
  114. package/docs/errors/E1105.md +23 -0
  115. package/docs/errors/E1106.md +23 -0
  116. package/docs/errors/E1107.md +23 -0
  117. package/docs/errors/E1108.md +23 -0
  118. package/docs/errors/E1109.md +23 -0
  119. package/docs/errors/E1110.md +23 -0
  120. package/docs/errors/E1111.md +23 -0
  121. package/docs/errors/E1112.md +23 -0
  122. package/docs/errors/E1203.md +23 -0
  123. package/docs/errors/E1204.md +23 -0
  124. package/docs/errors/E1205.md +23 -0
  125. package/docs/errors/E1206.md +23 -0
  126. package/docs/errors/E1207.md +23 -0
  127. package/docs/errors/E1208.md +23 -0
  128. package/docs/errors/E1209.md +23 -0
  129. package/docs/errors/E1213.md +23 -0
  130. package/docs/errors/E1214.md +23 -0
  131. package/docs/errors/E1215.md +23 -0
  132. package/docs/errors/E1216.md +23 -0
  133. package/docs/errors/E1217.md +23 -0
  134. package/docs/errors/E1218.md +23 -0
  135. package/docs/errors/E1219.md +23 -0
  136. package/docs/errors/E1220.md +23 -0
  137. package/docs/errors/E1221.md +23 -0
  138. package/docs/errors/E1222.md +23 -0
  139. package/docs/errors/E1223.md +23 -0
  140. package/docs/errors/E1224.md +23 -0
  141. package/docs/errors/E1225.md +23 -0
  142. package/docs/errors/E1301.md +23 -0
  143. package/docs/errors/E1302.md +23 -0
  144. package/docs/errors/E1303.md +23 -0
  145. package/docs/errors/E1304.md +23 -0
  146. package/docs/errors/E1305.md +23 -0
  147. package/docs/errors/E1306.md +23 -0
  148. package/docs/errors/E1307.md +23 -0
  149. package/docs/errors/E1401.md +23 -0
  150. package/docs/errors/E1402.md +23 -0
  151. package/docs/errors/E1403.md +23 -0
  152. package/docs/errors/E1404.md +23 -0
  153. package/docs/errors/E1405.md +23 -0
  154. package/docs/errors/E1406.md +23 -0
  155. package/docs/errors/E1407.md +23 -0
  156. package/docs/errors/E1408.md +23 -0
  157. package/docs/errors/E1409.md +23 -0
  158. package/docs/errors/E1410.md +23 -0
  159. package/docs/errors/E1411.md +23 -0
  160. package/docs/errors/E1412.md +23 -0
  161. package/docs/errors/E1413.md +23 -0
  162. package/docs/errors/E1414.md +23 -0
  163. package/docs/errors/E1415.md +23 -0
  164. package/docs/errors/E1416.md +23 -0
  165. package/docs/errors/E1417.md +23 -0
  166. package/docs/errors/E1418.md +23 -0
  167. package/docs/errors/E1419.md +23 -0
  168. package/docs/errors/E1420.md +23 -0
  169. package/docs/errors/E1421.md +23 -0
  170. package/docs/errors/E1422.md +23 -0
  171. package/docs/errors/E1423.md +23 -0
  172. package/docs/errors/E1424.md +23 -0
  173. package/docs/errors/E1425.md +23 -0
  174. package/docs/errors/E1426.md +23 -0
  175. package/docs/errors/E1430.md +23 -0
  176. package/docs/errors/E1431.md +23 -0
  177. package/docs/errors/E1432.md +23 -0
  178. package/docs/errors/E1433.md +23 -0
  179. package/docs/errors/E1434.md +23 -0
  180. package/docs/errors/E1435.md +23 -0
  181. package/docs/errors/E1436.md +23 -0
  182. package/docs/errors/E1437.md +23 -0
  183. package/docs/errors/E1501.md +23 -0
  184. package/docs/errors/E1502.md +23 -0
  185. package/docs/errors/E1503.md +23 -0
  186. package/docs/errors/E1504.md +23 -0
  187. package/docs/errors/E1505.md +23 -0
  188. package/docs/errors/E1506.md +23 -0
  189. package/docs/errors/index.md +93 -0
  190. package/docs/getting-started/cdn.md +235 -0
  191. package/docs/getting-started/first-scene.md +129 -0
  192. package/docs/getting-started/hosting.md +400 -0
  193. package/docs/getting-started/install.md +112 -0
  194. package/docs/getting-started/network-use.md +96 -0
  195. package/docs/getting-started/project-structure.md +78 -0
  196. package/docs/getting-started/third-party-notices.md +94 -0
  197. package/docs/guides/accessibility.md +96 -0
  198. package/docs/guides/add-ons.md +160 -0
  199. package/docs/guides/agents.md +77 -0
  200. package/docs/guides/assets-pipeline.md +505 -0
  201. package/docs/guides/audio.md +148 -0
  202. package/docs/guides/baked-light-data.md +176 -0
  203. package/docs/guides/car-paint.md +121 -0
  204. package/docs/guides/content-pages.md +238 -0
  205. package/docs/guides/custom-passes.md +586 -0
  206. package/docs/guides/custom-shaders.md +293 -0
  207. package/docs/guides/debugging.md +236 -0
  208. package/docs/guides/deploying.md +115 -0
  209. package/docs/guides/deterministic-simulation.md +226 -0
  210. package/docs/guides/first-use-shaders.md +57 -0
  211. package/docs/guides/lens-kit.md +134 -0
  212. package/docs/guides/loading-screens.md +263 -0
  213. package/docs/guides/multiple-views.md +122 -0
  214. package/docs/guides/performance.md +405 -0
  215. package/docs/guides/phones.md +138 -0
  216. package/docs/guides/physics.md +202 -0
  217. package/docs/guides/screens.md +125 -0
  218. package/docs/guides/start-time.md +328 -0
  219. package/docs/guides/testing.md +245 -0
  220. package/docs/guides/ui-overlays.md +182 -0
  221. package/docs/guides/video-textures.md +110 -0
  222. package/docs/index.md +49 -0
  223. package/docs/pages.md +242 -0
  224. package/docs/porting/react-three-fiber.md +238 -0
  225. package/docs/porting/threejs-loop-and-threads.md +229 -0
  226. package/docs/porting/threejs-mapping.md +297 -0
  227. package/docs/porting/threejs-materials.md +222 -0
  228. package/docs/porting/threejs-overview.md +228 -0
  229. package/docs/porting/threejs-postprocessing.md +256 -0
  230. package/docs/porting/threejs-shaders.md +308 -0
  231. package/docs/porting/threejs-unsupported.md +91 -0
  232. package/docs/porting/verification.md +191 -0
  233. package/docs/shaders/builtins.md +129 -0
  234. package/docs/shaders/library.md +1374 -0
  235. package/docs/shaders/surface-functions.md +626 -0
  236. package/docs/shaders/wgsl-rules.md +126 -0
  237. package/levels/pieces.d.ts +178 -0
  238. package/levels/pieces.js +759 -0
  239. package/levels/planner.d.ts +126 -0
  240. package/levels/planner.js +682 -0
  241. package/lib/debug/channel.d.ts +103 -0
  242. package/lib/debug/channel.js +269 -0
  243. package/lib/debug/debug.d.ts +180 -0
  244. package/lib/debug/debug.js +4 -0
  245. package/lib/debug/draw.d.ts +146 -0
  246. package/lib/debug/draw.js +719 -0
  247. package/lib/debug/frame-target.d.ts +11 -0
  248. package/lib/debug/frame-target.js +31 -0
  249. package/lib/debug/inspector.d.ts +60 -0
  250. package/lib/debug/inspector.js +475 -0
  251. package/lib/debug/overlay-look.d.ts +162 -0
  252. package/lib/debug/overlay-look.js +1365 -0
  253. package/lib/debug/overlay.d.ts +68 -0
  254. package/lib/debug/overlay.js +195 -0
  255. package/lib/debug/page-meters.d.ts +139 -0
  256. package/lib/debug/page-meters.js +267 -0
  257. package/lib/debug/sketch-debug.d.ts +41 -0
  258. package/lib/debug/sketch-debug.js +86 -0
  259. package/lib/debug/stats-options.d.ts +15 -0
  260. package/lib/debug/stats-options.js +3 -0
  261. package/lib/debug/stats-panel.d.ts +94 -0
  262. package/lib/debug/stats-panel.js +123 -0
  263. package/lib/debug/stats-text.d.ts +169 -0
  264. package/lib/debug/stats-text.js +126 -0
  265. package/lib/debug/stats.d.ts +195 -0
  266. package/lib/debug/stats.js +252 -0
  267. package/lib/debug/view-names.d.ts +15 -0
  268. package/lib/debug/view-names.js +22 -0
  269. package/lib/errors/checks.d.ts +24 -0
  270. package/lib/errors/checks.js +38 -0
  271. package/lib/errors/codes.d.ts +15 -0
  272. package/lib/errors/codes.js +489 -0
  273. package/lib/errors/core-failure.d.ts +19 -0
  274. package/lib/errors/core-failure.js +127 -0
  275. package/lib/errors/engine-error-core.d.ts +21 -0
  276. package/lib/errors/engine-error-core.js +39 -0
  277. package/lib/errors/engine-error.d.ts +38 -0
  278. package/lib/errors/engine-error.js +132 -0
  279. package/lib/errors/fixes.d.ts +89 -0
  280. package/lib/errors/fixes.js +86 -0
  281. package/lib/errors/message.d.ts +4 -0
  282. package/lib/errors/message.js +10 -0
  283. package/lib/generated/core.d.ts +657 -0
  284. package/lib/generated/core.js +659 -0
  285. package/lib/generated/gpu.d.ts +412 -0
  286. package/lib/generated/gpu.js +414 -0
  287. package/lib/generated/shader-features.d.ts +8 -0
  288. package/lib/generated/shader-permutations.d.ts +6 -0
  289. package/lib/generated/shader-permutations.js +9 -0
  290. package/lib/generated/shaders-environment-glsl.d.ts +11 -0
  291. package/lib/generated/shaders-environment-wgsl.d.ts +11 -0
  292. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-coverage-half.d.ts +3 -0
  293. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-coverage.d.ts +3 -0
  294. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-displacement-half.d.ts +3 -0
  295. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-displacement.d.ts +3 -0
  296. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-hash-half.d.ts +3 -0
  297. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-hash.d.ts +3 -0
  298. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-lod-fade-half.d.ts +3 -0
  299. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-lod-fade.d.ts +3 -0
  300. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-morph-half.d.ts +3 -0
  301. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-morph.d.ts +3 -0
  302. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-row-values-half.d.ts +3 -0
  303. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-row-values.d.ts +3 -0
  304. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-skinning-half.d.ts +3 -0
  305. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-skinning.d.ts +3 -0
  306. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-transmission-half.d.ts +3 -0
  307. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-transmission.d.ts +3 -0
  308. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-weighted-half.d.ts +3 -0
  309. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-and-weighted.d.ts +3 -0
  310. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen-half.d.ts +3 -0
  311. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coat-sheen.d.ts +3 -0
  312. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-and-displacement-half.d.ts +3 -0
  313. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-and-displacement.d.ts +3 -0
  314. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-and-lod-fade-half.d.ts +3 -0
  315. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-and-lod-fade.d.ts +3 -0
  316. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-and-morph-half.d.ts +3 -0
  317. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-and-morph.d.ts +3 -0
  318. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-and-row-values-half.d.ts +3 -0
  319. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-and-row-values.d.ts +3 -0
  320. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-and-skinning-half.d.ts +3 -0
  321. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-and-skinning.d.ts +3 -0
  322. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-and-translucency-half.d.ts +3 -0
  323. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-and-translucency.d.ts +3 -0
  324. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-and-transmission-half.d.ts +3 -0
  325. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-and-transmission.d.ts +3 -0
  326. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage-half.d.ts +3 -0
  327. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-coverage.d.ts +3 -0
  328. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-and-hash-half.d.ts +3 -0
  329. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-and-hash.d.ts +3 -0
  330. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-and-morph-half.d.ts +3 -0
  331. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-and-morph.d.ts +3 -0
  332. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-and-row-values-half.d.ts +3 -0
  333. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-and-row-values.d.ts +3 -0
  334. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-and-skinning-half.d.ts +3 -0
  335. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-and-skinning.d.ts +3 -0
  336. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-and-translucency-half.d.ts +3 -0
  337. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-and-translucency.d.ts +3 -0
  338. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-and-transmission-half.d.ts +3 -0
  339. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-and-transmission.d.ts +3 -0
  340. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-and-weighted-half.d.ts +3 -0
  341. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-and-weighted.d.ts +3 -0
  342. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement-half.d.ts +3 -0
  343. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-displacement.d.ts +3 -0
  344. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-hash-and-morph-half.d.ts +3 -0
  345. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-hash-and-morph.d.ts +3 -0
  346. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-hash-and-row-values-half.d.ts +3 -0
  347. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-hash-and-row-values.d.ts +3 -0
  348. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-hash-and-skinning-half.d.ts +3 -0
  349. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-hash-and-skinning.d.ts +3 -0
  350. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-hash-and-translucency-half.d.ts +3 -0
  351. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-hash-and-translucency.d.ts +3 -0
  352. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-hash-half.d.ts +3 -0
  353. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-hash.d.ts +3 -0
  354. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-lod-fade-and-row-values-half.d.ts +3 -0
  355. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-lod-fade-and-row-values.d.ts +3 -0
  356. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-lod-fade-and-translucency-half.d.ts +3 -0
  357. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-lod-fade-and-translucency.d.ts +3 -0
  358. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-lod-fade-half.d.ts +3 -0
  359. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-lod-fade.d.ts +3 -0
  360. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-morph-and-skinning-half.d.ts +3 -0
  361. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-morph-and-skinning.d.ts +3 -0
  362. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-morph-and-translucency-half.d.ts +3 -0
  363. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-morph-and-translucency.d.ts +3 -0
  364. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-morph-and-transmission-half.d.ts +3 -0
  365. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-morph-and-transmission.d.ts +3 -0
  366. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-morph-and-weighted-half.d.ts +3 -0
  367. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-morph-and-weighted.d.ts +3 -0
  368. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-morph-half.d.ts +3 -0
  369. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-morph.d.ts +3 -0
  370. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-row-values-and-translucency-half.d.ts +3 -0
  371. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-row-values-and-translucency.d.ts +3 -0
  372. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-row-values-and-weighted-half.d.ts +3 -0
  373. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-row-values-and-weighted.d.ts +3 -0
  374. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-row-values-half.d.ts +3 -0
  375. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-row-values.d.ts +3 -0
  376. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-skinning-and-translucency-half.d.ts +3 -0
  377. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-skinning-and-translucency.d.ts +3 -0
  378. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-skinning-and-transmission-half.d.ts +3 -0
  379. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-skinning-and-transmission.d.ts +3 -0
  380. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-skinning-and-weighted-half.d.ts +3 -0
  381. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-skinning-and-weighted.d.ts +3 -0
  382. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-skinning-half.d.ts +3 -0
  383. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-skinning.d.ts +3 -0
  384. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-translucency-half.d.ts +3 -0
  385. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-translucency.d.ts +3 -0
  386. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-transmission-half.d.ts +3 -0
  387. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-transmission.d.ts +3 -0
  388. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-weighted-half.d.ts +3 -0
  389. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-and-weighted.d.ts +3 -0
  390. package/lib/generated/shaders-glsl-combos-area-lights-and-bump-half.d.ts +3 -0
  391. package/lib/generated/shaders-glsl-combos-area-lights-and-bump.d.ts +3 -0
  392. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-coverage-and-displacement-half.d.ts +3 -0
  393. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-coverage-and-displacement.d.ts +3 -0
  394. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-coverage-and-lod-fade-half.d.ts +3 -0
  395. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-coverage-and-lod-fade.d.ts +3 -0
  396. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-coverage-and-morph-half.d.ts +3 -0
  397. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-coverage-and-morph.d.ts +3 -0
  398. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-coverage-and-row-values-half.d.ts +3 -0
  399. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-coverage-and-row-values.d.ts +3 -0
  400. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-coverage-and-skinning-half.d.ts +3 -0
  401. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-coverage-and-skinning.d.ts +3 -0
  402. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-coverage-and-transmission-half.d.ts +3 -0
  403. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-coverage-and-transmission.d.ts +3 -0
  404. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-coverage-half.d.ts +3 -0
  405. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-coverage.d.ts +3 -0
  406. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-displacement-and-hash-half.d.ts +3 -0
  407. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-displacement-and-hash.d.ts +3 -0
  408. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-displacement-and-morph-half.d.ts +3 -0
  409. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-displacement-and-morph.d.ts +3 -0
  410. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-displacement-and-row-values-half.d.ts +3 -0
  411. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-displacement-and-row-values.d.ts +3 -0
  412. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-displacement-and-skinning-half.d.ts +3 -0
  413. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-displacement-and-skinning.d.ts +3 -0
  414. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-displacement-and-transmission-half.d.ts +3 -0
  415. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-displacement-and-transmission.d.ts +3 -0
  416. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-displacement-and-weighted-half.d.ts +3 -0
  417. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-displacement-and-weighted.d.ts +3 -0
  418. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-displacement-half.d.ts +3 -0
  419. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-displacement.d.ts +3 -0
  420. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-hash-and-morph-half.d.ts +3 -0
  421. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-hash-and-morph.d.ts +3 -0
  422. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-hash-and-row-values-half.d.ts +3 -0
  423. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-hash-and-row-values.d.ts +3 -0
  424. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-hash-and-skinning-half.d.ts +3 -0
  425. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-hash-and-skinning.d.ts +3 -0
  426. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-hash-half.d.ts +3 -0
  427. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-hash.d.ts +3 -0
  428. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-lod-fade-and-row-values-half.d.ts +3 -0
  429. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-lod-fade-and-row-values.d.ts +3 -0
  430. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-lod-fade-half.d.ts +3 -0
  431. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-lod-fade.d.ts +3 -0
  432. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-morph-and-skinning-half.d.ts +3 -0
  433. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-morph-and-skinning.d.ts +3 -0
  434. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-morph-and-transmission-half.d.ts +3 -0
  435. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-morph-and-transmission.d.ts +3 -0
  436. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-morph-and-weighted-half.d.ts +3 -0
  437. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-morph-and-weighted.d.ts +3 -0
  438. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-morph-half.d.ts +3 -0
  439. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-morph.d.ts +3 -0
  440. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-row-values-and-weighted-half.d.ts +3 -0
  441. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-row-values-and-weighted.d.ts +3 -0
  442. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-row-values-half.d.ts +3 -0
  443. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-row-values.d.ts +3 -0
  444. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-skinning-and-transmission-half.d.ts +3 -0
  445. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-skinning-and-transmission.d.ts +3 -0
  446. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-skinning-and-weighted-half.d.ts +3 -0
  447. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-skinning-and-weighted.d.ts +3 -0
  448. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-skinning-half.d.ts +3 -0
  449. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-skinning.d.ts +3 -0
  450. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-transmission-half.d.ts +3 -0
  451. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-transmission.d.ts +3 -0
  452. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-weighted-half.d.ts +3 -0
  453. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-and-weighted.d.ts +3 -0
  454. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen-half.d.ts +3 -0
  455. package/lib/generated/shaders-glsl-combos-area-lights-and-coat-sheen.d.ts +3 -0
  456. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-displacement-and-morph-half.d.ts +3 -0
  457. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-displacement-and-morph.d.ts +3 -0
  458. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-displacement-and-row-values-half.d.ts +3 -0
  459. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-displacement-and-row-values.d.ts +3 -0
  460. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-displacement-and-skinning-half.d.ts +3 -0
  461. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-displacement-and-skinning.d.ts +3 -0
  462. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-displacement-and-translucency-half.d.ts +3 -0
  463. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-displacement-and-translucency.d.ts +3 -0
  464. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-displacement-and-transmission-half.d.ts +3 -0
  465. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-displacement-and-transmission.d.ts +3 -0
  466. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-displacement-half.d.ts +3 -0
  467. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-displacement.d.ts +3 -0
  468. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-lod-fade-and-row-values-half.d.ts +3 -0
  469. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-lod-fade-and-row-values.d.ts +3 -0
  470. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-lod-fade-and-translucency-half.d.ts +3 -0
  471. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-lod-fade-and-translucency.d.ts +3 -0
  472. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-lod-fade-half.d.ts +3 -0
  473. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-lod-fade.d.ts +3 -0
  474. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-morph-and-skinning-half.d.ts +3 -0
  475. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-morph-and-skinning.d.ts +3 -0
  476. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-morph-and-translucency-half.d.ts +3 -0
  477. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-morph-and-translucency.d.ts +3 -0
  478. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-morph-and-transmission-half.d.ts +3 -0
  479. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-morph-and-transmission.d.ts +3 -0
  480. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-morph-half.d.ts +3 -0
  481. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-morph.d.ts +3 -0
  482. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-row-values-and-translucency-half.d.ts +3 -0
  483. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-row-values-and-translucency.d.ts +3 -0
  484. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-row-values-half.d.ts +3 -0
  485. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-row-values.d.ts +3 -0
  486. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-skinning-and-translucency-half.d.ts +3 -0
  487. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-skinning-and-translucency.d.ts +3 -0
  488. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-skinning-and-transmission-half.d.ts +3 -0
  489. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-skinning-and-transmission.d.ts +3 -0
  490. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-skinning-half.d.ts +3 -0
  491. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-skinning.d.ts +3 -0
  492. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-translucency-half.d.ts +3 -0
  493. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-translucency.d.ts +3 -0
  494. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-transmission-half.d.ts +3 -0
  495. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-and-transmission.d.ts +3 -0
  496. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage-half.d.ts +3 -0
  497. package/lib/generated/shaders-glsl-combos-area-lights-and-coverage.d.ts +3 -0
  498. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-hash-and-morph-half.d.ts +3 -0
  499. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-hash-and-morph.d.ts +3 -0
  500. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-hash-and-row-values-half.d.ts +3 -0
  501. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-hash-and-row-values.d.ts +3 -0
  502. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-hash-and-skinning-half.d.ts +3 -0
  503. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-hash-and-skinning.d.ts +3 -0
  504. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-hash-and-translucency-half.d.ts +3 -0
  505. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-hash-and-translucency.d.ts +3 -0
  506. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-hash-half.d.ts +3 -0
  507. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-hash.d.ts +3 -0
  508. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-moment-and-morph-half.d.ts +3 -0
  509. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-moment-and-morph.d.ts +3 -0
  510. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-moment-and-row-values-half.d.ts +3 -0
  511. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-moment-and-row-values.d.ts +3 -0
  512. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-moment-and-skinning-half.d.ts +3 -0
  513. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-moment-and-skinning.d.ts +3 -0
  514. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-moment-and-translucency-half.d.ts +3 -0
  515. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-moment-and-translucency.d.ts +3 -0
  516. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-moment-half.d.ts +3 -0
  517. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-moment.d.ts +3 -0
  518. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-morph-and-skinning-half.d.ts +3 -0
  519. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-morph-and-skinning.d.ts +3 -0
  520. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-morph-and-translucency-half.d.ts +3 -0
  521. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-morph-and-translucency.d.ts +3 -0
  522. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-morph-and-transmission-half.d.ts +3 -0
  523. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-morph-and-transmission.d.ts +3 -0
  524. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-morph-and-weighted-half.d.ts +3 -0
  525. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-morph-and-weighted.d.ts +3 -0
  526. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-morph-half.d.ts +3 -0
  527. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-morph.d.ts +3 -0
  528. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-row-values-and-translucency-half.d.ts +3 -0
  529. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-row-values-and-translucency.d.ts +3 -0
  530. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-row-values-and-weighted-half.d.ts +3 -0
  531. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-row-values-and-weighted.d.ts +3 -0
  532. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-row-values-half.d.ts +3 -0
  533. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-row-values.d.ts +3 -0
  534. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-skinning-and-translucency-half.d.ts +3 -0
  535. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-skinning-and-translucency.d.ts +3 -0
  536. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-skinning-and-transmission-half.d.ts +3 -0
  537. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-skinning-and-transmission.d.ts +3 -0
  538. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-skinning-and-weighted-half.d.ts +3 -0
  539. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-skinning-and-weighted.d.ts +3 -0
  540. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-skinning-half.d.ts +3 -0
  541. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-skinning.d.ts +3 -0
  542. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-translucency-half.d.ts +3 -0
  543. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-translucency.d.ts +3 -0
  544. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-transmission-half.d.ts +3 -0
  545. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-transmission.d.ts +3 -0
  546. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-weighted-half.d.ts +3 -0
  547. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-and-weighted.d.ts +3 -0
  548. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement-half.d.ts +3 -0
  549. package/lib/generated/shaders-glsl-combos-area-lights-and-displacement.d.ts +3 -0
  550. package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-morph-and-skinning-half.d.ts +3 -0
  551. package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-morph-and-skinning.d.ts +3 -0
  552. package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-morph-and-translucency-half.d.ts +3 -0
  553. package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-morph-and-translucency.d.ts +3 -0
  554. package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-morph-half.d.ts +3 -0
  555. package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-morph.d.ts +3 -0
  556. package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-row-values-and-translucency-half.d.ts +3 -0
  557. package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-row-values-and-translucency.d.ts +3 -0
  558. package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-row-values-half.d.ts +3 -0
  559. package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-row-values.d.ts +3 -0
  560. package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-skinning-and-translucency-half.d.ts +3 -0
  561. package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-skinning-and-translucency.d.ts +3 -0
  562. package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-skinning-half.d.ts +3 -0
  563. package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-skinning.d.ts +3 -0
  564. package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-translucency-half.d.ts +3 -0
  565. package/lib/generated/shaders-glsl-combos-area-lights-and-hash-and-translucency.d.ts +3 -0
  566. package/lib/generated/shaders-glsl-combos-area-lights-and-hash-half.d.ts +3 -0
  567. package/lib/generated/shaders-glsl-combos-area-lights-and-hash.d.ts +3 -0
  568. package/lib/generated/shaders-glsl-combos-area-lights-and-lines.d.ts +3 -0
  569. package/lib/generated/shaders-glsl-combos-area-lights-and-lod-fade-and-row-values-and-translucency-half.d.ts +3 -0
  570. package/lib/generated/shaders-glsl-combos-area-lights-and-lod-fade-and-row-values-and-translucency.d.ts +3 -0
  571. package/lib/generated/shaders-glsl-combos-area-lights-and-lod-fade-and-row-values-half.d.ts +3 -0
  572. package/lib/generated/shaders-glsl-combos-area-lights-and-lod-fade-and-row-values.d.ts +3 -0
  573. package/lib/generated/shaders-glsl-combos-area-lights-and-lod-fade-and-translucency-half.d.ts +3 -0
  574. package/lib/generated/shaders-glsl-combos-area-lights-and-lod-fade-and-translucency.d.ts +3 -0
  575. package/lib/generated/shaders-glsl-combos-area-lights-and-lod-fade-half.d.ts +3 -0
  576. package/lib/generated/shaders-glsl-combos-area-lights-and-lod-fade.d.ts +3 -0
  577. package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-morph-and-skinning-half.d.ts +3 -0
  578. package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-morph-and-skinning.d.ts +3 -0
  579. package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-morph-and-translucency-half.d.ts +3 -0
  580. package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-morph-and-translucency.d.ts +3 -0
  581. package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-morph-half.d.ts +3 -0
  582. package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-morph.d.ts +3 -0
  583. package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-row-values-and-translucency-half.d.ts +3 -0
  584. package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-row-values-and-translucency.d.ts +3 -0
  585. package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-row-values-half.d.ts +3 -0
  586. package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-row-values.d.ts +3 -0
  587. package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-skinning-and-translucency-half.d.ts +3 -0
  588. package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-skinning-and-translucency.d.ts +3 -0
  589. package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-skinning-half.d.ts +3 -0
  590. package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-skinning.d.ts +3 -0
  591. package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-translucency-half.d.ts +3 -0
  592. package/lib/generated/shaders-glsl-combos-area-lights-and-moment-and-translucency.d.ts +3 -0
  593. package/lib/generated/shaders-glsl-combos-area-lights-and-moment-half.d.ts +3 -0
  594. package/lib/generated/shaders-glsl-combos-area-lights-and-moment.d.ts +3 -0
  595. package/lib/generated/shaders-glsl-combos-area-lights-and-morph-and-skinning-and-translucency-half.d.ts +3 -0
  596. package/lib/generated/shaders-glsl-combos-area-lights-and-morph-and-skinning-and-translucency.d.ts +3 -0
  597. package/lib/generated/shaders-glsl-combos-area-lights-and-morph-and-skinning-and-transmission-half.d.ts +3 -0
  598. package/lib/generated/shaders-glsl-combos-area-lights-and-morph-and-skinning-and-transmission.d.ts +3 -0
  599. package/lib/generated/shaders-glsl-combos-area-lights-and-morph-and-skinning-and-weighted-half.d.ts +3 -0
  600. package/lib/generated/shaders-glsl-combos-area-lights-and-morph-and-skinning-and-weighted.d.ts +3 -0
  601. package/lib/generated/shaders-glsl-combos-area-lights-and-morph-and-skinning-half.d.ts +3 -0
  602. package/lib/generated/shaders-glsl-combos-area-lights-and-morph-and-skinning.d.ts +3 -0
  603. package/lib/generated/shaders-glsl-combos-area-lights-and-morph-and-translucency-half.d.ts +3 -0
  604. package/lib/generated/shaders-glsl-combos-area-lights-and-morph-and-translucency.d.ts +3 -0
  605. package/lib/generated/shaders-glsl-combos-area-lights-and-morph-and-transmission-half.d.ts +3 -0
  606. package/lib/generated/shaders-glsl-combos-area-lights-and-morph-and-transmission.d.ts +3 -0
  607. package/lib/generated/shaders-glsl-combos-area-lights-and-morph-and-weighted-half.d.ts +3 -0
  608. package/lib/generated/shaders-glsl-combos-area-lights-and-morph-and-weighted.d.ts +3 -0
  609. package/lib/generated/shaders-glsl-combos-area-lights-and-morph-half.d.ts +3 -0
  610. package/lib/generated/shaders-glsl-combos-area-lights-and-morph.d.ts +3 -0
  611. package/lib/generated/shaders-glsl-combos-area-lights-and-row-values-and-translucency-half.d.ts +3 -0
  612. package/lib/generated/shaders-glsl-combos-area-lights-and-row-values-and-translucency.d.ts +3 -0
  613. package/lib/generated/shaders-glsl-combos-area-lights-and-row-values-and-weighted-half.d.ts +3 -0
  614. package/lib/generated/shaders-glsl-combos-area-lights-and-row-values-and-weighted.d.ts +3 -0
  615. package/lib/generated/shaders-glsl-combos-area-lights-and-row-values-half.d.ts +3 -0
  616. package/lib/generated/shaders-glsl-combos-area-lights-and-row-values.d.ts +3 -0
  617. package/lib/generated/shaders-glsl-combos-area-lights-and-skinning-and-translucency-half.d.ts +3 -0
  618. package/lib/generated/shaders-glsl-combos-area-lights-and-skinning-and-translucency.d.ts +3 -0
  619. package/lib/generated/shaders-glsl-combos-area-lights-and-skinning-and-transmission-half.d.ts +3 -0
  620. package/lib/generated/shaders-glsl-combos-area-lights-and-skinning-and-transmission.d.ts +3 -0
  621. package/lib/generated/shaders-glsl-combos-area-lights-and-skinning-and-weighted-half.d.ts +3 -0
  622. package/lib/generated/shaders-glsl-combos-area-lights-and-skinning-and-weighted.d.ts +3 -0
  623. package/lib/generated/shaders-glsl-combos-area-lights-and-skinning-half.d.ts +3 -0
  624. package/lib/generated/shaders-glsl-combos-area-lights-and-skinning.d.ts +3 -0
  625. package/lib/generated/shaders-glsl-combos-area-lights-and-translucency-half.d.ts +3 -0
  626. package/lib/generated/shaders-glsl-combos-area-lights-and-translucency.d.ts +3 -0
  627. package/lib/generated/shaders-glsl-combos-area-lights-and-transmission-half.d.ts +3 -0
  628. package/lib/generated/shaders-glsl-combos-area-lights-and-transmission.d.ts +3 -0
  629. package/lib/generated/shaders-glsl-combos-area-lights-and-weighted-half.d.ts +3 -0
  630. package/lib/generated/shaders-glsl-combos-area-lights-and-weighted.d.ts +3 -0
  631. package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-coverage-half.d.ts +3 -0
  632. package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-coverage.d.ts +3 -0
  633. package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-displacement-half.d.ts +3 -0
  634. package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-displacement.d.ts +3 -0
  635. package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-hash-half.d.ts +3 -0
  636. package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-hash.d.ts +3 -0
  637. package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-lod-fade-half.d.ts +3 -0
  638. package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-lod-fade.d.ts +3 -0
  639. package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-morph-half.d.ts +3 -0
  640. package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-morph.d.ts +3 -0
  641. package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-row-values-half.d.ts +3 -0
  642. package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-row-values.d.ts +3 -0
  643. package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-skinning-half.d.ts +3 -0
  644. package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-skinning.d.ts +3 -0
  645. package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-transmission-half.d.ts +3 -0
  646. package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-transmission.d.ts +3 -0
  647. package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-weighted-half.d.ts +3 -0
  648. package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-and-weighted.d.ts +3 -0
  649. package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen-half.d.ts +3 -0
  650. package/lib/generated/shaders-glsl-combos-bump-and-coat-sheen.d.ts +3 -0
  651. package/lib/generated/shaders-glsl-combos-bump-and-coverage-and-displacement-half.d.ts +3 -0
  652. package/lib/generated/shaders-glsl-combos-bump-and-coverage-and-displacement.d.ts +3 -0
  653. package/lib/generated/shaders-glsl-combos-bump-and-coverage-and-lod-fade-half.d.ts +3 -0
  654. package/lib/generated/shaders-glsl-combos-bump-and-coverage-and-lod-fade.d.ts +3 -0
  655. package/lib/generated/shaders-glsl-combos-bump-and-coverage-and-morph-half.d.ts +3 -0
  656. package/lib/generated/shaders-glsl-combos-bump-and-coverage-and-morph.d.ts +3 -0
  657. package/lib/generated/shaders-glsl-combos-bump-and-coverage-and-row-values-half.d.ts +3 -0
  658. package/lib/generated/shaders-glsl-combos-bump-and-coverage-and-row-values.d.ts +3 -0
  659. package/lib/generated/shaders-glsl-combos-bump-and-coverage-and-skinning-half.d.ts +3 -0
  660. package/lib/generated/shaders-glsl-combos-bump-and-coverage-and-skinning.d.ts +3 -0
  661. package/lib/generated/shaders-glsl-combos-bump-and-coverage-and-translucency-half.d.ts +3 -0
  662. package/lib/generated/shaders-glsl-combos-bump-and-coverage-and-translucency.d.ts +3 -0
  663. package/lib/generated/shaders-glsl-combos-bump-and-coverage-and-transmission-half.d.ts +3 -0
  664. package/lib/generated/shaders-glsl-combos-bump-and-coverage-and-transmission.d.ts +3 -0
  665. package/lib/generated/shaders-glsl-combos-bump-and-coverage-half.d.ts +3 -0
  666. package/lib/generated/shaders-glsl-combos-bump-and-coverage.d.ts +3 -0
  667. package/lib/generated/shaders-glsl-combos-bump-and-displacement-and-hash-half.d.ts +3 -0
  668. package/lib/generated/shaders-glsl-combos-bump-and-displacement-and-hash.d.ts +3 -0
  669. package/lib/generated/shaders-glsl-combos-bump-and-displacement-and-morph-half.d.ts +3 -0
  670. package/lib/generated/shaders-glsl-combos-bump-and-displacement-and-morph.d.ts +3 -0
  671. package/lib/generated/shaders-glsl-combos-bump-and-displacement-and-row-values-half.d.ts +3 -0
  672. package/lib/generated/shaders-glsl-combos-bump-and-displacement-and-row-values.d.ts +3 -0
  673. package/lib/generated/shaders-glsl-combos-bump-and-displacement-and-skinning-half.d.ts +3 -0
  674. package/lib/generated/shaders-glsl-combos-bump-and-displacement-and-skinning.d.ts +3 -0
  675. package/lib/generated/shaders-glsl-combos-bump-and-displacement-and-translucency-half.d.ts +3 -0
  676. package/lib/generated/shaders-glsl-combos-bump-and-displacement-and-translucency.d.ts +3 -0
  677. package/lib/generated/shaders-glsl-combos-bump-and-displacement-and-transmission-half.d.ts +3 -0
  678. package/lib/generated/shaders-glsl-combos-bump-and-displacement-and-transmission.d.ts +3 -0
  679. package/lib/generated/shaders-glsl-combos-bump-and-displacement-and-weighted-half.d.ts +3 -0
  680. package/lib/generated/shaders-glsl-combos-bump-and-displacement-and-weighted.d.ts +3 -0
  681. package/lib/generated/shaders-glsl-combos-bump-and-displacement-half.d.ts +3 -0
  682. package/lib/generated/shaders-glsl-combos-bump-and-displacement.d.ts +3 -0
  683. package/lib/generated/shaders-glsl-combos-bump-and-hash-and-morph-half.d.ts +3 -0
  684. package/lib/generated/shaders-glsl-combos-bump-and-hash-and-morph.d.ts +3 -0
  685. package/lib/generated/shaders-glsl-combos-bump-and-hash-and-row-values-half.d.ts +3 -0
  686. package/lib/generated/shaders-glsl-combos-bump-and-hash-and-row-values.d.ts +3 -0
  687. package/lib/generated/shaders-glsl-combos-bump-and-hash-and-skinning-half.d.ts +3 -0
  688. package/lib/generated/shaders-glsl-combos-bump-and-hash-and-skinning.d.ts +3 -0
  689. package/lib/generated/shaders-glsl-combos-bump-and-hash-and-translucency-half.d.ts +3 -0
  690. package/lib/generated/shaders-glsl-combos-bump-and-hash-and-translucency.d.ts +3 -0
  691. package/lib/generated/shaders-glsl-combos-bump-and-hash-half.d.ts +3 -0
  692. package/lib/generated/shaders-glsl-combos-bump-and-hash.d.ts +3 -0
  693. package/lib/generated/shaders-glsl-combos-bump-and-lod-fade-and-row-values-half.d.ts +3 -0
  694. package/lib/generated/shaders-glsl-combos-bump-and-lod-fade-and-row-values.d.ts +3 -0
  695. package/lib/generated/shaders-glsl-combos-bump-and-lod-fade-and-translucency-half.d.ts +3 -0
  696. package/lib/generated/shaders-glsl-combos-bump-and-lod-fade-and-translucency.d.ts +3 -0
  697. package/lib/generated/shaders-glsl-combos-bump-and-lod-fade-half.d.ts +3 -0
  698. package/lib/generated/shaders-glsl-combos-bump-and-lod-fade.d.ts +3 -0
  699. package/lib/generated/shaders-glsl-combos-bump-and-morph-and-skinning-half.d.ts +3 -0
  700. package/lib/generated/shaders-glsl-combos-bump-and-morph-and-skinning.d.ts +3 -0
  701. package/lib/generated/shaders-glsl-combos-bump-and-morph-and-translucency-half.d.ts +3 -0
  702. package/lib/generated/shaders-glsl-combos-bump-and-morph-and-translucency.d.ts +3 -0
  703. package/lib/generated/shaders-glsl-combos-bump-and-morph-and-transmission-half.d.ts +3 -0
  704. package/lib/generated/shaders-glsl-combos-bump-and-morph-and-transmission.d.ts +3 -0
  705. package/lib/generated/shaders-glsl-combos-bump-and-morph-and-weighted-half.d.ts +3 -0
  706. package/lib/generated/shaders-glsl-combos-bump-and-morph-and-weighted.d.ts +3 -0
  707. package/lib/generated/shaders-glsl-combos-bump-and-morph-half.d.ts +3 -0
  708. package/lib/generated/shaders-glsl-combos-bump-and-morph.d.ts +3 -0
  709. package/lib/generated/shaders-glsl-combos-bump-and-row-values-and-translucency-half.d.ts +3 -0
  710. package/lib/generated/shaders-glsl-combos-bump-and-row-values-and-translucency.d.ts +3 -0
  711. package/lib/generated/shaders-glsl-combos-bump-and-row-values-and-weighted-half.d.ts +3 -0
  712. package/lib/generated/shaders-glsl-combos-bump-and-row-values-and-weighted.d.ts +3 -0
  713. package/lib/generated/shaders-glsl-combos-bump-and-row-values-half.d.ts +3 -0
  714. package/lib/generated/shaders-glsl-combos-bump-and-row-values.d.ts +3 -0
  715. package/lib/generated/shaders-glsl-combos-bump-and-skinning-and-translucency-half.d.ts +3 -0
  716. package/lib/generated/shaders-glsl-combos-bump-and-skinning-and-translucency.d.ts +3 -0
  717. package/lib/generated/shaders-glsl-combos-bump-and-skinning-and-transmission-half.d.ts +3 -0
  718. package/lib/generated/shaders-glsl-combos-bump-and-skinning-and-transmission.d.ts +3 -0
  719. package/lib/generated/shaders-glsl-combos-bump-and-skinning-and-weighted-half.d.ts +3 -0
  720. package/lib/generated/shaders-glsl-combos-bump-and-skinning-and-weighted.d.ts +3 -0
  721. package/lib/generated/shaders-glsl-combos-bump-and-skinning-half.d.ts +3 -0
  722. package/lib/generated/shaders-glsl-combos-bump-and-skinning.d.ts +3 -0
  723. package/lib/generated/shaders-glsl-combos-bump-and-translucency-half.d.ts +3 -0
  724. package/lib/generated/shaders-glsl-combos-bump-and-translucency.d.ts +3 -0
  725. package/lib/generated/shaders-glsl-combos-bump-and-transmission-half.d.ts +3 -0
  726. package/lib/generated/shaders-glsl-combos-bump-and-transmission.d.ts +3 -0
  727. package/lib/generated/shaders-glsl-combos-bump-and-weighted-half.d.ts +3 -0
  728. package/lib/generated/shaders-glsl-combos-bump-and-weighted.d.ts +3 -0
  729. package/lib/generated/shaders-glsl-combos-coat-sheen-and-coverage-half.d.ts +3 -0
  730. package/lib/generated/shaders-glsl-combos-coat-sheen-and-coverage.d.ts +3 -0
  731. package/lib/generated/shaders-glsl-combos-coat-sheen-and-displacement-half.d.ts +3 -0
  732. package/lib/generated/shaders-glsl-combos-coat-sheen-and-displacement.d.ts +3 -0
  733. package/lib/generated/shaders-glsl-combos-coat-sheen-and-hash-half.d.ts +3 -0
  734. package/lib/generated/shaders-glsl-combos-coat-sheen-and-hash.d.ts +3 -0
  735. package/lib/generated/shaders-glsl-combos-coat-sheen-and-lod-fade-half.d.ts +3 -0
  736. package/lib/generated/shaders-glsl-combos-coat-sheen-and-lod-fade.d.ts +3 -0
  737. package/lib/generated/shaders-glsl-combos-coat-sheen-and-morph-half.d.ts +3 -0
  738. package/lib/generated/shaders-glsl-combos-coat-sheen-and-morph.d.ts +3 -0
  739. package/lib/generated/shaders-glsl-combos-coat-sheen-and-row-values-half.d.ts +3 -0
  740. package/lib/generated/shaders-glsl-combos-coat-sheen-and-row-values.d.ts +3 -0
  741. package/lib/generated/shaders-glsl-combos-coat-sheen-and-skinning-half.d.ts +3 -0
  742. package/lib/generated/shaders-glsl-combos-coat-sheen-and-skinning.d.ts +3 -0
  743. package/lib/generated/shaders-glsl-combos-coat-sheen-and-transmission-half.d.ts +3 -0
  744. package/lib/generated/shaders-glsl-combos-coat-sheen-and-transmission.d.ts +3 -0
  745. package/lib/generated/shaders-glsl-combos-coat-sheen-and-weighted-half.d.ts +3 -0
  746. package/lib/generated/shaders-glsl-combos-coat-sheen-and-weighted.d.ts +3 -0
  747. package/lib/generated/shaders-glsl-combos-coverage-half.d.ts +3 -0
  748. package/lib/generated/shaders-glsl-combos-coverage.d.ts +3 -0
  749. package/lib/generated/shaders-glsl-combos-cutout.d.ts +3 -0
  750. package/lib/generated/shaders-glsl-combos-decals-half.d.ts +3 -0
  751. package/lib/generated/shaders-glsl-combos-decals.d.ts +3 -0
  752. package/lib/generated/shaders-glsl-combos-displacement-half.d.ts +3 -0
  753. package/lib/generated/shaders-glsl-combos-displacement.d.ts +3 -0
  754. package/lib/generated/shaders-glsl-combos-hash-half.d.ts +3 -0
  755. package/lib/generated/shaders-glsl-combos-hash.d.ts +3 -0
  756. package/lib/generated/shaders-glsl-combos-lod-fade-half.d.ts +3 -0
  757. package/lib/generated/shaders-glsl-combos-lod-fade.d.ts +3 -0
  758. package/lib/generated/shaders-glsl-combos-moment-half.d.ts +3 -0
  759. package/lib/generated/shaders-glsl-combos-moment.d.ts +3 -0
  760. package/lib/generated/shaders-glsl-combos-morph-half.d.ts +3 -0
  761. package/lib/generated/shaders-glsl-combos-morph.d.ts +3 -0
  762. package/lib/generated/shaders-glsl-combos-motion.d.ts +3 -0
  763. package/lib/generated/shaders-glsl-combos-picking.d.ts +3 -0
  764. package/lib/generated/shaders-glsl-combos-probe-grid-half.d.ts +3 -0
  765. package/lib/generated/shaders-glsl-combos-probe-grid.d.ts +3 -0
  766. package/lib/generated/shaders-glsl-combos-row-values-half.d.ts +3 -0
  767. package/lib/generated/shaders-glsl-combos-row-values.d.ts +3 -0
  768. package/lib/generated/shaders-glsl-combos-skinning-half.d.ts +3 -0
  769. package/lib/generated/shaders-glsl-combos-skinning.d.ts +3 -0
  770. package/lib/generated/shaders-glsl-combos-sprites.d.ts +3 -0
  771. package/lib/generated/shaders-glsl-combos-subsurface-half.d.ts +3 -0
  772. package/lib/generated/shaders-glsl-combos-subsurface.d.ts +3 -0
  773. package/lib/generated/shaders-probe-glsl.d.ts +11 -0
  774. package/lib/generated/shaders-probe-wgsl.d.ts +11 -0
  775. package/lib/generated/shaders-sky-volume-env-glsl.d.ts +11 -0
  776. package/lib/generated/shaders-sky-volume-env-wgsl.d.ts +11 -0
  777. package/lib/generated/shaders-sky-volume-panorama-glsl.d.ts +11 -0
  778. package/lib/generated/shaders-sky-volume-panorama-wgsl.d.ts +11 -0
  779. package/lib/generated/shaders-wgsl-combos-area-lights-and-bump-half.d.ts +3 -0
  780. package/lib/generated/shaders-wgsl-combos-area-lights-and-bump.d.ts +3 -0
  781. package/lib/generated/shaders-wgsl-combos-area-lights-and-coat-sheen-half.d.ts +3 -0
  782. package/lib/generated/shaders-wgsl-combos-area-lights-and-coat-sheen.d.ts +3 -0
  783. package/lib/generated/shaders-wgsl-combos-area-lights-and-coverage-half.d.ts +3 -0
  784. package/lib/generated/shaders-wgsl-combos-area-lights-and-coverage.d.ts +3 -0
  785. package/lib/generated/shaders-wgsl-combos-area-lights-and-displacement-half.d.ts +3 -0
  786. package/lib/generated/shaders-wgsl-combos-area-lights-and-displacement.d.ts +3 -0
  787. package/lib/generated/shaders-wgsl-combos-area-lights-and-hash-half.d.ts +3 -0
  788. package/lib/generated/shaders-wgsl-combos-area-lights-and-hash.d.ts +3 -0
  789. package/lib/generated/shaders-wgsl-combos-area-lights-and-instance-index-half.d.ts +3 -0
  790. package/lib/generated/shaders-wgsl-combos-area-lights-and-instance-index.d.ts +3 -0
  791. package/lib/generated/shaders-wgsl-combos-area-lights-and-lines.d.ts +3 -0
  792. package/lib/generated/shaders-wgsl-combos-area-lights-and-lod-fade-half.d.ts +3 -0
  793. package/lib/generated/shaders-wgsl-combos-area-lights-and-lod-fade.d.ts +3 -0
  794. package/lib/generated/shaders-wgsl-combos-area-lights-and-moment-half.d.ts +3 -0
  795. package/lib/generated/shaders-wgsl-combos-area-lights-and-moment.d.ts +3 -0
  796. package/lib/generated/shaders-wgsl-combos-area-lights-and-row-values-half.d.ts +3 -0
  797. package/lib/generated/shaders-wgsl-combos-area-lights-and-row-values.d.ts +3 -0
  798. package/lib/generated/shaders-wgsl-combos-area-lights-and-skinning-half.d.ts +3 -0
  799. package/lib/generated/shaders-wgsl-combos-area-lights-and-skinning.d.ts +3 -0
  800. package/lib/generated/shaders-wgsl-combos-area-lights-and-translucency-half.d.ts +3 -0
  801. package/lib/generated/shaders-wgsl-combos-area-lights-and-translucency.d.ts +3 -0
  802. package/lib/generated/shaders-wgsl-combos-area-lights-and-transmission-half.d.ts +3 -0
  803. package/lib/generated/shaders-wgsl-combos-area-lights-and-transmission.d.ts +3 -0
  804. package/lib/generated/shaders-wgsl-combos-area-lights-and-weighted-half.d.ts +3 -0
  805. package/lib/generated/shaders-wgsl-combos-area-lights-and-weighted.d.ts +3 -0
  806. package/lib/generated/shaders-wgsl-combos-bump-half.d.ts +3 -0
  807. package/lib/generated/shaders-wgsl-combos-bump.d.ts +3 -0
  808. package/lib/generated/shaders-wgsl-combos-coat-sheen-half.d.ts +3 -0
  809. package/lib/generated/shaders-wgsl-combos-coat-sheen.d.ts +3 -0
  810. package/lib/generated/shaders-wgsl-combos-coverage-half.d.ts +3 -0
  811. package/lib/generated/shaders-wgsl-combos-coverage.d.ts +3 -0
  812. package/lib/generated/shaders-wgsl-combos-cutout.d.ts +3 -0
  813. package/lib/generated/shaders-wgsl-combos-decals-half.d.ts +3 -0
  814. package/lib/generated/shaders-wgsl-combos-decals.d.ts +3 -0
  815. package/lib/generated/shaders-wgsl-combos-displacement-half.d.ts +3 -0
  816. package/lib/generated/shaders-wgsl-combos-displacement.d.ts +3 -0
  817. package/lib/generated/shaders-wgsl-combos-hash-half.d.ts +3 -0
  818. package/lib/generated/shaders-wgsl-combos-hash.d.ts +3 -0
  819. package/lib/generated/shaders-wgsl-combos-instance-index-half.d.ts +3 -0
  820. package/lib/generated/shaders-wgsl-combos-instance-index.d.ts +3 -0
  821. package/lib/generated/shaders-wgsl-combos-lod-fade-half.d.ts +3 -0
  822. package/lib/generated/shaders-wgsl-combos-lod-fade.d.ts +3 -0
  823. package/lib/generated/shaders-wgsl-combos-moment-half.d.ts +3 -0
  824. package/lib/generated/shaders-wgsl-combos-moment.d.ts +3 -0
  825. package/lib/generated/shaders-wgsl-combos-motion.d.ts +3 -0
  826. package/lib/generated/shaders-wgsl-combos-picking.d.ts +3 -0
  827. package/lib/generated/shaders-wgsl-combos-probe-grid-half.d.ts +3 -0
  828. package/lib/generated/shaders-wgsl-combos-probe-grid.d.ts +3 -0
  829. package/lib/generated/shaders-wgsl-combos-row-values-half.d.ts +3 -0
  830. package/lib/generated/shaders-wgsl-combos-row-values.d.ts +3 -0
  831. package/lib/generated/shaders-wgsl-combos-skinning-half.d.ts +3 -0
  832. package/lib/generated/shaders-wgsl-combos-skinning.d.ts +3 -0
  833. package/lib/generated/shaders-wgsl-combos-sprites.d.ts +3 -0
  834. package/lib/generated/shaders-wgsl-combos-subsurface-half.d.ts +3 -0
  835. package/lib/generated/shaders-wgsl-combos-subsurface.d.ts +3 -0
  836. package/lib/generated/shaders.d.ts +1146 -0
  837. package/lib/gpu/canvas-release.d.ts +20 -0
  838. package/lib/gpu/canvas-release.js +67 -0
  839. package/lib/gpu/completion.d.ts +35 -0
  840. package/lib/gpu/completion.js +256 -0
  841. package/lib/gpu/device-shaders.d.ts +69 -0
  842. package/lib/gpu/device-shaders.js +177 -0
  843. package/lib/gpu/early-builds.d.ts +68 -0
  844. package/lib/gpu/early-builds.js +158 -0
  845. package/lib/gpu/effect-join.d.ts +83 -0
  846. package/lib/gpu/effect-join.js +134 -0
  847. package/lib/gpu/effect-joiner.d.ts +14 -0
  848. package/lib/gpu/effect-joiner.js +165 -0
  849. package/lib/gpu/environment-steps.d.ts +135 -0
  850. package/lib/gpu/environment-steps.js +210 -0
  851. package/lib/gpu/environment-words.d.ts +14 -0
  852. package/lib/gpu/environment-words.js +19 -0
  853. package/lib/gpu/environment.d.ts +4 -0
  854. package/lib/gpu/environment.js +8 -0
  855. package/lib/gpu/float-bits.d.ts +2 -0
  856. package/lib/gpu/float-bits.js +9 -0
  857. package/lib/gpu/line-vertices.d.ts +1 -0
  858. package/lib/gpu/line-vertices.js +14 -0
  859. package/lib/gpu/memory.d.ts +19 -0
  860. package/lib/gpu/memory.js +50 -0
  861. package/lib/gpu/particle-records.d.ts +1 -0
  862. package/lib/gpu/particle-records.js +15 -0
  863. package/lib/gpu/pipeline-name.d.ts +6 -0
  864. package/lib/gpu/pipeline-name.js +23 -0
  865. package/lib/gpu/probe-steps.d.ts +22 -0
  866. package/lib/gpu/probe-steps.js +43 -0
  867. package/lib/gpu/readback.d.ts +32 -0
  868. package/lib/gpu/readback.js +163 -0
  869. package/lib/gpu/variants.d.ts +16 -0
  870. package/lib/gpu/variants.js +67 -0
  871. package/lib/gpu/vertex-format.d.ts +46 -0
  872. package/lib/gpu/vertex-format.js +111 -0
  873. package/lib/gpu/webgl2/backend.d.ts +714 -0
  874. package/lib/gpu/webgl2/backend.js +2964 -0
  875. package/lib/gpu/webgl2/call-timing.d.ts +34 -0
  876. package/lib/gpu/webgl2/call-timing.js +143 -0
  877. package/lib/gpu/webgl2/context.d.ts +31 -0
  878. package/lib/gpu/webgl2/context.js +111 -0
  879. package/lib/gpu/webgl2/depth.d.ts +25 -0
  880. package/lib/gpu/webgl2/depth.js +30 -0
  881. package/lib/gpu/webgl2/environment.d.ts +65 -0
  882. package/lib/gpu/webgl2/environment.js +572 -0
  883. package/lib/gpu/webgl2/gpu-timer.d.ts +25 -0
  884. package/lib/gpu/webgl2/gpu-timer.js +93 -0
  885. package/lib/gpu/webgl2/probes.d.ts +38 -0
  886. package/lib/gpu/webgl2/probes.js +117 -0
  887. package/lib/gpu/webgl2/programs.d.ts +238 -0
  888. package/lib/gpu/webgl2/programs.js +487 -0
  889. package/lib/gpu/webgpu/backend.d.ts +460 -0
  890. package/lib/gpu/webgpu/backend.js +1812 -0
  891. package/lib/gpu/webgpu/buffer-reads.d.ts +42 -0
  892. package/lib/gpu/webgpu/buffer-reads.js +95 -0
  893. package/lib/gpu/webgpu/culled-counts.d.ts +79 -0
  894. package/lib/gpu/webgpu/culled-counts.js +259 -0
  895. package/lib/gpu/webgpu/draw-path-probe.d.ts +37 -0
  896. package/lib/gpu/webgpu/draw-path-probe.js +187 -0
  897. package/lib/gpu/webgpu/environment.d.ts +36 -0
  898. package/lib/gpu/webgpu/environment.js +735 -0
  899. package/lib/gpu/webgpu/first-pass.d.ts +13 -0
  900. package/lib/gpu/webgpu/first-pass.js +61 -0
  901. package/lib/gpu/webgpu/gpu-timer.d.ts +67 -0
  902. package/lib/gpu/webgpu/gpu-timer.js +328 -0
  903. package/lib/gpu/webgpu/indirect-arguments.d.ts +42 -0
  904. package/lib/gpu/webgpu/indirect-arguments.js +156 -0
  905. package/lib/gpu/webgpu/pipelines.d.ts +264 -0
  906. package/lib/gpu/webgpu/pipelines.js +2013 -0
  907. package/lib/gpu/webgpu/probes.d.ts +27 -0
  908. package/lib/gpu/webgpu/probes.js +190 -0
  909. package/lib/gpu/webgpu/reusable.d.ts +74 -0
  910. package/lib/gpu/webgpu/reusable.js +212 -0
  911. package/lib/gpu/webgpu/staging.d.ts +79 -0
  912. package/lib/gpu/webgpu/staging.js +238 -0
  913. package/lib/gpu/webgpu/upload-routes.d.ts +55 -0
  914. package/lib/gpu/webgpu/upload-routes.js +128 -0
  915. package/lib/index.d.ts +121 -0
  916. package/lib/index.js +54 -0
  917. package/lib/math/color.d.ts +18 -0
  918. package/lib/math/color.js +71 -0
  919. package/lib/math/create-math.d.ts +101 -0
  920. package/lib/math/create-math.js +207 -0
  921. package/lib/math/hex.d.ts +8 -0
  922. package/lib/math/hex.js +38 -0
  923. package/lib/math/index.d.ts +2 -0
  924. package/lib/math/index.js +11 -0
  925. package/lib/math/mat4.d.ts +22 -0
  926. package/lib/math/mat4.js +206 -0
  927. package/lib/math/math.d.ts +16 -0
  928. package/lib/math/math.js +42 -0
  929. package/lib/math/namespaces/math.d.ts +7 -0
  930. package/lib/math/namespaces/math.js +14 -0
  931. package/lib/math/namespaces/quat.d.ts +20 -0
  932. package/lib/math/namespaces/quat.js +30 -0
  933. package/lib/math/namespaces/vec3.d.ts +4 -0
  934. package/lib/math/namespaces/vec3.js +8 -0
  935. package/lib/math/quat.d.ts +36 -0
  936. package/lib/math/quat.js +224 -0
  937. package/lib/math/random.d.ts +16 -0
  938. package/lib/math/random.js +57 -0
  939. package/lib/math/types.d.ts +43 -0
  940. package/lib/math/types.js +4 -0
  941. package/lib/math/vec3.d.ts +43 -0
  942. package/lib/math/vec3.js +187 -0
  943. package/lib/page/abortable.d.ts +2 -0
  944. package/lib/page/abortable.js +19 -0
  945. package/lib/page/browser-check.d.ts +8 -0
  946. package/lib/page/browser-check.js +23 -0
  947. package/lib/page/canvas-watch.d.ts +34 -0
  948. package/lib/page/canvas-watch.js +141 -0
  949. package/lib/page/capabilities.d.ts +201 -0
  950. package/lib/page/capabilities.js +409 -0
  951. package/lib/page/check-store.d.ts +54 -0
  952. package/lib/page/check-store.js +169 -0
  953. package/lib/page/display.d.ts +2 -0
  954. package/lib/page/display.js +25 -0
  955. package/lib/page/early-core.d.ts +1 -0
  956. package/lib/page/early-core.js +23 -0
  957. package/lib/page/engine.d.ts +942 -0
  958. package/lib/page/engine.js +2459 -0
  959. package/lib/page/first-frame.d.ts +16 -0
  960. package/lib/page/first-frame.js +35 -0
  961. package/lib/page/frame-stats.d.ts +402 -0
  962. package/lib/page/frame-stats.js +389 -0
  963. package/lib/page/gamepads.d.ts +37 -0
  964. package/lib/page/gamepads.js +123 -0
  965. package/lib/page/held-input.d.ts +19 -0
  966. package/lib/page/held-input.js +54 -0
  967. package/lib/page/hold.d.ts +186 -0
  968. package/lib/page/hold.js +49 -0
  969. package/lib/page/input-ring.d.ts +13 -0
  970. package/lib/page/input-ring.js +25 -0
  971. package/lib/page/input.d.ts +6 -0
  972. package/lib/page/input.js +159 -0
  973. package/lib/page/isolation-check.d.ts +14 -0
  974. package/lib/page/isolation-check.js +21 -0
  975. package/lib/page/label-loop.d.ts +80 -0
  976. package/lib/page/label-loop.js +417 -0
  977. package/lib/page/labels.d.ts +56 -0
  978. package/lib/page/labels.js +102 -0
  979. package/lib/page/limits.d.ts +321 -0
  980. package/lib/page/limits.js +323 -0
  981. package/lib/page/loader.d.ts +78 -0
  982. package/lib/page/loader.js +149 -0
  983. package/lib/page/main-thread.d.ts +10 -0
  984. package/lib/page/main-thread.js +41 -0
  985. package/lib/page/memory-pool.d.ts +26 -0
  986. package/lib/page/memory-pool.js +69 -0
  987. package/lib/page/ownership.d.ts +65 -0
  988. package/lib/page/ownership.js +166 -0
  989. package/lib/page/permutation-recording.d.ts +26 -0
  990. package/lib/page/permutation-recording.js +32 -0
  991. package/lib/page/pipeline-store.d.ts +25 -0
  992. package/lib/page/pipeline-store.js +84 -0
  993. package/lib/page/pointer-lock.d.ts +14 -0
  994. package/lib/page/pointer-lock.js +60 -0
  995. package/lib/page/preferences.d.ts +2 -0
  996. package/lib/page/preferences.js +11 -0
  997. package/lib/page/record-button.d.ts +5 -0
  998. package/lib/page/record-button.js +60 -0
  999. package/lib/page/start-marker.d.ts +47 -0
  1000. package/lib/page/start-marker.js +119 -0
  1001. package/lib/page/stats-switch.d.ts +16 -0
  1002. package/lib/page/stats-switch.js +38 -0
  1003. package/lib/page/stop-jobs.d.ts +37 -0
  1004. package/lib/page/stop-jobs.js +87 -0
  1005. package/lib/page/switches.d.ts +347 -0
  1006. package/lib/page/switches.js +150 -0
  1007. package/lib/page/videos.d.ts +70 -0
  1008. package/lib/page/videos.js +244 -0
  1009. package/lib/quality/budget.d.ts +14 -0
  1010. package/lib/quality/budget.js +25 -0
  1011. package/lib/quality/check.d.ts +119 -0
  1012. package/lib/quality/check.js +84 -0
  1013. package/lib/quality/chooser.d.ts +98 -0
  1014. package/lib/quality/chooser.js +108 -0
  1015. package/lib/quality/device-hints.d.ts +8 -0
  1016. package/lib/quality/device-hints.js +18 -0
  1017. package/lib/quality/governor.d.ts +571 -0
  1018. package/lib/quality/governor.js +1293 -0
  1019. package/lib/quality/preset-docs.d.ts +402 -0
  1020. package/lib/quality/preset-docs.js +179 -0
  1021. package/lib/quality/presets.d.ts +821 -0
  1022. package/lib/quality/presets.js +678 -0
  1023. package/lib/render/direct-loop.d.ts +4 -0
  1024. package/lib/render/direct-loop.js +52 -0
  1025. package/lib/render/draw.d.ts +66 -0
  1026. package/lib/render/draw.js +111 -0
  1027. package/lib/render/load-draw.d.ts +12 -0
  1028. package/lib/render/load-draw.js +18 -0
  1029. package/lib/render/loop.d.ts +241 -0
  1030. package/lib/render/loop.js +566 -0
  1031. package/lib/render/loss.d.ts +53 -0
  1032. package/lib/render/loss.js +127 -0
  1033. package/lib/render/pacer.d.ts +24 -0
  1034. package/lib/render/pacer.js +51 -0
  1035. package/lib/render/recovery.d.ts +82 -0
  1036. package/lib/render/recovery.js +160 -0
  1037. package/lib/render/refresh.d.ts +38 -0
  1038. package/lib/render/refresh.js +111 -0
  1039. package/lib/render/renderer.d.ts +192 -0
  1040. package/lib/render/renderer.js +295 -0
  1041. package/lib/render/scene-renderer.d.ts +135 -0
  1042. package/lib/render/scene-renderer.js +216 -0
  1043. package/lib/render/shader-salt.d.ts +5 -0
  1044. package/lib/render/shader-salt.js +31 -0
  1045. package/lib/render/webgl2-renderers.d.ts +11 -0
  1046. package/lib/render/webgl2-renderers.js +227 -0
  1047. package/lib/render/webgpu-renderers.d.ts +10 -0
  1048. package/lib/render/webgpu-renderers.js +254 -0
  1049. package/lib/scene/addon-debug-views.d.ts +30 -0
  1050. package/lib/scene/addon-debug-views.js +63 -0
  1051. package/lib/scene/animation.d.ts +547 -0
  1052. package/lib/scene/animation.js +1425 -0
  1053. package/lib/scene/area-light-tables.d.ts +32 -0
  1054. package/lib/scene/area-light-tables.js +89 -0
  1055. package/lib/scene/assets.d.ts +375 -0
  1056. package/lib/scene/assets.js +736 -0
  1057. package/lib/scene/background.d.ts +238 -0
  1058. package/lib/scene/background.js +470 -0
  1059. package/lib/scene/baked-light.d.ts +60 -0
  1060. package/lib/scene/baked-light.js +300 -0
  1061. package/lib/scene/builtin-environments.d.ts +36 -0
  1062. package/lib/scene/builtin-environments.js +43 -0
  1063. package/lib/scene/chunk-rows.d.ts +81 -0
  1064. package/lib/scene/chunk-rows.js +146 -0
  1065. package/lib/scene/color.d.ts +22 -0
  1066. package/lib/scene/color.js +45 -0
  1067. package/lib/scene/derived-cache.d.ts +139 -0
  1068. package/lib/scene/derived-cache.js +547 -0
  1069. package/lib/scene/downloads.d.ts +2 -0
  1070. package/lib/scene/downloads.js +371 -0
  1071. package/lib/scene/effects.d.ts +193 -0
  1072. package/lib/scene/effects.js +476 -0
  1073. package/lib/scene/environment-file.d.ts +22 -0
  1074. package/lib/scene/environment-file.js +81 -0
  1075. package/lib/scene/environment.d.ts +57 -0
  1076. package/lib/scene/environment.js +131 -0
  1077. package/lib/scene/fake-call-values.d.ts +8 -0
  1078. package/lib/scene/fake-call-values.js +51 -0
  1079. package/lib/scene/feature-draws.d.ts +169 -0
  1080. package/lib/scene/feature-draws.js +269 -0
  1081. package/lib/scene/feature-effects.d.ts +42 -0
  1082. package/lib/scene/feature-effects.js +155 -0
  1083. package/lib/scene/feature-host.d.ts +129 -0
  1084. package/lib/scene/feature-host.js +299 -0
  1085. package/lib/scene/feature-instances.d.ts +130 -0
  1086. package/lib/scene/feature-instances.js +326 -0
  1087. package/lib/scene/features.d.ts +412 -0
  1088. package/lib/scene/features.js +550 -0
  1089. package/lib/scene/file-limits.d.ts +70 -0
  1090. package/lib/scene/file-limits.js +224 -0
  1091. package/lib/scene/fog.d.ts +101 -0
  1092. package/lib/scene/fog.js +148 -0
  1093. package/lib/scene/frame-cameras.d.ts +175 -0
  1094. package/lib/scene/frame-cameras.js +492 -0
  1095. package/lib/scene/gltf-animation.d.ts +129 -0
  1096. package/lib/scene/gltf-animation.js +887 -0
  1097. package/lib/scene/gltf-draco.d.ts +9 -0
  1098. package/lib/scene/gltf-draco.js +224 -0
  1099. package/lib/scene/gltf-extensions.d.ts +31 -0
  1100. package/lib/scene/gltf-extensions.js +92 -0
  1101. package/lib/scene/gltf-json.d.ts +49 -0
  1102. package/lib/scene/gltf-json.js +94 -0
  1103. package/lib/scene/gltf-math.d.ts +16 -0
  1104. package/lib/scene/gltf-math.js +129 -0
  1105. package/lib/scene/gltf-meshopt.d.ts +3 -0
  1106. package/lib/scene/gltf-meshopt.js +48 -0
  1107. package/lib/scene/gltf-parse.d.ts +600 -0
  1108. package/lib/scene/gltf-parse.js +1854 -0
  1109. package/lib/scene/gltf.d.ts +189 -0
  1110. package/lib/scene/gltf.js +1589 -0
  1111. package/lib/scene/grade-table.d.ts +9 -0
  1112. package/lib/scene/grade-table.js +23 -0
  1113. package/lib/scene/grade-task.d.ts +12 -0
  1114. package/lib/scene/grade-task.js +11 -0
  1115. package/lib/scene/grading.d.ts +110 -0
  1116. package/lib/scene/grading.js +142 -0
  1117. package/lib/scene/half-float.d.ts +4 -0
  1118. package/lib/scene/half-float.js +42 -0
  1119. package/lib/scene/ktx2-cache.d.ts +32 -0
  1120. package/lib/scene/ktx2-cache.js +62 -0
  1121. package/lib/scene/ktx2-file.d.ts +57 -0
  1122. package/lib/scene/ktx2-file.js +207 -0
  1123. package/lib/scene/ktx2-transcode.d.ts +15 -0
  1124. package/lib/scene/ktx2-transcode.js +94 -0
  1125. package/lib/scene/ktx2.d.ts +42 -0
  1126. package/lib/scene/ktx2.js +179 -0
  1127. package/lib/scene/lens.d.ts +61 -0
  1128. package/lib/scene/lens.js +101 -0
  1129. package/lib/scene/level-meshopt.d.ts +20 -0
  1130. package/lib/scene/level-meshopt.js +122 -0
  1131. package/lib/scene/level-pieces.d.ts +24 -0
  1132. package/lib/scene/level-pieces.js +138 -0
  1133. package/lib/scene/level-rule.d.ts +120 -0
  1134. package/lib/scene/level-rule.js +130 -0
  1135. package/lib/scene/level-words.d.ts +19 -0
  1136. package/lib/scene/level-words.js +34 -0
  1137. package/lib/scene/levels-task.d.ts +51 -0
  1138. package/lib/scene/levels-task.js +132 -0
  1139. package/lib/scene/light-images.d.ts +36 -0
  1140. package/lib/scene/light-images.js +88 -0
  1141. package/lib/scene/light-probes.d.ts +240 -0
  1142. package/lib/scene/light-probes.js +644 -0
  1143. package/lib/scene/lines.d.ts +188 -0
  1144. package/lib/scene/lines.js +257 -0
  1145. package/lib/scene/lut-files.d.ts +41 -0
  1146. package/lib/scene/lut-files.js +399 -0
  1147. package/lib/scene/lut.d.ts +55 -0
  1148. package/lib/scene/lut.js +47 -0
  1149. package/lib/scene/memory.d.ts +72 -0
  1150. package/lib/scene/memory.js +159 -0
  1151. package/lib/scene/mesh-arrays.d.ts +110 -0
  1152. package/lib/scene/mesh-arrays.js +701 -0
  1153. package/lib/scene/mesh-levels.d.ts +10 -0
  1154. package/lib/scene/mesh-levels.js +52 -0
  1155. package/lib/scene/namespaces.d.ts +125 -0
  1156. package/lib/scene/namespaces.js +313 -0
  1157. package/lib/scene/panorama-files.d.ts +71 -0
  1158. package/lib/scene/panorama-files.js +1103 -0
  1159. package/lib/scene/panorama.d.ts +23 -0
  1160. package/lib/scene/panorama.js +108 -0
  1161. package/lib/scene/particles.d.ts +452 -0
  1162. package/lib/scene/particles.js +814 -0
  1163. package/lib/scene/pass-reads.d.ts +70 -0
  1164. package/lib/scene/pass-reads.js +220 -0
  1165. package/lib/scene/picks.d.ts +69 -0
  1166. package/lib/scene/picks.js +208 -0
  1167. package/lib/scene/pointer-events.d.ts +202 -0
  1168. package/lib/scene/pointer-events.js +500 -0
  1169. package/lib/scene/post.d.ts +567 -0
  1170. package/lib/scene/post.js +928 -0
  1171. package/lib/scene/prefab.d.ts +109 -0
  1172. package/lib/scene/prefab.js +166 -0
  1173. package/lib/scene/probes.d.ts +71 -0
  1174. package/lib/scene/probes.js +169 -0
  1175. package/lib/scene/property-animation.d.ts +160 -0
  1176. package/lib/scene/property-animation.js +276 -0
  1177. package/lib/scene/queries.d.ts +176 -0
  1178. package/lib/scene/queries.js +393 -0
  1179. package/lib/scene/render.d.ts +487 -0
  1180. package/lib/scene/render.js +829 -0
  1181. package/lib/scene/resources.d.ts +1598 -0
  1182. package/lib/scene/resources.js +2843 -0
  1183. package/lib/scene/rotation.d.ts +6 -0
  1184. package/lib/scene/rotation.js +12 -0
  1185. package/lib/scene/scene.d.ts +1858 -0
  1186. package/lib/scene/scene.js +4680 -0
  1187. package/lib/scene/serial-loads.d.ts +29 -0
  1188. package/lib/scene/serial-loads.js +68 -0
  1189. package/lib/scene/shader-preloads.d.ts +74 -0
  1190. package/lib/scene/shader-preloads.js +116 -0
  1191. package/lib/scene/shader-templates.d.ts +60 -0
  1192. package/lib/scene/shader-templates.js +156 -0
  1193. package/lib/scene/sprites.d.ts +262 -0
  1194. package/lib/scene/sprites.js +292 -0
  1195. package/lib/scene/stale-calls-scenario.d.ts +20 -0
  1196. package/lib/scene/stale-calls-scenario.js +175 -0
  1197. package/lib/scene/textures.d.ts +323 -0
  1198. package/lib/scene/textures.js +953 -0
  1199. package/lib/scene/time-of-day.d.ts +145 -0
  1200. package/lib/scene/time-of-day.js +644 -0
  1201. package/lib/scene/unmarked-writes.d.ts +118 -0
  1202. package/lib/scene/unmarked-writes.js +283 -0
  1203. package/lib/scene/unread-extensions-scenario.d.ts +6 -0
  1204. package/lib/scene/unread-extensions-scenario.js +26 -0
  1205. package/lib/scene/vertex-draws.d.ts +82 -0
  1206. package/lib/scene/vertex-draws.js +85 -0
  1207. package/lib/scene/wgsl-uniforms.d.ts +167 -0
  1208. package/lib/scene/wgsl-uniforms.js +12 -0
  1209. package/lib/shader-artifact.json +1 -0
  1210. package/lib/shared/await-later.d.ts +5 -0
  1211. package/lib/shared/await-later.js +10 -0
  1212. package/lib/shared/control.d.ts +94 -0
  1213. package/lib/shared/control.js +150 -0
  1214. package/lib/shared/core-sources.d.ts +2 -0
  1215. package/lib/shared/core-sources.js +7 -0
  1216. package/lib/shared/core.d.ts +1254 -0
  1217. package/lib/shared/core.js +381 -0
  1218. package/lib/shared/counter.d.ts +52 -0
  1219. package/lib/shared/counter.js +55 -0
  1220. package/lib/shared/dev.d.ts +8 -0
  1221. package/lib/shared/dev.js +13 -0
  1222. package/lib/shared/feature-stats.d.ts +16 -0
  1223. package/lib/shared/feature-stats.js +27 -0
  1224. package/lib/shared/frame-image.d.ts +13 -0
  1225. package/lib/shared/frame-image.js +32 -0
  1226. package/lib/shared/gpu-clock.d.ts +14 -0
  1227. package/lib/shared/gpu-clock.js +38 -0
  1228. package/lib/shared/gpu-counter.d.ts +12 -0
  1229. package/lib/shared/gpu-counter.js +15 -0
  1230. package/lib/shared/gpu-scope.d.ts +14 -0
  1231. package/lib/shared/gpu-scope.js +104 -0
  1232. package/lib/shared/helper-workers.d.ts +4 -0
  1233. package/lib/shared/helper-workers.js +23 -0
  1234. package/lib/shared/images.d.ts +255 -0
  1235. package/lib/shared/images.js +450 -0
  1236. package/lib/shared/import-once.d.ts +6 -0
  1237. package/lib/shared/import-once.js +19 -0
  1238. package/lib/shared/key-codes.d.ts +2 -0
  1239. package/lib/shared/key-codes.js +69 -0
  1240. package/lib/shared/labels.d.ts +94 -0
  1241. package/lib/shared/labels.js +172 -0
  1242. package/lib/shared/memory-area.d.ts +6 -0
  1243. package/lib/shared/memory-area.js +21 -0
  1244. package/lib/shared/memory-figure.d.ts +14 -0
  1245. package/lib/shared/memory-figure.js +18 -0
  1246. package/lib/shared/memory-views.d.ts +48 -0
  1247. package/lib/shared/memory-views.js +90 -0
  1248. package/lib/shared/metrics.d.ts +353 -0
  1249. package/lib/shared/metrics.js +799 -0
  1250. package/lib/shared/page-measurement.d.ts +9 -0
  1251. package/lib/shared/page-measurement.js +37 -0
  1252. package/lib/shared/phase.d.ts +17 -0
  1253. package/lib/shared/phase.js +20 -0
  1254. package/lib/shared/policy.d.ts +20 -0
  1255. package/lib/shared/policy.js +46 -0
  1256. package/lib/shared/recording.d.ts +100 -0
  1257. package/lib/shared/recording.js +378 -0
  1258. package/lib/shared/role.d.ts +10 -0
  1259. package/lib/shared/role.js +13 -0
  1260. package/lib/shared/run-task.d.ts +39 -0
  1261. package/lib/shared/run-task.js +69 -0
  1262. package/lib/shared/slot.d.ts +218 -0
  1263. package/lib/shared/slot.js +221 -0
  1264. package/lib/shared/software.d.ts +24 -0
  1265. package/lib/shared/software.js +22 -0
  1266. package/lib/shared/stats.d.ts +62 -0
  1267. package/lib/shared/stats.js +86 -0
  1268. package/lib/shared/task-failure.d.ts +24 -0
  1269. package/lib/shared/task-failure.js +36 -0
  1270. package/lib/shared/task-host.d.ts +42 -0
  1271. package/lib/shared/task-host.js +60 -0
  1272. package/lib/shared/task-load-error.d.ts +10 -0
  1273. package/lib/shared/task-load-error.js +13 -0
  1274. package/lib/shared/task-modules.d.ts +2 -0
  1275. package/lib/shared/task-modules.js +8 -0
  1276. package/lib/shared/task-pending.d.ts +24 -0
  1277. package/lib/shared/task-pending.js +101 -0
  1278. package/lib/shared/tasks.d.ts +54 -0
  1279. package/lib/shared/tasks.js +426 -0
  1280. package/lib/shared/tier.d.ts +7 -0
  1281. package/lib/shared/tier.js +3 -0
  1282. package/lib/shared/version.d.ts +72 -0
  1283. package/lib/shared/version.js +103 -0
  1284. package/lib/shared/videos.d.ts +15 -0
  1285. package/lib/shared/videos.js +11 -0
  1286. package/lib/shared/wake.d.ts +38 -0
  1287. package/lib/shared/wake.js +76 -0
  1288. package/lib/shared/wasm-limits.d.ts +13 -0
  1289. package/lib/shared/wasm-limits.js +75 -0
  1290. package/lib/shared/wasm.d.ts +34 -0
  1291. package/lib/shared/wasm.js +151 -0
  1292. package/lib/shared/webkit.d.ts +33 -0
  1293. package/lib/shared/webkit.js +59 -0
  1294. package/lib/shared/wgsl-updates.d.ts +9 -0
  1295. package/lib/shared/wgsl-updates.js +8 -0
  1296. package/lib/shared/worker-start.d.ts +56 -0
  1297. package/lib/shared/worker-start.js +186 -0
  1298. package/lib/sketch/clock.d.ts +61 -0
  1299. package/lib/sketch/clock.js +98 -0
  1300. package/lib/sketch/define-sketch.d.ts +269 -0
  1301. package/lib/sketch/define-sketch.js +103 -0
  1302. package/lib/sketch/input-off-scenario.d.ts +7 -0
  1303. package/lib/sketch/input-off-scenario.js +24 -0
  1304. package/lib/sketch/input-off.d.ts +16 -0
  1305. package/lib/sketch/input-off.js +38 -0
  1306. package/lib/sketch/input.d.ts +243 -0
  1307. package/lib/sketch/input.js +554 -0
  1308. package/lib/sketch/preset-check.d.ts +42 -0
  1309. package/lib/sketch/preset-check.js +120 -0
  1310. package/lib/sketch/quality.d.ts +392 -0
  1311. package/lib/sketch/quality.js +355 -0
  1312. package/lib/sketch/random.d.ts +13 -0
  1313. package/lib/sketch/random.js +25 -0
  1314. package/lib/sketch/runner.d.ts +574 -0
  1315. package/lib/sketch/runner.js +2159 -0
  1316. package/lib/sketch/ui.d.ts +94 -0
  1317. package/lib/sketch/ui.js +391 -0
  1318. package/lib/stats.d.ts +4 -0
  1319. package/lib/stats.js +8 -0
  1320. package/lib/workers/drawing-host.d.ts +24 -0
  1321. package/lib/workers/drawing-host.js +48 -0
  1322. package/lib/workers/gltf-worker.d.ts +35 -0
  1323. package/lib/workers/gltf-worker.js +210 -0
  1324. package/lib/workers/job-worker.d.ts +1 -0
  1325. package/lib/workers/job-worker.js +102 -0
  1326. package/lib/workers/panorama-worker.d.ts +15 -0
  1327. package/lib/workers/panorama-worker.js +21 -0
  1328. package/lib/workers/probe-worker.d.ts +34 -0
  1329. package/lib/workers/probe-worker.js +58 -0
  1330. package/lib/workers/protocol.d.ts +377 -0
  1331. package/lib/workers/protocol.js +57 -0
  1332. package/lib/workers/render-worker.d.ts +1 -0
  1333. package/lib/workers/render-worker.js +103 -0
  1334. package/lib/workers/sketch-worker.d.ts +1 -0
  1335. package/lib/workers/sketch-worker.js +295 -0
  1336. package/lib/workers/task-worker.d.ts +1 -0
  1337. package/lib/workers/task-worker.js +5 -0
  1338. package/lib/workers/tasks.d.ts +65 -0
  1339. package/lib/workers/tasks.js +85 -0
  1340. package/package.json +106 -5
  1341. package/vendor/basis/LICENSE +201 -0
  1342. package/vendor/basis/LICENSE-zstd +30 -0
  1343. package/vendor/basis/NOTICE +15 -0
  1344. package/vendor/basis/basis_transcoder.d.mts +36 -0
  1345. package/vendor/basis/basis_transcoder.mjs +2 -0
  1346. package/vendor/basis/basis_transcoder.wasm +0 -0
  1347. package/vendor/draco/LICENSE +252 -0
  1348. package/vendor/draco/draco_decoder_gltf.wasm +0 -0
  1349. package/vendor/draco/draco_wasm_wrapper_gltf.d.ts +71 -0
  1350. package/vendor/draco/draco_wasm_wrapper_gltf.js +116 -0
  1351. package/vendor/ltc/LICENSE +31 -0
  1352. package/vendor/ltc/area-light-tables.bin +0 -0
  1353. package/vendor/meshopt/LICENSE.md +21 -0
  1354. package/vendor/meshopt/meshopt_clusterizer.wasm +0 -0
  1355. package/vendor/meshopt/meshopt_decoder.wasm +0 -0
  1356. package/vendor/meshopt/meshopt_encoder.wasm +0 -0
  1357. package/vendor/meshopt/meshopt_simplifier.wasm +0 -0
@@ -0,0 +1,2964 @@
1
+ // The WebGL2 backend: owns every GL object in tables indexed by the core's resource ids, and
2
+ // replays binary draw lists into WebGL2 calls. A state cache skips calls that would set what is
3
+ // already set. The replay loop reads 32-bit words from views on engine memory, uploads straight
4
+ // from them, and allocates nothing per command, except when a command creates a GL object. Where
5
+ // WebGL refuses views on shared memory, uploads first copy their words out of it into a staging
6
+ // buffer.
7
+ //
8
+ // A texture's first write goes straight into it. Later writes into a data texture of 32-bit
9
+ // values, which may land in a texture that the GPU still reads for an earlier frame, go through a
10
+ // pixel unpack buffer, so the GPU copies them in order with its other work. A direct write there
11
+ // makes Safari wait until the GPU has finished every frame that reads the texture. Color textures
12
+ // keep direct writes: through an unpack buffer, Chrome on the Mac stored sRGB texels brighter.
13
+ //
14
+ // GL counts rows from the bottom, and the engine keeps GL's row order in what a render pass draws.
15
+ // The backend flips viewport and scissor rectangles, which the draw list gives from the top, so each
16
+ // covers the same part of the image as on WebGPU. Writes, uploads and copies address texels as
17
+ // stored, the same on both paths.
18
+ //
19
+ // Draw lists give depth as WebGPU's reversed depth. The backend draws it in its depth mode, and
20
+ // turns clear values and viewport depth ranges around for standard depth.
21
+ import * as G from '../../generated/gpu.js';
22
+ import { DEV } from '../../shared/dev.js';
23
+ import { ImageTable } from '../../shared/images.js';
24
+ import { EarlyBuilds, PipelineListing } from '../early-builds.js';
25
+ import { JoinedBuilds, joinedReady } from '../effect-join.js';
26
+ import { CLOUD_FIELD_WORD, CLOUD_STEPS_WORD, LAYER_WORD, LIGHT_BUFFER_WORD, } from '../environment-words.js';
27
+ import { floatOfBits } from '../float-bits.js';
28
+ import { GpuMemory, textureBytes } from '../memory.js';
29
+ import { pipelineName } from '../pipeline-name.js';
30
+ import { variantFor } from '../variants.js';
31
+ import { forEachFallbackAttribute, forEachVertexAttribute, isNormalized, vertexStride, } from '../vertex-format.js';
32
+ import { setDepthMode } from './depth.js';
33
+ import { buildPermutation, createProgram, customTemplate, engineTemplates, LinkFailure, linkLogs, metalFault, mipmapTemplate, prepareProgram, programHost, relink, slotOf, UPLOAD_UNIT, } from './programs.js';
34
+ /** The unit that the mip level shader samples: its source texture's group 0, binding 0. */
35
+ const MIP_UNIT = 0;
36
+ /** The key of the mip level program among the programs of pipelines. */
37
+ const MIP_PROGRAM = 'mipmap';
38
+ /** The key of the program that copies a layer texel by texel. */
39
+ const COPY_PROGRAM = 'mipmap copy';
40
+ /** The key of the program that draws a texture into a corner of another at a size of its own. */
41
+ const SCALE_PROGRAM = 'mipmap scale';
42
+ /**
43
+ * Bits of the scale draw's instance that hold the texels across the destination: a light's image
44
+ * takes at most 512, so they fit in ten. The source's layer sits above them. The mipmap shader's
45
+ * scale pipeline reads both.
46
+ */
47
+ const SCALE_SIZE_BITS = 10;
48
+ // Attachment names, for invalidating what a pass does not store.
49
+ const COLOR_ATTACHMENT0 = 0x8ce0;
50
+ const DEPTH_ATTACHMENT = 0x8d00;
51
+ const DISCARD_COLOR = [COLOR_ATTACHMENT0];
52
+ const DISCARD_DEPTH = [DEPTH_ATTACHMENT];
53
+ /** The second color attachment, which only the weighted layer's pass draws into. */
54
+ const COLOR_ATTACHMENT1 = 0x8ce1;
55
+ /** The draw buffers of a framebuffer with two color targets. */
56
+ const TWO_DRAW_BUFFERS = [COLOR_ATTACHMENT0, COLOR_ATTACHMENT1];
57
+ /** The draw buffer of a pass that draws into depth alone. */
58
+ const NO_DRAW_BUFFERS = [0];
59
+ const DISCARD_BOTH = [COLOR_ATTACHMENT0, DEPTH_ATTACHMENT];
60
+ /** The color that a cleared texture's layer takes: black, fully transparent. */
61
+ const CLEAR_ZERO = new Float32Array([0, 0, 0, 0]);
62
+ /** GL's `BACK`, the faces that a context culls until it is told otherwise. */
63
+ const CULL_BACK = 0x0405;
64
+ /** GL's `TRIANGLES`, the mode of every pipeline that does not draw lines. */
65
+ const TRIANGLES = 0x0004;
66
+ /**
67
+ * Pixel unpack buffers in the ring that texture rewrites go through: one for the frame being
68
+ * replayed and one for each frame that the GPU may still be reading.
69
+ */
70
+ const UNPACK_RING = 3;
71
+ /** Each write's place in a pixel unpack buffer is aligned to this, the largest texel's size. */
72
+ const UNPACK_ALIGNMENT = 16;
73
+ /**
74
+ * Features whose builds vary in every material bit, tens of programs for each device. A scene's
75
+ * materials draw with a few of them, so a preload compiles none, and `scene.warmUp()` builds those.
76
+ */
77
+ const WARM_UP_FEATURES = new Set(['skinning', 'morph']);
78
+ /** GL's size, type and normalization of a WebGPU vertex format that the backend reads. */
79
+ function glAttribute(gl, format) {
80
+ switch (format) {
81
+ case 'uint32':
82
+ return [1, gl.UNSIGNED_INT, false];
83
+ case 'float32x2':
84
+ return [2, gl.FLOAT, false];
85
+ case 'float32x3':
86
+ return [3, gl.FLOAT, false];
87
+ case 'float32x4':
88
+ return [4, gl.FLOAT, false];
89
+ case 'unorm8x4':
90
+ return [4, gl.UNSIGNED_BYTE, true];
91
+ default:
92
+ throw new Error(`the WebGL2 backend reads no vertex format ${format}`);
93
+ }
94
+ }
95
+ /** GL's types of vertex attribute values. */
96
+ const GL_FLOAT = 0x1406;
97
+ const GL_BYTE = 0x1400;
98
+ const GL_UNSIGNED_BYTE = 0x1401;
99
+ const GL_SHORT = 0x1402;
100
+ const GL_UNSIGNED_SHORT = 0x1403;
101
+ /** GL's type of each vertex attribute type's values, by code. */
102
+ const GL_VERTEX_TYPES = {
103
+ [G.VERTEX_TYPE_F32]: GL_FLOAT,
104
+ [G.VERTEX_TYPE_UNORM8]: GL_UNSIGNED_BYTE,
105
+ [G.VERTEX_TYPE_SNORM8]: GL_BYTE,
106
+ [G.VERTEX_TYPE_UNORM16]: GL_UNSIGNED_SHORT,
107
+ [G.VERTEX_TYPE_SNORM16]: GL_SHORT,
108
+ [G.VERTEX_TYPE_UINT8]: GL_UNSIGNED_BYTE,
109
+ [G.VERTEX_TYPE_SINT8]: GL_BYTE,
110
+ [G.VERTEX_TYPE_UINT16]: GL_UNSIGNED_SHORT,
111
+ [G.VERTEX_TYPE_SINT16]: GL_SHORT,
112
+ };
113
+ /**
114
+ * Makes each primitive's flat values come from its first vertex, where the device has
115
+ * `WEBGL_provoking_vertex`. The shaders' flat values come from WGSL's `@interpolate(flat, either)`,
116
+ * so any vertex of a primitive may give them. GLSL's default is the last vertex, which Metal does not
117
+ * have, so ANGLE on Metal rewrites the bound index buffer into a new buffer before each draw that
118
+ * reads a flat value, and that buffer is as large as the whole index buffer. The first vertex is
119
+ * Metal's own convention, which needs no rewrite.
120
+ */
121
+ export function useFirstProvokingVertex(gl) {
122
+ const provoking = gl.getExtension('WEBGL_provoking_vertex');
123
+ provoking?.provokingVertexWEBGL(provoking.FIRST_VERTEX_CONVENTION_WEBGL);
124
+ }
125
+ /**
126
+ * Points a vertex array's location at a mesh attribute. Attributes that shaders read as whole
127
+ * numbers take the integer pointer. The others take the float pointer, which reads normalized
128
+ * integers as fractions and plain integers as whole values, as glTF reads them.
129
+ */
130
+ function pointAttribute(gl, stride, a) {
131
+ const type = GL_VERTEX_TYPES[a.type];
132
+ gl.enableVertexAttribArray(a.location);
133
+ if (a.integer)
134
+ gl.vertexAttribIPointer(a.location, a.size, type, stride, a.offset);
135
+ else
136
+ gl.vertexAttribPointer(a.location, a.size, type, isNormalized(a), stride, a.offset);
137
+ }
138
+ /**
139
+ * A framebuffer that a live context refused. The backend skips the frame and asks again on the
140
+ * next one, because a driver can answer a lost context's check with a refusal before the loss flag
141
+ * is set; the same refusal on the next frame is a format the device does not draw into.
142
+ */
143
+ export class WebGL2TargetRefused extends Error {
144
+ }
145
+ /**
146
+ * How GL stores each texture format, by format code, for a canvas with alpha or without. A
147
+ * compressed format is there only when the context turned on its extension, which the backend
148
+ * asks for by name.
149
+ */
150
+ function glFormats(gl, canvasAlpha) {
151
+ const formats = [];
152
+ const add = (code, internal, format, type, attachment) => {
153
+ formats[code] = {
154
+ code,
155
+ internal,
156
+ format,
157
+ type,
158
+ attachment,
159
+ bytes: G.FORMAT_BLOCK_BYTES[code] ?? 0,
160
+ block: G.FORMAT_BLOCK_SIZE[code] ?? 1,
161
+ };
162
+ };
163
+ // A compressed format's writes read bytes.
164
+ const compressed = (code, internal) => add(code, internal, 0, gl.UNSIGNED_BYTE, 0);
165
+ const astc = gl.getExtension('WEBGL_compressed_texture_astc');
166
+ if (astc) {
167
+ compressed(G.FORMAT_ASTC_4X4_UNORM, astc.COMPRESSED_RGBA_ASTC_4x4_KHR);
168
+ compressed(G.FORMAT_ASTC_4X4_UNORM_SRGB, astc.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR);
169
+ }
170
+ const bptc = gl.getExtension('EXT_texture_compression_bptc');
171
+ if (bptc) {
172
+ compressed(G.FORMAT_BC7_RGBA_UNORM, bptc.COMPRESSED_RGBA_BPTC_UNORM_EXT);
173
+ compressed(G.FORMAT_BC7_RGBA_UNORM_SRGB, bptc.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT);
174
+ compressed(G.FORMAT_BC6H_RGB_UFLOAT, bptc.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT);
175
+ }
176
+ const etc = gl.getExtension('WEBGL_compressed_texture_etc');
177
+ if (etc) {
178
+ compressed(G.FORMAT_ETC2_RGB8_UNORM, etc.COMPRESSED_RGB8_ETC2);
179
+ compressed(G.FORMAT_ETC2_RGB8_UNORM_SRGB, etc.COMPRESSED_SRGB8_ETC2);
180
+ compressed(G.FORMAT_ETC2_RGBA8_UNORM, etc.COMPRESSED_RGBA8_ETC2_EAC);
181
+ compressed(G.FORMAT_ETC2_RGBA8_UNORM_SRGB, etc.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC);
182
+ }
183
+ const color = gl.COLOR_ATTACHMENT0;
184
+ // The canvas holds three channels when its context has no alpha, and a multisampled image
185
+ // resolves only into the same format.
186
+ if (canvasAlpha)
187
+ add(G.FORMAT_CANVAS, gl.RGBA8, gl.RGBA, gl.UNSIGNED_BYTE, color);
188
+ else
189
+ add(G.FORMAT_CANVAS, gl.RGB8, gl.RGB, gl.UNSIGNED_BYTE, color);
190
+ add(G.FORMAT_RGBA8_UNORM, gl.RGBA8, gl.RGBA, gl.UNSIGNED_BYTE, color);
191
+ add(G.FORMAT_RGBA8_UNORM_SRGB, gl.SRGB8_ALPHA8, gl.RGBA, gl.UNSIGNED_BYTE, color);
192
+ add(G.FORMAT_RGBA16_FLOAT, gl.RGBA16F, gl.RGBA, gl.HALF_FLOAT, color);
193
+ add(G.FORMAT_RG16_FLOAT, gl.RG16F, gl.RG, gl.HALF_FLOAT, color);
194
+ add(G.FORMAT_RG11B10_UFLOAT, gl.R11F_G11F_B10F, gl.RGB, gl.UNSIGNED_INT_10F_11F_11F_REV, color);
195
+ add(G.FORMAT_RGB9E5_UFLOAT, gl.RGB9_E5, gl.RGB, gl.UNSIGNED_INT_5_9_9_9_REV, color);
196
+ add(G.FORMAT_RGBA32_FLOAT, gl.RGBA32F, gl.RGBA, gl.FLOAT, color);
197
+ add(G.FORMAT_R32_UINT, gl.R32UI, gl.RED_INTEGER, gl.UNSIGNED_INT, color);
198
+ add(G.FORMAT_R32_FLOAT, gl.R32F, gl.RED, gl.FLOAT, color);
199
+ add(G.FORMAT_RGBA32_UINT, gl.RGBA32UI, gl.RGBA_INTEGER, gl.UNSIGNED_INT, color);
200
+ add(G.FORMAT_R16_FLOAT, gl.R16F, gl.RED, gl.HALF_FLOAT, color);
201
+ const depth = gl.DEPTH_ATTACHMENT;
202
+ add(G.FORMAT_DEPTH24_PLUS, gl.DEPTH_COMPONENT24, gl.DEPTH_COMPONENT, gl.UNSIGNED_INT, depth);
203
+ add(G.FORMAT_DEPTH32_FLOAT, gl.DEPTH_COMPONENT32F, gl.DEPTH_COMPONENT, gl.FLOAT, depth);
204
+ add(G.FORMAT_DEPTH16_UNORM, gl.DEPTH_COMPONENT16, gl.DEPTH_COMPONENT, gl.UNSIGNED_SHORT, depth);
205
+ return formats;
206
+ }
207
+ /** The name of each format that a framebuffer's attachments may take. */
208
+ const FORMAT_NAMES = {
209
+ [G.FORMAT_CANVAS]: 'the canvas',
210
+ [G.FORMAT_RGBA8_UNORM]: 'RGBA8',
211
+ [G.FORMAT_RGBA8_UNORM_SRGB]: 'sRGB8',
212
+ [G.FORMAT_RGBA16_FLOAT]: 'RGBA16F',
213
+ [G.FORMAT_RG16_FLOAT]: 'RG16F',
214
+ [G.FORMAT_RG11B10_UFLOAT]: 'R11G11B10F',
215
+ [G.FORMAT_RGB9E5_UFLOAT]: 'RGB9E5',
216
+ [G.FORMAT_RGBA32_FLOAT]: 'RGBA32F',
217
+ [G.FORMAT_R32_UINT]: 'R32UI',
218
+ [G.FORMAT_R32_FLOAT]: 'R32F',
219
+ [G.FORMAT_RGBA32_UINT]: 'RGBA32UI',
220
+ [G.FORMAT_R16_FLOAT]: 'R16F',
221
+ [G.FORMAT_DEPTH24_PLUS]: 'depth24',
222
+ [G.FORMAT_DEPTH32_FLOAT]: 'depth32f',
223
+ [G.FORMAT_DEPTH16_UNORM]: 'depth16',
224
+ };
225
+ /** A framebuffer's attachments by name and GL's own format number, for a driver report. */
226
+ function describeFramebuffer(first, depth, second) {
227
+ const name = (target) => `${FORMAT_NAMES[target.format.code] ?? `format ${target.format.code}`} (0x${target.format.internal.toString(16)})`;
228
+ const parts = [`color ${name(first)}`];
229
+ if (second)
230
+ parts.push(`second color ${name(second)}`);
231
+ if (depth)
232
+ parts.push(`depth ${name(depth)}`);
233
+ return parts.join(', ');
234
+ }
235
+ /** The linear color formats that WebGL2 both renders into and filters, so `generateMipmap` takes them. */
236
+ const NATIVE_MIP_FORMATS = new Set([
237
+ G.FORMAT_RGBA8_UNORM,
238
+ G.FORMAT_RGBA16_FLOAT,
239
+ G.FORMAT_RG11B10_UFLOAT,
240
+ ]);
241
+ /**
242
+ * True when GL's own `generateMipmap` makes a texture's levels: a render target of the frame, which
243
+ * takes no uploads, with one layer and more levels, in a linear format that WebGL2 renders into and
244
+ * filters. The engine's own draws make the levels of other textures, such as uploaded images
245
+ * (`generateMipmaps` in the backend says why).
246
+ */
247
+ /** True when `error` is a link that the driver refused, on a context that is not lost. */
248
+ function linkRefused(gl, error) {
249
+ return error instanceof LinkFailure && !gl.isContextLost();
250
+ }
251
+ function linearMips(format, usage, layers, mips) {
252
+ const target = G.TEXTURE_USAGE_RENDER_ATTACHMENT | G.TEXTURE_USAGE_COPY_DST;
253
+ return (mips > 1 &&
254
+ layers === 1 &&
255
+ (usage & target) === G.TEXTURE_USAGE_RENDER_ATTACHMENT &&
256
+ NATIVE_MIP_FORMATS.has(format));
257
+ }
258
+ function glTexture(texture, renderbuffer, target, width, height, format, mips, level, layer, view, bytes, nativeMips = false) {
259
+ return {
260
+ texture,
261
+ renderbuffer,
262
+ target,
263
+ width,
264
+ height,
265
+ format,
266
+ mips,
267
+ nativeMips,
268
+ level,
269
+ layer,
270
+ view,
271
+ bytes,
272
+ written: false,
273
+ framebuffer: null,
274
+ framebufferDepth: null,
275
+ soloFramebuffer: null,
276
+ copyFramebuffer: null,
277
+ pairFramebuffer: null,
278
+ pairSecond: null,
279
+ pairDepth: null,
280
+ };
281
+ }
282
+ export class WebGL2Backend {
283
+ gl;
284
+ canvas;
285
+ sharedUploads;
286
+ buffers = [];
287
+ textures = [];
288
+ /**
289
+ * The targets that hold a framebuffer with another target in it, and the texture views. The table
290
+ * of textures is sparse and long, and a target's release must find these without walking it.
291
+ */
292
+ joined = new Set();
293
+ views = new Set();
294
+ /**
295
+ * The texture that each bind view of a layer range names. GL binds a texture array whole, so a
296
+ * view's layer range reaches the shader through the pass's block instead.
297
+ */
298
+ bindViewBase = [];
299
+ samplers = [];
300
+ /** Images for uploads, by id, which outlive the backend when the drawing thread owns them. */
301
+ images;
302
+ ownsImages;
303
+ pipelines = [];
304
+ /** The programs of the templates and permutations in use, which their pipelines share. */
305
+ programs = new Map();
306
+ templates;
307
+ /** The template of the program that draws mip levels. */
308
+ mipTemplate;
309
+ copyTemplate;
310
+ scaleTemplate;
311
+ bindGroups = [];
312
+ vertexArrays = [];
313
+ /** Vertex arrays of the buffers that templates with their own vertex layout draw from, by id. */
314
+ layoutArrays = [];
315
+ formats;
316
+ /** GL's address modes and min filters, by the draw list's codes. */
317
+ addressModes = [];
318
+ /** GL's texture target for each binding view dimension. */
319
+ targets = [];
320
+ minFilters = [];
321
+ multiDraw;
322
+ /**
323
+ * `KHR_parallel_shader_compile`, where the context has it and the device uses it: programs then
324
+ * compile in the background, and the backend asks whether each has finished.
325
+ */
326
+ parallel;
327
+ /** Programs that may still be compiling in the background. */
328
+ compiling = [];
329
+ /** The builds of joined effects' shaders, which never stop the engine when they fail. */
330
+ joins;
331
+ /** True once a list has replayed, after which no frame waits for a joined shader's compile. */
332
+ replayed = false;
333
+ /**
334
+ * How many frames in a row a live context has refused a target, and the target's message, so
335
+ * the next frame may refuse one again before the engine ends: a lost context can answer the
336
+ * check this way before its flag is set, and a cadence can put two targets in the way.
337
+ */
338
+ refusedFrames = 0;
339
+ refusedTarget = '';
340
+ /** The opcode and word of the command that the replay is carrying out. */
341
+ replayOp = -1;
342
+ replayWord = -1;
343
+ /**
344
+ * The operands of each `CreateRenderPipeline` whose custom material's shader has not reached
345
+ * this thread yet, by pipeline id. Each is created once its shader arrives; until then, its
346
+ * draws draw nothing.
347
+ */
348
+ parked = new Map();
349
+ /** The create commands of the pipelines that the lists before the first frame create. */
350
+ listing = new PipelineListing();
351
+ /** The compiles of the programs that the last start's first frame built, until this first frame. */
352
+ early;
353
+ /**
354
+ * In development builds, the programs that a hot update of a custom material's shader compiles,
355
+ * each under the key of the program it replaces once it has compiled. `relinked` is set once the
356
+ * program has linked a second time after Safari's random Metal fault.
357
+ */
358
+ swapping = new Map();
359
+ /**
360
+ * The device shaders that load another module when a pipeline needs builds with other fixed
361
+ * bits. Without it, every pipeline's build must be in the shaders that the backend got.
362
+ */
363
+ moreShaders;
364
+ /**
365
+ * Hears each program of the scene's objects that the driver refused to link twice, by its
366
+ * pipeline's name and the link's logs. Its draws draw nothing from then on, and the frames go
367
+ * on without them.
368
+ */
369
+ refused;
370
+ /**
371
+ * True while the current pipeline's program is compiling, or after the driver refused it: draws
372
+ * draw nothing until it is set again.
373
+ */
374
+ skipDraws = false;
375
+ anisotropic;
376
+ maxAnisotropy;
377
+ maxSamples;
378
+ depth;
379
+ /** A vertex array with no attributes, for draws whose vertex shaders make their vertices. */
380
+ shaderVertices = null;
381
+ /** The framebuffer through which copies read their source. */
382
+ copyFramebuffer = null;
383
+ /**
384
+ * Where the bytes of `ReadBuffer` commands land, which the frame replay sets. Without it, as
385
+ * when a test replays a list outside a running engine, a read still runs, and copies nowhere.
386
+ */
387
+ readSink;
388
+ /** The reads whose fences have not signalled yet, in the order of their commands. */
389
+ pendingReads = [];
390
+ /** Finished reads, which later reads use again, so a read in every frame allocates nothing. */
391
+ freeReads = [];
392
+ /** The bytes that a read copies out of its buffer, before they go into engine memory. */
393
+ readBytes = new Uint8Array(0);
394
+ /** The ring of pixel unpack buffers that texture rewrites go through, and their sizes in bytes. */
395
+ unpackBuffers = new Array(UNPACK_RING).fill(null);
396
+ unpackSizes = new Array(UNPACK_RING).fill(0);
397
+ /** The ring slot of the replay under way, and the bytes that its writes have taken in it. */
398
+ unpackSlot = 0;
399
+ unpackUsed = 0;
400
+ /** The framebuffer through which a mip level is drawn, and the sampler that reads the level before. */
401
+ mipFramebuffer = null;
402
+ /** The framebuffer that clears a range of a texture's layers. */
403
+ clearFramebuffer = null;
404
+ mipSampler = null;
405
+ /** How the texture generators draw with programs of their own. */
406
+ programHost;
407
+ /**
408
+ * The texture that each mip level, and each copied layer of an array, draws into before it
409
+ * copies into its place, by format.
410
+ */
411
+ spares = new Map();
412
+ /** The GPU memory of every buffer, texture and renderbuffer that the backend holds. */
413
+ gpuMemory = new GpuMemory();
414
+ /** Where drawing into the canvas goes during a capture; the canvas itself otherwise. */
415
+ canvasTarget;
416
+ /**
417
+ * What the replays since the last reset uploaded, drew and built, the other objects they made,
418
+ * and the draw commands they skipped because the program was still compiling. The triangles and
419
+ * instances are those that the draws drew.
420
+ */
421
+ counts = {
422
+ uploadBytes: 0,
423
+ drawCalls: 0,
424
+ pipelines: 0,
425
+ objects: 0,
426
+ skippedDraws: 0,
427
+ triangles: 0,
428
+ instances: 0,
429
+ };
430
+ // Views on engine memory, rebuilt when it grows, and copies for browsers that refuse views on
431
+ // shared memory. The replay's own views give the words and the floats.
432
+ memory;
433
+ bytes = new Uint8Array(0);
434
+ halves = new Uint16Array(0);
435
+ ints = new Int32Array(0);
436
+ uints = new Uint32Array(0);
437
+ floats = new Float32Array(0);
438
+ copying = false;
439
+ staging = new ArrayBuffer(0);
440
+ stagingBytes = new Uint8Array(0);
441
+ stagingHalves = new Uint16Array(0);
442
+ stagingFloats = new Float32Array(0);
443
+ stagingUints = new Uint32Array(0);
444
+ stagingInts = new Int32Array(0);
445
+ /** A multi-draw call's counts, offsets and instance counts, one after another. */
446
+ drawLists = new Int32Array(3 * G.SIZE_MULTI_DRAW_RECORDS);
447
+ // The state cache.
448
+ program = null;
449
+ vertexArray = null;
450
+ activeUnit = -1;
451
+ unitTextures = [];
452
+ unitSamplers = [];
453
+ /** The texture that bind groups set at each slot, which the program's unit for the slot gets. */
454
+ slotTextures = [];
455
+ /** The target of each slot's texture. */
456
+ slotTargets = [];
457
+ /** The sampler that bind groups set at each slot, which the units that read it get. */
458
+ slotSamplers = [];
459
+ /**
460
+ * True when the program, the bind groups' textures or samplers, or a unit that a spare program
461
+ * borrowed changed since the program's units were set.
462
+ */
463
+ unitsChanged = true;
464
+ blockBuffers = [];
465
+ blockOffsets = [];
466
+ blockSizes = [];
467
+ /** The faces that GL culls: `BACK` or `FRONT`, or 0 while culling is off. */
468
+ cullFace = 0;
469
+ /** The faces that GL culls while culling is on, which starts as GL's default. */
470
+ cullMode = CULL_BACK;
471
+ depthTest = false;
472
+ depthMask = true;
473
+ /** GL's depth function, which starts as the depth mode's own. */
474
+ depthFunc;
475
+ colorMask = true;
476
+ blend = 0;
477
+ alphaToCoverage = false;
478
+ offsetFactor = 0;
479
+ offsetUnits = 0;
480
+ // Fractions passed to WebGL become new number objects, so the clear values and the depth range
481
+ // are set only when they change. The depth values are the draw list's, before any turn.
482
+ clearColor = [0, 0, 0, 0];
483
+ clearDepth;
484
+ viewport = [0, 0, 0, 0];
485
+ depthNear = 0;
486
+ depthFar = 1;
487
+ scissorTest = false;
488
+ scissor = [0, 0, 0, 0];
489
+ // The pass and draw state the list set last.
490
+ current;
491
+ vertexBuffer = 0;
492
+ indexBuffer = 0;
493
+ indexType = 0;
494
+ indexBytes = 2;
495
+ passFramebuffer = null;
496
+ passWidth = 0;
497
+ passHeight = 0;
498
+ passResolve = G.NO_TARGET;
499
+ /** The pass's depth target, whose one-sample copy the pass's end updates when it has one. */
500
+ passDepth = null;
501
+ /** The pass's color target, or null for the canvas and for a depth-only pass. */
502
+ passColor = null;
503
+ passFlags = 0;
504
+ passToCanvas = false;
505
+ /**
506
+ * `shaders` are the GLSL builds that the device loaded (`loadGlslShaders`), with the bits
507
+ * that it fixes. `sharedUploads` is false where WebGL refuses views on shared memory, so uploads
508
+ * and multi-draw arrays go through copies. `depthMode` is how the backend stores depth.
509
+ * `images` holds the images that uploads read, which the thread that draws keeps across GPU
510
+ * devices; by default the backend has its own. `parallelCompile` lets programs compile in the
511
+ * background where the context has `KHR_parallel_shader_compile`. `canvasAlpha` says whether
512
+ * the canvas's context has alpha. `multiDraw` says whether the device draws many ranges in one
513
+ * call, and defaults to the context's own answer.
514
+ */
515
+ constructor(gl, canvas, shaders, sharedUploads, depthMode, images, parallelCompile = true, canvasAlpha = false, multiDraw = gl.getExtension('WEBGL_multi_draw') !== null) {
516
+ this.gl = gl;
517
+ this.canvas = canvas;
518
+ this.sharedUploads = sharedUploads;
519
+ this.templates = engineTemplates(shaders);
520
+ this.mipTemplate = mipmapTemplate(shaders, 'main');
521
+ this.copyTemplate = mipmapTemplate(shaders, 'copy');
522
+ this.scaleTemplate = mipmapTemplate(shaders, 'scale');
523
+ this.images = images ?? new ImageTable();
524
+ this.ownsImages = !images;
525
+ this.joins = new JoinedBuilds(this.images.shaders);
526
+ this.multiDraw = multiDraw ? gl.getExtension('WEBGL_multi_draw') : null;
527
+ this.parallel = parallelCompile ? gl.getExtension('KHR_parallel_shader_compile') : null;
528
+ // Float render targets, for HDR color, where the device draws them: WebGL turns them on only
529
+ // when the extensions are asked for by name.
530
+ gl.getExtension('EXT_color_buffer_float');
531
+ gl.getExtension('EXT_color_buffer_half_float');
532
+ useFirstProvokingVertex(gl);
533
+ this.anisotropic = gl.getExtension('EXT_texture_filter_anisotropic');
534
+ this.maxAnisotropy = this.anisotropic
535
+ ? gl.getParameter(this.anisotropic.MAX_TEXTURE_MAX_ANISOTROPY_EXT)
536
+ : 1;
537
+ this.maxSamples = gl.getParameter(gl.MAX_SAMPLES);
538
+ this.formats = glFormats(gl, canvasAlpha);
539
+ this.targets[G.VIEW_2D] = gl.TEXTURE_2D;
540
+ this.targets[G.VIEW_2D_ARRAY] = gl.TEXTURE_2D_ARRAY;
541
+ this.targets[G.VIEW_CUBE] = gl.TEXTURE_CUBE_MAP;
542
+ this.targets[G.VIEW_3D] = gl.TEXTURE_3D;
543
+ this.addressModes[G.ADDRESS_CLAMP_TO_EDGE] = gl.CLAMP_TO_EDGE;
544
+ this.addressModes[G.ADDRESS_REPEAT] = gl.REPEAT;
545
+ this.addressModes[G.ADDRESS_MIRROR_REPEAT] = gl.MIRRORED_REPEAT;
546
+ this.minFilters[G.FILTER_NEAREST] = [];
547
+ this.minFilters[G.FILTER_LINEAR] = [];
548
+ this.minFilters[G.FILTER_NEAREST][G.FILTER_NEAREST] = gl.NEAREST_MIPMAP_NEAREST;
549
+ this.minFilters[G.FILTER_NEAREST][G.FILTER_LINEAR] = gl.NEAREST_MIPMAP_LINEAR;
550
+ this.minFilters[G.FILTER_LINEAR][G.FILTER_NEAREST] = gl.LINEAR_MIPMAP_NEAREST;
551
+ this.minFilters[G.FILTER_LINEAR][G.FILTER_LINEAR] = gl.LINEAR_MIPMAP_LINEAR;
552
+ this.indexType = gl.UNSIGNED_SHORT;
553
+ this.depth = setDepthMode(gl, depthMode);
554
+ this.programHost = programHost(gl, this.depth, this.parallel);
555
+ const host = this.programHost;
556
+ this.images.warmGeneratorsWith((code) => {
557
+ const { environment, probes } = code;
558
+ return Promise.all([environment.prepare(host), probes.prepare(host)]);
559
+ });
560
+ this.depthFunc = this.nearerPasses();
561
+ // GL clears depth to 1 until told otherwise, which is the draw list's 0 in standard depth.
562
+ this.clearDepth = this.depth.standard ? 0 : 1;
563
+ // Texel rows in engine memory are tightly packed, whatever their width.
564
+ gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
565
+ this.prebuildSparePrograms();
566
+ }
567
+ need(table, id, what) {
568
+ const value = table[id];
569
+ if (value === undefined)
570
+ throw new Error(`draw list names ${what} ${id}, which does not exist${this.replayWord < 0 ? '' : `, in command ${this.replayOp} at word ${this.replayWord}`}`);
571
+ return value;
572
+ }
573
+ /**
574
+ * Adds a render pipeline template, which `CreateRenderPipeline` then builds programs from. The
575
+ * id must be one that no engine template has.
576
+ */
577
+ defineTemplate(id, template) {
578
+ if (this.templates[id])
579
+ throw new Error(`render pipeline template ${id} already exists`);
580
+ this.templates[id] = template;
581
+ }
582
+ /** Hands the backend an image for `UploadImage` commands to copy from, under the draw list's id. */
583
+ setImage(id, image) {
584
+ this.images.set(id, image);
585
+ }
586
+ /**
587
+ * Starts to build each pipeline that the list in `words[start, end)` creates before its first
588
+ * other command, and returns where the rest of the list starts. Programs compile without
589
+ * blocking where the context has `KHR_parallel_shader_compile`. Until one has compiled,
590
+ * `building` is true and the draws that use it draw nothing. Without the extension, a program's
591
+ * first draw waits for its compile.
592
+ */
593
+ prepare(words, start, end) {
594
+ this.replayWord = -1;
595
+ let i = start;
596
+ while (i < end && (words[i] & 0xff) === G.OP_CREATE_RENDER_PIPELINE) {
597
+ this.listing.add(G.OP_CREATE_RENDER_PIPELINE, words, i + 1);
598
+ this.createPipeline(words, i + 1, true);
599
+ i += words[i] >>> 8;
600
+ }
601
+ if (this.listing.active && this.parallel)
602
+ this.compileAhead(words, i, end);
603
+ return i;
604
+ }
605
+ /**
606
+ * Starts to compile, in the background, the program of each pipeline that the list in
607
+ * `words[start, end)` creates after other commands. The frame before the first one then waits
608
+ * for them, as for the programs of the pipelines at the list's front, instead of its first draw
609
+ * with each waiting for its compile.
610
+ */
611
+ compileAhead(words, start, end) {
612
+ for (let i = start; i < end;) {
613
+ const header = words[i];
614
+ const length = header >>> 8;
615
+ if (length === 0)
616
+ return;
617
+ if ((header & 0xff) === G.OP_CREATE_RENDER_PIPELINE) {
618
+ const template = words[i + 2];
619
+ const permutation = words[i + 3];
620
+ try {
621
+ if (!this.joins.joined(template) && this.templateReady(template, permutation))
622
+ this.programOf(template, permutation, true);
623
+ }
624
+ catch {
625
+ // The pipeline's own command meets the error.
626
+ }
627
+ }
628
+ i += length;
629
+ }
630
+ }
631
+ /**
632
+ * Where the draw section of the list in `words[start, end)` begins, after the pipelines it
633
+ * creates. It walks the same ops as `prepare` and starts no build.
634
+ */
635
+ restStart(words, start, end) {
636
+ let i = start;
637
+ while (i < end && (words[i] & 0xff) === G.OP_CREATE_RENDER_PIPELINE)
638
+ i += words[i] >>> 8;
639
+ return i;
640
+ }
641
+ /** The programs that may still be compiling in the background, for the two-step probe. */
642
+ get compilingCount() {
643
+ return this.compiling.length;
644
+ }
645
+ /** True when the context has `KHR_parallel_shader_compile` and the device compiles with it. */
646
+ get parallelCompile() {
647
+ return this.parallel !== null;
648
+ }
649
+ /**
650
+ * True while a program is compiling in the background, or a pipeline waits for its custom
651
+ * material's shader. Pipelines whose shaders arrived are created first.
652
+ */
653
+ get building() {
654
+ if (DEV && (this.images.replaced.length > 0 || this.swapping.size > 0))
655
+ this.swapReplaced();
656
+ if (this.parked.size > 0)
657
+ this.unpark();
658
+ const compiling = this.compiling;
659
+ for (let k = compiling.length - 1; k >= 0; k--) {
660
+ const program = compiling[k];
661
+ if (this.compiled(program)) {
662
+ if (program.joined)
663
+ this.joinCompiled(program);
664
+ compiling[k] = compiling[compiling.length - 1];
665
+ compiling.pop();
666
+ }
667
+ }
668
+ return compiling.length > 0 || this.parked.size > 0 || this.swapping.size > 0;
669
+ }
670
+ /**
671
+ * Compiles each program of a custom material whose shader a hot update replaced again, in the
672
+ * background where the context can, and swaps each in once it has linked. The old program
673
+ * draws until then, so no frame loses the material's objects. A link that fails with Safari's
674
+ * random Metal fault is done once more, also in the background. A program that fails to link
675
+ * otherwise keeps the old one and logs why.
676
+ */
677
+ swapReplaced() {
678
+ if (!DEV)
679
+ return;
680
+ const gl = this.gl;
681
+ for (const template of this.images.replaced.splice(0)) {
682
+ const shader = this.images.shaders.get(template);
683
+ // A template that no pipeline has used takes the new shader at its first use.
684
+ if (!shader || !this.templates[template])
685
+ continue;
686
+ const defined = customTemplate(shader);
687
+ this.templates[template] = defined;
688
+ for (const key of this.programs.keys()) {
689
+ const [owner, permutation] = key.split(' ').map(Number);
690
+ if (owner !== template)
691
+ continue;
692
+ const earlier = this.swapping.get(key);
693
+ if (earlier)
694
+ this.deleteProgram(earlier.program);
695
+ const program = createProgram(gl, defined, permutation);
696
+ program.background = true;
697
+ this.swapping.set(key, { program, relinked: false });
698
+ this.counts.pipelines++;
699
+ }
700
+ }
701
+ for (const [key, swap] of this.swapping) {
702
+ const program = swap.program;
703
+ if (!this.compiled(program))
704
+ continue;
705
+ const old = this.programs.get(key);
706
+ const linked = gl.getProgramParameter(program.program, gl.LINK_STATUS);
707
+ if (old && !linked && !swap.relinked && metalFault(gl, program)) {
708
+ relink(gl, program);
709
+ swap.relinked = true;
710
+ continue;
711
+ }
712
+ this.swapping.delete(key);
713
+ if (!old || !linked) {
714
+ if (old)
715
+ console.error(`null3D could not build the new WGSL of a custom material on this GPU, so its objects keep the old shader: ${linkLogs(gl, program)}`);
716
+ this.deleteProgram(program);
717
+ continue;
718
+ }
719
+ this.programs.set(key, program);
720
+ this.pipelines.forEach((pipeline, id) => {
721
+ if (pipeline?.program === old)
722
+ this.pipelines[id] = { ...pipeline, program };
723
+ });
724
+ this.deleteProgram(old);
725
+ }
726
+ }
727
+ /**
728
+ * True when a render pipeline template can create a program of `permutation` now: an engine
729
+ * template whose build for it is loaded, or a custom material's whose shader arrived, which it
730
+ * defines at its first use, once the set of its builds that holds the build has arrived too. A
731
+ * group's or a fold's shader is joined then too, once its host's file has arrived.
732
+ */
733
+ templateReady(template, permutation) {
734
+ let defined = this.templates[template];
735
+ if (!defined) {
736
+ const shader = this.images.shaders.get(template);
737
+ if (!shader || !joinedReady(shader, this.images.shaders, this.moreShaders, 'glsl'))
738
+ return false;
739
+ defined = customTemplate(shader);
740
+ this.templates[template] = defined;
741
+ }
742
+ const build = buildPermutation(defined, permutation);
743
+ if (!this.images.buildsReady(template, build, 'glsl'))
744
+ return false;
745
+ return this.moreShaders?.ready(defined.shader, build, 'glsl') ?? true;
746
+ }
747
+ /**
748
+ * Starts to compile the programs of the builds of `module`, a module that the page or the sketch
749
+ * preloaded, whose builds need `features`, so that the features' first objects draw at once.
750
+ * They compile in the background where the browser can, and the first frame waits for them.
751
+ * Skinning's and morph targets' builds vary in every material bit, and a scene's materials draw
752
+ * with a few of them, so `scene.warmUp()` builds those, as for any material.
753
+ */
754
+ precompile(features, module) {
755
+ if (features.some((feature) => WARM_UP_FEATURES.has(feature)))
756
+ return;
757
+ const held = this.moreShaders?.shaders;
758
+ for (const [name, builds] of Object.entries(module)) {
759
+ const variants = held?.[name];
760
+ if (!variants)
761
+ continue;
762
+ this.templates.forEach((template, id) => {
763
+ if (template?.shader !== variants)
764
+ return;
765
+ for (const build of Object.values(builds))
766
+ if (build.glsl?.[template.pipeline])
767
+ this.programOf(id, build.permutation, true);
768
+ });
769
+ }
770
+ }
771
+ /**
772
+ * Starts to compile the programs of `list`, a pipeline list of the pipelines that the first frame
773
+ * of the sketch's last start built (`gpu/early-builds.ts`). Each compile starts once its shader
774
+ * is there, and a pipeline of the same template and permutation takes the program. No frame
775
+ * waits for a program that no pipeline takes. A joined shader's program compiles when its
776
+ * pipeline comes, as its failure sends the effects back to a pass each.
777
+ */
778
+ buildEarly(list) {
779
+ this.early?.stop();
780
+ this.early = new EarlyBuilds(list, (op, operands) => {
781
+ const template = operands[1];
782
+ const permutation = operands[2];
783
+ if (op !== G.OP_CREATE_RENDER_PIPELINE || this.joins.joined(template))
784
+ return null;
785
+ if (!this.templateReady(template, permutation))
786
+ return undefined;
787
+ const key = `${template} ${permutation}`;
788
+ if (this.programs.has(key))
789
+ return null;
790
+ const glsl = this.need(this.templates, template, 'render pipeline template');
791
+ const program = createProgram(this.gl, glsl, permutation);
792
+ program.early = true;
793
+ this.programs.set(key, program);
794
+ return null;
795
+ });
796
+ }
797
+ /**
798
+ * Ends the list of the pipelines that the frames before the first one created, and returns it,
799
+ * once: the first frame has drawn. The compiles of the last start's list that have not started
800
+ * stop.
801
+ */
802
+ takeListing() {
803
+ this.early?.stop();
804
+ this.early = undefined;
805
+ return this.listing.take();
806
+ }
807
+ /** Creates each parked pipeline whose custom material's shader has arrived. */
808
+ unpark() {
809
+ for (const [id, operands] of this.parked) {
810
+ if (!this.templateReady(operands[1], operands[2]))
811
+ continue;
812
+ this.parked.delete(id);
813
+ this.counts.pipelines--;
814
+ this.createPipeline(operands, 0, true);
815
+ }
816
+ }
817
+ /**
818
+ * True once a program may be used without waiting: it has compiled and linked, or failed to, or
819
+ * its first draw waits for its compile.
820
+ */
821
+ compiled(p) {
822
+ const parallel = this.parallel;
823
+ return (p.ready ||
824
+ !p.background ||
825
+ !parallel ||
826
+ this.gl.getProgramParameter(p.program, parallel.COMPLETION_STATUS_KHR) === true);
827
+ }
828
+ /**
829
+ * Creates the pipeline of a `CreateRenderPipeline` command with its operands at `a`. A new
830
+ * program compiles in the background when `background` is set; otherwise its first draw waits
831
+ * for it.
832
+ */
833
+ createPipeline(words, a, background) {
834
+ const template = words[a + 1];
835
+ const flags = words[a + 6];
836
+ if (!this.templateReady(template, words[a + 2])) {
837
+ // The command's header, before its operands, gives its length in words.
838
+ this.parked.set(words[a], words.slice(a, a - 1 + (words[a - 1] >>> 8)));
839
+ this.counts.pipelines++;
840
+ return;
841
+ }
842
+ const depth = words[a + 4] !== G.FORMAT_NONE;
843
+ // The list's bias is in reversed depth. Standard depth stores the near plane as 0, so a bias
844
+ // toward the camera turns negative there.
845
+ const sign = this.depth.standard ? -1 : 1;
846
+ this.pipelines[words[a]] = {
847
+ program: this.programOf(template, words[a + 2], background),
848
+ cull: this.cullOf(flags),
849
+ depth,
850
+ depthWrite: depth && (flags & (G.STATE_NO_DEPTH_WRITE | G.STATE_NO_DEPTH_TEST)) === 0,
851
+ depthFunc: this.depthFuncOf(flags),
852
+ colorWrite: (flags & G.STATE_NO_COLOR_WRITE) === 0,
853
+ blend: flags & G.STATE_BLEND,
854
+ alphaToCoverage: (flags & G.STATE_ALPHA_TO_COVERAGE) !== 0,
855
+ offsetUnits: sign * (words[a + 8] | 0),
856
+ offsetFactor: sign * floatOfBits(words[a + 9]),
857
+ vertexFormat: words[a + 7],
858
+ mode: flags & G.STATE_LINE_LIST ? this.gl.LINES : this.gl.TRIANGLES,
859
+ vertices: this.need(this.templates, template, 'render pipeline template').vertices,
860
+ };
861
+ this.counts.pipelines++;
862
+ }
863
+ resetCounts() {
864
+ this.counts.uploadBytes = 0;
865
+ this.counts.drawCalls = 0;
866
+ this.counts.pipelines = 0;
867
+ this.counts.objects = 0;
868
+ this.counts.skippedDraws = 0;
869
+ this.counts.triangles = 0;
870
+ this.counts.instances = 0;
871
+ }
872
+ /** Counts a draw of `count` vertices or indices, `instances` times, with the current pipeline. */
873
+ countDraw(count, instances) {
874
+ this.counts.drawCalls++;
875
+ this.counts.instances += instances;
876
+ if (this.current.mode === TRIANGLES)
877
+ this.counts.triangles += Math.floor(count / 3) * instances;
878
+ }
879
+ /**
880
+ * Replays the draw list in `words[start, end)`. `floats` views the same memory as `words`, for
881
+ * float operands; `memory` is the engine memory that uploads read from. A target that a live
882
+ * context refuses ends the replay without an error, and the next frame asks again before the
883
+ * refusal is reported: a lost context can answer the check that way before its flag is set.
884
+ */
885
+ replay(words, floats, start, end, memory) {
886
+ if (memory !== this.memory) {
887
+ this.memory = memory;
888
+ this.bytes = new Uint8Array(memory);
889
+ this.halves = new Uint16Array(memory);
890
+ this.ints = new Int32Array(memory);
891
+ this.copying =
892
+ !this.sharedUploads &&
893
+ typeof SharedArrayBuffer === 'function' &&
894
+ memory instanceof SharedArrayBuffer;
895
+ }
896
+ this.uints = words;
897
+ this.floats = floats;
898
+ this.unpackSlot = (this.unpackSlot + 1) % UNPACK_RING;
899
+ this.unpackUsed = 0;
900
+ try {
901
+ this.replayOps(words, floats, start, end);
902
+ }
903
+ catch (error) {
904
+ if (!(error instanceof WebGL2TargetRefused))
905
+ throw error;
906
+ // A live context refused a target. The driver can answer a lost context's check this
907
+ // way before the loss flag is set, so this frame draws nothing and the next frame asks
908
+ // again. A cadence can put two targets in the way on alternating frames, so the retry
909
+ // counts frames, not names.
910
+ if (this.refusedFrames > 0) {
911
+ const before = this.refusedTarget;
912
+ throw new WebGL2TargetRefused(before === error.message
913
+ ? error.message
914
+ : `${error.message}; the frame before refused ${before}`);
915
+ }
916
+ this.refusedFrames = 1;
917
+ this.refusedTarget = error.message;
918
+ // The frame's finished reads still go, as at the end of every replay: a read that waits
919
+ // for a frame which never draws again would hold its page waiting.
920
+ this.flushReads();
921
+ return;
922
+ }
923
+ this.refusedFrames = 0;
924
+ this.refusedTarget = '';
925
+ this.flushReads();
926
+ this.replayed = true;
927
+ }
928
+ /** Replays a draw list's commands, as `replay` describes them. */
929
+ replayOps(words, floats, start, end) {
930
+ const gl = this.gl;
931
+ for (let i = start; i < end;) {
932
+ const header = words[i];
933
+ const op = header & 0xff;
934
+ const length = header >>> 8;
935
+ if (length === 0 || i + length > end)
936
+ throw new Error(`draw list is truncated at word ${i}`);
937
+ const a = i + 1;
938
+ this.replayOp = op;
939
+ this.replayWord = i;
940
+ switch (op) {
941
+ case G.OP_CREATE_BUFFER:
942
+ // A capture draws the frame again, and the buffers of that frame exist already:
943
+ // making one again would destroy the buffer that a read waits on.
944
+ if (this.canvasTarget && this.buffers[words[a]])
945
+ break;
946
+ this.counts.objects++;
947
+ this.createBuffer(words[a], words[a + 1], words[a + 2]);
948
+ break;
949
+ case G.OP_WRITE_BUFFER: {
950
+ const record = this.need(this.buffers, words[a], 'buffer');
951
+ const offset = words[a + 1];
952
+ const source = words[a + 2];
953
+ const bytes = words[a + 3];
954
+ record.writes++;
955
+ // Units that read a texture copy of the buffer copy it again before they draw.
956
+ if (record.copies)
957
+ this.unitsChanged = true;
958
+ gl.bindBuffer(gl.COPY_WRITE_BUFFER, record.buffer);
959
+ this.writeBytes(gl.COPY_WRITE_BUFFER, offset, source, bytes);
960
+ this.counts.uploadBytes += bytes;
961
+ break;
962
+ }
963
+ case G.OP_DESTROY_BUFFER:
964
+ this.destroyBuffer(words[a]);
965
+ break;
966
+ case G.OP_CREATE_TEXTURE:
967
+ this.counts.objects++;
968
+ this.createTexture(words, a);
969
+ break;
970
+ case G.OP_CREATE_TEXTURE_VIEW:
971
+ this.counts.objects++;
972
+ this.createView(words, a);
973
+ break;
974
+ case G.OP_CREATE_BIND_VIEW:
975
+ this.createBindView(words, a);
976
+ break;
977
+ case G.OP_CLEAR_TEXTURE:
978
+ this.clearTexture(words, a);
979
+ break;
980
+ case G.OP_DESTROY_TEXTURE:
981
+ this.destroyTexture(words[a]);
982
+ break;
983
+ case G.OP_WRITE_TEXTURE:
984
+ this.writeTexture(words, a);
985
+ break;
986
+ case G.OP_UPLOAD_IMAGE:
987
+ this.uploadImage(words, a);
988
+ break;
989
+ case G.OP_RELEASE_IMAGE:
990
+ this.images.release(words[a]);
991
+ break;
992
+ case G.OP_DESTROY_PIPELINE:
993
+ this.destroyPipeline(words[a]);
994
+ break;
995
+ case G.OP_PROBE_FILTER:
996
+ this.filterProbe(words, a);
997
+ break;
998
+ case G.OP_GENERATE_TEXTURE:
999
+ case G.OP_SKY_MAP_STEP:
1000
+ this.generateTexture(op, words, floats, a);
1001
+ break;
1002
+ case G.OP_GENERATE_MIPMAPS:
1003
+ this.generateMipmaps(words[a], words[a + 1]);
1004
+ break;
1005
+ case G.OP_COPY_INTO_IMAGE:
1006
+ this.copyIntoImage(words, a);
1007
+ break;
1008
+ case G.OP_COPY_TEXTURE_TO_TEXTURE:
1009
+ this.copyTexture(words, a);
1010
+ break;
1011
+ // A capture replays a frame that the loop replayed already, whose reads would land twice.
1012
+ case G.OP_COPY_TEXTURE_TO_BUFFER:
1013
+ if (!this.canvasTarget)
1014
+ this.copyTextureToBuffer(words, a);
1015
+ break;
1016
+ case G.OP_READ_BUFFER:
1017
+ if (!this.canvasTarget)
1018
+ this.readBuffer(words, a);
1019
+ break;
1020
+ case G.OP_CREATE_SAMPLER:
1021
+ this.counts.objects++;
1022
+ this.createSampler(words, floats, a);
1023
+ break;
1024
+ case G.OP_RESIZE_CANVAS: {
1025
+ const width = words[a];
1026
+ const height = words[a + 1];
1027
+ if (this.canvas.width !== width || this.canvas.height !== height) {
1028
+ this.canvas.width = width;
1029
+ this.canvas.height = height;
1030
+ }
1031
+ break;
1032
+ }
1033
+ case G.OP_CREATE_RENDER_PIPELINE:
1034
+ // A list that creates a pipeline after other commands waits for it at its first draw.
1035
+ this.listing.add(op, words, a);
1036
+ this.createPipeline(words, a, false);
1037
+ break;
1038
+ case G.OP_CREATE_BIND_GROUP: {
1039
+ this.counts.objects++;
1040
+ const entries = [];
1041
+ for (let k = 0; k < words[a + 2]; k++) {
1042
+ const e = a + 3 + k * 5;
1043
+ entries.push({
1044
+ binding: words[e],
1045
+ kind: words[e + 1],
1046
+ resource: words[e + 2],
1047
+ offset: words[e + 3],
1048
+ size: words[e + 4],
1049
+ });
1050
+ }
1051
+ this.bindGroups[words[a]] = entries;
1052
+ break;
1053
+ }
1054
+ case G.OP_BEGIN_RENDER_PASS:
1055
+ this.beginPass(words, floats, a, length);
1056
+ break;
1057
+ case G.OP_END_RENDER_PASS:
1058
+ this.endPass();
1059
+ break;
1060
+ case G.OP_SET_VIEWPORT:
1061
+ this.setViewport(words[a], words[a + 1], words[a + 2], words[a + 3]);
1062
+ this.setDepthRange(floats[a + 4], floats[a + 5]);
1063
+ break;
1064
+ case G.OP_SET_SCISSOR:
1065
+ this.setScissor(words[a], words[a + 1], words[a + 2], words[a + 3]);
1066
+ break;
1067
+ case G.OP_SET_PIPELINE: {
1068
+ const id = words[a];
1069
+ // A pipeline that waits for its custom material's shader draws nothing.
1070
+ if (this.parked.has(id))
1071
+ this.skipDraws = true;
1072
+ else
1073
+ this.setPipeline(this.need(this.pipelines, id, 'render pipeline'));
1074
+ break;
1075
+ }
1076
+ case G.OP_SET_BIND_GROUP:
1077
+ this.setBindGroup(words, a);
1078
+ break;
1079
+ case G.OP_SET_VERTEX_BUFFER:
1080
+ if (words[a] !== 0)
1081
+ throw new Error('the WebGL2 backend reads vertices from slot 0 only');
1082
+ this.vertexBuffer = words[a + 1];
1083
+ break;
1084
+ case G.OP_SET_INDEX_BUFFER:
1085
+ this.indexBuffer = words[a];
1086
+ this.indexType =
1087
+ words[a + 1] === G.INDEX_FORMAT_UINT32 ? gl.UNSIGNED_INT : gl.UNSIGNED_SHORT;
1088
+ this.indexBytes = words[a + 1] === G.INDEX_FORMAT_UINT32 ? 4 : 2;
1089
+ break;
1090
+ case G.OP_DRAW:
1091
+ if (this.skipDraws) {
1092
+ this.counts.skippedDraws++;
1093
+ break;
1094
+ }
1095
+ this.useVertexArray(this.drawVertexArray());
1096
+ this.prepareDraw(words[a + 3]);
1097
+ gl.drawArraysInstanced(this.current.mode, words[a + 2], words[a], words[a + 1]);
1098
+ this.countDraw(words[a], words[a + 1]);
1099
+ break;
1100
+ case G.OP_DRAW_INDEXED: {
1101
+ if (this.skipDraws) {
1102
+ this.counts.skippedDraws++;
1103
+ break;
1104
+ }
1105
+ if (words[a + 3] !== 0)
1106
+ throw new Error('WebGL2 has no base vertex for draws');
1107
+ this.useMeshVertexArray();
1108
+ this.prepareDraw(words[a + 4]);
1109
+ gl.drawElementsInstanced(this.current.mode, words[a], this.indexType, words[a + 2] * this.indexBytes, words[a + 1]);
1110
+ this.countDraw(words[a], words[a + 1]);
1111
+ break;
1112
+ }
1113
+ case G.OP_MULTI_DRAW_INDEXED:
1114
+ if (this.skipDraws)
1115
+ this.counts.skippedDraws++;
1116
+ else
1117
+ this.multiDrawIndexed(words, a);
1118
+ break;
1119
+ case G.OP_SUBMIT:
1120
+ break;
1121
+ default:
1122
+ throw new Error(`the WebGL2 backend cannot replay draw list command ${op} at word ${i}`);
1123
+ }
1124
+ i += length;
1125
+ }
1126
+ }
1127
+ /**
1128
+ * The program that draws mip levels, or the one that copies a layer, which starts compiling the
1129
+ * first time.
1130
+ */
1131
+ spareProgramOf(key) {
1132
+ let program = this.programs.get(key);
1133
+ if (!program) {
1134
+ const template = key === MIP_PROGRAM
1135
+ ? this.mipTemplate
1136
+ : key === COPY_PROGRAM
1137
+ ? this.copyTemplate
1138
+ : this.scaleTemplate;
1139
+ program = createProgram(this.gl, template, 0);
1140
+ this.programs.set(key, program);
1141
+ }
1142
+ return program;
1143
+ }
1144
+ /**
1145
+ * Starts compiling the programs that draw mip levels, copy layers and scale one texture into
1146
+ * another, so that the driver can compile them before the first texture needs them. Nothing
1147
+ * waits for their link here. A program that fails to start is made again at first use, which
1148
+ * reports the failure.
1149
+ */
1150
+ prebuildSparePrograms() {
1151
+ for (const key of [MIP_PROGRAM, COPY_PROGRAM, SCALE_PROGRAM]) {
1152
+ try {
1153
+ this.spareProgramOf(key);
1154
+ }
1155
+ catch { }
1156
+ }
1157
+ }
1158
+ /**
1159
+ * The program that draws mip levels, or the one that copies a layer, in use. Its first use
1160
+ * waits for its link when the driver has not finished it.
1161
+ */
1162
+ spareProgram(key) {
1163
+ const program = this.spareProgramOf(key);
1164
+ this.useProgram(program);
1165
+ return program;
1166
+ }
1167
+ /**
1168
+ * Puts a program of the scene's objects in use, as `useProgram` does, and returns true. A link
1169
+ * that the driver refused links once more, from new shaders: a driver can run short of memory
1170
+ * while it links. A second refusal marks the program, so its draws draw nothing from then on,
1171
+ * reports it, and returns false. Any other failure, such as a material with more textures than
1172
+ * the stages hold, still stops the replay, and so does a link on a lost context, which the
1173
+ * renderer recovers from as a loss.
1174
+ */
1175
+ useObjectsProgram(program) {
1176
+ const objects = program.objects;
1177
+ try {
1178
+ this.useProgram(program);
1179
+ return true;
1180
+ }
1181
+ catch (error) {
1182
+ if (!linkRefused(this.gl, error))
1183
+ throw error;
1184
+ }
1185
+ relink(this.gl, program);
1186
+ try {
1187
+ this.useProgram(program);
1188
+ return true;
1189
+ }
1190
+ catch (error) {
1191
+ if (!linkRefused(this.gl, error))
1192
+ throw error;
1193
+ objects.refused = true;
1194
+ this.refused?.(pipelineName(objects.template, objects.permutation), error.message);
1195
+ return false;
1196
+ }
1197
+ }
1198
+ /** Puts a program in use, first checking its link and binding its slots at its first use. */
1199
+ useProgram(program) {
1200
+ if (!program.ready) {
1201
+ prepareProgram(this.gl, program, this.depth);
1202
+ this.program = program.program;
1203
+ }
1204
+ if (this.program !== program.program) {
1205
+ this.gl.useProgram(program.program);
1206
+ this.program = program.program;
1207
+ }
1208
+ }
1209
+ /**
1210
+ * Forgets a render pipeline, and deletes its program once no other pipeline uses it. A pipeline
1211
+ * that is gone already, as when a capture replays a list again, changes nothing.
1212
+ */
1213
+ destroyPipeline(id) {
1214
+ this.parked.delete(id);
1215
+ const program = this.pipelines[id]?.program;
1216
+ this.pipelines[id] = undefined;
1217
+ if (!program || this.pipelines.some((p) => p?.program === program))
1218
+ return;
1219
+ this.deleteProgram(program);
1220
+ }
1221
+ /** Deletes a program and its shaders, and forgets it. */
1222
+ deleteProgram(program) {
1223
+ for (const [key, held] of this.programs)
1224
+ if (held === program)
1225
+ this.programs.delete(key);
1226
+ const compiling = this.compiling.indexOf(program);
1227
+ if (compiling >= 0)
1228
+ this.compiling.splice(compiling, 1);
1229
+ for (const shader of program.shaders)
1230
+ this.gl.deleteShader(shader);
1231
+ this.gl.deleteProgram(program.program);
1232
+ }
1233
+ /**
1234
+ * The program of a template and permutation, which starts compiling the first time, in the
1235
+ * background when `background` is set and the context can.
1236
+ */
1237
+ programOf(template, permutation, background) {
1238
+ const key = `${template} ${permutation}`;
1239
+ let program = this.programs.get(key);
1240
+ if (!program) {
1241
+ const glsl = this.need(this.templates, template, 'render pipeline template');
1242
+ program = createProgram(this.gl, glsl, permutation);
1243
+ this.programs.set(key, program);
1244
+ const joined = this.joins.joined(template)
1245
+ ? { template, start: performance.now(), failed: false }
1246
+ : undefined;
1247
+ if (joined)
1248
+ program.joined = joined;
1249
+ if (glsl.meshPrepass)
1250
+ program.objects = { template, permutation, refused: false };
1251
+ if ((background || joined) && this.parallel) {
1252
+ program.background = true;
1253
+ this.compiling.push(program);
1254
+ }
1255
+ else if (joined && this.replayed) {
1256
+ // Without background compiles, the first draw would wait for the compile, so the
1257
+ // effects stay one pass each after the first frame, which waits for every program.
1258
+ joined.failed = true;
1259
+ this.joins.keptApart(template);
1260
+ }
1261
+ }
1262
+ else if (program.early) {
1263
+ // A program that compiled ahead of its pipeline: the frames wait for it from now on.
1264
+ program.early = undefined;
1265
+ if (background && this.parallel) {
1266
+ program.background = true;
1267
+ this.compiling.push(program);
1268
+ }
1269
+ }
1270
+ return program;
1271
+ }
1272
+ /**
1273
+ * Notes a joined shader's program whose background compile finished: its time, or its failure
1274
+ * to link, which sends its effects back to a pass each.
1275
+ */
1276
+ joinCompiled(program) {
1277
+ const joined = program.joined;
1278
+ if (!joined || joined.failed)
1279
+ return;
1280
+ if (this.gl.getProgramParameter(program.program, this.gl.LINK_STATUS) !== true)
1281
+ this.joinFailed(program, linkLogs(this.gl, program) || 'its link failed');
1282
+ else
1283
+ this.joins.built(joined.template, performance.now() - joined.start);
1284
+ }
1285
+ /** Marks a joined shader's program as failed, so its draws draw nothing, and reports it. */
1286
+ joinFailed(program, reason) {
1287
+ const joined = program.joined;
1288
+ if (!joined || joined.failed)
1289
+ return;
1290
+ joined.failed = true;
1291
+ this.joins.failed(joined.template, reason);
1292
+ }
1293
+ /** Makes the staging buffer hold at least `bytes`. */
1294
+ ensureStaging(bytes) {
1295
+ if (this.staging.byteLength >= bytes)
1296
+ return;
1297
+ this.staging = new ArrayBuffer(Math.max(bytes, this.staging.byteLength * 2));
1298
+ this.stagingBytes = new Uint8Array(this.staging);
1299
+ this.stagingHalves = new Uint16Array(this.staging);
1300
+ this.stagingFloats = new Float32Array(this.staging);
1301
+ this.stagingUints = new Uint32Array(this.staging);
1302
+ this.stagingInts = new Int32Array(this.staging);
1303
+ }
1304
+ /**
1305
+ * Copies bytes out of shared memory into the staging buffer, and returns them. Uploads start and
1306
+ * end on four-byte boundaries, so a loop copies whole words, which makes no view per upload.
1307
+ */
1308
+ stage(source, bytes) {
1309
+ this.ensureStaging(bytes);
1310
+ const from = source >>> 2;
1311
+ const staged = this.stagingInts;
1312
+ const ints = this.ints;
1313
+ for (let k = 0; k < bytes >>> 2; k++)
1314
+ staged[k] = ints[from + k];
1315
+ return this.stagingBytes;
1316
+ }
1317
+ /** True for the GL types whose texels uploads read as whole 32-bit words: packed and integer. */
1318
+ wordTexels(type) {
1319
+ const gl = this.gl;
1320
+ return (type === gl.UNSIGNED_INT ||
1321
+ type === gl.UNSIGNED_INT_5_9_9_9_REV ||
1322
+ type === gl.UNSIGNED_INT_10F_11F_11F_REV);
1323
+ }
1324
+ /** The view of values of GL type `type` that texel uploads read: engine memory, or its staged copy. */
1325
+ texels(type) {
1326
+ const gl = this.gl;
1327
+ const staged = this.copying;
1328
+ if (type === gl.FLOAT)
1329
+ return staged ? this.stagingFloats : this.floats;
1330
+ if (this.wordTexels(type))
1331
+ return staged ? this.stagingUints : this.uints;
1332
+ if (type === gl.HALF_FLOAT)
1333
+ return staged ? this.stagingHalves : this.halves;
1334
+ return staged ? this.stagingBytes : this.bytes;
1335
+ }
1336
+ /**
1337
+ * The index in the view of `texels(type)` of the value `offset` bytes after byte `source` of
1338
+ * engine memory. A staged upload starts at the staging buffer's first byte.
1339
+ */
1340
+ texelIndex(type, source, offset) {
1341
+ const byte = (this.copying ? 0 : source) + offset;
1342
+ const gl = this.gl;
1343
+ if (type === gl.FLOAT || this.wordTexels(type))
1344
+ return byte >>> 2;
1345
+ return type === gl.HALF_FLOAT ? byte >>> 1 : byte;
1346
+ }
1347
+ /** True for the GL targets whose layers or depth slices a call reaches with a third coordinate. */
1348
+ layered(target) {
1349
+ return target === this.gl.TEXTURE_2D_ARRAY || target === this.gl.TEXTURE_3D;
1350
+ }
1351
+ /**
1352
+ * The GL target of one layer of a texture that calls in two dimensions reach: a cube's face, or
1353
+ * the texture itself when it is 2D.
1354
+ */
1355
+ planeTarget(texture, layer) {
1356
+ const gl = this.gl;
1357
+ return texture.target === gl.TEXTURE_CUBE_MAP
1358
+ ? gl.TEXTURE_CUBE_MAP_POSITIVE_X + layer
1359
+ : texture.target;
1360
+ }
1361
+ useVertexArray(vao) {
1362
+ if (this.vertexArray === vao)
1363
+ return;
1364
+ this.gl.bindVertexArray(vao);
1365
+ this.vertexArray = vao;
1366
+ }
1367
+ bindTexture(unit, target, texture) {
1368
+ if (this.unitTextures[unit] === texture)
1369
+ return;
1370
+ this.activate(unit);
1371
+ this.gl.bindTexture(target, texture);
1372
+ this.unitTextures[unit] = texture;
1373
+ }
1374
+ activate(unit) {
1375
+ if (this.activeUnit === unit)
1376
+ return;
1377
+ this.gl.activeTexture(this.gl.TEXTURE0 + unit);
1378
+ this.activeUnit = unit;
1379
+ }
1380
+ /**
1381
+ * Binds a texture for the calls that change it, which act on the active unit: when the texture
1382
+ * is bound already, a bind group may have made another unit active since.
1383
+ */
1384
+ editTexture(unit, target, texture) {
1385
+ this.bindTexture(unit, target, texture);
1386
+ this.activate(unit);
1387
+ }
1388
+ createBuffer(id, size, usage) {
1389
+ const gl = this.gl;
1390
+ this.destroyBuffer(id);
1391
+ const buffer = gl.createBuffer();
1392
+ if (!buffer)
1393
+ throw new Error('WebGL2 could not create a buffer');
1394
+ // A buffer's first binding fixes its kind; an index buffer must first bind as one, which
1395
+ // also binds it to the current vertex array, so none may be current.
1396
+ const target = usage & G.BUFFER_USAGE_INDEX
1397
+ ? gl.ELEMENT_ARRAY_BUFFER
1398
+ : usage & G.BUFFER_USAGE_UNIFORM
1399
+ ? gl.UNIFORM_BUFFER
1400
+ : gl.ARRAY_BUFFER;
1401
+ this.useVertexArray(null);
1402
+ gl.bindBuffer(target, buffer);
1403
+ gl.bufferData(target, size, gl.DYNAMIC_DRAW);
1404
+ this.buffers[id] = { buffer, size, writes: 0, copies: null };
1405
+ this.gpuMemory.addBuffers(size);
1406
+ }
1407
+ destroyBuffer(id) {
1408
+ const old = this.buffers[id];
1409
+ if (!old)
1410
+ return;
1411
+ if (this.pendingReads.length > 0)
1412
+ this.dropReads(id);
1413
+ this.gl.deleteBuffer(old.buffer);
1414
+ this.gpuMemory.addBuffers(-old.size);
1415
+ if (old.copies)
1416
+ for (const copy of old.copies) {
1417
+ this.gl.deleteTexture(copy.texture);
1418
+ this.gpuMemory.addTextures(-copy.width * 16);
1419
+ }
1420
+ this.buffers[id] = undefined;
1421
+ for (let slot = 0; slot < this.blockBuffers.length; slot++)
1422
+ if (this.blockBuffers[slot] === old)
1423
+ this.blockBuffers[slot] = null;
1424
+ }
1425
+ format(code) {
1426
+ const format = this.formats[code];
1427
+ if (!format)
1428
+ throw new Error(`the WebGL2 backend has no texture format ${code}`);
1429
+ return format;
1430
+ }
1431
+ /**
1432
+ * Creates a texture. A render target that nothing samples or copies lives in a renderbuffer,
1433
+ * and so does every multisampled one, since WebGL2 has no multisampled textures. A multisampled
1434
+ * depth target that shaders read also gets a texture of one sample, which they read instead:
1435
+ * WebGPU's shaders read its sample 0, and WebGL2 copies one sample of each pixel.
1436
+ */
1437
+ createTexture(words, a) {
1438
+ const gl = this.gl;
1439
+ const id = words[a];
1440
+ const width = words[a + 1];
1441
+ const height = words[a + 2];
1442
+ const layers = words[a + 3];
1443
+ const format = this.format(words[a + 4]);
1444
+ const usage = words[a + 5];
1445
+ const samples = words[a + 6];
1446
+ const mips = words[a + 7];
1447
+ this.destroyTexture(id);
1448
+ const read = G.TEXTURE_USAGE_TEXTURE_BINDING | G.TEXTURE_USAGE_COPY_SRC | G.TEXTURE_USAGE_COPY_DST;
1449
+ if (samples > 1 || (usage & G.TEXTURE_USAGE_RENDER_ATTACHMENT && !(usage & read))) {
1450
+ const renderbuffer = gl.createRenderbuffer();
1451
+ if (!renderbuffer)
1452
+ throw new Error('WebGL2 could not create a renderbuffer');
1453
+ gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer);
1454
+ const stored = samples > 1 ? Math.min(samples, this.maxSamples) : 1;
1455
+ if (samples > 1) {
1456
+ gl.renderbufferStorageMultisample(gl.RENDERBUFFER, stored, format.internal, width, height);
1457
+ }
1458
+ else {
1459
+ gl.renderbufferStorage(gl.RENDERBUFFER, format.internal, width, height);
1460
+ }
1461
+ const copied = samples > 1 && usage & G.TEXTURE_USAGE_TEXTURE_BINDING;
1462
+ const copy = copied ? this.depthCopy(width, height, format) : null;
1463
+ const target = copy ? gl.TEXTURE_2D : 0;
1464
+ const bytes = textureBytes(format.code, width, height, 1, 1, stored) +
1465
+ (copy ? textureBytes(format.code, width, height, 1, 1, 1) : 0);
1466
+ this.gpuMemory.addTextures(bytes);
1467
+ this.textures[id] = glTexture(copy, renderbuffer, target, width, height, format, 1, 0, 0, false, bytes);
1468
+ return;
1469
+ }
1470
+ const texture = gl.createTexture();
1471
+ if (!texture)
1472
+ throw new Error('WebGL2 could not create a texture');
1473
+ // WebGL2 fixes a texture's kind at its first binding, as compatibility mode fixes its view.
1474
+ const target = this.targets[words[a + 8]];
1475
+ if (target === undefined)
1476
+ throw new Error(`unknown texture view dimension ${words[a + 8]}`);
1477
+ this.editTexture(UPLOAD_UNIT, target, texture);
1478
+ if (this.layered(target))
1479
+ gl.texStorage3D(target, mips, format.internal, width, height, layers);
1480
+ else
1481
+ gl.texStorage2D(target, mips, format.internal, width, height);
1482
+ // Shaders sample through sampler objects, which set their own filters. The texture's own
1483
+ // filters serve texelFetch, which needs a complete texture: 32-bit float and integer
1484
+ // textures are complete only with nearest filters.
1485
+ gl.texParameteri(target, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
1486
+ gl.texParameteri(target, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
1487
+ const volume = target === gl.TEXTURE_3D;
1488
+ const bytes = textureBytes(format.code, width, height, layers, mips, 1, volume);
1489
+ this.gpuMemory.addTextures(bytes);
1490
+ this.textures[id] = glTexture(texture, null, target, width, height, format, mips, 0, 0, false, bytes, linearMips(format.code, usage, layers, mips));
1491
+ }
1492
+ /** The texture of one sample that shaders read in place of a multisampled depth target. */
1493
+ depthCopy(width, height, format) {
1494
+ const gl = this.gl;
1495
+ if (format.attachment !== gl.DEPTH_ATTACHMENT)
1496
+ throw new Error('WebGL2 reads only multisampled depth targets, through a copy of one sample');
1497
+ const texture = gl.createTexture();
1498
+ if (!texture)
1499
+ throw new Error('WebGL2 could not create a texture');
1500
+ this.editTexture(UPLOAD_UNIT, gl.TEXTURE_2D, texture);
1501
+ gl.texStorage2D(gl.TEXTURE_2D, 1, format.internal, width, height);
1502
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
1503
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
1504
+ return texture;
1505
+ }
1506
+ /** A texture by id, which a view, a write, an upload or a copy can use: not a render-only one. */
1507
+ textureOf(id) {
1508
+ const record = this.need(this.textures, id, 'texture');
1509
+ if (!record.texture || record.view)
1510
+ throw new Error(`texture ${id} is a render target or a view, without texels of its own`);
1511
+ return record;
1512
+ }
1513
+ /** The texture that a bind group entry names, following a bind view to its texture. */
1514
+ boundTextureOf(id) {
1515
+ const base = this.bindViewBase[id];
1516
+ return this.textureOf(base === undefined ? id : base);
1517
+ }
1518
+ /**
1519
+ * Names a range of a texture's array layers as a bind view. GL binds the whole array, so the
1520
+ * recorded base texture is what a bind group sees.
1521
+ */
1522
+ createBindView(words, a) {
1523
+ const id = words[a];
1524
+ this.bindViewBase[id] = words[a + 1];
1525
+ }
1526
+ /** Clears a range of a texture's layers to zero, one layer at a time, outside the passes. */
1527
+ clearTexture(words, a) {
1528
+ const gl = this.gl;
1529
+ const texture = this.textureOf(words[a]);
1530
+ const base = words[a + 1];
1531
+ const count = words[a + 2];
1532
+ if (!this.clearFramebuffer)
1533
+ this.clearFramebuffer = gl.createFramebuffer();
1534
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this.clearFramebuffer);
1535
+ const scissor = gl.isEnabled(gl.SCISSOR_TEST);
1536
+ gl.disable(gl.SCISSOR_TEST);
1537
+ gl.colorMask(true, true, true, true);
1538
+ for (let layer = 0; layer < count; layer++) {
1539
+ gl.framebufferTextureLayer(gl.FRAMEBUFFER, texture.format.attachment, texture.texture, 0, base + layer);
1540
+ gl.clearBufferfv(gl.COLOR, 0, CLEAR_ZERO);
1541
+ }
1542
+ if (scissor)
1543
+ gl.enable(gl.SCISSOR_TEST);
1544
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
1545
+ }
1546
+ createView(words, a) {
1547
+ const id = words[a];
1548
+ this.destroyTexture(id);
1549
+ const texture = this.textureOf(words[a + 1]);
1550
+ const level = words[a + 2];
1551
+ const view = glTexture(texture.texture, null, texture.target, Math.max(1, texture.width >> level), Math.max(1, texture.height >> level), texture.format, texture.mips, level, words[a + 3], true, 0);
1552
+ this.textures[id] = view;
1553
+ this.views.add(view);
1554
+ }
1555
+ destroyTexture(id) {
1556
+ const gl = this.gl;
1557
+ this.bindViewBase[id] = undefined;
1558
+ const old = this.textures[id];
1559
+ if (!old)
1560
+ return;
1561
+ this.textures[id] = undefined;
1562
+ this.forgetFramebuffers(old);
1563
+ this.views.delete(old);
1564
+ if (old.view)
1565
+ return;
1566
+ this.gpuMemory.addTextures(-old.bytes);
1567
+ if (old.texture) {
1568
+ this.generators?.release(gl, old.texture, this.gpuMemory);
1569
+ for (const other of this.views)
1570
+ if (other.texture === old.texture)
1571
+ this.forgetFramebuffers(other);
1572
+ gl.deleteTexture(old.texture);
1573
+ for (let unit = 0; unit < this.unitTextures.length; unit++)
1574
+ if (this.unitTextures[unit] === old.texture)
1575
+ this.unitTextures[unit] = null;
1576
+ for (let slot = 0; slot < this.slotTextures.length; slot++)
1577
+ if (this.slotTextures[slot] === old.texture)
1578
+ this.slotTextures[slot] = null;
1579
+ }
1580
+ if (old.renderbuffer)
1581
+ gl.deleteRenderbuffer(old.renderbuffer);
1582
+ }
1583
+ /** Deletes the framebuffers that draw into a target, and those that pair it as their depth. */
1584
+ forgetFramebuffers(target) {
1585
+ const gl = this.gl;
1586
+ if (target.framebuffer)
1587
+ gl.deleteFramebuffer(target.framebuffer);
1588
+ if (target.soloFramebuffer)
1589
+ gl.deleteFramebuffer(target.soloFramebuffer);
1590
+ if (target.copyFramebuffer)
1591
+ gl.deleteFramebuffer(target.copyFramebuffer);
1592
+ target.copyFramebuffer = null;
1593
+ target.framebuffer = null;
1594
+ target.framebufferDepth = null;
1595
+ target.soloFramebuffer = null;
1596
+ this.forgetPair(target);
1597
+ this.joined.delete(target);
1598
+ for (const other of this.joined) {
1599
+ if (other.pairSecond === target || other.pairDepth === target)
1600
+ this.forgetPair(other);
1601
+ if (other.framebufferDepth === target) {
1602
+ gl.deleteFramebuffer(other.framebuffer);
1603
+ other.framebuffer = null;
1604
+ other.framebufferDepth = null;
1605
+ }
1606
+ if (!other.framebufferDepth && !other.pairFramebuffer)
1607
+ this.joined.delete(other);
1608
+ }
1609
+ }
1610
+ /** Deletes the framebuffer that draws into `target` and a second color target. */
1611
+ forgetPair(target) {
1612
+ if (target.pairFramebuffer)
1613
+ this.gl.deleteFramebuffer(target.pairFramebuffer);
1614
+ target.pairFramebuffer = null;
1615
+ target.pairSecond = null;
1616
+ target.pairDepth = null;
1617
+ }
1618
+ /** Writes `bytes` bytes of engine memory from byte `source` into the buffer bound at `target`. */
1619
+ writeBytes(target, offset, source, bytes) {
1620
+ if (this.copying)
1621
+ this.gl.bufferSubData(target, offset, this.stage(source, bytes), 0, bytes);
1622
+ else
1623
+ this.gl.bufferSubData(target, offset, this.bytes, source, bytes);
1624
+ }
1625
+ /**
1626
+ * Copies `bytes` bytes of engine memory into this replay's pixel unpack buffer, which it leaves
1627
+ * bound, and returns where they start. A buffer too small for the replay's writes is made again
1628
+ * larger: the writes already given keep the data of the buffer they read.
1629
+ */
1630
+ unpack(source, bytes) {
1631
+ const gl = this.gl;
1632
+ const slot = this.unpackSlot;
1633
+ let buffer = this.unpackBuffers[slot] ?? null;
1634
+ if (!buffer) {
1635
+ buffer = gl.createBuffer();
1636
+ this.unpackBuffers[slot] = buffer;
1637
+ }
1638
+ gl.bindBuffer(gl.PIXEL_UNPACK_BUFFER, buffer);
1639
+ let at = Math.ceil(this.unpackUsed / UNPACK_ALIGNMENT) * UNPACK_ALIGNMENT;
1640
+ const size = this.unpackSizes[slot];
1641
+ if (at + bytes > size) {
1642
+ const grown = Math.max(bytes, 2 * size);
1643
+ gl.bufferData(gl.PIXEL_UNPACK_BUFFER, grown, gl.STREAM_DRAW);
1644
+ this.unpackSizes[slot] = grown;
1645
+ this.gpuMemory.addBuffers(grown - size);
1646
+ at = 0;
1647
+ }
1648
+ this.writeBytes(gl.PIXEL_UNPACK_BUFFER, at, source, bytes);
1649
+ this.unpackUsed = at + bytes;
1650
+ return at;
1651
+ }
1652
+ /**
1653
+ * Writes a box of texels, layer after layer, from tightly packed rows in engine memory. The
1654
+ * layers of a cube are its faces, and those of a 3D texture its depth slices. A
1655
+ * compressed format's rows are rows of blocks: WebGL2 takes the box in texels, cut by the
1656
+ * level's edge, and the bytes of its whole blocks. The texture's first write reads engine
1657
+ * memory directly. Later writes into a texture of 32-bit values read a pixel unpack buffer, as
1658
+ * the GPU may still read the texture.
1659
+ */
1660
+ writeTexture(words, a) {
1661
+ const gl = this.gl;
1662
+ const texture = this.textureOf(words[a]);
1663
+ const source = words[a + 8];
1664
+ const bytes = words[a + 9];
1665
+ const { format, type, internal } = texture.format;
1666
+ const compressed = texture.format.block > 1;
1667
+ const level = words[a + 1];
1668
+ const x = words[a + 2];
1669
+ const y = words[a + 3];
1670
+ const z = words[a + 4];
1671
+ const width = words[a + 5];
1672
+ const height = words[a + 6];
1673
+ const depth = words[a + 7];
1674
+ const target = texture.target;
1675
+ this.editTexture(UPLOAD_UNIT, target, texture.texture);
1676
+ const unpacked = texture.written && (type === gl.FLOAT || type === gl.UNSIGNED_INT);
1677
+ texture.written = true;
1678
+ const layered = this.layered(target);
1679
+ // A cube's faces take one call each, as calls in two dimensions reach one face.
1680
+ const planeBytes = bytes / depth;
1681
+ if (unpacked) {
1682
+ const at = this.unpack(source, bytes);
1683
+ if (layered)
1684
+ gl.texSubImage3D(target, level, x, y, z, width, height, depth, format, type, at);
1685
+ else
1686
+ for (let k = 0; k < depth; k++)
1687
+ gl.texSubImage2D(this.planeTarget(texture, z + k), level, x, y, width, height, format, type, at + k * planeBytes);
1688
+ // Image uploads and direct writes read no unpack buffer.
1689
+ gl.bindBuffer(gl.PIXEL_UNPACK_BUFFER, null);
1690
+ }
1691
+ else {
1692
+ if (this.copying)
1693
+ this.stage(source, bytes);
1694
+ const data = this.texels(type);
1695
+ if (layered && compressed)
1696
+ gl.compressedTexSubImage3D(target, level, x, y, z, width, height, depth, internal, data, this.texelIndex(type, source, 0), bytes);
1697
+ else if (layered)
1698
+ gl.texSubImage3D(target, level, x, y, z, width, height, depth, format, type, data, this.texelIndex(type, source, 0));
1699
+ else
1700
+ for (let k = 0; k < depth; k++) {
1701
+ const plane = this.planeTarget(texture, z + k);
1702
+ const index = this.texelIndex(type, source, k * planeBytes);
1703
+ if (compressed)
1704
+ gl.compressedTexSubImage2D(plane, level, x, y, width, height, internal, data, index, planeBytes);
1705
+ else
1706
+ gl.texSubImage2D(plane, level, x, y, width, height, format, type, data, index);
1707
+ }
1708
+ }
1709
+ this.counts.uploadBytes += bytes;
1710
+ }
1711
+ /**
1712
+ * Copies part of an image into a texture. WebGL applies no flip and no premultiplication to an
1713
+ * image bitmap, so the texture gets the bitmap as its decoder made it. The pixel store's skips
1714
+ * pick the part, as WebGL2 applies them to images too.
1715
+ */
1716
+ uploadImage(words, a) {
1717
+ const gl = this.gl;
1718
+ const texture = this.textureOf(words[a]);
1719
+ const id = words[a + 7];
1720
+ const image = this.images.need(id);
1721
+ const width = words[a + 5];
1722
+ const height = words[a + 6];
1723
+ const skipPixels = words[a + 9];
1724
+ const skipRows = words[a + 10];
1725
+ const { format, type } = texture.format;
1726
+ this.editTexture(UPLOAD_UNIT, texture.target, texture.texture);
1727
+ if (skipPixels)
1728
+ gl.pixelStorei(gl.UNPACK_SKIP_PIXELS, skipPixels);
1729
+ if (skipRows)
1730
+ gl.pixelStorei(gl.UNPACK_SKIP_ROWS, skipRows);
1731
+ if (this.layered(texture.target)) {
1732
+ gl.texSubImage3D(texture.target, words[a + 1], words[a + 2], words[a + 3], words[a + 4], width, height, 1, format, type, image);
1733
+ }
1734
+ else {
1735
+ gl.texSubImage2D(this.planeTarget(texture, words[a + 4]), words[a + 1], words[a + 2], words[a + 3], width, height, format, type, image);
1736
+ }
1737
+ // Writes from engine memory read whole rows from their first texel.
1738
+ if (skipPixels)
1739
+ gl.pixelStorei(gl.UNPACK_SKIP_PIXELS, 0);
1740
+ if (skipRows)
1741
+ gl.pixelStorei(gl.UNPACK_SKIP_ROWS, 0);
1742
+ this.counts.uploadBytes += width * height * texture.format.bytes;
1743
+ if (words[a + 8] & G.UPLOAD_RELEASE)
1744
+ this.images.release(id);
1745
+ }
1746
+ /**
1747
+ * Makes mip levels 1 and up of one layer of a texture array, as the WebGPU backend does: a
1748
+ * triangle over each level samples the level before it with a linear filter. Each level draws
1749
+ * into the spare texture and then copies into its place, so no draw writes the texture it
1750
+ * reads. Chrome on Adreno 830 refuses a draw into one level of a texture that the draw samples
1751
+ * at another level, although WebGL allows it. A blit per level fails there too, and in Firefox
1752
+ * it averages the stored bytes of sRGB texels, not their linear values. `generateMipmap` would
1753
+ * remake every layer. A frame's render target of one layer in a linear format takes
1754
+ * `generateMipmap` instead. Its levels are made in every frame, as the copy behind glass is, and
1755
+ * a draw and a copy per level cost far more GPU time than the levels' own work. `levels` holds
1756
+ * how many levels an image needs, or 0 for the texture's own count.
1757
+ */
1758
+ generateMipmaps(id, layer, levels = 0) {
1759
+ const texture = this.textureOf(id);
1760
+ if (texture.nativeMips) {
1761
+ this.editTexture(MIP_UNIT, texture.target, texture.texture);
1762
+ this.gl.generateMipmap(texture.target);
1763
+ return;
1764
+ }
1765
+ const program = this.beginSpareDraws(MIP_PROGRAM, texture, texture.format, texture.width, texture.height);
1766
+ const count = levels === 0 ? texture.mips : Math.min(levels, texture.mips);
1767
+ for (let level = 1; level < count; level++) {
1768
+ const width = Math.max(1, texture.width >> level);
1769
+ const height = Math.max(1, texture.height >> level);
1770
+ this.drawIntoSpare(program, texture, level - 1, layer, width, height);
1771
+ this.copyFromSpare(texture, level, 0, 0, layer, 0, 0, width, height);
1772
+ }
1773
+ this.endSpareDraws(texture, texture.format);
1774
+ }
1775
+ /**
1776
+ * Draws one layer of a source texture into the first texels of one layer of a light's image,
1777
+ * at a size of its own, then makes that layer's mip levels: a spot light's picture that a
1778
+ * sketch set as a texture. The image's corner is the smallest `size` by `size` texels of the
1779
+ * layer, which the light tables' shaders read, so a source larger than the corner is reduced.
1780
+ */
1781
+ copyIntoImage(words, a) {
1782
+ const sourceId = words[a];
1783
+ const sourceLayer = words[a + 1];
1784
+ const destId = words[a + 2];
1785
+ const destLayer = words[a + 3];
1786
+ const size = words[a + 4];
1787
+ const levels = words[a + 5];
1788
+ const source = this.textureOf(sourceId);
1789
+ const dest = this.textureOf(destId);
1790
+ const program = this.beginSpareDraws(SCALE_PROGRAM, source, dest.format, size, size);
1791
+ this.drawScaleIntoSpare(program, source, size | (sourceLayer << SCALE_SIZE_BITS), size, size);
1792
+ this.copyFromSpare(dest, 0, 0, 0, destLayer, 0, 0, size, size);
1793
+ this.endSpareDraws(source, dest.format);
1794
+ this.generateMipmaps(destId, destLayer, levels);
1795
+ }
1796
+ /** The generators' code once a generator ran, which frees a sky map with its texture. */
1797
+ generators;
1798
+ /**
1799
+ * Runs a generator that the table holds on a cube texture: the whole map, or one stage of a sky
1800
+ * map, whose stages before the last write only what the generator keeps. The generator draws
1801
+ * full-screen triangles with no depth test, culling, scissor or blending, and writes every
1802
+ * channel. It changes bindings that the state cache holds, so the cache forgets them, and the
1803
+ * next draws bind what they need again.
1804
+ */
1805
+ generateTexture(op, words, floats, a) {
1806
+ const texture = this.textureOf(words[a]);
1807
+ const id = words[a + 1];
1808
+ const code = this.images.generatorCodeFor(id).environment;
1809
+ this.generators = code;
1810
+ this.beforeGenerator();
1811
+ const target = texture.texture;
1812
+ const { width, mips } = texture;
1813
+ if (op === G.OP_SKY_MAP_STEP) {
1814
+ const from = words[a + 3];
1815
+ const panorama = from === 0 ? null : this.textureOf(from).texture;
1816
+ // The cloud tier's noise field exists once the tier's first frame made it, and the
1817
+ // generator reads it only while the tier draws.
1818
+ const cloudSteps = words[a + CLOUD_STEPS_WORD];
1819
+ const field = words[a + CLOUD_FIELD_WORD];
1820
+ const noise = cloudSteps > 0 && field !== 0 ? this.textureOf(field).texture : null;
1821
+ const host = this.programHost;
1822
+ // The page's sky layer, once its shader is here: the map's texels then hold the layer
1823
+ // that the background shows, and so do the reflections and the light taken from them.
1824
+ const template = words[a + LAYER_WORD];
1825
+ const layer = template === 0
1826
+ ? undefined
1827
+ : variantFor(this.images.shaders.get(template)?.variants ?? {}, 0, 'glsl');
1828
+ const capture = words[a + LIGHT_BUFFER_WORD];
1829
+ // A capture draws the frame again to read it back, and the light capture already ran in
1830
+ // the frame that it draws again.
1831
+ const readback = capture === 0 || this.canvasTarget
1832
+ ? undefined
1833
+ : this.need(this.buffers, capture, 'buffer').buffer;
1834
+ code.skyStage(host, target, width, mips, words, floats, a, this.gpuMemory, panorama, layer, readback, noise);
1835
+ }
1836
+ else
1837
+ code.run(this.programHost, target, width, mips, this.images.generator(id)[0]);
1838
+ this.afterGenerator();
1839
+ }
1840
+ /** The six capture views' images of the probe that a filter makes, kept so it allocates none. */
1841
+ probeFaces = [];
1842
+ /**
1843
+ * Makes a reflection probe's map from its six capture views' images, ahead of the frame's
1844
+ * passes, with the filter of the generators' code under the command's image id.
1845
+ */
1846
+ filterProbe(words, a) {
1847
+ const probes = this.textureOf(words[a]);
1848
+ const chain = this.textureOf(words[a + 1]);
1849
+ const code = this.images.generatorCodeFor(words[a + 3]).probes;
1850
+ for (let face = 0; face < 6; face++)
1851
+ this.probeFaces[face] = this.textureOf(words[a + 4 + face]);
1852
+ this.beforeGenerator();
1853
+ const layer = words[a + 2];
1854
+ code.run(this.programHost, probes, chain, layer, this.probeFaces, this.gpuMemory);
1855
+ this.afterGenerator();
1856
+ }
1857
+ /** Sets the state that a generator's draws take: no depth test, culling, scissor or blending. */
1858
+ beforeGenerator() {
1859
+ this.setScissorTest(false);
1860
+ this.setDepthTest(false);
1861
+ this.setCullFace(0);
1862
+ this.setColorMask(true);
1863
+ if (this.blend)
1864
+ this.setBlend(0);
1865
+ this.setAlphaToCoverage(false);
1866
+ this.useVertexArray(null);
1867
+ for (let unit = 0; unit < this.unitSamplers.length; unit++)
1868
+ this.bindUnitSampler(unit, null);
1869
+ }
1870
+ /**
1871
+ * Forgets the bindings that a generator changed, so the next draws bind what they need. The
1872
+ * caches keep their length, so a sky map's stage in every frame grows no array again.
1873
+ */
1874
+ afterGenerator() {
1875
+ this.program = null;
1876
+ this.activeUnit = -1;
1877
+ // Loops rather than `fill`, which takes the browser's slow path on these sparse arrays.
1878
+ for (let unit = 0; unit < this.unitTextures.length; unit++)
1879
+ this.unitTextures[unit] = undefined;
1880
+ for (let slot = 0; slot < this.blockBuffers.length; slot++)
1881
+ this.blockBuffers[slot] = undefined;
1882
+ this.viewport.fill(-1);
1883
+ this.unitsChanged = true;
1884
+ }
1885
+ /**
1886
+ * Gets ready to draw layers of `source` into the spare texture of `format`, at least `width`
1887
+ * by `height`, with the program that `key` names. The source is bound for sampling. The spare
1888
+ * takes the format of what the draws go into, which a scale draw writes into another texture.
1889
+ */
1890
+ beginSpareDraws(key, source, format, width, height) {
1891
+ const gl = this.gl;
1892
+ const spare = this.spareOf(format, width, height);
1893
+ const program = this.spareProgram(key);
1894
+ if (!this.mipFramebuffer)
1895
+ this.mipFramebuffer = gl.createFramebuffer();
1896
+ if (!this.mipSampler) {
1897
+ this.mipSampler = gl.createSampler();
1898
+ gl.samplerParameteri(this.mipSampler, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
1899
+ gl.samplerParameteri(this.mipSampler, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
1900
+ gl.samplerParameteri(this.mipSampler, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
1901
+ }
1902
+ // The copies read the spare through the same framebuffer that the draws write.
1903
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this.mipFramebuffer);
1904
+ const attachment = format.attachment;
1905
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D, spare.texture, 0);
1906
+ this.useVertexArray(this.emptyVertexArray());
1907
+ this.setScissorTest(false);
1908
+ this.setDepthTest(false);
1909
+ this.setCullFace(0);
1910
+ this.setColorMask(true);
1911
+ if (this.blend)
1912
+ this.setBlend(0);
1913
+ this.setAlphaToCoverage(false);
1914
+ this.editTexture(MIP_UNIT, gl.TEXTURE_2D_ARRAY, source.texture);
1915
+ this.bindUnitSampler(MIP_UNIT, this.mipSampler);
1916
+ this.unitsChanged = true;
1917
+ return program;
1918
+ }
1919
+ /**
1920
+ * Draws one layer of the bound source into the spare's lower-left `width` by `height` texels.
1921
+ * The program reads `level` of the source as its first level.
1922
+ */
1923
+ drawIntoSpare(program, source, level, layer, width, height) {
1924
+ const gl = this.gl;
1925
+ if (program.firstInstance && program.firstInstanceValue !== layer) {
1926
+ gl.uniform1ui(program.firstInstance, layer);
1927
+ program.firstInstanceValue = layer;
1928
+ }
1929
+ this.editTexture(MIP_UNIT, gl.TEXTURE_2D_ARRAY, source.texture);
1930
+ gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_BASE_LEVEL, level);
1931
+ gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MAX_LEVEL, level);
1932
+ this.setGlViewport(0, 0, width, height);
1933
+ gl.drawArrays(gl.TRIANGLES, 0, 3);
1934
+ }
1935
+ /**
1936
+ * Draws the source into the spare's lower-left `width` by `height` texels at a size of its
1937
+ * own: `instance` holds the destination's size and the source's layer, as the scale program
1938
+ * reads them. The program reads the source's first level.
1939
+ */
1940
+ drawScaleIntoSpare(program, source, instance, width, height) {
1941
+ const gl = this.gl;
1942
+ if (program.firstInstance && program.firstInstanceValue !== instance) {
1943
+ gl.uniform1ui(program.firstInstance, instance);
1944
+ program.firstInstanceValue = instance;
1945
+ }
1946
+ this.editTexture(MIP_UNIT, gl.TEXTURE_2D_ARRAY, source.texture);
1947
+ gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_BASE_LEVEL, 0);
1948
+ gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MAX_LEVEL, 0);
1949
+ this.setGlViewport(0, 0, width, height);
1950
+ gl.drawArrays(gl.TRIANGLES, 0, 3);
1951
+ }
1952
+ /** Copies a rectangle of the spare into a level of `into`: a layer, a cube face or a 3D slice. */
1953
+ copyFromSpare(into, level, x, y, layer, spareX, spareY, width, height) {
1954
+ const gl = this.gl;
1955
+ this.editTexture(MIP_UNIT, into.target, into.texture);
1956
+ if (this.layered(into.target))
1957
+ gl.copyTexSubImage3D(into.target, level, x, y, layer, spareX, spareY, width, height);
1958
+ else {
1959
+ const plane = this.planeTarget(into, layer);
1960
+ gl.copyTexSubImage2D(plane, level, x, y, spareX, spareY, width, height);
1961
+ }
1962
+ }
1963
+ /** Gives the source back all its levels, and takes the spare of `format` out of the framebuffer. */
1964
+ endSpareDraws(source, format) {
1965
+ const gl = this.gl;
1966
+ this.editTexture(MIP_UNIT, gl.TEXTURE_2D_ARRAY, source.texture);
1967
+ gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_BASE_LEVEL, 0);
1968
+ gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MAX_LEVEL, source.mips - 1);
1969
+ // A framebuffer that is not bound keeps what it holds alive, so the spare leaves it.
1970
+ const attachment = format.attachment;
1971
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D, null, 0);
1972
+ }
1973
+ /**
1974
+ * The spare texture of a format, at least `width` by `height`. A smaller spare gives way to
1975
+ * one that fits both sizes. Each spare stays for the next draws of its format.
1976
+ */
1977
+ spareOf(format, width, height) {
1978
+ const gl = this.gl;
1979
+ const old = this.spares.get(format.internal);
1980
+ const w = Math.max(1, width, old?.width ?? 0);
1981
+ const h = Math.max(1, height, old?.height ?? 0);
1982
+ if (old && old.width === w && old.height === h)
1983
+ return old;
1984
+ if (old)
1985
+ this.deleteSpare(old);
1986
+ const spare = gl.createTexture();
1987
+ if (!spare)
1988
+ throw new Error('WebGL2 could not create a texture');
1989
+ this.editTexture(UPLOAD_UNIT, gl.TEXTURE_2D, spare);
1990
+ gl.texStorage2D(gl.TEXTURE_2D, 1, format.internal, w, h);
1991
+ const bytes = textureBytes(format.code, w, h, 1, 1, 1);
1992
+ this.gpuMemory.addTextures(bytes);
1993
+ const made = glTexture(spare, null, gl.TEXTURE_2D, w, h, format, 1, 0, 0, false, bytes);
1994
+ this.spares.set(format.internal, made);
1995
+ return made;
1996
+ }
1997
+ /** Attaches one mip level and layer of a texture to a framebuffer. */
1998
+ attachLevel(framebuffer, attachment, texture, level, layer) {
1999
+ const gl = this.gl;
2000
+ if (this.layered(texture.target))
2001
+ gl.framebufferTextureLayer(framebuffer, attachment, texture.texture, level, layer);
2002
+ else
2003
+ gl.framebufferTexture2D(framebuffer, attachment, this.planeTarget(texture, layer), texture.texture, level);
2004
+ }
2005
+ /**
2006
+ * Copies texels layer by layer. Rows count as stored, the same as on WebGPU. A layer of a color
2007
+ * texture array draws into the spare texture, which then copies into the destination: Chrome
2008
+ * on Adreno 830 copies layer 0 from a framebuffer that holds another layer of an array. Other
2009
+ * sources attach to a framebuffer, which WebGL2 copies from.
2010
+ */
2011
+ copyTexture(words, a) {
2012
+ const gl = this.gl;
2013
+ const source = this.textureOf(words[a]);
2014
+ const sourceLevel = words[a + 1];
2015
+ const sourceX = words[a + 2];
2016
+ const sourceY = words[a + 3];
2017
+ const sourceLayer = words[a + 4];
2018
+ const destination = this.textureOf(words[a + 5]);
2019
+ const level = words[a + 6];
2020
+ const x = words[a + 7];
2021
+ const y = words[a + 8];
2022
+ const layer = words[a + 9];
2023
+ const width = words[a + 10];
2024
+ const height = words[a + 11];
2025
+ const layers = words[a + 12];
2026
+ const attachment = source.format.attachment;
2027
+ if (source.target === gl.TEXTURE_2D_ARRAY && attachment === gl.COLOR_ATTACHMENT0) {
2028
+ const right = sourceX + width;
2029
+ const top = sourceY + height;
2030
+ const program = this.beginSpareDraws(COPY_PROGRAM, source, source.format, right, top);
2031
+ for (let k = 0; k < layers; k++) {
2032
+ this.drawIntoSpare(program, source, sourceLevel, sourceLayer + k, right, top);
2033
+ this.copyFromSpare(destination, level, x, y, layer + k, sourceX, sourceY, width, height);
2034
+ }
2035
+ this.endSpareDraws(source, source.format);
2036
+ return;
2037
+ }
2038
+ if (!this.copyFramebuffer)
2039
+ this.copyFramebuffer = gl.createFramebuffer();
2040
+ gl.bindFramebuffer(gl.READ_FRAMEBUFFER, this.copyFramebuffer);
2041
+ this.editTexture(UPLOAD_UNIT, destination.target, destination.texture);
2042
+ for (let k = 0; k < layers; k++) {
2043
+ this.attachLevel(gl.READ_FRAMEBUFFER, attachment, source, sourceLevel, sourceLayer + k);
2044
+ if (this.layered(destination.target)) {
2045
+ gl.copyTexSubImage3D(destination.target, level, x, y, layer + k, sourceX, sourceY, width, height);
2046
+ }
2047
+ else {
2048
+ gl.copyTexSubImage2D(this.planeTarget(destination, layer + k), level, x, y, sourceX, sourceY, width, height);
2049
+ }
2050
+ }
2051
+ // A framebuffer that is not bound keeps what it holds alive, so the source leaves it.
2052
+ gl.framebufferTexture2D(gl.READ_FRAMEBUFFER, attachment, gl.TEXTURE_2D, null, 0);
2053
+ }
2054
+ /**
2055
+ * Reads a box of texels of a texture into a buffer with `readPixels`, which GL runs after the
2056
+ * commands recorded before it. The pack row length spaces the rows by the command's bytes per
2057
+ * row, as WebGPU's copy does. The rows are the texture's stored rows, from `y` up.
2058
+ */
2059
+ copyTextureToBuffer(words, a) {
2060
+ const gl = this.gl;
2061
+ const source = this.textureOf(words[a]);
2062
+ const level = words[a + 1];
2063
+ const layer = words[a + 4];
2064
+ const record = this.need(this.buffers, words[a + 5], 'buffer');
2065
+ const { attachment, format, type, bytes } = source.format;
2066
+ if (!this.copyFramebuffer)
2067
+ this.copyFramebuffer = gl.createFramebuffer();
2068
+ gl.bindFramebuffer(gl.READ_FRAMEBUFFER, this.copyFramebuffer);
2069
+ this.attachLevel(gl.READ_FRAMEBUFFER, attachment, source, level, layer);
2070
+ gl.readBuffer(attachment);
2071
+ gl.bindBuffer(gl.PIXEL_PACK_BUFFER, record.buffer);
2072
+ gl.pixelStorei(gl.PACK_ROW_LENGTH, words[a + 7] / bytes);
2073
+ gl.readPixels(words[a + 2], words[a + 3], words[a + 9], words[a + 10], format, type, words[a + 6]);
2074
+ gl.pixelStorei(gl.PACK_ROW_LENGTH, 0);
2075
+ gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);
2076
+ // A framebuffer that is not bound keeps what it holds alive, so the source leaves it.
2077
+ gl.framebufferTexture2D(gl.READ_FRAMEBUFFER, attachment, gl.TEXTURE_2D, null, 0);
2078
+ }
2079
+ /**
2080
+ * Puts a fence after the commands before a `ReadBuffer`, which `flushReads` waits for without
2081
+ * stalling the GPU.
2082
+ */
2083
+ readBuffer(words, a) {
2084
+ const read = this.freeReads.pop() ?? {
2085
+ buffer: 0,
2086
+ offset: 0,
2087
+ size: 0,
2088
+ destination: 0,
2089
+ slot: 0,
2090
+ fence: null,
2091
+ };
2092
+ read.buffer = words[a];
2093
+ read.offset = words[a + 1];
2094
+ read.size = words[a + 2];
2095
+ read.destination = words[a + 3];
2096
+ read.slot = words[a + 4];
2097
+ read.fence = this.gl.fenceSync(this.gl.SYNC_GPU_COMMANDS_COMPLETE, 0);
2098
+ this.pendingReads.push(read);
2099
+ }
2100
+ /**
2101
+ * Finishes the reads whose fences have signalled: the GPU has run the commands before each, so
2102
+ * its bytes copy into engine memory and its control slot rises by one. A read whose fence has
2103
+ * not signalled waits for a later frame, so a read never stalls the GPU.
2104
+ */
2105
+ flushReads() {
2106
+ const reads = this.pendingReads;
2107
+ if (reads.length === 0)
2108
+ return;
2109
+ const gl = this.gl;
2110
+ let kept = 0;
2111
+ for (const read of reads) {
2112
+ const status = read.fence && gl.clientWaitSync(read.fence, 0, 0);
2113
+ if (status !== gl.ALREADY_SIGNALED && status !== gl.CONDITION_SATISFIED) {
2114
+ reads[kept++] = read;
2115
+ continue;
2116
+ }
2117
+ const sink = this.readSink;
2118
+ if (sink) {
2119
+ // WebGL may refuse a view on shared memory, so the bytes come out through a copy.
2120
+ if (this.readBytes.length !== read.size)
2121
+ this.readBytes = new Uint8Array(read.size);
2122
+ const record = this.need(this.buffers, read.buffer, 'buffer');
2123
+ gl.bindBuffer(gl.COPY_READ_BUFFER, record.buffer);
2124
+ gl.getBufferSubData(gl.COPY_READ_BUFFER, read.offset, this.readBytes);
2125
+ gl.bindBuffer(gl.COPY_READ_BUFFER, null);
2126
+ sink.bytes.set(this.readBytes, read.destination);
2127
+ }
2128
+ this.releaseRead(read);
2129
+ sink?.done(read.slot);
2130
+ }
2131
+ reads.length = kept;
2132
+ }
2133
+ /** Deletes a read's fence and keeps the read for later ones. */
2134
+ releaseRead(read) {
2135
+ if (read.fence)
2136
+ this.gl.deleteSync(read.fence);
2137
+ read.fence = null;
2138
+ this.freeReads.push(read);
2139
+ }
2140
+ /** Drops the reads of a buffer that is destroyed: their slots never rise. */
2141
+ dropReads(buffer) {
2142
+ const reads = this.pendingReads;
2143
+ let kept = 0;
2144
+ for (const read of reads) {
2145
+ if (read.buffer === buffer)
2146
+ this.releaseRead(read);
2147
+ else
2148
+ reads[kept++] = read;
2149
+ }
2150
+ reads.length = kept;
2151
+ }
2152
+ createSampler(words, floats, a) {
2153
+ const gl = this.gl;
2154
+ const id = words[a];
2155
+ this.destroySampler(id);
2156
+ const sampler = gl.createSampler();
2157
+ if (!sampler)
2158
+ throw new Error('WebGL2 could not create a sampler');
2159
+ gl.samplerParameteri(sampler, gl.TEXTURE_WRAP_S, this.addressMode(words[a + 1]));
2160
+ gl.samplerParameteri(sampler, gl.TEXTURE_WRAP_T, this.addressMode(words[a + 2]));
2161
+ gl.samplerParameteri(sampler, gl.TEXTURE_WRAP_R, this.addressMode(words[a + 3]));
2162
+ const magnify = words[a + 4] === G.FILTER_LINEAR ? gl.LINEAR : gl.NEAREST;
2163
+ const minify = this.minFilters[words[a + 5]]?.[words[a + 6]];
2164
+ if (minify === undefined)
2165
+ throw new Error('unknown sampler filter');
2166
+ gl.samplerParameteri(sampler, gl.TEXTURE_MAG_FILTER, magnify);
2167
+ gl.samplerParameteri(sampler, gl.TEXTURE_MIN_FILTER, minify);
2168
+ gl.samplerParameterf(sampler, gl.TEXTURE_MIN_LOD, floats[a + 7]);
2169
+ gl.samplerParameterf(sampler, gl.TEXTURE_MAX_LOD, floats[a + 8]);
2170
+ const compare = words[a + 9];
2171
+ if (compare !== G.COMPARE_NONE) {
2172
+ gl.samplerParameteri(sampler, gl.TEXTURE_COMPARE_MODE, gl.COMPARE_REF_TO_TEXTURE);
2173
+ // WebGL's compare functions run from NEVER to ALWAYS in the draw list's order. Standard
2174
+ // depth stores one minus WebGPU's depth, which the shaders' reference values do not
2175
+ // match, so every comparison passes there: shadows then light every surface.
2176
+ const func = this.depth.standard ? gl.ALWAYS : gl.NEVER + compare - G.COMPARE_NEVER;
2177
+ gl.samplerParameteri(sampler, gl.TEXTURE_COMPARE_FUNC, func);
2178
+ }
2179
+ const anisotropy = words[a + 10];
2180
+ // Without the extension, a sampler filters as well as the device can, without anisotropy.
2181
+ if (anisotropy > 1 && this.anisotropic)
2182
+ gl.samplerParameterf(sampler, this.anisotropic.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(anisotropy, this.maxAnisotropy));
2183
+ this.samplers[id] = sampler;
2184
+ }
2185
+ addressMode(code) {
2186
+ const mode = this.addressModes[code];
2187
+ if (mode === undefined)
2188
+ throw new Error(`unknown sampler address mode ${code}`);
2189
+ return mode;
2190
+ }
2191
+ destroySampler(id) {
2192
+ const old = this.samplers[id];
2193
+ if (!old)
2194
+ return;
2195
+ // Deleting a sampler unbinds it from every unit.
2196
+ this.gl.deleteSampler(old);
2197
+ this.samplers[id] = undefined;
2198
+ for (let slot = 0; slot < this.slotSamplers.length; slot++)
2199
+ if (this.slotSamplers[slot] === old)
2200
+ this.slotSamplers[slot] = null;
2201
+ for (let unit = 0; unit < this.unitSamplers.length; unit++)
2202
+ if (this.unitSamplers[unit] === old)
2203
+ this.unitSamplers[unit] = null;
2204
+ this.unitsChanged = true;
2205
+ }
2206
+ /** Attaches a render target to the bound framebuffer. */
2207
+ attach(target) {
2208
+ const gl = this.gl;
2209
+ const point = target.format.attachment;
2210
+ if (target.renderbuffer)
2211
+ gl.framebufferRenderbuffer(gl.FRAMEBUFFER, point, gl.RENDERBUFFER, target.renderbuffer);
2212
+ else
2213
+ this.attachLevel(gl.FRAMEBUFFER, point, target, target.level, target.layer);
2214
+ }
2215
+ /**
2216
+ * Makes a framebuffer with `first` in it, and `depth` when given. A `second` color target goes
2217
+ * into the second color attachment, and the framebuffer then draws into both. It leaves the
2218
+ * framebuffer bound.
2219
+ */
2220
+ makeFramebuffer(first, depth, second = null) {
2221
+ const gl = this.gl;
2222
+ const framebuffer = gl.createFramebuffer();
2223
+ if (!framebuffer)
2224
+ throw new Error('WebGL2 could not create a framebuffer');
2225
+ gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
2226
+ this.attach(first);
2227
+ if (depth)
2228
+ this.attach(depth);
2229
+ if (second) {
2230
+ this.attachLevel(gl.FRAMEBUFFER, COLOR_ATTACHMENT1, second, second.level, second.layer);
2231
+ gl.drawBuffers(TWO_DRAW_BUFFERS);
2232
+ }
2233
+ const status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
2234
+ if (status !== gl.FRAMEBUFFER_COMPLETE) {
2235
+ gl.deleteFramebuffer(framebuffer);
2236
+ const target = describeFramebuffer(first, depth, second);
2237
+ const text = `${target} (status 0x${status.toString(16)})`;
2238
+ // A driver can answer a lost context's check with this status before the loss flag is
2239
+ // set. The renderer drops a frame error while the context is lost, and its recovery
2240
+ // then starts.
2241
+ if (gl.isContextLost())
2242
+ throw new Error(`WebGL2 lost its context inside a framebuffer check: ${text}`);
2243
+ throw new WebGL2TargetRefused(`WebGL2 cannot draw into ${text}`);
2244
+ }
2245
+ return framebuffer;
2246
+ }
2247
+ /**
2248
+ * The framebuffer of passes that draw into `color`, with `depth` when given. A target that the
2249
+ * render graph shares between a pass with depth and one without, as the scene color and a
2250
+ * custom effect's target, keeps a framebuffer for each, so no frame makes one again: each new
2251
+ * framebuffer's completeness check waits for the browser's GPU process, about 1.5 ms on a
2252
+ * Pixel 10. A framebuffer is made again when its depth target changes.
2253
+ */
2254
+ colorFramebuffer(color, depth) {
2255
+ if (!depth)
2256
+ return this.soloFramebuffer(color);
2257
+ if (color.framebuffer && color.framebufferDepth === depth)
2258
+ return color.framebuffer;
2259
+ if (color.framebuffer)
2260
+ this.gl.deleteFramebuffer(color.framebuffer);
2261
+ color.framebuffer = this.makeFramebuffer(color, depth);
2262
+ color.framebufferDepth = depth;
2263
+ if (depth)
2264
+ this.joined.add(color);
2265
+ return color.framebuffer;
2266
+ }
2267
+ /**
2268
+ * The framebuffer of a pass that draws into `color` and `second`, with `depth` when given, as
2269
+ * the weighted layer's pass draws into its two sums. It is made again when a target changes.
2270
+ */
2271
+ pairFramebuffer(color, second, depth) {
2272
+ if (color.pairFramebuffer && color.pairSecond === second && color.pairDepth === depth)
2273
+ return color.pairFramebuffer;
2274
+ this.forgetPair(color);
2275
+ color.pairFramebuffer = this.makeFramebuffer(color, depth, second);
2276
+ color.pairSecond = second;
2277
+ color.pairDepth = depth;
2278
+ this.joined.add(color);
2279
+ return color.pairFramebuffer;
2280
+ }
2281
+ /**
2282
+ * The framebuffer with only `target` in it. A depth target draws with no draw buffer, so the
2283
+ * pass never names a color that it does not write. Safari's WebGL2 path costs time for a color
2284
+ * that a pass binds and invalidates without writing it, and that time follows the target's
2285
+ * size (WebKit bug 328158).
2286
+ */
2287
+ soloFramebuffer(target) {
2288
+ if (!target.soloFramebuffer) {
2289
+ const framebuffer = this.makeFramebuffer(target, null);
2290
+ if (target.format.attachment === this.gl.DEPTH_ATTACHMENT)
2291
+ this.gl.drawBuffers(NO_DRAW_BUFFERS);
2292
+ target.soloFramebuffer = framebuffer;
2293
+ }
2294
+ return target.soloFramebuffer;
2295
+ }
2296
+ beginPass(words, floats, a, length) {
2297
+ const gl = this.gl;
2298
+ this.skipDraws = false;
2299
+ const color = words[a];
2300
+ const depth = words[a + 2];
2301
+ // The weighted layer's pass names a second color target after the flags, before the label
2302
+ // and the scope. A pass without one leaves its word out, so the command is shorter.
2303
+ const second = length > 12 ? words[a + 9] : G.NO_TARGET;
2304
+ const flags = words[a + 8];
2305
+ this.passResolve = words[a + 1];
2306
+ this.passFlags = flags;
2307
+ this.passToCanvas = color === 0;
2308
+ this.passColor = null;
2309
+ const depthTarget = depth === G.NO_TARGET ? null : this.need(this.textures, depth, 'texture');
2310
+ this.passDepth = depthTarget;
2311
+ let framebuffer;
2312
+ if (color === 0) {
2313
+ if (depthTarget)
2314
+ throw new Error('WebGL2 cannot draw into the canvas with a depth target');
2315
+ framebuffer = this.canvasTarget?.framebuffer ?? null;
2316
+ this.passWidth = this.canvasTarget?.width ?? this.canvas.width;
2317
+ this.passHeight = this.canvasTarget?.height ?? this.canvas.height;
2318
+ }
2319
+ else if (color === G.NO_TARGET) {
2320
+ if (!depthTarget)
2321
+ throw new Error('a render pass needs a color target or a depth target');
2322
+ framebuffer = this.soloFramebuffer(depthTarget);
2323
+ this.passWidth = depthTarget.width;
2324
+ this.passHeight = depthTarget.height;
2325
+ }
2326
+ else {
2327
+ const target = this.need(this.textures, color, 'texture');
2328
+ this.passColor = target;
2329
+ framebuffer =
2330
+ second === G.NO_TARGET
2331
+ ? this.colorFramebuffer(target, depthTarget)
2332
+ : this.pairFramebuffer(target, this.need(this.textures, second, 'texture'), depthTarget);
2333
+ this.passWidth = target.width;
2334
+ this.passHeight = target.height;
2335
+ }
2336
+ gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
2337
+ this.passFramebuffer = framebuffer;
2338
+ // Each pass starts with its whole target, and with no vertex or index buffer, as on WebGPU.
2339
+ this.setViewport(0, 0, this.passWidth, this.passHeight);
2340
+ this.setDepthRange(0, 1);
2341
+ this.setScissorTest(false);
2342
+ this.vertexBuffer = 0;
2343
+ this.indexBuffer = 0;
2344
+ let clear = 0;
2345
+ if (flags & G.PASS_CLEAR_COLOR && color !== G.NO_TARGET) {
2346
+ this.setColorMask(true);
2347
+ const clearColor = this.clearColor;
2348
+ if (clearColor[0] !== floats[a + 3] ||
2349
+ clearColor[1] !== floats[a + 4] ||
2350
+ clearColor[2] !== floats[a + 5] ||
2351
+ clearColor[3] !== floats[a + 6]) {
2352
+ for (let k = 0; k < 4; k++)
2353
+ clearColor[k] = floats[a + 3 + k];
2354
+ gl.clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
2355
+ }
2356
+ clear |= gl.COLOR_BUFFER_BIT;
2357
+ }
2358
+ if (flags & G.PASS_CLEAR_DEPTH && depthTarget) {
2359
+ if (!this.depthMask) {
2360
+ gl.depthMask(true);
2361
+ this.depthMask = true;
2362
+ }
2363
+ if (this.clearDepth !== floats[a + 7]) {
2364
+ this.clearDepth = floats[a + 7];
2365
+ gl.clearDepth(this.depth.standard ? 1 - this.clearDepth : this.clearDepth);
2366
+ }
2367
+ clear |= gl.DEPTH_BUFFER_BIT;
2368
+ }
2369
+ if (clear)
2370
+ gl.clear(clear);
2371
+ }
2372
+ endPass() {
2373
+ const gl = this.gl;
2374
+ // A resolve covers the whole target, as on WebGPU, but GL's scissor would limit it.
2375
+ this.setScissorTest(false);
2376
+ if (this.passToCanvas)
2377
+ return;
2378
+ const framebuffer = this.passFramebuffer;
2379
+ // Tile-based GPUs skip writing a target that the pass discards back to memory. A discard
2380
+ // comes while the pass's framebuffer is still the one drawn into, as ANGLE on Metal ends the
2381
+ // pass, with its stores, at a resolve's blit, which it draws as a pass of its own. The blit
2382
+ // reads the color, so a pass that resolves discards its color after the blit.
2383
+ const storeColor = (this.passFlags & G.PASS_STORE_COLOR) !== 0;
2384
+ const storeDepth = (this.passFlags & G.PASS_STORE_DEPTH) !== 0;
2385
+ const resolves = this.passResolve !== G.NO_TARGET;
2386
+ const keepsColor = storeColor || resolves;
2387
+ // Invalidate only the attachments the pass has. GL ignores one it lacks, but a color-only
2388
+ // pass, as each fullscreen step of an effect, need not name a depth it never bound: Safari
2389
+ // runs the invalidate on the thread that draws before it draws the pass. The lists are made
2390
+ // once, because this runs for every pass of every frame.
2391
+ const discardColor = this.passColor !== null && !keepsColor;
2392
+ const discardDepth = this.passDepth !== null && !storeDepth;
2393
+ if (discardColor && discardDepth)
2394
+ gl.invalidateFramebuffer(gl.DRAW_FRAMEBUFFER, DISCARD_BOTH);
2395
+ else if (discardColor)
2396
+ gl.invalidateFramebuffer(gl.DRAW_FRAMEBUFFER, DISCARD_COLOR);
2397
+ else if (discardDepth)
2398
+ gl.invalidateFramebuffer(gl.DRAW_FRAMEBUFFER, DISCARD_DEPTH);
2399
+ if (resolves) {
2400
+ const into = this.passResolve === 0
2401
+ ? (this.canvasTarget?.framebuffer ?? null)
2402
+ : this.soloFramebuffer(this.need(this.textures, this.passResolve, 'texture'));
2403
+ gl.bindFramebuffer(gl.READ_FRAMEBUFFER, framebuffer);
2404
+ gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, into);
2405
+ this.setColorMask(true);
2406
+ const width = this.passWidth;
2407
+ const height = this.passHeight;
2408
+ gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, gl.COLOR_BUFFER_BIT, gl.NEAREST);
2409
+ }
2410
+ const depth = this.passDepth;
2411
+ if (storeDepth && depth?.renderbuffer && depth.texture)
2412
+ this.copyDepth(framebuffer, depth);
2413
+ if (resolves && !storeColor) {
2414
+ gl.bindFramebuffer(gl.READ_FRAMEBUFFER, framebuffer);
2415
+ gl.invalidateFramebuffer(gl.READ_FRAMEBUFFER, DISCARD_COLOR);
2416
+ }
2417
+ }
2418
+ /**
2419
+ * Copies one sample of each pixel of a multisampled depth target into the texture that shaders
2420
+ * read in its place. GL copies a multisampled depth through a blit, of the whole target.
2421
+ */
2422
+ copyDepth(framebuffer, depth) {
2423
+ const gl = this.gl;
2424
+ if (!depth.copyFramebuffer) {
2425
+ const copy = gl.createFramebuffer();
2426
+ if (!copy)
2427
+ throw new Error('WebGL2 could not create a framebuffer');
2428
+ gl.bindFramebuffer(gl.FRAMEBUFFER, copy);
2429
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, depth.texture, 0);
2430
+ depth.copyFramebuffer = copy;
2431
+ }
2432
+ gl.bindFramebuffer(gl.READ_FRAMEBUFFER, framebuffer);
2433
+ gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, depth.copyFramebuffer);
2434
+ if (!this.depthMask) {
2435
+ gl.depthMask(true);
2436
+ this.depthMask = true;
2437
+ }
2438
+ const { width, height } = depth;
2439
+ gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, gl.DEPTH_BUFFER_BIT, gl.NEAREST);
2440
+ }
2441
+ /** Sets the viewport from a rectangle given from the target's top, as GL counts from its bottom. */
2442
+ setViewport(x, y, width, height) {
2443
+ this.setGlViewport(x, this.passHeight - y - height, width, height);
2444
+ }
2445
+ /** Sets GL's viewport, a rectangle counted from the target's bottom. */
2446
+ setGlViewport(x, bottom, width, height) {
2447
+ const viewport = this.viewport;
2448
+ if (viewport[0] === x &&
2449
+ viewport[1] === bottom &&
2450
+ viewport[2] === width &&
2451
+ viewport[3] === height)
2452
+ return;
2453
+ this.gl.viewport(x, bottom, width, height);
2454
+ viewport[0] = x;
2455
+ viewport[1] = bottom;
2456
+ viewport[2] = width;
2457
+ viewport[3] = height;
2458
+ }
2459
+ setDepthRange(near, far) {
2460
+ if (this.depthNear === near && this.depthFar === far)
2461
+ return;
2462
+ if (this.depth.standard)
2463
+ this.gl.depthRange(1 - far, 1 - near);
2464
+ else
2465
+ this.gl.depthRange(near, far);
2466
+ this.depthNear = near;
2467
+ this.depthFar = far;
2468
+ }
2469
+ /** The faces that a pipeline's state flags cull: GL's `BACK` or `FRONT`, or 0 for none. */
2470
+ cullOf(flags) {
2471
+ if (flags & G.STATE_CULL_NONE)
2472
+ return 0;
2473
+ return flags & G.STATE_CULL_FRONT ? this.gl.FRONT : this.gl.BACK;
2474
+ }
2475
+ /** Culls `face`, GL's `BACK` or `FRONT`, or nothing for 0. */
2476
+ setCullFace(face) {
2477
+ const gl = this.gl;
2478
+ const was = this.cullFace;
2479
+ if (was === face)
2480
+ return;
2481
+ if (face === 0)
2482
+ gl.disable(gl.CULL_FACE);
2483
+ else {
2484
+ if (was === 0)
2485
+ gl.enable(gl.CULL_FACE);
2486
+ if (face !== this.cullMode) {
2487
+ gl.cullFace(face);
2488
+ this.cullMode = face;
2489
+ }
2490
+ }
2491
+ this.cullFace = face;
2492
+ }
2493
+ setDepthTest(on) {
2494
+ if (this.depthTest === on)
2495
+ return;
2496
+ if (on)
2497
+ this.gl.enable(this.gl.DEPTH_TEST);
2498
+ else
2499
+ this.gl.disable(this.gl.DEPTH_TEST);
2500
+ this.depthTest = on;
2501
+ }
2502
+ setScissorTest(on) {
2503
+ if (this.scissorTest === on)
2504
+ return;
2505
+ if (on)
2506
+ this.gl.enable(this.gl.SCISSOR_TEST);
2507
+ else
2508
+ this.gl.disable(this.gl.SCISSOR_TEST);
2509
+ this.scissorTest = on;
2510
+ }
2511
+ /** Sets the scissor from a rectangle given from the target's top, as GL counts from its bottom. */
2512
+ setScissor(x, y, width, height) {
2513
+ this.setScissorTest(true);
2514
+ const bottom = this.passHeight - y - height;
2515
+ const scissor = this.scissor;
2516
+ if (scissor[0] === x && scissor[1] === bottom && scissor[2] === width && scissor[3] === height)
2517
+ return;
2518
+ this.gl.scissor(x, bottom, width, height);
2519
+ scissor[0] = x;
2520
+ scissor[1] = bottom;
2521
+ scissor[2] = width;
2522
+ scissor[3] = height;
2523
+ }
2524
+ setPipeline(p) {
2525
+ const program = p.program;
2526
+ this.skipDraws =
2527
+ program.joined?.failed === true ||
2528
+ program.objects?.refused === true ||
2529
+ !this.compiled(program);
2530
+ if (this.skipDraws)
2531
+ return;
2532
+ if (program.joined) {
2533
+ try {
2534
+ this.useProgram(program);
2535
+ }
2536
+ catch (error) {
2537
+ this.joinFailed(program, error instanceof Error ? error.message : String(error));
2538
+ this.skipDraws = true;
2539
+ return;
2540
+ }
2541
+ }
2542
+ else if (program.objects) {
2543
+ if (!this.useObjectsProgram(program)) {
2544
+ this.skipDraws = true;
2545
+ return;
2546
+ }
2547
+ }
2548
+ else
2549
+ this.useProgram(program);
2550
+ if (this.current?.program !== program && program.textureUnits.length > 0)
2551
+ this.unitsChanged = true;
2552
+ this.current = p;
2553
+ this.setCullFace(p.cull);
2554
+ this.setDepthTest(p.depth);
2555
+ if (p.depthWrite !== this.depthMask) {
2556
+ this.gl.depthMask(p.depthWrite);
2557
+ this.depthMask = p.depthWrite;
2558
+ }
2559
+ if (p.depthFunc !== this.depthFunc) {
2560
+ this.gl.depthFunc(p.depthFunc);
2561
+ this.depthFunc = p.depthFunc;
2562
+ }
2563
+ this.setColorMask(p.colorWrite);
2564
+ this.setPolygonOffset(p.offsetFactor, p.offsetUnits);
2565
+ if (p.blend !== this.blend)
2566
+ this.setBlend(p.blend);
2567
+ this.setAlphaToCoverage(p.alphaToCoverage);
2568
+ }
2569
+ /** GL's depth function that passes nearer surfaces in the backend's depth mode. */
2570
+ nearerPasses() {
2571
+ return this.depth.standard ? this.gl.LESS : this.gl.GREATER;
2572
+ }
2573
+ /**
2574
+ * GL's depth function of a pipeline's state flags. A pipeline without the depth test still
2575
+ * keeps GL's test on, with a function that passes every fragment: GL writes no depth while its
2576
+ * test is off, and the pipeline writes none either way. After the depth prepass, the opaque
2577
+ * pass draws only at the depth that the prepass found, in every depth mode. A background at the
2578
+ * far plane draws where the target still holds the far plane.
2579
+ */
2580
+ depthFuncOf(flags) {
2581
+ const gl = this.gl;
2582
+ if (flags & G.STATE_NO_DEPTH_TEST)
2583
+ return gl.ALWAYS;
2584
+ if (flags & G.STATE_DEPTH_OR_EQUAL)
2585
+ return this.depth.standard ? gl.LEQUAL : gl.GEQUAL;
2586
+ return flags & G.STATE_DEPTH_EQUAL ? gl.EQUAL : this.nearerPasses();
2587
+ }
2588
+ /** Lets draws write color, or keeps the color targets as they are. */
2589
+ setColorMask(on) {
2590
+ if (on === this.colorMask)
2591
+ return;
2592
+ this.gl.colorMask(on, on, on, on);
2593
+ this.colorMask = on;
2594
+ }
2595
+ /**
2596
+ * Sets GL's blending for a blend mode, whose fragments write color premultiplied by alpha, as
2597
+ * the WebGPU backend's blend states do.
2598
+ */
2599
+ setBlend(mode) {
2600
+ const gl = this.gl;
2601
+ if (!mode)
2602
+ gl.disable(gl.BLEND);
2603
+ else {
2604
+ if (!this.blend)
2605
+ gl.enable(gl.BLEND);
2606
+ if (mode === G.STATE_BLEND_ADDITIVE)
2607
+ gl.blendFunc(gl.ONE, gl.ONE);
2608
+ else if (mode === G.STATE_BLEND_MULTIPLY)
2609
+ gl.blendFuncSeparate(gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA, gl.ZERO, gl.ONE);
2610
+ else
2611
+ gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
2612
+ }
2613
+ this.blend = mode;
2614
+ }
2615
+ /** Turns GL's alpha to coverage on or off, which only multisampled targets heed. */
2616
+ setAlphaToCoverage(on) {
2617
+ if (on === this.alphaToCoverage)
2618
+ return;
2619
+ if (on)
2620
+ this.gl.enable(this.gl.SAMPLE_ALPHA_TO_COVERAGE);
2621
+ else
2622
+ this.gl.disable(this.gl.SAMPLE_ALPHA_TO_COVERAGE);
2623
+ this.alphaToCoverage = on;
2624
+ }
2625
+ /** Sets GL's polygon offset, switched on only while it moves depth. */
2626
+ setPolygonOffset(factor, units) {
2627
+ if (this.offsetFactor === factor && this.offsetUnits === units)
2628
+ return;
2629
+ const gl = this.gl;
2630
+ const on = factor !== 0 || units !== 0;
2631
+ if (on !== (this.offsetFactor !== 0 || this.offsetUnits !== 0)) {
2632
+ if (on)
2633
+ gl.enable(gl.POLYGON_OFFSET_FILL);
2634
+ else
2635
+ gl.disable(gl.POLYGON_OFFSET_FILL);
2636
+ }
2637
+ if (on)
2638
+ gl.polygonOffset(factor, units);
2639
+ this.offsetFactor = factor;
2640
+ this.offsetUnits = units;
2641
+ }
2642
+ setBindGroup(words, a) {
2643
+ const gl = this.gl;
2644
+ const group = words[a];
2645
+ const entries = this.need(this.bindGroups, words[a + 1], 'bind group');
2646
+ const offsets = words[a + 2];
2647
+ // The group's dynamic offsets apply to its buffer entries, in order.
2648
+ let dynamic = 0;
2649
+ for (let k = 0; k < entries.length; k++) {
2650
+ const entry = entries[k];
2651
+ const slot = slotOf(group, entry.binding);
2652
+ if (entry.kind === G.RESOURCE_BUFFER) {
2653
+ const buffer = this.need(this.buffers, entry.resource, 'buffer');
2654
+ const offset = entry.offset + (dynamic < offsets ? words[a + 3 + dynamic] : 0);
2655
+ dynamic++;
2656
+ const size = entry.size || buffer.size - offset;
2657
+ if (this.blockBuffers[slot] !== buffer ||
2658
+ this.blockOffsets[slot] !== offset ||
2659
+ this.blockSizes[slot] !== size) {
2660
+ gl.bindBufferRange(gl.UNIFORM_BUFFER, slot, buffer.buffer, offset, size);
2661
+ this.blockBuffers[slot] = buffer;
2662
+ this.blockOffsets[slot] = offset;
2663
+ this.blockSizes[slot] = size;
2664
+ // A program that reads the slot as a texture reads a copy of the range.
2665
+ this.slotTextures[slot] = null;
2666
+ this.unitsChanged = true;
2667
+ }
2668
+ }
2669
+ else if (entry.kind === G.RESOURCE_TEXTURE) {
2670
+ const texture = this.boundTextureOf(entry.resource);
2671
+ if (this.slotTextures[slot] !== texture.texture) {
2672
+ this.slotTextures[slot] = texture.texture;
2673
+ this.slotTargets[slot] = texture.target;
2674
+ this.unitsChanged = true;
2675
+ }
2676
+ // The slot's texture replaces a buffer range that a program read through a copy, so
2677
+ // the range binds again when a bind group next leaves it there.
2678
+ this.blockBuffers[slot] = undefined;
2679
+ }
2680
+ else if (entry.kind === G.RESOURCE_SAMPLER) {
2681
+ const sampler = this.need(this.samplers, entry.resource, 'sampler');
2682
+ if (this.slotSamplers[slot] !== sampler) {
2683
+ this.slotSamplers[slot] = sampler;
2684
+ this.unitsChanged = true;
2685
+ }
2686
+ }
2687
+ }
2688
+ }
2689
+ /**
2690
+ * The vertex array of a draw without indices: the current vertex buffer in the layout of the
2691
+ * pipeline's template, or none where the template's vertex shader makes its vertices. Such a
2692
+ * draw ignores a vertex buffer that earlier draws of the pass bound, as WebGPU does: the
2693
+ * background draws after the depth prepass's meshes in one pass.
2694
+ */
2695
+ drawVertexArray() {
2696
+ const layout = this.current?.vertices;
2697
+ return layout ? this.layoutVertexArray(layout) : this.emptyVertexArray();
2698
+ }
2699
+ /** The vertex array of the current vertex buffer in a template's own layout. */
2700
+ layoutVertexArray(layout) {
2701
+ const vertices = this.need(this.buffers, this.vertexBuffer, 'buffer').buffer;
2702
+ const cached = this.layoutArrays[this.vertexBuffer];
2703
+ if (cached && cached.vertices === vertices && cached.layout === layout)
2704
+ return cached.vao;
2705
+ if (cached)
2706
+ this.gl.deleteVertexArray(cached.vao);
2707
+ return this.createLayoutVertexArray(vertices, layout);
2708
+ }
2709
+ /**
2710
+ * Makes the vertex array of the current vertex buffer in a template's layout. It runs only when
2711
+ * the buffer or the layout change.
2712
+ */
2713
+ createLayoutVertexArray(vertices, layout) {
2714
+ const gl = this.gl;
2715
+ const vao = gl.createVertexArray();
2716
+ if (!vao)
2717
+ throw new Error('WebGL2 could not create a vertex array');
2718
+ this.useVertexArray(vao);
2719
+ gl.bindBuffer(gl.ARRAY_BUFFER, vertices);
2720
+ // An attribute of the instance's step moves on once for each instance. Integer formats
2721
+ // reach the shader as integers.
2722
+ const divisor = layout.stepMode === 'instance' ? 1 : 0;
2723
+ for (const attribute of layout.attributes) {
2724
+ const [size, type, normalized] = glAttribute(gl, attribute.format);
2725
+ const location = attribute.shaderLocation;
2726
+ gl.enableVertexAttribArray(location);
2727
+ if (attribute.format.startsWith('uint') || attribute.format.startsWith('sint'))
2728
+ gl.vertexAttribIPointer(location, size, type, layout.arrayStride, attribute.offset);
2729
+ else
2730
+ gl.vertexAttribPointer(location, size, type, normalized, layout.arrayStride, attribute.offset);
2731
+ gl.vertexAttribDivisor(location, divisor);
2732
+ }
2733
+ this.layoutArrays[this.vertexBuffer] = { vao, vertices, layout };
2734
+ return vao;
2735
+ }
2736
+ /**
2737
+ * A vertex array with no attributes, for draws that read no vertex buffer: their vertex shaders
2738
+ * make vertices.
2739
+ */
2740
+ emptyVertexArray() {
2741
+ if (!this.shaderVertices) {
2742
+ this.shaderVertices = this.gl.createVertexArray();
2743
+ if (!this.shaderVertices)
2744
+ throw new Error('WebGL2 could not create a vertex array');
2745
+ }
2746
+ return this.shaderVertices;
2747
+ }
2748
+ /**
2749
+ * Binds the vertex array of the current vertex and index buffers, which holds every attribute
2750
+ * of the current pipeline's vertex format. A program reads the attributes it declares, and any
2751
+ * other location reads GL's constant default.
2752
+ */
2753
+ useMeshVertexArray() {
2754
+ const gl = this.gl;
2755
+ const p = this.current;
2756
+ if (!p)
2757
+ throw new Error('draw list draws before it sets a pipeline');
2758
+ const format = p.vertexFormat;
2759
+ const vertices = this.need(this.buffers, this.vertexBuffer, 'buffer').buffer;
2760
+ const indices = this.need(this.buffers, this.indexBuffer, 'buffer').buffer;
2761
+ const cached = this.vertexArrays[this.vertexBuffer];
2762
+ if (cached &&
2763
+ cached.vertices === vertices &&
2764
+ cached.indices === indices &&
2765
+ cached.format === format) {
2766
+ this.useVertexArray(cached.vao);
2767
+ return;
2768
+ }
2769
+ if (cached)
2770
+ gl.deleteVertexArray(cached.vao);
2771
+ this.createMeshVertexArray(vertices, indices, format);
2772
+ }
2773
+ /**
2774
+ * Makes and binds the vertex array of the current vertex buffer. It runs only when the buffers
2775
+ * or the format change, and keeps its closure out of the function that every draw calls.
2776
+ */
2777
+ createMeshVertexArray(vertices, indices, format) {
2778
+ const gl = this.gl;
2779
+ const vao = gl.createVertexArray();
2780
+ if (!vao)
2781
+ throw new Error('WebGL2 could not create a vertex array');
2782
+ this.useVertexArray(vao);
2783
+ gl.bindBuffer(gl.ARRAY_BUFFER, vertices);
2784
+ const stride = vertexStride(format);
2785
+ const point = (attribute) => pointAttribute(gl, stride, attribute);
2786
+ forEachVertexAttribute(format, point);
2787
+ forEachFallbackAttribute(format, point);
2788
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indices);
2789
+ this.vertexArrays[this.vertexBuffer] = { vao, vertices, indices, format };
2790
+ }
2791
+ /** Readies the current program for a draw: its first instance, and its units' samplers. */
2792
+ prepareDraw(firstInstance) {
2793
+ const gl = this.gl;
2794
+ const p = this.current?.program;
2795
+ if (!p)
2796
+ throw new Error('draw list draws before it sets a pipeline');
2797
+ if (p.firstInstance && p.firstInstanceValue !== firstInstance) {
2798
+ gl.uniform1ui(p.firstInstance, firstInstance);
2799
+ p.firstInstanceValue = firstInstance;
2800
+ }
2801
+ if (!this.unitsChanged)
2802
+ return;
2803
+ // Each unit that the program reads gets the texture of its slot, and the sampler that its
2804
+ // triple names, or none for texelFetch, which a comparison sampler left on the unit would
2805
+ // break.
2806
+ const units = p.textureUnits;
2807
+ for (let k = 0; k < units.length; k += 3) {
2808
+ const unit = units[k];
2809
+ const slot = units[k + 1];
2810
+ const sampler = units[k + 2];
2811
+ const texture = this.slotTextures[slot];
2812
+ if (texture)
2813
+ this.bindTexture(unit, this.slotTargets[slot], texture);
2814
+ else if (this.blockBuffers[slot])
2815
+ this.bindTexture(unit, this.gl.TEXTURE_2D, this.copyOfBlock(slot));
2816
+ this.bindUnitSampler(unit, sampler < 0 ? null : (this.slotSamplers[sampler] ?? null));
2817
+ }
2818
+ this.unitsChanged = false;
2819
+ }
2820
+ /**
2821
+ * The texture copy of the uniform buffer range that a bind group left at a slot, for a shader
2822
+ * that reads the slot as a texture: one texel of four unsigned integers per 16 bytes, in one
2823
+ * row. The multi-draw vertex shaders read their draw records so, since some Adreno drivers fail
2824
+ * to link a program whose vertex shader reads a uniform array at the draw index. The copy runs on
2825
+ * the GPU, from the buffer, and again only after a write into the buffer.
2826
+ */
2827
+ copyOfBlock(slot) {
2828
+ const gl = this.gl;
2829
+ const buffer = this.blockBuffers[slot];
2830
+ const offset = this.blockOffsets[slot];
2831
+ const width = this.blockSizes[slot] >> 4;
2832
+ buffer.copies ??= [];
2833
+ const copies = buffer.copies;
2834
+ let copy;
2835
+ for (let k = 0; k < copies.length && !copy; k++) {
2836
+ const known = copies[k];
2837
+ if (known.offset === offset && known.width === width)
2838
+ copy = known;
2839
+ }
2840
+ // A copy that no draw has read since the buffer's last write takes the new range, so the
2841
+ // textures stay as many as the ranges that draws read between two writes. Ranges move each
2842
+ // frame with the ring's slots, so the copies are taken over in place, which allocates nothing.
2843
+ for (let k = 0; k < copies.length && !copy; k++) {
2844
+ const stale = copies[k];
2845
+ if (stale.writes !== buffer.writes && stale.width === width) {
2846
+ stale.offset = offset;
2847
+ stale.writes = -1;
2848
+ copy = stale;
2849
+ }
2850
+ }
2851
+ if (!copy) {
2852
+ const texture = gl.createTexture();
2853
+ if (!texture)
2854
+ throw new Error('WebGL2 could not create a texture');
2855
+ this.editTexture(UPLOAD_UNIT, gl.TEXTURE_2D, texture);
2856
+ gl.texStorage2D(gl.TEXTURE_2D, 1, gl.RGBA32UI, width, 1);
2857
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
2858
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
2859
+ this.gpuMemory.addTextures(width * 16);
2860
+ copy = { texture, offset, width, writes: -1 };
2861
+ copies.push(copy);
2862
+ }
2863
+ if (copy.writes !== buffer.writes) {
2864
+ this.editTexture(UPLOAD_UNIT, gl.TEXTURE_2D, copy.texture);
2865
+ gl.bindBuffer(gl.PIXEL_UNPACK_BUFFER, buffer.buffer);
2866
+ gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, width, 1, gl.RGBA_INTEGER, gl.UNSIGNED_INT, offset);
2867
+ gl.bindBuffer(gl.PIXEL_UNPACK_BUFFER, null);
2868
+ copy.writes = buffer.writes;
2869
+ }
2870
+ return copy.texture;
2871
+ }
2872
+ /** Binds a sampler to a texture unit, or none. */
2873
+ bindUnitSampler(unit, sampler) {
2874
+ if ((this.unitSamplers[unit] ?? null) === sampler)
2875
+ return;
2876
+ this.gl.bindSampler(unit, sampler);
2877
+ this.unitSamplers[unit] = sampler;
2878
+ }
2879
+ /**
2880
+ * Draws a run of buckets in one multi-draw call. Safari reads all of an array that a multi-draw
2881
+ * call gets, not just the entries its draws use, so a view on engine memory would cost time in
2882
+ * proportion to the memory: over 200 ms a call at 16 MB. The draws' three lists therefore go
2883
+ * into a small array of their own, which a loop fills without making a view.
2884
+ */
2885
+ multiDrawIndexed(words, a) {
2886
+ const ext = this.multiDraw;
2887
+ if (!ext)
2888
+ throw new Error('this WebGL2 context has no WEBGL_multi_draw');
2889
+ const count = words[a];
2890
+ const ints = this.ints;
2891
+ const counts = words[a + 1] / 4;
2892
+ const offsets = words[a + 2] / 4;
2893
+ const instances = words[a + 3] / 4;
2894
+ this.useMeshVertexArray();
2895
+ this.prepareDraw(0);
2896
+ const mode = this.current.mode;
2897
+ // Even one draw takes the multi-draw call: a plain draw leaves gl_DrawID undefined, and a
2898
+ // build that reads it for its draw record would read another record's data. The call
2899
+ // defines it as the draw's place, 0 for the first.
2900
+ if (this.drawLists.length < 3 * count)
2901
+ this.drawLists = new Int32Array(3 * count);
2902
+ const lists = this.drawLists;
2903
+ let drawn = 0;
2904
+ let triangles = 0;
2905
+ for (let k = 0; k < count; k++) {
2906
+ const instanceCount = ints[instances + k];
2907
+ lists[k] = ints[counts + k];
2908
+ lists[count + k] = ints[offsets + k];
2909
+ lists[2 * count + k] = instanceCount;
2910
+ drawn += instanceCount;
2911
+ triangles += Math.floor(ints[counts + k] / 3) * instanceCount;
2912
+ }
2913
+ this.counts.instances += drawn;
2914
+ if (mode === TRIANGLES)
2915
+ this.counts.triangles += triangles;
2916
+ ext.multiDrawElementsInstancedWEBGL(mode, lists, 0, this.indexType, lists, count, lists, 2 * count, count);
2917
+ this.counts.drawCalls += count;
2918
+ }
2919
+ destroy() {
2920
+ this.early?.stop();
2921
+ this.early = undefined;
2922
+ const gl = this.gl;
2923
+ for (let id = 0; id < this.buffers.length; id++)
2924
+ this.destroyBuffer(id);
2925
+ for (let id = 0; id < this.textures.length; id++)
2926
+ this.destroyTexture(id);
2927
+ for (let id = 0; id < this.samplers.length; id++)
2928
+ this.destroySampler(id);
2929
+ if (this.ownsImages)
2930
+ this.images.clear();
2931
+ for (const p of this.programs.values())
2932
+ gl.deleteProgram(p.program);
2933
+ for (const v of this.vertexArrays)
2934
+ if (v)
2935
+ gl.deleteVertexArray(v.vao);
2936
+ for (const v of this.layoutArrays)
2937
+ if (v)
2938
+ gl.deleteVertexArray(v.vao);
2939
+ if (this.shaderVertices)
2940
+ gl.deleteVertexArray(this.shaderVertices);
2941
+ if (this.copyFramebuffer)
2942
+ gl.deleteFramebuffer(this.copyFramebuffer);
2943
+ for (let slot = 0; slot < UNPACK_RING; slot++) {
2944
+ const buffer = this.unpackBuffers[slot];
2945
+ if (buffer)
2946
+ gl.deleteBuffer(buffer);
2947
+ this.unpackBuffers[slot] = null;
2948
+ this.gpuMemory.addBuffers(-this.unpackSizes[slot]);
2949
+ this.unpackSizes[slot] = 0;
2950
+ }
2951
+ if (this.mipFramebuffer)
2952
+ gl.deleteFramebuffer(this.mipFramebuffer);
2953
+ if (this.mipSampler)
2954
+ gl.deleteSampler(this.mipSampler);
2955
+ for (const spare of this.spares.values())
2956
+ this.deleteSpare(spare);
2957
+ this.spares.clear();
2958
+ }
2959
+ /** Deletes a spare texture, and takes its bytes off the memory total. */
2960
+ deleteSpare(spare) {
2961
+ this.gl.deleteTexture(spare.texture);
2962
+ this.gpuMemory.addTextures(-spare.bytes);
2963
+ }
2964
+ }