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