@babylonjs/viewer 7.35.2-alpha → 7.35.2

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 (599) hide show
  1. package/configuration/configuration.d.ts +107 -0
  2. package/configuration/configuration.js +16 -0
  3. package/configuration/configuration.js.map +1 -0
  4. package/configuration/configurationCompatibility.d.ts +8 -0
  5. package/configuration/configurationCompatibility.js +66 -0
  6. package/configuration/configurationCompatibility.js.map +1 -0
  7. package/configuration/configurationContainer.d.ts +10 -0
  8. package/configuration/configurationContainer.js +10 -0
  9. package/configuration/configurationContainer.js.map +1 -0
  10. package/configuration/globals.d.ts +6 -0
  11. package/configuration/globals.js +18 -0
  12. package/configuration/globals.js.map +1 -0
  13. package/configuration/index.d.ts +2 -0
  14. package/configuration/index.js +4 -0
  15. package/configuration/index.js.map +1 -0
  16. package/configuration/interfaces/cameraConfiguration.d.ts +31 -0
  17. package/configuration/interfaces/cameraConfiguration.js +2 -0
  18. package/configuration/interfaces/cameraConfiguration.js.map +1 -0
  19. package/configuration/interfaces/colorGradingConfiguration.d.ts +81 -0
  20. package/configuration/interfaces/colorGradingConfiguration.js +2 -0
  21. package/configuration/interfaces/colorGradingConfiguration.js.map +1 -0
  22. package/configuration/interfaces/defaultRenderingPipelineConfiguration.d.ts +20 -0
  23. package/configuration/interfaces/defaultRenderingPipelineConfiguration.js +2 -0
  24. package/configuration/interfaces/defaultRenderingPipelineConfiguration.js.map +1 -0
  25. package/configuration/interfaces/environmentMapConfiguration.d.ts +22 -0
  26. package/configuration/interfaces/environmentMapConfiguration.js +2 -0
  27. package/configuration/interfaces/environmentMapConfiguration.js.map +1 -0
  28. package/configuration/interfaces/groundConfiguration.d.ts +24 -0
  29. package/configuration/interfaces/groundConfiguration.js +2 -0
  30. package/configuration/interfaces/groundConfiguration.js.map +1 -0
  31. package/configuration/interfaces/imageProcessingConfiguration.d.ts +45 -0
  32. package/configuration/interfaces/imageProcessingConfiguration.js +2 -0
  33. package/configuration/interfaces/imageProcessingConfiguration.js.map +1 -0
  34. package/configuration/interfaces/index.d.ts +15 -0
  35. package/configuration/interfaces/index.js +16 -0
  36. package/configuration/interfaces/index.js.map +1 -0
  37. package/configuration/interfaces/lightConfiguration.d.ts +60 -0
  38. package/configuration/interfaces/lightConfiguration.js +2 -0
  39. package/configuration/interfaces/lightConfiguration.js.map +1 -0
  40. package/configuration/interfaces/modelAnimationConfiguration.d.ts +26 -0
  41. package/configuration/interfaces/modelAnimationConfiguration.js +2 -0
  42. package/configuration/interfaces/modelAnimationConfiguration.js.map +1 -0
  43. package/configuration/interfaces/modelConfiguration.d.ts +65 -0
  44. package/configuration/interfaces/modelConfiguration.js +2 -0
  45. package/configuration/interfaces/modelConfiguration.js.map +1 -0
  46. package/configuration/interfaces/observersConfiguration.d.ts +5 -0
  47. package/configuration/interfaces/observersConfiguration.js +2 -0
  48. package/configuration/interfaces/observersConfiguration.js.map +1 -0
  49. package/configuration/interfaces/sceneConfiguration.d.ts +48 -0
  50. package/configuration/interfaces/sceneConfiguration.js +2 -0
  51. package/configuration/interfaces/sceneConfiguration.js.map +1 -0
  52. package/configuration/interfaces/sceneOptimizerConfiguration.d.ts +23 -0
  53. package/configuration/interfaces/sceneOptimizerConfiguration.js +2 -0
  54. package/configuration/interfaces/sceneOptimizerConfiguration.js.map +1 -0
  55. package/configuration/interfaces/skyboxConfiguration.d.ts +21 -0
  56. package/configuration/interfaces/skyboxConfiguration.js +2 -0
  57. package/configuration/interfaces/skyboxConfiguration.js.map +1 -0
  58. package/configuration/interfaces/templateConfiguration.d.ts +67 -0
  59. package/configuration/interfaces/templateConfiguration.js +2 -0
  60. package/configuration/interfaces/templateConfiguration.js.map +1 -0
  61. package/configuration/interfaces/vrConfiguration.d.ts +16 -0
  62. package/configuration/interfaces/vrConfiguration.js +2 -0
  63. package/configuration/interfaces/vrConfiguration.js.map +1 -0
  64. package/configuration/loader.d.ts +4 -0
  65. package/configuration/loader.js +17 -0
  66. package/configuration/loader.js.map +1 -0
  67. package/configuration/mappers.d.ts +43 -0
  68. package/configuration/mappers.js +193 -0
  69. package/configuration/mappers.js.map +1 -0
  70. package/configuration/renderOnlyLoader.d.ts +33 -0
  71. package/configuration/renderOnlyLoader.js +162 -0
  72. package/configuration/renderOnlyLoader.js.map +1 -0
  73. package/configuration/types/default.d.ts +6 -0
  74. package/configuration/types/default.js +121 -0
  75. package/configuration/types/default.js.map +1 -0
  76. package/configuration/types/environmentMap.d.ts +5 -0
  77. package/configuration/types/environmentMap.js +14 -0
  78. package/configuration/types/environmentMap.js.map +1 -0
  79. package/configuration/types/extended.d.ts +6 -0
  80. package/configuration/types/extended.js +317 -0
  81. package/configuration/types/extended.js.map +1 -0
  82. package/configuration/types/index.d.ts +14 -0
  83. package/configuration/types/index.js +51 -0
  84. package/configuration/types/index.js.map +1 -0
  85. package/configuration/types/minimal.d.ts +6 -0
  86. package/configuration/types/minimal.js +43 -0
  87. package/configuration/types/minimal.js.map +1 -0
  88. package/configuration/types/renderOnlyDefault.d.ts +30 -0
  89. package/configuration/types/renderOnlyDefault.js +31 -0
  90. package/configuration/types/renderOnlyDefault.js.map +1 -0
  91. package/configuration/types/shadowLight.d.ts +9 -0
  92. package/configuration/types/shadowLight.js +64 -0
  93. package/configuration/types/shadowLight.js.map +1 -0
  94. package/helper/index.d.ts +29 -0
  95. package/helper/index.js +66 -0
  96. package/helper/index.js.map +1 -0
  97. package/index.d.ts +30 -0
  98. package/index.js +46 -0
  99. package/index.js.map +1 -0
  100. package/initializer.d.ts +11 -0
  101. package/initializer.js +35 -0
  102. package/initializer.js.map +1 -0
  103. package/interfaces.d.ts +5 -0
  104. package/interfaces.js +7 -0
  105. package/interfaces.js.map +1 -0
  106. package/labs/environmentSerializer.d.ts +126 -0
  107. package/labs/environmentSerializer.js +191 -0
  108. package/labs/environmentSerializer.js.map +1 -0
  109. package/labs/texture.d.ts +183 -0
  110. package/labs/texture.js +351 -0
  111. package/labs/texture.js.map +1 -0
  112. package/labs/viewerLabs.d.ts +51 -0
  113. package/labs/viewerLabs.js +134 -0
  114. package/labs/viewerLabs.js.map +1 -0
  115. package/loader/modelLoader.d.ts +56 -0
  116. package/loader/modelLoader.js +202 -0
  117. package/loader/modelLoader.js.map +1 -0
  118. package/loader/plugins/applyMaterialConfig.d.ts +12 -0
  119. package/loader/plugins/applyMaterialConfig.js +16 -0
  120. package/loader/plugins/applyMaterialConfig.js.map +1 -0
  121. package/loader/plugins/extendedMaterialLoaderPlugin.d.ts +9 -0
  122. package/loader/plugins/extendedMaterialLoaderPlugin.js +16 -0
  123. package/loader/plugins/extendedMaterialLoaderPlugin.js.map +1 -0
  124. package/loader/plugins/index.d.ts +19 -0
  125. package/loader/plugins/index.js +44 -0
  126. package/loader/plugins/index.js.map +1 -0
  127. package/loader/plugins/loaderPlugin.d.ts +24 -0
  128. package/loader/plugins/loaderPlugin.js +2 -0
  129. package/loader/plugins/loaderPlugin.js.map +1 -0
  130. package/loader/plugins/msftLodLoaderPlugin.d.ts +12 -0
  131. package/loader/plugins/msftLodLoaderPlugin.js +21 -0
  132. package/loader/plugins/msftLodLoaderPlugin.js.map +1 -0
  133. package/loader/plugins/telemetryLoaderPlugin.d.ts +12 -0
  134. package/loader/plugins/telemetryLoaderPlugin.js +36 -0
  135. package/loader/plugins/telemetryLoaderPlugin.js.map +1 -0
  136. package/managers/observablesManager.d.ts +66 -0
  137. package/managers/observablesManager.js +35 -0
  138. package/managers/observablesManager.js.map +1 -0
  139. package/managers/sceneManager.d.ts +245 -0
  140. package/managers/sceneManager.js +1375 -0
  141. package/managers/sceneManager.js.map +1 -0
  142. package/managers/telemetryManager.d.ts +78 -0
  143. package/managers/telemetryManager.js +117 -0
  144. package/managers/telemetryManager.js.map +1 -0
  145. package/model/modelAnimation.d.ts +215 -0
  146. package/model/modelAnimation.js +237 -0
  147. package/model/modelAnimation.js.map +1 -0
  148. package/model/viewerModel.d.ts +233 -0
  149. package/model/viewerModel.js +673 -0
  150. package/model/viewerModel.js.map +1 -0
  151. package/optimizer/custom/extended.d.ts +13 -0
  152. package/optimizer/custom/extended.js +101 -0
  153. package/optimizer/custom/extended.js.map +1 -0
  154. package/optimizer/custom/index.d.ts +9 -0
  155. package/optimizer/custom/index.js +26 -0
  156. package/optimizer/custom/index.js.map +1 -0
  157. package/package.json +27 -18
  158. package/readme.md +21 -145
  159. package/renderOnlyIndex.d.ts +11 -0
  160. package/renderOnlyIndex.js +18 -0
  161. package/renderOnlyIndex.js.map +1 -0
  162. package/templating/eventManager.d.ts +35 -0
  163. package/templating/eventManager.js +66 -0
  164. package/templating/eventManager.js.map +1 -0
  165. package/templating/plugins/hdButtonPlugin.d.ts +9 -0
  166. package/templating/plugins/hdButtonPlugin.js +22 -0
  167. package/templating/plugins/hdButtonPlugin.js.map +1 -0
  168. package/templating/plugins/printButton.d.ts +9 -0
  169. package/templating/plugins/printButton.js +41 -0
  170. package/templating/plugins/printButton.js.map +1 -0
  171. package/templating/templateManager.d.ts +197 -0
  172. package/templating/templateManager.js +561 -0
  173. package/templating/templateManager.js.map +1 -0
  174. package/templating/viewerTemplatePlugin.d.ts +21 -0
  175. package/templating/viewerTemplatePlugin.js +69 -0
  176. package/templating/viewerTemplatePlugin.js.map +1 -0
  177. package/viewer/defaultViewer.d.ts +130 -0
  178. package/viewer/defaultViewer.js +672 -0
  179. package/viewer/defaultViewer.js.map +1 -0
  180. package/viewer/renderOnlyViewer.d.ts +9 -0
  181. package/viewer/renderOnlyViewer.js +46 -0
  182. package/viewer/renderOnlyViewer.js.map +1 -0
  183. package/viewer/viewer.d.ts +258 -0
  184. package/viewer/viewer.js +783 -0
  185. package/viewer/viewer.js.map +1 -0
  186. package/viewer/viewerManager.d.ts +58 -0
  187. package/viewer/viewerManager.js +91 -0
  188. package/viewer/viewerManager.js.map +1 -0
  189. package/viewer/viewerWithTemplate.d.ts +9 -0
  190. package/viewer/viewerWithTemplate.js +20 -0
  191. package/viewer/viewerWithTemplate.js.map +1 -0
  192. package/assets/photoStudio.env +0 -0
  193. package/dist/babylon-viewer.esm.js +0 -2
  194. package/dist/babylon-viewer.esm.js.map +0 -1
  195. package/dist/babylon-viewer.esm.min.js +0 -2
  196. package/dist/babylon-viewer.esm.min.js.map +0 -1
  197. package/dist/chunks/EXT_lights_image_based-I6dGStsg.esm.min.js +0 -2
  198. package/dist/chunks/EXT_lights_image_based-I6dGStsg.esm.min.js.map +0 -1
  199. package/dist/chunks/EXT_lights_image_based-gqNsOFez.esm.js +0 -171
  200. package/dist/chunks/EXT_lights_image_based-gqNsOFez.esm.js.map +0 -1
  201. package/dist/chunks/EXT_mesh_gpu_instancing-DFS6xr5n.esm.min.js +0 -2
  202. package/dist/chunks/EXT_mesh_gpu_instancing-DFS6xr5n.esm.min.js.map +0 -1
  203. package/dist/chunks/EXT_mesh_gpu_instancing-lOryCKIX.esm.js +0 -86
  204. package/dist/chunks/EXT_mesh_gpu_instancing-lOryCKIX.esm.js.map +0 -1
  205. package/dist/chunks/EXT_meshopt_compression-BQZ0hBff.esm.js +0 -134
  206. package/dist/chunks/EXT_meshopt_compression-BQZ0hBff.esm.js.map +0 -1
  207. package/dist/chunks/EXT_meshopt_compression-Dv_WoTzw.esm.min.js +0 -2
  208. package/dist/chunks/EXT_meshopt_compression-Dv_WoTzw.esm.min.js.map +0 -1
  209. package/dist/chunks/EXT_texture_avif-BLib9ZsW.esm.js +0 -44
  210. package/dist/chunks/EXT_texture_avif-BLib9ZsW.esm.js.map +0 -1
  211. package/dist/chunks/EXT_texture_avif-BMUg03OA.esm.min.js +0 -2
  212. package/dist/chunks/EXT_texture_avif-BMUg03OA.esm.min.js.map +0 -1
  213. package/dist/chunks/EXT_texture_webp-DPJIMXIs.esm.js +0 -43
  214. package/dist/chunks/EXT_texture_webp-DPJIMXIs.esm.js.map +0 -1
  215. package/dist/chunks/EXT_texture_webp-DPzL7RO5.esm.min.js +0 -2
  216. package/dist/chunks/EXT_texture_webp-DPzL7RO5.esm.min.js.map +0 -1
  217. package/dist/chunks/ExtrasAsMetadata-CL0k4Btm.esm.js +0 -64
  218. package/dist/chunks/ExtrasAsMetadata-CL0k4Btm.esm.js.map +0 -1
  219. package/dist/chunks/ExtrasAsMetadata-O8gteBcK.esm.min.js +0 -2
  220. package/dist/chunks/ExtrasAsMetadata-O8gteBcK.esm.min.js.map +0 -1
  221. package/dist/chunks/KHR_animation_pointer-BFyC08_R.esm.js +0 -343
  222. package/dist/chunks/KHR_animation_pointer-BFyC08_R.esm.js.map +0 -1
  223. package/dist/chunks/KHR_animation_pointer-BZvneRZ7.esm.min.js +0 -2
  224. package/dist/chunks/KHR_animation_pointer-BZvneRZ7.esm.min.js.map +0 -1
  225. package/dist/chunks/KHR_draco_mesh_compression-CjzLflHM.esm.js +0 -610
  226. package/dist/chunks/KHR_draco_mesh_compression-CjzLflHM.esm.js.map +0 -1
  227. package/dist/chunks/KHR_draco_mesh_compression-sHuqiNW-.esm.min.js +0 -2
  228. package/dist/chunks/KHR_draco_mesh_compression-sHuqiNW-.esm.min.js.map +0 -1
  229. package/dist/chunks/KHR_interactivity-CA1NQ9Fc.esm.js +0 -4033
  230. package/dist/chunks/KHR_interactivity-CA1NQ9Fc.esm.js.map +0 -1
  231. package/dist/chunks/KHR_interactivity-CVvexOkD.esm.min.js +0 -2
  232. package/dist/chunks/KHR_interactivity-CVvexOkD.esm.min.js.map +0 -1
  233. package/dist/chunks/KHR_lights_punctual-CIEvgNk7.esm.js +0 -1253
  234. package/dist/chunks/KHR_lights_punctual-CIEvgNk7.esm.js.map +0 -1
  235. package/dist/chunks/KHR_lights_punctual-CTm7ey2n.esm.min.js +0 -2
  236. package/dist/chunks/KHR_lights_punctual-CTm7ey2n.esm.min.js.map +0 -1
  237. package/dist/chunks/KHR_materials_anisotropy-B8l2iZjl.esm.min.js +0 -2
  238. package/dist/chunks/KHR_materials_anisotropy-B8l2iZjl.esm.min.js.map +0 -1
  239. package/dist/chunks/KHR_materials_anisotropy-vnjucfaw.esm.js +0 -65
  240. package/dist/chunks/KHR_materials_anisotropy-vnjucfaw.esm.js.map +0 -1
  241. package/dist/chunks/KHR_materials_clearcoat-BhZGttd-.esm.js +0 -96
  242. package/dist/chunks/KHR_materials_clearcoat-BhZGttd-.esm.js.map +0 -1
  243. package/dist/chunks/KHR_materials_clearcoat-BlhYeFYN.esm.min.js +0 -2
  244. package/dist/chunks/KHR_materials_clearcoat-BlhYeFYN.esm.min.js.map +0 -1
  245. package/dist/chunks/KHR_materials_diffuse_transmission-DJiKAnah.esm.js +0 -97
  246. package/dist/chunks/KHR_materials_diffuse_transmission-DJiKAnah.esm.js.map +0 -1
  247. package/dist/chunks/KHR_materials_diffuse_transmission-DmzdysxQ.esm.min.js +0 -2
  248. package/dist/chunks/KHR_materials_diffuse_transmission-DmzdysxQ.esm.min.js.map +0 -1
  249. package/dist/chunks/KHR_materials_dispersion-B1e8i3BQ.esm.js +0 -62
  250. package/dist/chunks/KHR_materials_dispersion-B1e8i3BQ.esm.js.map +0 -1
  251. package/dist/chunks/KHR_materials_dispersion-B_uhZ_r0.esm.min.js +0 -2
  252. package/dist/chunks/KHR_materials_dispersion-B_uhZ_r0.esm.min.js.map +0 -1
  253. package/dist/chunks/KHR_materials_emissive_strength-Bdc1fhX3.esm.js +0 -55
  254. package/dist/chunks/KHR_materials_emissive_strength-Bdc1fhX3.esm.js.map +0 -1
  255. package/dist/chunks/KHR_materials_emissive_strength-CujgLUsQ.esm.min.js +0 -2
  256. package/dist/chunks/KHR_materials_emissive_strength-CujgLUsQ.esm.min.js.map +0 -1
  257. package/dist/chunks/KHR_materials_ior-DAITk5f0.esm.js +0 -64
  258. package/dist/chunks/KHR_materials_ior-DAITk5f0.esm.js.map +0 -1
  259. package/dist/chunks/KHR_materials_ior-DDjIIueh.esm.min.js +0 -2
  260. package/dist/chunks/KHR_materials_ior-DDjIIueh.esm.min.js.map +0 -1
  261. package/dist/chunks/KHR_materials_iridescence-Bs4XQdUc.esm.js +0 -72
  262. package/dist/chunks/KHR_materials_iridescence-Bs4XQdUc.esm.js.map +0 -1
  263. package/dist/chunks/KHR_materials_iridescence-CofsEJxf.esm.min.js +0 -2
  264. package/dist/chunks/KHR_materials_iridescence-CofsEJxf.esm.min.js.map +0 -1
  265. package/dist/chunks/KHR_materials_pbrSpecularGlossiness-D2cm0Qti.esm.js +0 -81
  266. package/dist/chunks/KHR_materials_pbrSpecularGlossiness-D2cm0Qti.esm.js.map +0 -1
  267. package/dist/chunks/KHR_materials_pbrSpecularGlossiness-Na22WakQ.esm.min.js +0 -2
  268. package/dist/chunks/KHR_materials_pbrSpecularGlossiness-Na22WakQ.esm.min.js.map +0 -1
  269. package/dist/chunks/KHR_materials_sheen-BCY5GSrv.esm.js +0 -85
  270. package/dist/chunks/KHR_materials_sheen-BCY5GSrv.esm.js.map +0 -1
  271. package/dist/chunks/KHR_materials_sheen-BEHiRviB.esm.min.js +0 -2
  272. package/dist/chunks/KHR_materials_sheen-BEHiRviB.esm.min.js.map +0 -1
  273. package/dist/chunks/KHR_materials_specular-BFt2dwLj.esm.js +0 -75
  274. package/dist/chunks/KHR_materials_specular-BFt2dwLj.esm.js.map +0 -1
  275. package/dist/chunks/KHR_materials_specular-BGIPQ1rQ.esm.min.js +0 -2
  276. package/dist/chunks/KHR_materials_specular-BGIPQ1rQ.esm.min.js.map +0 -1
  277. package/dist/chunks/KHR_materials_transmission-BgbdeIB3.esm.js +0 -307
  278. package/dist/chunks/KHR_materials_transmission-BgbdeIB3.esm.js.map +0 -1
  279. package/dist/chunks/KHR_materials_transmission-C-tRBJu4.esm.min.js +0 -2
  280. package/dist/chunks/KHR_materials_transmission-C-tRBJu4.esm.min.js.map +0 -1
  281. package/dist/chunks/KHR_materials_unlit-CcRsVA_x.esm.min.js +0 -2
  282. package/dist/chunks/KHR_materials_unlit-CcRsVA_x.esm.min.js.map +0 -1
  283. package/dist/chunks/KHR_materials_unlit-DNhfBz4E.esm.js +0 -74
  284. package/dist/chunks/KHR_materials_unlit-DNhfBz4E.esm.js.map +0 -1
  285. package/dist/chunks/KHR_materials_variants-77adpgBk.esm.min.js +0 -2
  286. package/dist/chunks/KHR_materials_variants-77adpgBk.esm.min.js.map +0 -1
  287. package/dist/chunks/KHR_materials_variants-CSaSbOzl.esm.js +0 -238
  288. package/dist/chunks/KHR_materials_variants-CSaSbOzl.esm.js.map +0 -1
  289. package/dist/chunks/KHR_materials_volume-AOCoYNKI.esm.min.js +0 -2
  290. package/dist/chunks/KHR_materials_volume-AOCoYNKI.esm.min.js.map +0 -1
  291. package/dist/chunks/KHR_materials_volume-BWHhpmNH.esm.js +0 -87
  292. package/dist/chunks/KHR_materials_volume-BWHhpmNH.esm.js.map +0 -1
  293. package/dist/chunks/KHR_mesh_quantization-BB7EL2M1.esm.min.js +0 -2
  294. package/dist/chunks/KHR_mesh_quantization-BB7EL2M1.esm.min.js.map +0 -1
  295. package/dist/chunks/KHR_mesh_quantization-D2-xHrHe.esm.js +0 -26
  296. package/dist/chunks/KHR_mesh_quantization-D2-xHrHe.esm.js.map +0 -1
  297. package/dist/chunks/KHR_node_visibility-Di8sseTY.esm.min.js +0 -2
  298. package/dist/chunks/KHR_node_visibility-Di8sseTY.esm.min.js.map +0 -1
  299. package/dist/chunks/KHR_node_visibility-qzuskO3u.esm.js +0 -46
  300. package/dist/chunks/KHR_node_visibility-qzuskO3u.esm.js.map +0 -1
  301. package/dist/chunks/KHR_texture_basisu-BUP7AAVF.esm.min.js +0 -2
  302. package/dist/chunks/KHR_texture_basisu-BUP7AAVF.esm.min.js.map +0 -1
  303. package/dist/chunks/KHR_texture_basisu-C60Bt2Ic.esm.js +0 -43
  304. package/dist/chunks/KHR_texture_basisu-C60Bt2Ic.esm.js.map +0 -1
  305. package/dist/chunks/KHR_texture_transform-BUOLLEYP.esm.min.js +0 -2
  306. package/dist/chunks/KHR_texture_transform-BUOLLEYP.esm.min.js.map +0 -1
  307. package/dist/chunks/KHR_texture_transform-Dg-cPDyd.esm.js +0 -63
  308. package/dist/chunks/KHR_texture_transform-Dg-cPDyd.esm.js.map +0 -1
  309. package/dist/chunks/KHR_xmp_json_ld-CsFE0gfF.esm.min.js +0 -2
  310. package/dist/chunks/KHR_xmp_json_ld-CsFE0gfF.esm.min.js.map +0 -1
  311. package/dist/chunks/KHR_xmp_json_ld-DgCKwEEO.esm.js +0 -51
  312. package/dist/chunks/KHR_xmp_json_ld-DgCKwEEO.esm.js.map +0 -1
  313. package/dist/chunks/MSFT_audio_emitter-VHBse1UH.esm.js +0 -2207
  314. package/dist/chunks/MSFT_audio_emitter-VHBse1UH.esm.js.map +0 -1
  315. package/dist/chunks/MSFT_audio_emitter-iFlly5g-.esm.min.js +0 -2
  316. package/dist/chunks/MSFT_audio_emitter-iFlly5g-.esm.min.js.map +0 -1
  317. package/dist/chunks/MSFT_lod-Bwsctx65.esm.js +0 -337
  318. package/dist/chunks/MSFT_lod-Bwsctx65.esm.js.map +0 -1
  319. package/dist/chunks/MSFT_lod-CbiRs9Kc.esm.min.js +0 -2
  320. package/dist/chunks/MSFT_lod-CbiRs9Kc.esm.min.js.map +0 -1
  321. package/dist/chunks/MSFT_minecraftMesh-Dl6WKmxG.esm.min.js +0 -2
  322. package/dist/chunks/MSFT_minecraftMesh-Dl6WKmxG.esm.min.js.map +0 -1
  323. package/dist/chunks/MSFT_minecraftMesh-MBaTkra4.esm.js +0 -46
  324. package/dist/chunks/MSFT_minecraftMesh-MBaTkra4.esm.js.map +0 -1
  325. package/dist/chunks/MSFT_sRGBFactors-DJvNL0IJ.esm.js +0 -47
  326. package/dist/chunks/MSFT_sRGBFactors-DJvNL0IJ.esm.js.map +0 -1
  327. package/dist/chunks/MSFT_sRGBFactors-Drf21tSs.esm.min.js +0 -2
  328. package/dist/chunks/MSFT_sRGBFactors-Drf21tSs.esm.min.js.map +0 -1
  329. package/dist/chunks/animationGroup-CgbfLDgX.esm.min.js +0 -2
  330. package/dist/chunks/animationGroup-CgbfLDgX.esm.min.js.map +0 -1
  331. package/dist/chunks/animationGroup-eowyl97W.esm.js +0 -2482
  332. package/dist/chunks/animationGroup-eowyl97W.esm.js.map +0 -1
  333. package/dist/chunks/assetContainer-Bsqe9swA.esm.min.js +0 -2
  334. package/dist/chunks/assetContainer-Bsqe9swA.esm.min.js.map +0 -1
  335. package/dist/chunks/assetContainer-DO29qm5j.esm.js +0 -1720
  336. package/dist/chunks/assetContainer-DO29qm5j.esm.js.map +0 -1
  337. package/dist/chunks/audioEngine-ByiWmXaG.esm.js +0 -305
  338. package/dist/chunks/audioEngine-ByiWmXaG.esm.js.map +0 -1
  339. package/dist/chunks/audioEngine-Tyl5gl5Y.esm.min.js +0 -2
  340. package/dist/chunks/audioEngine-Tyl5gl5Y.esm.min.js.map +0 -1
  341. package/dist/chunks/bakedVertexAnimation-BxUlezN-.esm.min.js +0 -2
  342. package/dist/chunks/bakedVertexAnimation-BxUlezN-.esm.min.js.map +0 -1
  343. package/dist/chunks/bakedVertexAnimation-Co7tF_AI.esm.js +0 -114
  344. package/dist/chunks/bakedVertexAnimation-Co7tF_AI.esm.js.map +0 -1
  345. package/dist/chunks/basisTextureLoader-C6h2HrT5.esm.min.js +0 -2
  346. package/dist/chunks/basisTextureLoader-C6h2HrT5.esm.min.js.map +0 -1
  347. package/dist/chunks/basisTextureLoader-CFdjlTQv.esm.js +0 -600
  348. package/dist/chunks/basisTextureLoader-CFdjlTQv.esm.js.map +0 -1
  349. package/dist/chunks/dds--AOY6KMC.esm.js +0 -540
  350. package/dist/chunks/dds--AOY6KMC.esm.js.map +0 -1
  351. package/dist/chunks/dds-mtdSIG7y.esm.min.js +0 -2
  352. package/dist/chunks/dds-mtdSIG7y.esm.min.js.map +0 -1
  353. package/dist/chunks/ddsTextureLoader-CS64tfyO.esm.min.js +0 -2
  354. package/dist/chunks/ddsTextureLoader-CS64tfyO.esm.min.js.map +0 -1
  355. package/dist/chunks/ddsTextureLoader-Cm3kvldL.esm.js +0 -88
  356. package/dist/chunks/ddsTextureLoader-Cm3kvldL.esm.js.map +0 -1
  357. package/dist/chunks/decalFragment-B_EoELPt.esm.min.js +0 -2
  358. package/dist/chunks/decalFragment-B_EoELPt.esm.min.js.map +0 -1
  359. package/dist/chunks/decalFragment-CrQo80qe.esm.js +0 -18
  360. package/dist/chunks/decalFragment-CrQo80qe.esm.js.map +0 -1
  361. package/dist/chunks/default.fragment-B7BZK7Wn.esm.js +0 -433
  362. package/dist/chunks/default.fragment-B7BZK7Wn.esm.js.map +0 -1
  363. package/dist/chunks/default.fragment-CDe0T1Vr.esm.min.js +0 -2
  364. package/dist/chunks/default.fragment-CDe0T1Vr.esm.min.js.map +0 -1
  365. package/dist/chunks/default.fragment-DE-fL82A.esm.min.js +0 -2
  366. package/dist/chunks/default.fragment-DE-fL82A.esm.min.js.map +0 -1
  367. package/dist/chunks/default.fragment-OyO2ek5x.esm.js +0 -497
  368. package/dist/chunks/default.fragment-OyO2ek5x.esm.js.map +0 -1
  369. package/dist/chunks/default.vertex-CNUfzDP1.esm.js +0 -181
  370. package/dist/chunks/default.vertex-CNUfzDP1.esm.js.map +0 -1
  371. package/dist/chunks/default.vertex-CfR6AC0W.esm.js +0 -201
  372. package/dist/chunks/default.vertex-CfR6AC0W.esm.js.map +0 -1
  373. package/dist/chunks/default.vertex-CxON4TPV.esm.min.js +0 -2
  374. package/dist/chunks/default.vertex-CxON4TPV.esm.min.js.map +0 -1
  375. package/dist/chunks/default.vertex-vn2_ZsRf.esm.min.js +0 -2
  376. package/dist/chunks/default.vertex-vn2_ZsRf.esm.min.js.map +0 -1
  377. package/dist/chunks/defaultUboDeclaration-DOEnRk8l.esm.min.js +0 -2
  378. package/dist/chunks/defaultUboDeclaration-DOEnRk8l.esm.min.js.map +0 -1
  379. package/dist/chunks/defaultUboDeclaration-D_cdCN09.esm.js +0 -15
  380. package/dist/chunks/defaultUboDeclaration-D_cdCN09.esm.js.map +0 -1
  381. package/dist/chunks/defaultUboDeclaration-DulGgNIT.esm.js +0 -13
  382. package/dist/chunks/defaultUboDeclaration-DulGgNIT.esm.js.map +0 -1
  383. package/dist/chunks/defaultUboDeclaration-DuvDKzIc.esm.min.js +0 -2
  384. package/dist/chunks/defaultUboDeclaration-DuvDKzIc.esm.min.js.map +0 -1
  385. package/dist/chunks/drawWrapper.functions-CKg3_9x4.esm.js +0 -11
  386. package/dist/chunks/drawWrapper.functions-CKg3_9x4.esm.js.map +0 -1
  387. package/dist/chunks/drawWrapper.functions-ng7lvueZ.esm.min.js +0 -2
  388. package/dist/chunks/drawWrapper.functions-ng7lvueZ.esm.min.js.map +0 -1
  389. package/dist/chunks/dumpTools-CDmW-p2A.esm.js +0 -200
  390. package/dist/chunks/dumpTools-CDmW-p2A.esm.js.map +0 -1
  391. package/dist/chunks/dumpTools-hJHAozcu.esm.min.js +0 -2
  392. package/dist/chunks/dumpTools-hJHAozcu.esm.min.js.map +0 -1
  393. package/dist/chunks/engine-CfBkxMlv.esm.min.js +0 -2
  394. package/dist/chunks/engine-CfBkxMlv.esm.min.js.map +0 -1
  395. package/dist/chunks/engine-DaA20vkg.esm.js +0 -2187
  396. package/dist/chunks/engine-DaA20vkg.esm.js.map +0 -1
  397. package/dist/chunks/engine.common-B1nX1uOv.esm.min.js +0 -2
  398. package/dist/chunks/engine.common-B1nX1uOv.esm.min.js.map +0 -1
  399. package/dist/chunks/engine.common-Da03TQs0.esm.js +0 -1103
  400. package/dist/chunks/engine.common-Da03TQs0.esm.js.map +0 -1
  401. package/dist/chunks/envTextureLoader-BRXi1pZo.esm.js +0 -64
  402. package/dist/chunks/envTextureLoader-BRXi1pZo.esm.js.map +0 -1
  403. package/dist/chunks/envTextureLoader-CS1eu96I.esm.min.js +0 -2
  404. package/dist/chunks/envTextureLoader-CS1eu96I.esm.min.js.map +0 -1
  405. package/dist/chunks/environmentTextureTools-BCSQExyv.esm.js +0 -382
  406. package/dist/chunks/environmentTextureTools-BCSQExyv.esm.js.map +0 -1
  407. package/dist/chunks/environmentTextureTools-DaBia0zg.esm.min.js +0 -2
  408. package/dist/chunks/environmentTextureTools-DaBia0zg.esm.min.js.map +0 -1
  409. package/dist/chunks/exrTextureLoader-DOcIuOg9.esm.min.js +0 -2
  410. package/dist/chunks/exrTextureLoader-DOcIuOg9.esm.min.js.map +0 -1
  411. package/dist/chunks/exrTextureLoader-NVzNFU10.esm.js +0 -1682
  412. package/dist/chunks/exrTextureLoader-NVzNFU10.esm.js.map +0 -1
  413. package/dist/chunks/fogFragment-7C9DmW8b.esm.js +0 -102
  414. package/dist/chunks/fogFragment-7C9DmW8b.esm.js.map +0 -1
  415. package/dist/chunks/fogFragment-B9F5aJAx.esm.min.js +0 -2
  416. package/dist/chunks/fogFragment-B9F5aJAx.esm.min.js.map +0 -1
  417. package/dist/chunks/fogFragment-BnQp0Spj.esm.js +0 -101
  418. package/dist/chunks/fogFragment-BnQp0Spj.esm.js.map +0 -1
  419. package/dist/chunks/fogFragment-Rqu9S2gV.esm.min.js +0 -2
  420. package/dist/chunks/fogFragment-Rqu9S2gV.esm.min.js.map +0 -1
  421. package/dist/chunks/fresnelFunction--bGC1bW6.esm.min.js +0 -2
  422. package/dist/chunks/fresnelFunction--bGC1bW6.esm.min.js.map +0 -1
  423. package/dist/chunks/fresnelFunction-YurpC61U.esm.js +0 -12
  424. package/dist/chunks/fresnelFunction-YurpC61U.esm.js.map +0 -1
  425. package/dist/chunks/glTFLoader--eb4oZZe.esm.min.js +0 -2
  426. package/dist/chunks/glTFLoader--eb4oZZe.esm.min.js.map +0 -1
  427. package/dist/chunks/glTFLoader-DDABr3tc.esm.js +0 -7595
  428. package/dist/chunks/glTFLoader-DDABr3tc.esm.js.map +0 -1
  429. package/dist/chunks/glTFLoaderAnimation-C_jvKQZc.esm.min.js +0 -2
  430. package/dist/chunks/glTFLoaderAnimation-C_jvKQZc.esm.min.js.map +0 -1
  431. package/dist/chunks/glTFLoaderAnimation-Ce1T-HK4.esm.js +0 -77
  432. package/dist/chunks/glTFLoaderAnimation-Ce1T-HK4.esm.js.map +0 -1
  433. package/dist/chunks/gltfPathToObjectConverter-Dyt_Y9jE.esm.min.js +0 -2
  434. package/dist/chunks/gltfPathToObjectConverter-Dyt_Y9jE.esm.min.js.map +0 -1
  435. package/dist/chunks/gltfPathToObjectConverter-GcUmfOyo.esm.js +0 -67
  436. package/dist/chunks/gltfPathToObjectConverter-GcUmfOyo.esm.js.map +0 -1
  437. package/dist/chunks/harmonicsFunctions-BVJDExzF.esm.js +0 -35
  438. package/dist/chunks/harmonicsFunctions-BVJDExzF.esm.js.map +0 -1
  439. package/dist/chunks/harmonicsFunctions-Cpf19SYh.esm.min.js +0 -2
  440. package/dist/chunks/harmonicsFunctions-Cpf19SYh.esm.min.js.map +0 -1
  441. package/dist/chunks/harmonicsFunctions-EwGi7mvH.esm.js +0 -34
  442. package/dist/chunks/harmonicsFunctions-EwGi7mvH.esm.js.map +0 -1
  443. package/dist/chunks/harmonicsFunctions-sCDYMnE7.esm.min.js +0 -2
  444. package/dist/chunks/harmonicsFunctions-sCDYMnE7.esm.min.js.map +0 -1
  445. package/dist/chunks/hdrTextureLoader-CHt5g_Ro.esm.js +0 -252
  446. package/dist/chunks/hdrTextureLoader-CHt5g_Ro.esm.js.map +0 -1
  447. package/dist/chunks/hdrTextureLoader-CcljcQGM.esm.min.js +0 -2
  448. package/dist/chunks/hdrTextureLoader-CcljcQGM.esm.min.js.map +0 -1
  449. package/dist/chunks/helperFunctions-BLQP90J_.esm.min.js +0 -2
  450. package/dist/chunks/helperFunctions-BLQP90J_.esm.min.js.map +0 -1
  451. package/dist/chunks/helperFunctions-BeWEDUrw.esm.js +0 -108
  452. package/dist/chunks/helperFunctions-BeWEDUrw.esm.js.map +0 -1
  453. package/dist/chunks/helperFunctions-CkmR3WUA.esm.min.js +0 -2
  454. package/dist/chunks/helperFunctions-CkmR3WUA.esm.min.js.map +0 -1
  455. package/dist/chunks/helperFunctions-Vnio5Zy4.esm.js +0 -80
  456. package/dist/chunks/helperFunctions-Vnio5Zy4.esm.js.map +0 -1
  457. package/dist/chunks/index-CVMH5-nD.esm.js +0 -74148
  458. package/dist/chunks/index-CVMH5-nD.esm.js.map +0 -1
  459. package/dist/chunks/index-bkYfr-SD.esm.min.js +0 -57
  460. package/dist/chunks/index-bkYfr-SD.esm.min.js.map +0 -1
  461. package/dist/chunks/ktxTextureLoader-CmYn3AjU.esm.min.js +0 -2
  462. package/dist/chunks/ktxTextureLoader-CmYn3AjU.esm.min.js.map +0 -1
  463. package/dist/chunks/ktxTextureLoader-Ct4ygDpl.esm.js +0 -814
  464. package/dist/chunks/ktxTextureLoader-Ct4ygDpl.esm.js.map +0 -1
  465. package/dist/chunks/logDepthDeclaration-CCVJgklB.esm.js +0 -11
  466. package/dist/chunks/logDepthDeclaration-CCVJgklB.esm.js.map +0 -1
  467. package/dist/chunks/logDepthDeclaration-CmefuysH.esm.min.js +0 -2
  468. package/dist/chunks/logDepthDeclaration-CmefuysH.esm.min.js.map +0 -1
  469. package/dist/chunks/logDepthDeclaration-kbT8jgiS.esm.js +0 -35
  470. package/dist/chunks/logDepthDeclaration-kbT8jgiS.esm.js.map +0 -1
  471. package/dist/chunks/logDepthDeclaration-utQE6RQm.esm.min.js +0 -2
  472. package/dist/chunks/logDepthDeclaration-utQE6RQm.esm.min.js.map +0 -1
  473. package/dist/chunks/logDepthVertex-BwAXuZcJ.esm.js +0 -77
  474. package/dist/chunks/logDepthVertex-BwAXuZcJ.esm.js.map +0 -1
  475. package/dist/chunks/logDepthVertex-CIU5ihJc.esm.min.js +0 -2
  476. package/dist/chunks/logDepthVertex-CIU5ihJc.esm.min.js.map +0 -1
  477. package/dist/chunks/logDepthVertex-DBdj3JQF.esm.js +0 -77
  478. package/dist/chunks/logDepthVertex-DBdj3JQF.esm.js.map +0 -1
  479. package/dist/chunks/logDepthVertex-L5SVOP7a.esm.min.js +0 -2
  480. package/dist/chunks/logDepthVertex-L5SVOP7a.esm.min.js.map +0 -1
  481. package/dist/chunks/mainUVVaryingDeclaration-BjN3rZcV.esm.js +0 -11
  482. package/dist/chunks/mainUVVaryingDeclaration-BjN3rZcV.esm.js.map +0 -1
  483. package/dist/chunks/mainUVVaryingDeclaration-CS8fR4k6.esm.min.js +0 -2
  484. package/dist/chunks/mainUVVaryingDeclaration-CS8fR4k6.esm.min.js.map +0 -1
  485. package/dist/chunks/mainUVVaryingDeclaration-F_ldv7kC.esm.min.js +0 -2
  486. package/dist/chunks/mainUVVaryingDeclaration-F_ldv7kC.esm.min.js.map +0 -1
  487. package/dist/chunks/mainUVVaryingDeclaration-JJ1eiwN7.esm.js +0 -11
  488. package/dist/chunks/mainUVVaryingDeclaration-JJ1eiwN7.esm.js.map +0 -1
  489. package/dist/chunks/meshUboDeclaration-Cqhjf76p.esm.min.js +0 -2
  490. package/dist/chunks/meshUboDeclaration-Cqhjf76p.esm.min.js.map +0 -1
  491. package/dist/chunks/meshUboDeclaration-TC3Qb9qA.esm.js +0 -24
  492. package/dist/chunks/meshUboDeclaration-TC3Qb9qA.esm.js.map +0 -1
  493. package/dist/chunks/objFileLoader-DUbUzdM7.esm.js +0 -1338
  494. package/dist/chunks/objFileLoader-DUbUzdM7.esm.js.map +0 -1
  495. package/dist/chunks/objFileLoader-cuX0R9Ll.esm.min.js +0 -2
  496. package/dist/chunks/objFileLoader-cuX0R9Ll.esm.min.js.map +0 -1
  497. package/dist/chunks/oitFragment-BuvtdYuN.esm.min.js +0 -2
  498. package/dist/chunks/oitFragment-BuvtdYuN.esm.min.js.map +0 -1
  499. package/dist/chunks/oitFragment-CsHXm-hs.esm.min.js +0 -2
  500. package/dist/chunks/oitFragment-CsHXm-hs.esm.min.js.map +0 -1
  501. package/dist/chunks/oitFragment-Jsj4VCRm.esm.js +0 -1051
  502. package/dist/chunks/oitFragment-Jsj4VCRm.esm.js.map +0 -1
  503. package/dist/chunks/oitFragment-bE1j7vLE.esm.js +0 -1210
  504. package/dist/chunks/oitFragment-bE1j7vLE.esm.js.map +0 -1
  505. package/dist/chunks/pass.fragment-7Tm4v4I5.esm.min.js +0 -2
  506. package/dist/chunks/pass.fragment-7Tm4v4I5.esm.min.js.map +0 -1
  507. package/dist/chunks/pass.fragment-Bim4VPEO.esm.js +0 -15
  508. package/dist/chunks/pass.fragment-Bim4VPEO.esm.js.map +0 -1
  509. package/dist/chunks/pass.fragment-CYz9acmH.esm.js +0 -15
  510. package/dist/chunks/pass.fragment-CYz9acmH.esm.js.map +0 -1
  511. package/dist/chunks/pass.fragment-CzPpw3iK.esm.min.js +0 -2
  512. package/dist/chunks/pass.fragment-CzPpw3iK.esm.min.js.map +0 -1
  513. package/dist/chunks/pbr.fragment-C0EyEtjU.esm.js +0 -3218
  514. package/dist/chunks/pbr.fragment-C0EyEtjU.esm.js.map +0 -1
  515. package/dist/chunks/pbr.fragment-D7KGHlr3.esm.min.js +0 -2
  516. package/dist/chunks/pbr.fragment-D7KGHlr3.esm.min.js.map +0 -1
  517. package/dist/chunks/pbr.fragment-DRo704mz.esm.js +0 -3164
  518. package/dist/chunks/pbr.fragment-DRo704mz.esm.js.map +0 -1
  519. package/dist/chunks/pbr.fragment-Dw30RsZq.esm.min.js +0 -2
  520. package/dist/chunks/pbr.fragment-Dw30RsZq.esm.min.js.map +0 -1
  521. package/dist/chunks/pbr.vertex-BFjD6j1a.esm.min.js +0 -2
  522. package/dist/chunks/pbr.vertex-BFjD6j1a.esm.min.js.map +0 -1
  523. package/dist/chunks/pbr.vertex-BNL0Ih3S.esm.js +0 -214
  524. package/dist/chunks/pbr.vertex-BNL0Ih3S.esm.js.map +0 -1
  525. package/dist/chunks/pbr.vertex-DCYsZj4K.esm.js +0 -338
  526. package/dist/chunks/pbr.vertex-DCYsZj4K.esm.js.map +0 -1
  527. package/dist/chunks/pbr.vertex-DQWB7B3n.esm.min.js +0 -2
  528. package/dist/chunks/pbr.vertex-DQWB7B3n.esm.min.js.map +0 -1
  529. package/dist/chunks/postprocess.vertex-BKTxzIr3.esm.js +0 -20
  530. package/dist/chunks/postprocess.vertex-BKTxzIr3.esm.js.map +0 -1
  531. package/dist/chunks/postprocess.vertex-BLM-tBsI.esm.min.js +0 -2
  532. package/dist/chunks/postprocess.vertex-BLM-tBsI.esm.min.js.map +0 -1
  533. package/dist/chunks/rawTexture-B4sxPzau.esm.js +0 -191
  534. package/dist/chunks/rawTexture-B4sxPzau.esm.js.map +0 -1
  535. package/dist/chunks/rawTexture-C8eTjsTL.esm.min.js +0 -2
  536. package/dist/chunks/rawTexture-C8eTjsTL.esm.min.js.map +0 -1
  537. package/dist/chunks/rgbdDecode.fragment-B1JRUB2c.esm.js +0 -17
  538. package/dist/chunks/rgbdDecode.fragment-B1JRUB2c.esm.js.map +0 -1
  539. package/dist/chunks/rgbdDecode.fragment-BQDhe3Gm.esm.min.js +0 -2
  540. package/dist/chunks/rgbdDecode.fragment-BQDhe3Gm.esm.min.js.map +0 -1
  541. package/dist/chunks/rgbdDecode.fragment-Bqwzk3c0.esm.js +0 -17
  542. package/dist/chunks/rgbdDecode.fragment-Bqwzk3c0.esm.js.map +0 -1
  543. package/dist/chunks/rgbdDecode.fragment-De929itq.esm.min.js +0 -2
  544. package/dist/chunks/rgbdDecode.fragment-De929itq.esm.min.js.map +0 -1
  545. package/dist/chunks/rgbdEncode.fragment-B2mbOgZ1.esm.js +0 -17
  546. package/dist/chunks/rgbdEncode.fragment-B2mbOgZ1.esm.js.map +0 -1
  547. package/dist/chunks/rgbdEncode.fragment-BR4bMAPw.esm.min.js +0 -2
  548. package/dist/chunks/rgbdEncode.fragment-BR4bMAPw.esm.min.js.map +0 -1
  549. package/dist/chunks/rgbdEncode.fragment-CnnkzvSU.esm.min.js +0 -2
  550. package/dist/chunks/rgbdEncode.fragment-CnnkzvSU.esm.min.js.map +0 -1
  551. package/dist/chunks/rgbdEncode.fragment-DdsDf_tZ.esm.js +0 -17
  552. package/dist/chunks/rgbdEncode.fragment-DdsDf_tZ.esm.js.map +0 -1
  553. package/dist/chunks/splatFileLoader-ByV2g6RW.esm.js +0 -3947
  554. package/dist/chunks/splatFileLoader-ByV2g6RW.esm.js.map +0 -1
  555. package/dist/chunks/splatFileLoader-DZtkydoO.esm.min.js +0 -2
  556. package/dist/chunks/splatFileLoader-DZtkydoO.esm.min.js.map +0 -1
  557. package/dist/chunks/standardMaterial-DUti--Yk.esm.js +0 -1805
  558. package/dist/chunks/standardMaterial-DUti--Yk.esm.js.map +0 -1
  559. package/dist/chunks/standardMaterial-DxPZ0yEO.esm.min.js +0 -2
  560. package/dist/chunks/standardMaterial-DxPZ0yEO.esm.min.js.map +0 -1
  561. package/dist/chunks/stlFileLoader-BddM0ohC.esm.js +0 -238
  562. package/dist/chunks/stlFileLoader-BddM0ohC.esm.js.map +0 -1
  563. package/dist/chunks/stlFileLoader-Daj_Ow9k.esm.min.js +0 -2
  564. package/dist/chunks/stlFileLoader-Daj_Ow9k.esm.min.js.map +0 -1
  565. package/dist/chunks/tgaTextureLoader-DDmm8z9e.esm.js +0 -349
  566. package/dist/chunks/tgaTextureLoader-DDmm8z9e.esm.js.map +0 -1
  567. package/dist/chunks/tgaTextureLoader-NZ1m7gDb.esm.min.js +0 -2
  568. package/dist/chunks/tgaTextureLoader-NZ1m7gDb.esm.min.js.map +0 -1
  569. package/dist/chunks/thinEngine-CvGTeAY9.esm.js +0 -3723
  570. package/dist/chunks/thinEngine-CvGTeAY9.esm.js.map +0 -1
  571. package/dist/chunks/thinEngine-Czvj0W_2.esm.min.js +0 -2
  572. package/dist/chunks/thinEngine-Czvj0W_2.esm.min.js.map +0 -1
  573. package/dist/chunks/thinInstanceMesh-BGeYKYJu.esm.js +0 -314
  574. package/dist/chunks/thinInstanceMesh-BGeYKYJu.esm.js.map +0 -1
  575. package/dist/chunks/thinInstanceMesh-Byk1sPWi.esm.min.js +0 -2
  576. package/dist/chunks/thinInstanceMesh-Byk1sPWi.esm.min.js.map +0 -1
  577. package/dist/chunks/vertexColorMixing-5MVqrbuQ.esm.js +0 -412
  578. package/dist/chunks/vertexColorMixing-5MVqrbuQ.esm.js.map +0 -1
  579. package/dist/chunks/vertexColorMixing-BTHtPksv.esm.min.js +0 -2
  580. package/dist/chunks/vertexColorMixing-BTHtPksv.esm.min.js.map +0 -1
  581. package/dist/chunks/vertexColorMixing-C-JxO1th.esm.js +0 -522
  582. package/dist/chunks/vertexColorMixing-C-JxO1th.esm.js.map +0 -1
  583. package/dist/chunks/vertexColorMixing-DpW1_vsz.esm.min.js +0 -2
  584. package/dist/chunks/vertexColorMixing-DpW1_vsz.esm.min.js.map +0 -1
  585. package/dist/chunks/webgpuEngine-Dz_96swZ.esm.min.js +0 -2
  586. package/dist/chunks/webgpuEngine-Dz_96swZ.esm.min.js.map +0 -1
  587. package/dist/chunks/webgpuEngine-iwYQqIrX.esm.js +0 -11465
  588. package/dist/chunks/webgpuEngine-iwYQqIrX.esm.js.map +0 -1
  589. package/dist/chunks/workerPool-BUOov2K1.esm.js +0 -122
  590. package/dist/chunks/workerPool-BUOov2K1.esm.js.map +0 -1
  591. package/dist/chunks/workerPool-BWHiDmEZ.esm.min.js +0 -2
  592. package/dist/chunks/workerPool-BWHiDmEZ.esm.min.js.map +0 -1
  593. package/docs/ViewerDefault.jpg +0 -0
  594. package/docs/ViewerParts.jpg +0 -0
  595. package/docs/ViewerSlots.jpg +0 -0
  596. package/docs/ViewerStyled.jpg +0 -0
  597. package/lib/index.d.ts +0 -534
  598. package/lib/index.js +0 -1939
  599. package/lib/index.js.map +0 -1
@@ -1,3723 +0,0 @@
1
- import { D as DataBuffer, a_ as _ConcatenateShader, A as AbstractEngine, m as Effect, L as Logger, a$ as getStateObject, C as Constants, r as resetCachedPipeline, b0 as _getGlobalDefines, b1 as createRawShaderProgram, b2 as createShaderProgram, b3 as createPipelineContext, b4 as _finalizePipelineContext, b5 as _preparePipelineContext, b6 as _createShaderProgram, b7 as _executeWhenRenderingStateIsCompiled, I as InternalTexture, G as GetExponentOfTwo, b8 as _setProgram, o as IsWindowObjectExist, b9 as deleteStateObject } from './index-CVMH5-nD.esm.js';
2
- import { I as IsWrapper } from './drawWrapper.functions-CKg3_9x4.esm.js';
3
-
4
- /** @internal */
5
- class WebGLShaderProcessor {
6
- constructor() {
7
- this.shaderLanguage = 0 /* ShaderLanguage.GLSL */;
8
- }
9
- postProcessor(code, defines, isFragment, processingContext, parameters) {
10
- // Remove extensions
11
- if (parameters.drawBuffersExtensionDisabled) {
12
- // even if enclosed in #if/#endif, IE11 does parse the #extension declaration, so we need to remove it altogether
13
- const regex = /#extension.+GL_EXT_draw_buffers.+(enable|require)/g;
14
- code = code.replace(regex, "");
15
- }
16
- return code;
17
- }
18
- }
19
-
20
- const varyingRegex = /(flat\s)?\s*varying\s*.*/;
21
- /** @internal */
22
- class WebGL2ShaderProcessor {
23
- constructor() {
24
- this.shaderLanguage = 0 /* ShaderLanguage.GLSL */;
25
- }
26
- attributeProcessor(attribute) {
27
- return attribute.replace("attribute", "in");
28
- }
29
- varyingCheck(varying, _isFragment) {
30
- return varyingRegex.test(varying);
31
- }
32
- varyingProcessor(varying, isFragment) {
33
- return varying.replace("varying", isFragment ? "in" : "out");
34
- }
35
- postProcessor(code, defines, isFragment) {
36
- const hasDrawBuffersExtension = code.search(/#extension.+GL_EXT_draw_buffers.+require/) !== -1;
37
- // Remove extensions
38
- const regex = /#extension.+(GL_OVR_multiview2|GL_OES_standard_derivatives|GL_EXT_shader_texture_lod|GL_EXT_frag_depth|GL_EXT_draw_buffers).+(enable|require)/g;
39
- code = code.replace(regex, "");
40
- // Replace instructions
41
- code = code.replace(/texture2D\s*\(/g, "texture(");
42
- if (isFragment) {
43
- const hasOutput = code.search(/layout *\(location *= *0\) *out/g) !== -1;
44
- code = code.replace(/texture2DLodEXT\s*\(/g, "textureLod(");
45
- code = code.replace(/textureCubeLodEXT\s*\(/g, "textureLod(");
46
- code = code.replace(/textureCube\s*\(/g, "texture(");
47
- code = code.replace(/gl_FragDepthEXT/g, "gl_FragDepth");
48
- code = code.replace(/gl_FragColor/g, "glFragColor");
49
- code = code.replace(/gl_FragData/g, "glFragData");
50
- code = code.replace(/void\s+?main\s*\(/g, (hasDrawBuffersExtension || hasOutput ? "" : "layout(location = 0) out vec4 glFragColor;\n") + "void main(");
51
- }
52
- else {
53
- const hasMultiviewExtension = defines.indexOf("#define MULTIVIEW") !== -1;
54
- if (hasMultiviewExtension) {
55
- return "#extension GL_OVR_multiview2 : require\nlayout (num_views = 2) in;\n" + code;
56
- }
57
- }
58
- return code;
59
- }
60
- }
61
-
62
- /** @internal */
63
- class WebGLDataBuffer extends DataBuffer {
64
- constructor(resource) {
65
- super();
66
- this._buffer = resource;
67
- }
68
- get underlyingResource() {
69
- return this._buffer;
70
- }
71
- }
72
-
73
- /** @internal */
74
- class WebGLHardwareTexture {
75
- get underlyingResource() {
76
- return this._webGLTexture;
77
- }
78
- constructor(existingTexture = null, context) {
79
- // There can be multiple buffers for a single WebGL texture because different layers of a 2DArrayTexture / 3DTexture
80
- // or different faces of a cube texture can be bound to different render targets at the same time.
81
- // eslint-disable-next-line @typescript-eslint/naming-convention
82
- this._MSAARenderBuffers = null;
83
- this._context = context;
84
- if (!existingTexture) {
85
- existingTexture = context.createTexture();
86
- if (!existingTexture) {
87
- throw new Error("Unable to create webGL texture");
88
- }
89
- }
90
- this.set(existingTexture);
91
- }
92
- setUsage() { }
93
- set(hardwareTexture) {
94
- this._webGLTexture = hardwareTexture;
95
- }
96
- reset() {
97
- this._webGLTexture = null;
98
- this._MSAARenderBuffers = null;
99
- }
100
- addMSAARenderBuffer(buffer) {
101
- if (!this._MSAARenderBuffers) {
102
- this._MSAARenderBuffers = [];
103
- }
104
- this._MSAARenderBuffers.push(buffer);
105
- }
106
- releaseMSAARenderBuffers() {
107
- if (this._MSAARenderBuffers) {
108
- for (const buffer of this._MSAARenderBuffers) {
109
- this._context.deleteRenderbuffer(buffer);
110
- }
111
- this._MSAARenderBuffers = null;
112
- }
113
- }
114
- getMSAARenderBuffer(index = 0) {
115
- return this._MSAARenderBuffers?.[index] ?? null;
116
- }
117
- release() {
118
- this.releaseMSAARenderBuffers();
119
- if (this._webGLTexture) {
120
- this._context.deleteTexture(this._webGLTexture);
121
- }
122
- this.reset();
123
- }
124
- }
125
-
126
- /**
127
- * Keeps track of all the buffer info used in engine.
128
- */
129
- class BufferPointer {
130
- }
131
- /**
132
- * The base engine class (root of all engines)
133
- */
134
- class ThinEngine extends AbstractEngine {
135
- /**
136
- * Gets or sets the name of the engine
137
- */
138
- get name() {
139
- return this._name;
140
- }
141
- set name(value) {
142
- this._name = value;
143
- }
144
- /**
145
- * Returns the version of the engine
146
- */
147
- get version() {
148
- return this._webGLVersion;
149
- }
150
- /**
151
- * Gets or sets the relative url used to load shaders if using the engine in non-minified mode
152
- */
153
- static get ShadersRepository() {
154
- return Effect.ShadersRepository;
155
- }
156
- static set ShadersRepository(value) {
157
- Effect.ShadersRepository = value;
158
- }
159
- /**
160
- * Gets a boolean indicating that the engine supports uniform buffers
161
- * @see https://doc.babylonjs.com/setup/support/webGL2#uniform-buffer-objets
162
- */
163
- get supportsUniformBuffers() {
164
- return this.webGLVersion > 1 && !this.disableUniformBuffers;
165
- }
166
- /**
167
- * Gets a boolean indicating that only power of 2 textures are supported
168
- * Please note that you can still use non power of 2 textures but in this case the engine will forcefully convert them
169
- */
170
- get needPOTTextures() {
171
- return this._webGLVersion < 2 || this.forcePOTTextures;
172
- }
173
- get _supportsHardwareTextureRescaling() {
174
- return false;
175
- }
176
- /**
177
- * sets the object from which width and height will be taken from when getting render width and height
178
- * Will fallback to the gl object
179
- * @param dimensions the framebuffer width and height that will be used.
180
- */
181
- set framebufferDimensionsObject(dimensions) {
182
- this._framebufferDimensionsObject = dimensions;
183
- }
184
- /**
185
- * Creates a new snapshot at the next frame using the current snapshotRenderingMode
186
- */
187
- snapshotRenderingReset() {
188
- this.snapshotRendering = false;
189
- }
190
- /**
191
- * Creates a new engine
192
- * @param canvasOrContext defines the canvas or WebGL context to use for rendering. If you provide a WebGL context, Babylon.js will not hook events on the canvas (like pointers, keyboards, etc...) so no event observables will be available. This is mostly used when Babylon.js is used as a plugin on a system which already used the WebGL context
193
- * @param antialias defines whether anti-aliasing should be enabled (default value is "undefined", meaning that the browser may or may not enable it)
194
- * @param options defines further options to be sent to the getContext() function
195
- * @param adaptToDeviceRatio defines whether to adapt to the device's viewport characteristics (default: false)
196
- */
197
- constructor(canvasOrContext, antialias, options, adaptToDeviceRatio) {
198
- options = options || {};
199
- super(antialias ?? options.antialias, options, adaptToDeviceRatio);
200
- /** @internal */
201
- this._name = "WebGL";
202
- /**
203
- * Gets or sets a boolean that indicates if textures must be forced to power of 2 size even if not required
204
- */
205
- this.forcePOTTextures = false;
206
- /** Gets or sets a boolean indicating if the engine should validate programs after compilation */
207
- this.validateShaderPrograms = false;
208
- /**
209
- * Gets or sets a boolean indicating that uniform buffers must be disabled even if they are supported
210
- */
211
- this.disableUniformBuffers = false;
212
- /** @internal */
213
- this._webGLVersion = 1.0;
214
- this._vertexAttribArraysEnabled = [];
215
- this._uintIndicesCurrentlySet = false;
216
- this._currentBoundBuffer = new Array();
217
- /** @internal */
218
- this._currentFramebuffer = null;
219
- /** @internal */
220
- this._dummyFramebuffer = null;
221
- this._currentBufferPointers = new Array();
222
- this._currentInstanceLocations = new Array();
223
- this._currentInstanceBuffers = new Array();
224
- this._vaoRecordInProgress = false;
225
- this._mustWipeVertexAttributes = false;
226
- this._nextFreeTextureSlots = new Array();
227
- this._maxSimultaneousTextures = 0;
228
- this._maxMSAASamplesOverride = null;
229
- this._unpackFlipYCached = null;
230
- /**
231
- * In case you are sharing the context with other applications, it might
232
- * be interested to not cache the unpack flip y state to ensure a consistent
233
- * value would be set.
234
- */
235
- this.enableUnpackFlipYCached = true;
236
- /**
237
- * @internal
238
- */
239
- this._boundUniforms = {};
240
- if (!canvasOrContext) {
241
- return;
242
- }
243
- let canvas = null;
244
- if (canvasOrContext.getContext) {
245
- canvas = canvasOrContext;
246
- this._renderingCanvas = canvas;
247
- if (options.preserveDrawingBuffer === undefined) {
248
- options.preserveDrawingBuffer = false;
249
- }
250
- if (options.xrCompatible === undefined) {
251
- options.xrCompatible = false;
252
- }
253
- // Exceptions
254
- if (navigator && navigator.userAgent) {
255
- this._setupMobileChecks();
256
- const ua = navigator.userAgent;
257
- for (const exception of ThinEngine.ExceptionList) {
258
- const key = exception.key;
259
- const targets = exception.targets;
260
- const check = new RegExp(key);
261
- if (check.test(ua)) {
262
- if (exception.capture && exception.captureConstraint) {
263
- const capture = exception.capture;
264
- const constraint = exception.captureConstraint;
265
- const regex = new RegExp(capture);
266
- const matches = regex.exec(ua);
267
- if (matches && matches.length > 0) {
268
- const capturedValue = parseInt(matches[matches.length - 1]);
269
- if (capturedValue >= constraint) {
270
- continue;
271
- }
272
- }
273
- }
274
- for (const target of targets) {
275
- switch (target) {
276
- case "uniformBuffer":
277
- this.disableUniformBuffers = true;
278
- break;
279
- case "vao":
280
- this.disableVertexArrayObjects = true;
281
- break;
282
- case "antialias":
283
- options.antialias = false;
284
- break;
285
- case "maxMSAASamples":
286
- this._maxMSAASamplesOverride = 1;
287
- break;
288
- }
289
- }
290
- }
291
- }
292
- }
293
- // Context lost
294
- if (!this._doNotHandleContextLost) {
295
- this._onContextLost = (evt) => {
296
- evt.preventDefault();
297
- this._contextWasLost = true;
298
- Logger.Warn("WebGL context lost.");
299
- this.onContextLostObservable.notifyObservers(this);
300
- };
301
- this._onContextRestored = () => {
302
- this._restoreEngineAfterContextLost(() => this._initGLContext());
303
- };
304
- canvas.addEventListener("webglcontextlost", this._onContextLost, false);
305
- canvas.addEventListener("webglcontextrestored", this._onContextRestored, false);
306
- options.powerPreference = options.powerPreference || "high-performance";
307
- }
308
- if (this._badDesktopOS) {
309
- options.xrCompatible = false;
310
- }
311
- // GL
312
- if (!options.disableWebGL2Support) {
313
- try {
314
- this._gl = (canvas.getContext("webgl2", options) || canvas.getContext("experimental-webgl2", options));
315
- if (this._gl) {
316
- this._webGLVersion = 2.0;
317
- this._shaderPlatformName = "WEBGL2";
318
- // Prevent weird browsers to lie (yeah that happens!)
319
- if (!this._gl.deleteQuery) {
320
- this._webGLVersion = 1.0;
321
- this._shaderPlatformName = "WEBGL1";
322
- }
323
- }
324
- }
325
- catch (e) {
326
- // Do nothing
327
- }
328
- }
329
- if (!this._gl) {
330
- if (!canvas) {
331
- throw new Error("The provided canvas is null or undefined.");
332
- }
333
- try {
334
- this._gl = (canvas.getContext("webgl", options) || canvas.getContext("experimental-webgl", options));
335
- }
336
- catch (e) {
337
- throw new Error("WebGL not supported");
338
- }
339
- }
340
- if (!this._gl) {
341
- throw new Error("WebGL not supported");
342
- }
343
- }
344
- else {
345
- this._gl = canvasOrContext;
346
- this._renderingCanvas = this._gl.canvas;
347
- if (this._gl.renderbufferStorageMultisample) {
348
- this._webGLVersion = 2.0;
349
- this._shaderPlatformName = "WEBGL2";
350
- }
351
- else {
352
- this._shaderPlatformName = "WEBGL1";
353
- }
354
- const attributes = this._gl.getContextAttributes();
355
- if (attributes) {
356
- options.stencil = attributes.stencil;
357
- }
358
- }
359
- // Ensures a consistent color space unpacking of textures cross browser.
360
- this._gl.pixelStorei(this._gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, this._gl.NONE);
361
- if (options.useHighPrecisionFloats !== undefined) {
362
- this._highPrecisionShadersAllowed = options.useHighPrecisionFloats;
363
- }
364
- this.resize();
365
- this._initGLContext();
366
- this._initFeatures();
367
- // Prepare buffer pointers
368
- for (let i = 0; i < this._caps.maxVertexAttribs; i++) {
369
- this._currentBufferPointers[i] = new BufferPointer();
370
- }
371
- // Shader processor
372
- this._shaderProcessor = this.webGLVersion > 1 ? new WebGL2ShaderProcessor() : new WebGLShaderProcessor();
373
- // Starting with iOS 14, we can trust the browser
374
- // let matches = navigator.userAgent.match(/Version\/(\d+)/);
375
- // if (matches && matches.length === 2) {
376
- // if (parseInt(matches[1]) >= 14) {
377
- // this._badOS = false;
378
- // }
379
- // }
380
- const versionToLog = `Babylon.js v${ThinEngine.Version}`;
381
- Logger.Log(versionToLog + ` - ${this.description}`);
382
- // Check setAttribute in case of workers
383
- if (this._renderingCanvas && this._renderingCanvas.setAttribute) {
384
- this._renderingCanvas.setAttribute("data-engine", versionToLog);
385
- }
386
- const stateObject = getStateObject(this._gl);
387
- // update state object with the current engine state
388
- stateObject.validateShaderPrograms = this.validateShaderPrograms;
389
- stateObject.parallelShaderCompile = this._caps.parallelShaderCompile;
390
- }
391
- _clearEmptyResources() {
392
- this._dummyFramebuffer = null;
393
- super._clearEmptyResources();
394
- }
395
- /**
396
- * @internal
397
- */
398
- _getShaderProcessingContext(shaderLanguage) {
399
- return null;
400
- }
401
- /**
402
- * Gets a boolean indicating if all created effects are ready
403
- * @returns true if all effects are ready
404
- */
405
- areAllEffectsReady() {
406
- for (const key in this._compiledEffects) {
407
- const effect = this._compiledEffects[key];
408
- if (!effect.isReady()) {
409
- return false;
410
- }
411
- }
412
- return true;
413
- }
414
- _initGLContext() {
415
- // Caps
416
- this._caps = {
417
- maxTexturesImageUnits: this._gl.getParameter(this._gl.MAX_TEXTURE_IMAGE_UNITS),
418
- maxCombinedTexturesImageUnits: this._gl.getParameter(this._gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS),
419
- maxVertexTextureImageUnits: this._gl.getParameter(this._gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS),
420
- maxTextureSize: this._gl.getParameter(this._gl.MAX_TEXTURE_SIZE),
421
- maxSamples: this._webGLVersion > 1 ? this._gl.getParameter(this._gl.MAX_SAMPLES) : 1,
422
- maxCubemapTextureSize: this._gl.getParameter(this._gl.MAX_CUBE_MAP_TEXTURE_SIZE),
423
- maxRenderTextureSize: this._gl.getParameter(this._gl.MAX_RENDERBUFFER_SIZE),
424
- maxVertexAttribs: this._gl.getParameter(this._gl.MAX_VERTEX_ATTRIBS),
425
- maxVaryingVectors: this._gl.getParameter(this._gl.MAX_VARYING_VECTORS),
426
- maxFragmentUniformVectors: this._gl.getParameter(this._gl.MAX_FRAGMENT_UNIFORM_VECTORS),
427
- maxVertexUniformVectors: this._gl.getParameter(this._gl.MAX_VERTEX_UNIFORM_VECTORS),
428
- parallelShaderCompile: this._gl.getExtension("KHR_parallel_shader_compile") || undefined,
429
- standardDerivatives: this._webGLVersion > 1 || this._gl.getExtension("OES_standard_derivatives") !== null,
430
- maxAnisotropy: 1,
431
- astc: this._gl.getExtension("WEBGL_compressed_texture_astc") || this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_astc"),
432
- bptc: this._gl.getExtension("EXT_texture_compression_bptc") || this._gl.getExtension("WEBKIT_EXT_texture_compression_bptc"),
433
- s3tc: this._gl.getExtension("WEBGL_compressed_texture_s3tc") || this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc"),
434
- // eslint-disable-next-line @typescript-eslint/naming-convention
435
- s3tc_srgb: this._gl.getExtension("WEBGL_compressed_texture_s3tc_srgb") || this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc_srgb"),
436
- pvrtc: this._gl.getExtension("WEBGL_compressed_texture_pvrtc") || this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),
437
- etc1: this._gl.getExtension("WEBGL_compressed_texture_etc1") || this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_etc1"),
438
- etc2: this._gl.getExtension("WEBGL_compressed_texture_etc") ||
439
- this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_etc") ||
440
- this._gl.getExtension("WEBGL_compressed_texture_es3_0"), // also a requirement of OpenGL ES 3
441
- textureAnisotropicFilterExtension: this._gl.getExtension("EXT_texture_filter_anisotropic") ||
442
- this._gl.getExtension("WEBKIT_EXT_texture_filter_anisotropic") ||
443
- this._gl.getExtension("MOZ_EXT_texture_filter_anisotropic"),
444
- uintIndices: this._webGLVersion > 1 || this._gl.getExtension("OES_element_index_uint") !== null,
445
- fragmentDepthSupported: this._webGLVersion > 1 || this._gl.getExtension("EXT_frag_depth") !== null,
446
- highPrecisionShaderSupported: false,
447
- timerQuery: this._gl.getExtension("EXT_disjoint_timer_query_webgl2") || this._gl.getExtension("EXT_disjoint_timer_query"),
448
- supportOcclusionQuery: this._webGLVersion > 1,
449
- canUseTimestampForTimerQuery: false,
450
- drawBuffersExtension: false,
451
- maxMSAASamples: 1,
452
- colorBufferFloat: !!(this._webGLVersion > 1 && this._gl.getExtension("EXT_color_buffer_float")),
453
- supportFloatTexturesResolve: false,
454
- rg11b10ufColorRenderable: false,
455
- colorBufferHalfFloat: !!(this._webGLVersion > 1 && this._gl.getExtension("EXT_color_buffer_half_float")),
456
- textureFloat: this._webGLVersion > 1 || this._gl.getExtension("OES_texture_float") ? true : false,
457
- textureHalfFloat: this._webGLVersion > 1 || this._gl.getExtension("OES_texture_half_float") ? true : false,
458
- textureHalfFloatRender: false,
459
- textureFloatLinearFiltering: false,
460
- textureFloatRender: false,
461
- textureHalfFloatLinearFiltering: false,
462
- vertexArrayObject: false,
463
- instancedArrays: false,
464
- textureLOD: this._webGLVersion > 1 || this._gl.getExtension("EXT_shader_texture_lod") ? true : false,
465
- texelFetch: this._webGLVersion !== 1,
466
- blendMinMax: false,
467
- multiview: this._gl.getExtension("OVR_multiview2"),
468
- oculusMultiview: this._gl.getExtension("OCULUS_multiview"),
469
- depthTextureExtension: false,
470
- canUseGLInstanceID: this._webGLVersion > 1,
471
- canUseGLVertexID: this._webGLVersion > 1,
472
- supportComputeShaders: false,
473
- supportSRGBBuffers: false,
474
- supportTransformFeedbacks: this._webGLVersion > 1,
475
- textureMaxLevel: this._webGLVersion > 1,
476
- texture2DArrayMaxLayerCount: this._webGLVersion > 1 ? this._gl.getParameter(this._gl.MAX_ARRAY_TEXTURE_LAYERS) : 128,
477
- disableMorphTargetTexture: false,
478
- };
479
- this._caps.supportFloatTexturesResolve = this._caps.colorBufferFloat;
480
- this._caps.rg11b10ufColorRenderable = this._caps.colorBufferFloat;
481
- // Infos
482
- this._glVersion = this._gl.getParameter(this._gl.VERSION);
483
- const rendererInfo = this._gl.getExtension("WEBGL_debug_renderer_info");
484
- if (rendererInfo != null) {
485
- this._glRenderer = this._gl.getParameter(rendererInfo.UNMASKED_RENDERER_WEBGL);
486
- this._glVendor = this._gl.getParameter(rendererInfo.UNMASKED_VENDOR_WEBGL);
487
- }
488
- if (!this._glVendor) {
489
- this._glVendor = this._gl.getParameter(this._gl.VENDOR) || "Unknown vendor";
490
- }
491
- if (!this._glRenderer) {
492
- this._glRenderer = this._gl.getParameter(this._gl.RENDERER) || "Unknown renderer";
493
- }
494
- // Constants
495
- if (this._gl.HALF_FLOAT_OES !== 0x8d61) {
496
- this._gl.HALF_FLOAT_OES = 0x8d61; // Half floating-point type (16-bit).
497
- }
498
- if (this._gl.RGBA16F !== 0x881a) {
499
- this._gl.RGBA16F = 0x881a; // RGBA 16-bit floating-point color-renderable internal sized format.
500
- }
501
- if (this._gl.RGBA32F !== 0x8814) {
502
- this._gl.RGBA32F = 0x8814; // RGBA 32-bit floating-point color-renderable internal sized format.
503
- }
504
- if (this._gl.DEPTH24_STENCIL8 !== 35056) {
505
- this._gl.DEPTH24_STENCIL8 = 35056;
506
- }
507
- // Extensions
508
- if (this._caps.timerQuery) {
509
- if (this._webGLVersion === 1) {
510
- this._gl.getQuery = this._caps.timerQuery.getQueryEXT.bind(this._caps.timerQuery);
511
- }
512
- // WebGLQuery casted to number to avoid TS error
513
- this._caps.canUseTimestampForTimerQuery = (this._gl.getQuery(this._caps.timerQuery.TIMESTAMP_EXT, this._caps.timerQuery.QUERY_COUNTER_BITS_EXT) ?? 0) > 0;
514
- }
515
- this._caps.maxAnisotropy = this._caps.textureAnisotropicFilterExtension
516
- ? this._gl.getParameter(this._caps.textureAnisotropicFilterExtension.MAX_TEXTURE_MAX_ANISOTROPY_EXT)
517
- : 0;
518
- this._caps.textureFloatLinearFiltering = this._caps.textureFloat && this._gl.getExtension("OES_texture_float_linear") ? true : false;
519
- this._caps.textureFloatRender = this._caps.textureFloat && this._canRenderToFloatFramebuffer() ? true : false;
520
- this._caps.textureHalfFloatLinearFiltering =
521
- this._webGLVersion > 1 || (this._caps.textureHalfFloat && this._gl.getExtension("OES_texture_half_float_linear")) ? true : false;
522
- // Compressed formats
523
- if (this._caps.astc) {
524
- this._gl.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR = this._caps.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
525
- }
526
- if (this._caps.bptc) {
527
- this._gl.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT = this._caps.bptc.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT;
528
- }
529
- if (this._caps.s3tc_srgb) {
530
- this._gl.COMPRESSED_SRGB_S3TC_DXT1_EXT = this._caps.s3tc_srgb.COMPRESSED_SRGB_S3TC_DXT1_EXT;
531
- this._gl.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT = this._caps.s3tc_srgb.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
532
- this._gl.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT = this._caps.s3tc_srgb.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
533
- }
534
- if (this._caps.etc2) {
535
- this._gl.COMPRESSED_SRGB8_ETC2 = this._caps.etc2.COMPRESSED_SRGB8_ETC2;
536
- this._gl.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = this._caps.etc2.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
537
- }
538
- // Checks if some of the format renders first to allow the use of webgl inspector.
539
- if (this._webGLVersion > 1) {
540
- if (this._gl.HALF_FLOAT_OES !== 0x140b) {
541
- this._gl.HALF_FLOAT_OES = 0x140b;
542
- }
543
- }
544
- this._caps.textureHalfFloatRender = this._caps.textureHalfFloat && this._canRenderToHalfFloatFramebuffer();
545
- // Draw buffers
546
- if (this._webGLVersion > 1) {
547
- this._caps.drawBuffersExtension = true;
548
- this._caps.maxMSAASamples = this._maxMSAASamplesOverride !== null ? this._maxMSAASamplesOverride : this._gl.getParameter(this._gl.MAX_SAMPLES);
549
- this._caps.maxDrawBuffers = this._gl.getParameter(this._gl.MAX_DRAW_BUFFERS);
550
- }
551
- else {
552
- const drawBuffersExtension = this._gl.getExtension("WEBGL_draw_buffers");
553
- if (drawBuffersExtension !== null) {
554
- this._caps.drawBuffersExtension = true;
555
- this._gl.drawBuffers = drawBuffersExtension.drawBuffersWEBGL.bind(drawBuffersExtension);
556
- this._caps.maxDrawBuffers = this._gl.getParameter(drawBuffersExtension.MAX_DRAW_BUFFERS_WEBGL);
557
- this._gl.DRAW_FRAMEBUFFER = this._gl.FRAMEBUFFER;
558
- for (let i = 0; i < 16; i++) {
559
- this._gl["COLOR_ATTACHMENT" + i + "_WEBGL"] = drawBuffersExtension["COLOR_ATTACHMENT" + i + "_WEBGL"];
560
- }
561
- }
562
- }
563
- // Depth Texture
564
- if (this._webGLVersion > 1) {
565
- this._caps.depthTextureExtension = true;
566
- }
567
- else {
568
- const depthTextureExtension = this._gl.getExtension("WEBGL_depth_texture");
569
- if (depthTextureExtension != null) {
570
- this._caps.depthTextureExtension = true;
571
- this._gl.UNSIGNED_INT_24_8 = depthTextureExtension.UNSIGNED_INT_24_8_WEBGL;
572
- }
573
- }
574
- // Vertex array object
575
- if (this.disableVertexArrayObjects) {
576
- this._caps.vertexArrayObject = false;
577
- }
578
- else if (this._webGLVersion > 1) {
579
- this._caps.vertexArrayObject = true;
580
- }
581
- else {
582
- const vertexArrayObjectExtension = this._gl.getExtension("OES_vertex_array_object");
583
- if (vertexArrayObjectExtension != null) {
584
- this._caps.vertexArrayObject = true;
585
- this._gl.createVertexArray = vertexArrayObjectExtension.createVertexArrayOES.bind(vertexArrayObjectExtension);
586
- this._gl.bindVertexArray = vertexArrayObjectExtension.bindVertexArrayOES.bind(vertexArrayObjectExtension);
587
- this._gl.deleteVertexArray = vertexArrayObjectExtension.deleteVertexArrayOES.bind(vertexArrayObjectExtension);
588
- }
589
- }
590
- // Instances count
591
- if (this._webGLVersion > 1) {
592
- this._caps.instancedArrays = true;
593
- }
594
- else {
595
- const instanceExtension = this._gl.getExtension("ANGLE_instanced_arrays");
596
- if (instanceExtension != null) {
597
- this._caps.instancedArrays = true;
598
- this._gl.drawArraysInstanced = instanceExtension.drawArraysInstancedANGLE.bind(instanceExtension);
599
- this._gl.drawElementsInstanced = instanceExtension.drawElementsInstancedANGLE.bind(instanceExtension);
600
- this._gl.vertexAttribDivisor = instanceExtension.vertexAttribDivisorANGLE.bind(instanceExtension);
601
- }
602
- else {
603
- this._caps.instancedArrays = false;
604
- }
605
- }
606
- if (this._gl.getShaderPrecisionFormat) {
607
- const vertexhighp = this._gl.getShaderPrecisionFormat(this._gl.VERTEX_SHADER, this._gl.HIGH_FLOAT);
608
- const fragmenthighp = this._gl.getShaderPrecisionFormat(this._gl.FRAGMENT_SHADER, this._gl.HIGH_FLOAT);
609
- if (vertexhighp && fragmenthighp) {
610
- this._caps.highPrecisionShaderSupported = vertexhighp.precision !== 0 && fragmenthighp.precision !== 0;
611
- }
612
- }
613
- if (this._webGLVersion > 1) {
614
- this._caps.blendMinMax = true;
615
- }
616
- else {
617
- const blendMinMaxExtension = this._gl.getExtension("EXT_blend_minmax");
618
- if (blendMinMaxExtension != null) {
619
- this._caps.blendMinMax = true;
620
- this._gl.MAX = blendMinMaxExtension.MAX_EXT;
621
- this._gl.MIN = blendMinMaxExtension.MIN_EXT;
622
- }
623
- }
624
- // sRGB buffers
625
- // only run this if not already set to true (in the constructor, for example)
626
- if (!this._caps.supportSRGBBuffers) {
627
- if (this._webGLVersion > 1) {
628
- this._caps.supportSRGBBuffers = true;
629
- this._glSRGBExtensionValues = {
630
- SRGB: WebGL2RenderingContext.SRGB,
631
- SRGB8: WebGL2RenderingContext.SRGB8,
632
- SRGB8_ALPHA8: WebGL2RenderingContext.SRGB8_ALPHA8,
633
- };
634
- }
635
- else {
636
- const sRGBExtension = this._gl.getExtension("EXT_sRGB");
637
- if (sRGBExtension != null) {
638
- this._caps.supportSRGBBuffers = true;
639
- this._glSRGBExtensionValues = {
640
- SRGB: sRGBExtension.SRGB_EXT,
641
- SRGB8: sRGBExtension.SRGB_ALPHA_EXT,
642
- SRGB8_ALPHA8: sRGBExtension.SRGB_ALPHA_EXT,
643
- };
644
- }
645
- }
646
- // take into account the forced state that was provided in options
647
- if (this._creationOptions) {
648
- const forceSRGBBufferSupportState = this._creationOptions.forceSRGBBufferSupportState;
649
- if (forceSRGBBufferSupportState !== undefined) {
650
- this._caps.supportSRGBBuffers = this._caps.supportSRGBBuffers && forceSRGBBufferSupportState;
651
- }
652
- }
653
- }
654
- // Depth buffer
655
- this._depthCullingState.depthTest = true;
656
- this._depthCullingState.depthFunc = this._gl.LEQUAL;
657
- this._depthCullingState.depthMask = true;
658
- // Texture maps
659
- this._maxSimultaneousTextures = this._caps.maxCombinedTexturesImageUnits;
660
- for (let slot = 0; slot < this._maxSimultaneousTextures; slot++) {
661
- this._nextFreeTextureSlots.push(slot);
662
- }
663
- if (this._glRenderer === "Mali-G72") {
664
- // Overcome a bug when using a texture to store morph targets on Mali-G72
665
- this._caps.disableMorphTargetTexture = true;
666
- }
667
- }
668
- _initFeatures() {
669
- this._features = {
670
- forceBitmapOverHTMLImageElement: typeof HTMLImageElement === "undefined",
671
- supportRenderAndCopyToLodForFloatTextures: this._webGLVersion !== 1,
672
- supportDepthStencilTexture: this._webGLVersion !== 1,
673
- supportShadowSamplers: this._webGLVersion !== 1,
674
- uniformBufferHardCheckMatrix: false,
675
- allowTexturePrefiltering: this._webGLVersion !== 1,
676
- trackUbosInFrame: false,
677
- checkUbosContentBeforeUpload: false,
678
- supportCSM: this._webGLVersion !== 1,
679
- basisNeedsPOT: this._webGLVersion === 1,
680
- support3DTextures: this._webGLVersion !== 1,
681
- needTypeSuffixInShaderConstants: this._webGLVersion !== 1,
682
- supportMSAA: this._webGLVersion !== 1,
683
- supportSSAO2: this._webGLVersion !== 1,
684
- supportIBLShadows: this._webGLVersion !== 1,
685
- supportExtendedTextureFormats: this._webGLVersion !== 1,
686
- supportSwitchCaseInShader: this._webGLVersion !== 1,
687
- supportSyncTextureRead: true,
688
- needsInvertingBitmap: true,
689
- useUBOBindingCache: true,
690
- needShaderCodeInlining: false,
691
- needToAlwaysBindUniformBuffers: false,
692
- supportRenderPasses: false,
693
- supportSpriteInstancing: true,
694
- forceVertexBufferStrideAndOffsetMultiple4Bytes: false,
695
- _checkNonFloatVertexBuffersDontRecreatePipelineContext: false,
696
- _collectUbosUpdatedInFrame: false,
697
- };
698
- }
699
- /**
700
- * Gets version of the current webGL context
701
- * Keep it for back compat - use version instead
702
- */
703
- get webGLVersion() {
704
- return this._webGLVersion;
705
- }
706
- /**
707
- * Gets a string identifying the name of the class
708
- * @returns "Engine" string
709
- */
710
- getClassName() {
711
- return "ThinEngine";
712
- }
713
- /** @internal */
714
- _prepareWorkingCanvas() {
715
- if (this._workingCanvas) {
716
- return;
717
- }
718
- this._workingCanvas = this.createCanvas(1, 1);
719
- const context = this._workingCanvas.getContext("2d");
720
- if (context) {
721
- this._workingContext = context;
722
- }
723
- }
724
- /**
725
- * Gets an object containing information about the current engine context
726
- * @returns an object containing the vendor, the renderer and the version of the current engine context
727
- */
728
- getInfo() {
729
- return this.getGlInfo();
730
- }
731
- /**
732
- * Gets an object containing information about the current webGL context
733
- * @returns an object containing the vendor, the renderer and the version of the current webGL context
734
- */
735
- getGlInfo() {
736
- return {
737
- vendor: this._glVendor,
738
- renderer: this._glRenderer,
739
- version: this._glVersion,
740
- };
741
- }
742
- /**Gets driver info if available */
743
- extractDriverInfo() {
744
- const glInfo = this.getGlInfo();
745
- if (glInfo && glInfo.renderer) {
746
- return glInfo.renderer;
747
- }
748
- return "";
749
- }
750
- /**
751
- * Gets the current render width
752
- * @param useScreen defines if screen size must be used (or the current render target if any)
753
- * @returns a number defining the current render width
754
- */
755
- getRenderWidth(useScreen = false) {
756
- if (!useScreen && this._currentRenderTarget) {
757
- return this._currentRenderTarget.width;
758
- }
759
- return this._framebufferDimensionsObject ? this._framebufferDimensionsObject.framebufferWidth : this._gl.drawingBufferWidth;
760
- }
761
- /**
762
- * Gets the current render height
763
- * @param useScreen defines if screen size must be used (or the current render target if any)
764
- * @returns a number defining the current render height
765
- */
766
- getRenderHeight(useScreen = false) {
767
- if (!useScreen && this._currentRenderTarget) {
768
- return this._currentRenderTarget.height;
769
- }
770
- return this._framebufferDimensionsObject ? this._framebufferDimensionsObject.framebufferHeight : this._gl.drawingBufferHeight;
771
- }
772
- /**
773
- * Clear the current render buffer or the current render target (if any is set up)
774
- * @param color defines the color to use
775
- * @param backBuffer defines if the back buffer must be cleared
776
- * @param depth defines if the depth buffer must be cleared
777
- * @param stencil defines if the stencil buffer must be cleared
778
- */
779
- clear(color, backBuffer, depth, stencil = false) {
780
- const useStencilGlobalOnly = this.stencilStateComposer.useStencilGlobalOnly;
781
- this.stencilStateComposer.useStencilGlobalOnly = true; // make sure the stencil mask is coming from the global stencil and not from a material (effect) which would currently be in effect
782
- this.applyStates();
783
- this.stencilStateComposer.useStencilGlobalOnly = useStencilGlobalOnly;
784
- let mode = 0;
785
- if (backBuffer && color) {
786
- let setBackBufferColor = true;
787
- if (this._currentRenderTarget) {
788
- const textureFormat = this._currentRenderTarget.texture?.format;
789
- if (textureFormat === Constants.TEXTUREFORMAT_RED_INTEGER ||
790
- textureFormat === Constants.TEXTUREFORMAT_RG_INTEGER ||
791
- textureFormat === Constants.TEXTUREFORMAT_RGB_INTEGER ||
792
- textureFormat === Constants.TEXTUREFORMAT_RGBA_INTEGER) {
793
- const textureType = this._currentRenderTarget.texture?.type;
794
- if (textureType === Constants.TEXTURETYPE_UNSIGNED_INTEGER || textureType === Constants.TEXTURETYPE_UNSIGNED_SHORT) {
795
- ThinEngine._TempClearColorUint32[0] = color.r * 255;
796
- ThinEngine._TempClearColorUint32[1] = color.g * 255;
797
- ThinEngine._TempClearColorUint32[2] = color.b * 255;
798
- ThinEngine._TempClearColorUint32[3] = color.a * 255;
799
- this._gl.clearBufferuiv(this._gl.COLOR, 0, ThinEngine._TempClearColorUint32);
800
- setBackBufferColor = false;
801
- }
802
- else {
803
- ThinEngine._TempClearColorInt32[0] = color.r * 255;
804
- ThinEngine._TempClearColorInt32[1] = color.g * 255;
805
- ThinEngine._TempClearColorInt32[2] = color.b * 255;
806
- ThinEngine._TempClearColorInt32[3] = color.a * 255;
807
- this._gl.clearBufferiv(this._gl.COLOR, 0, ThinEngine._TempClearColorInt32);
808
- setBackBufferColor = false;
809
- }
810
- }
811
- }
812
- if (setBackBufferColor) {
813
- this._gl.clearColor(color.r, color.g, color.b, color.a !== undefined ? color.a : 1.0);
814
- mode |= this._gl.COLOR_BUFFER_BIT;
815
- }
816
- }
817
- if (depth) {
818
- if (this.useReverseDepthBuffer) {
819
- this._depthCullingState.depthFunc = this._gl.GEQUAL;
820
- this._gl.clearDepth(0.0);
821
- }
822
- else {
823
- this._gl.clearDepth(1.0);
824
- }
825
- mode |= this._gl.DEPTH_BUFFER_BIT;
826
- }
827
- if (stencil) {
828
- this._gl.clearStencil(0);
829
- mode |= this._gl.STENCIL_BUFFER_BIT;
830
- }
831
- this._gl.clear(mode);
832
- }
833
- /**
834
- * @internal
835
- */
836
- _viewport(x, y, width, height) {
837
- if (x !== this._viewportCached.x || y !== this._viewportCached.y || width !== this._viewportCached.z || height !== this._viewportCached.w) {
838
- this._viewportCached.x = x;
839
- this._viewportCached.y = y;
840
- this._viewportCached.z = width;
841
- this._viewportCached.w = height;
842
- this._gl.viewport(x, y, width, height);
843
- }
844
- }
845
- /**
846
- * End the current frame
847
- */
848
- endFrame() {
849
- super.endFrame();
850
- // Force a flush in case we are using a bad OS.
851
- if (this._badOS) {
852
- this.flushFramebuffer();
853
- }
854
- }
855
- /**
856
- * Gets the performance monitor attached to this engine
857
- * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimize_your_scene#engineinstrumentation
858
- */
859
- get performanceMonitor() {
860
- throw new Error("Not Supported by ThinEngine");
861
- }
862
- /**
863
- * Binds the frame buffer to the specified texture.
864
- * @param rtWrapper The render target wrapper to render to
865
- * @param faceIndex The face of the texture to render to in case of cube texture and if the render target wrapper is not a multi render target
866
- * @param requiredWidth The width of the target to render to
867
- * @param requiredHeight The height of the target to render to
868
- * @param forceFullscreenViewport Forces the viewport to be the entire texture/screen if true
869
- * @param lodLevel Defines the lod level to bind to the frame buffer
870
- * @param layer Defines the 2d array index to bind to the frame buffer if the render target wrapper is not a multi render target
871
- */
872
- bindFramebuffer(rtWrapper, faceIndex = 0, requiredWidth, requiredHeight, forceFullscreenViewport, lodLevel = 0, layer = 0) {
873
- const webglRTWrapper = rtWrapper;
874
- if (this._currentRenderTarget) {
875
- this.unBindFramebuffer(this._currentRenderTarget);
876
- }
877
- this._currentRenderTarget = rtWrapper;
878
- this._bindUnboundFramebuffer(webglRTWrapper._framebuffer);
879
- const gl = this._gl;
880
- if (!rtWrapper.isMulti) {
881
- if (rtWrapper.is2DArray || rtWrapper.is3D) {
882
- gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, rtWrapper.texture._hardwareTexture?.underlyingResource, lodLevel, layer);
883
- webglRTWrapper._currentLOD = lodLevel;
884
- }
885
- else if (rtWrapper.isCube) {
886
- gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, rtWrapper.texture._hardwareTexture?.underlyingResource, lodLevel);
887
- }
888
- else if (webglRTWrapper._currentLOD !== lodLevel) {
889
- gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, rtWrapper.texture._hardwareTexture?.underlyingResource, lodLevel);
890
- webglRTWrapper._currentLOD = lodLevel;
891
- }
892
- }
893
- const depthStencilTexture = rtWrapper._depthStencilTexture;
894
- if (depthStencilTexture) {
895
- if (rtWrapper.is3D) {
896
- if (rtWrapper.texture.width !== depthStencilTexture.width ||
897
- rtWrapper.texture.height !== depthStencilTexture.height ||
898
- rtWrapper.texture.depth !== depthStencilTexture.depth) {
899
- Logger.Warn("Depth/Stencil attachment for 3D target must have same dimensions as color attachment");
900
- }
901
- }
902
- const attachment = rtWrapper._depthStencilTextureWithStencil ? gl.DEPTH_STENCIL_ATTACHMENT : gl.DEPTH_ATTACHMENT;
903
- if (rtWrapper.is2DArray || rtWrapper.is3D) {
904
- gl.framebufferTextureLayer(gl.FRAMEBUFFER, attachment, depthStencilTexture._hardwareTexture?.underlyingResource, lodLevel, layer);
905
- }
906
- else if (rtWrapper.isCube) {
907
- gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, depthStencilTexture._hardwareTexture?.underlyingResource, lodLevel);
908
- }
909
- else {
910
- gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D, depthStencilTexture._hardwareTexture?.underlyingResource, lodLevel);
911
- }
912
- }
913
- if (webglRTWrapper._MSAAFramebuffer) {
914
- this._bindUnboundFramebuffer(webglRTWrapper._MSAAFramebuffer);
915
- }
916
- if (this._cachedViewport && !forceFullscreenViewport) {
917
- this.setViewport(this._cachedViewport, requiredWidth, requiredHeight);
918
- }
919
- else {
920
- if (!requiredWidth) {
921
- requiredWidth = rtWrapper.width;
922
- if (lodLevel) {
923
- requiredWidth = requiredWidth / Math.pow(2, lodLevel);
924
- }
925
- }
926
- if (!requiredHeight) {
927
- requiredHeight = rtWrapper.height;
928
- if (lodLevel) {
929
- requiredHeight = requiredHeight / Math.pow(2, lodLevel);
930
- }
931
- }
932
- this._viewport(0, 0, requiredWidth, requiredHeight);
933
- }
934
- this.wipeCaches();
935
- }
936
- /**
937
- * Set various states to the webGL context
938
- * @param culling defines culling state: true to enable culling, false to disable it
939
- * @param zOffset defines the value to apply to zOffset (0 by default)
940
- * @param force defines if states must be applied even if cache is up to date
941
- * @param reverseSide defines if culling must be reversed (CCW if false, CW if true)
942
- * @param cullBackFaces true to cull back faces, false to cull front faces (if culling is enabled)
943
- * @param stencil stencil states to set
944
- * @param zOffsetUnits defines the value to apply to zOffsetUnits (0 by default)
945
- */
946
- setState(culling, zOffset = 0, force, reverseSide = false, cullBackFaces, stencil, zOffsetUnits = 0) {
947
- // Culling
948
- if (this._depthCullingState.cull !== culling || force) {
949
- this._depthCullingState.cull = culling;
950
- }
951
- // Cull face
952
- const cullFace = (this.cullBackFaces ?? cullBackFaces ?? true) ? this._gl.BACK : this._gl.FRONT;
953
- if (this._depthCullingState.cullFace !== cullFace || force) {
954
- this._depthCullingState.cullFace = cullFace;
955
- }
956
- // Z offset
957
- this.setZOffset(zOffset);
958
- this.setZOffsetUnits(zOffsetUnits);
959
- // Front face
960
- const frontFace = reverseSide ? this._gl.CW : this._gl.CCW;
961
- if (this._depthCullingState.frontFace !== frontFace || force) {
962
- this._depthCullingState.frontFace = frontFace;
963
- }
964
- this._stencilStateComposer.stencilMaterial = stencil;
965
- }
966
- /**
967
- * @internal
968
- */
969
- _bindUnboundFramebuffer(framebuffer) {
970
- if (this._currentFramebuffer !== framebuffer) {
971
- this._gl.bindFramebuffer(this._gl.FRAMEBUFFER, framebuffer);
972
- this._currentFramebuffer = framebuffer;
973
- }
974
- }
975
- /** @internal */
976
- _currentFrameBufferIsDefaultFrameBuffer() {
977
- return this._currentFramebuffer === null;
978
- }
979
- /**
980
- * Generates the mipmaps for a texture
981
- * @param texture texture to generate the mipmaps for
982
- */
983
- generateMipmaps(texture) {
984
- const target = this._getTextureTarget(texture);
985
- this._bindTextureDirectly(target, texture, true);
986
- this._gl.generateMipmap(target);
987
- this._bindTextureDirectly(target, null);
988
- }
989
- /**
990
- * Unbind the current render target texture from the webGL context
991
- * @param texture defines the render target wrapper to unbind
992
- * @param disableGenerateMipMaps defines a boolean indicating that mipmaps must not be generated
993
- * @param onBeforeUnbind defines a function which will be called before the effective unbind
994
- */
995
- unBindFramebuffer(texture, disableGenerateMipMaps = false, onBeforeUnbind) {
996
- const webglRTWrapper = texture;
997
- this._currentRenderTarget = null;
998
- // If MSAA, we need to bitblt back to main texture
999
- const gl = this._gl;
1000
- if (webglRTWrapper._MSAAFramebuffer) {
1001
- if (texture.isMulti) {
1002
- // This texture is part of a MRT texture, we need to treat all attachments
1003
- this.unBindMultiColorAttachmentFramebuffer(texture, disableGenerateMipMaps, onBeforeUnbind);
1004
- return;
1005
- }
1006
- gl.bindFramebuffer(gl.READ_FRAMEBUFFER, webglRTWrapper._MSAAFramebuffer);
1007
- gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, webglRTWrapper._framebuffer);
1008
- gl.blitFramebuffer(0, 0, texture.width, texture.height, 0, 0, texture.width, texture.height, gl.COLOR_BUFFER_BIT, gl.NEAREST);
1009
- }
1010
- if (texture.texture?.generateMipMaps && !disableGenerateMipMaps && !texture.isCube) {
1011
- this.generateMipmaps(texture.texture);
1012
- }
1013
- if (onBeforeUnbind) {
1014
- if (webglRTWrapper._MSAAFramebuffer) {
1015
- // Bind the correct framebuffer
1016
- this._bindUnboundFramebuffer(webglRTWrapper._framebuffer);
1017
- }
1018
- onBeforeUnbind();
1019
- }
1020
- this._bindUnboundFramebuffer(null);
1021
- }
1022
- /**
1023
- * Force a webGL flush (ie. a flush of all waiting webGL commands)
1024
- */
1025
- flushFramebuffer() {
1026
- this._gl.flush();
1027
- }
1028
- /**
1029
- * Unbind the current render target and bind the default framebuffer
1030
- */
1031
- restoreDefaultFramebuffer() {
1032
- if (this._currentRenderTarget) {
1033
- this.unBindFramebuffer(this._currentRenderTarget);
1034
- }
1035
- else {
1036
- this._bindUnboundFramebuffer(null);
1037
- }
1038
- if (this._cachedViewport) {
1039
- this.setViewport(this._cachedViewport);
1040
- }
1041
- this.wipeCaches();
1042
- }
1043
- // VBOs
1044
- /** @internal */
1045
- _resetVertexBufferBinding() {
1046
- this.bindArrayBuffer(null);
1047
- this._cachedVertexBuffers = null;
1048
- }
1049
- /**
1050
- * Creates a vertex buffer
1051
- * @param data the data or size for the vertex buffer
1052
- * @param _updatable whether the buffer should be created as updatable
1053
- * @param _label defines the label of the buffer (for debug purpose)
1054
- * @returns the new WebGL static buffer
1055
- */
1056
- createVertexBuffer(data, _updatable, _label) {
1057
- return this._createVertexBuffer(data, this._gl.STATIC_DRAW);
1058
- }
1059
- _createVertexBuffer(data, usage) {
1060
- const vbo = this._gl.createBuffer();
1061
- if (!vbo) {
1062
- throw new Error("Unable to create vertex buffer");
1063
- }
1064
- const dataBuffer = new WebGLDataBuffer(vbo);
1065
- this.bindArrayBuffer(dataBuffer);
1066
- if (typeof data !== "number") {
1067
- if (data instanceof Array) {
1068
- this._gl.bufferData(this._gl.ARRAY_BUFFER, new Float32Array(data), usage);
1069
- dataBuffer.capacity = data.length * 4;
1070
- }
1071
- else {
1072
- this._gl.bufferData(this._gl.ARRAY_BUFFER, data, usage);
1073
- dataBuffer.capacity = data.byteLength;
1074
- }
1075
- }
1076
- else {
1077
- this._gl.bufferData(this._gl.ARRAY_BUFFER, new Uint8Array(data), usage);
1078
- dataBuffer.capacity = data;
1079
- }
1080
- this._resetVertexBufferBinding();
1081
- dataBuffer.references = 1;
1082
- return dataBuffer;
1083
- }
1084
- /**
1085
- * Creates a dynamic vertex buffer
1086
- * @param data the data for the dynamic vertex buffer
1087
- * @param _label defines the label of the buffer (for debug purpose)
1088
- * @returns the new WebGL dynamic buffer
1089
- */
1090
- createDynamicVertexBuffer(data, _label) {
1091
- return this._createVertexBuffer(data, this._gl.DYNAMIC_DRAW);
1092
- }
1093
- _resetIndexBufferBinding() {
1094
- this.bindIndexBuffer(null);
1095
- this._cachedIndexBuffer = null;
1096
- }
1097
- /**
1098
- * Creates a new index buffer
1099
- * @param indices defines the content of the index buffer
1100
- * @param updatable defines if the index buffer must be updatable
1101
- * @param _label defines the label of the buffer (for debug purpose)
1102
- * @returns a new webGL buffer
1103
- */
1104
- createIndexBuffer(indices, updatable, _label) {
1105
- const vbo = this._gl.createBuffer();
1106
- const dataBuffer = new WebGLDataBuffer(vbo);
1107
- if (!vbo) {
1108
- throw new Error("Unable to create index buffer");
1109
- }
1110
- this.bindIndexBuffer(dataBuffer);
1111
- const data = this._normalizeIndexData(indices);
1112
- this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER, data, updatable ? this._gl.DYNAMIC_DRAW : this._gl.STATIC_DRAW);
1113
- this._resetIndexBufferBinding();
1114
- dataBuffer.references = 1;
1115
- dataBuffer.is32Bits = data.BYTES_PER_ELEMENT === 4;
1116
- return dataBuffer;
1117
- }
1118
- _normalizeIndexData(indices) {
1119
- const bytesPerElement = indices.BYTES_PER_ELEMENT;
1120
- if (bytesPerElement === 2) {
1121
- return indices;
1122
- }
1123
- // Check 32 bit support
1124
- if (this._caps.uintIndices) {
1125
- if (indices instanceof Uint32Array) {
1126
- return indices;
1127
- }
1128
- else {
1129
- // number[] or Int32Array, check if 32 bit is necessary
1130
- for (let index = 0; index < indices.length; index++) {
1131
- if (indices[index] >= 65535) {
1132
- return new Uint32Array(indices);
1133
- }
1134
- }
1135
- return new Uint16Array(indices);
1136
- }
1137
- }
1138
- // No 32 bit support, force conversion to 16 bit (values greater 16 bit are lost)
1139
- return new Uint16Array(indices);
1140
- }
1141
- /**
1142
- * Bind a webGL buffer to the webGL context
1143
- * @param buffer defines the buffer to bind
1144
- */
1145
- bindArrayBuffer(buffer) {
1146
- if (!this._vaoRecordInProgress) {
1147
- this._unbindVertexArrayObject();
1148
- }
1149
- this._bindBuffer(buffer, this._gl.ARRAY_BUFFER);
1150
- }
1151
- /**
1152
- * Bind a specific block at a given index in a specific shader program
1153
- * @param pipelineContext defines the pipeline context to use
1154
- * @param blockName defines the block name
1155
- * @param index defines the index where to bind the block
1156
- */
1157
- bindUniformBlock(pipelineContext, blockName, index) {
1158
- const program = pipelineContext.program;
1159
- const uniformLocation = this._gl.getUniformBlockIndex(program, blockName);
1160
- this._gl.uniformBlockBinding(program, uniformLocation, index);
1161
- }
1162
- // eslint-disable-next-line @typescript-eslint/naming-convention
1163
- bindIndexBuffer(buffer) {
1164
- if (!this._vaoRecordInProgress) {
1165
- this._unbindVertexArrayObject();
1166
- }
1167
- this._bindBuffer(buffer, this._gl.ELEMENT_ARRAY_BUFFER);
1168
- }
1169
- _bindBuffer(buffer, target) {
1170
- if (this._vaoRecordInProgress || this._currentBoundBuffer[target] !== buffer) {
1171
- this._gl.bindBuffer(target, buffer ? buffer.underlyingResource : null);
1172
- this._currentBoundBuffer[target] = buffer;
1173
- }
1174
- }
1175
- /**
1176
- * update the bound buffer with the given data
1177
- * @param data defines the data to update
1178
- */
1179
- updateArrayBuffer(data) {
1180
- this._gl.bufferSubData(this._gl.ARRAY_BUFFER, 0, data);
1181
- }
1182
- _vertexAttribPointer(buffer, indx, size, type, normalized, stride, offset) {
1183
- const pointer = this._currentBufferPointers[indx];
1184
- if (!pointer) {
1185
- return;
1186
- }
1187
- let changed = false;
1188
- if (!pointer.active) {
1189
- changed = true;
1190
- pointer.active = true;
1191
- pointer.index = indx;
1192
- pointer.size = size;
1193
- pointer.type = type;
1194
- pointer.normalized = normalized;
1195
- pointer.stride = stride;
1196
- pointer.offset = offset;
1197
- pointer.buffer = buffer;
1198
- }
1199
- else {
1200
- if (pointer.buffer !== buffer) {
1201
- pointer.buffer = buffer;
1202
- changed = true;
1203
- }
1204
- if (pointer.size !== size) {
1205
- pointer.size = size;
1206
- changed = true;
1207
- }
1208
- if (pointer.type !== type) {
1209
- pointer.type = type;
1210
- changed = true;
1211
- }
1212
- if (pointer.normalized !== normalized) {
1213
- pointer.normalized = normalized;
1214
- changed = true;
1215
- }
1216
- if (pointer.stride !== stride) {
1217
- pointer.stride = stride;
1218
- changed = true;
1219
- }
1220
- if (pointer.offset !== offset) {
1221
- pointer.offset = offset;
1222
- changed = true;
1223
- }
1224
- }
1225
- if (changed || this._vaoRecordInProgress) {
1226
- this.bindArrayBuffer(buffer);
1227
- if (type === this._gl.UNSIGNED_INT || type === this._gl.INT) {
1228
- this._gl.vertexAttribIPointer(indx, size, type, stride, offset);
1229
- }
1230
- else {
1231
- this._gl.vertexAttribPointer(indx, size, type, normalized, stride, offset);
1232
- }
1233
- }
1234
- }
1235
- /**
1236
- * @internal
1237
- */
1238
- _bindIndexBufferWithCache(indexBuffer) {
1239
- if (indexBuffer == null) {
1240
- return;
1241
- }
1242
- if (this._cachedIndexBuffer !== indexBuffer) {
1243
- this._cachedIndexBuffer = indexBuffer;
1244
- this.bindIndexBuffer(indexBuffer);
1245
- this._uintIndicesCurrentlySet = indexBuffer.is32Bits;
1246
- }
1247
- }
1248
- _bindVertexBuffersAttributes(vertexBuffers, effect, overrideVertexBuffers) {
1249
- const attributes = effect.getAttributesNames();
1250
- if (!this._vaoRecordInProgress) {
1251
- this._unbindVertexArrayObject();
1252
- }
1253
- this.unbindAllAttributes();
1254
- for (let index = 0; index < attributes.length; index++) {
1255
- const order = effect.getAttributeLocation(index);
1256
- if (order >= 0) {
1257
- const ai = attributes[index];
1258
- let vertexBuffer = null;
1259
- if (overrideVertexBuffers) {
1260
- vertexBuffer = overrideVertexBuffers[ai];
1261
- }
1262
- if (!vertexBuffer) {
1263
- vertexBuffer = vertexBuffers[ai];
1264
- }
1265
- if (!vertexBuffer) {
1266
- continue;
1267
- }
1268
- this._gl.enableVertexAttribArray(order);
1269
- if (!this._vaoRecordInProgress) {
1270
- this._vertexAttribArraysEnabled[order] = true;
1271
- }
1272
- const buffer = vertexBuffer.getBuffer();
1273
- if (buffer) {
1274
- this._vertexAttribPointer(buffer, order, vertexBuffer.getSize(), vertexBuffer.type, vertexBuffer.normalized, vertexBuffer.byteStride, vertexBuffer.byteOffset);
1275
- if (vertexBuffer.getIsInstanced()) {
1276
- this._gl.vertexAttribDivisor(order, vertexBuffer.getInstanceDivisor());
1277
- if (!this._vaoRecordInProgress) {
1278
- this._currentInstanceLocations.push(order);
1279
- this._currentInstanceBuffers.push(buffer);
1280
- }
1281
- }
1282
- }
1283
- }
1284
- }
1285
- }
1286
- /**
1287
- * Records a vertex array object
1288
- * @see https://doc.babylonjs.com/setup/support/webGL2#vertex-array-objects
1289
- * @param vertexBuffers defines the list of vertex buffers to store
1290
- * @param indexBuffer defines the index buffer to store
1291
- * @param effect defines the effect to store
1292
- * @param overrideVertexBuffers defines optional list of avertex buffers that overrides the entries in vertexBuffers
1293
- * @returns the new vertex array object
1294
- */
1295
- recordVertexArrayObject(vertexBuffers, indexBuffer, effect, overrideVertexBuffers) {
1296
- const vao = this._gl.createVertexArray();
1297
- if (!vao) {
1298
- throw new Error("Unable to create VAO");
1299
- }
1300
- this._vaoRecordInProgress = true;
1301
- this._gl.bindVertexArray(vao);
1302
- this._mustWipeVertexAttributes = true;
1303
- this._bindVertexBuffersAttributes(vertexBuffers, effect, overrideVertexBuffers);
1304
- this.bindIndexBuffer(indexBuffer);
1305
- this._vaoRecordInProgress = false;
1306
- this._gl.bindVertexArray(null);
1307
- return vao;
1308
- }
1309
- /**
1310
- * Bind a specific vertex array object
1311
- * @see https://doc.babylonjs.com/setup/support/webGL2#vertex-array-objects
1312
- * @param vertexArrayObject defines the vertex array object to bind
1313
- * @param indexBuffer defines the index buffer to bind
1314
- */
1315
- bindVertexArrayObject(vertexArrayObject, indexBuffer) {
1316
- if (this._cachedVertexArrayObject !== vertexArrayObject) {
1317
- this._cachedVertexArrayObject = vertexArrayObject;
1318
- this._gl.bindVertexArray(vertexArrayObject);
1319
- this._cachedVertexBuffers = null;
1320
- this._cachedIndexBuffer = null;
1321
- this._uintIndicesCurrentlySet = indexBuffer != null && indexBuffer.is32Bits;
1322
- this._mustWipeVertexAttributes = true;
1323
- }
1324
- }
1325
- /**
1326
- * Bind webGl buffers directly to the webGL context
1327
- * @param vertexBuffer defines the vertex buffer to bind
1328
- * @param indexBuffer defines the index buffer to bind
1329
- * @param vertexDeclaration defines the vertex declaration to use with the vertex buffer
1330
- * @param vertexStrideSize defines the vertex stride of the vertex buffer
1331
- * @param effect defines the effect associated with the vertex buffer
1332
- */
1333
- bindBuffersDirectly(vertexBuffer, indexBuffer, vertexDeclaration, vertexStrideSize, effect) {
1334
- if (this._cachedVertexBuffers !== vertexBuffer || this._cachedEffectForVertexBuffers !== effect) {
1335
- this._cachedVertexBuffers = vertexBuffer;
1336
- this._cachedEffectForVertexBuffers = effect;
1337
- const attributesCount = effect.getAttributesCount();
1338
- this._unbindVertexArrayObject();
1339
- this.unbindAllAttributes();
1340
- let offset = 0;
1341
- for (let index = 0; index < attributesCount; index++) {
1342
- if (index < vertexDeclaration.length) {
1343
- const order = effect.getAttributeLocation(index);
1344
- if (order >= 0) {
1345
- this._gl.enableVertexAttribArray(order);
1346
- this._vertexAttribArraysEnabled[order] = true;
1347
- this._vertexAttribPointer(vertexBuffer, order, vertexDeclaration[index], this._gl.FLOAT, false, vertexStrideSize, offset);
1348
- }
1349
- offset += vertexDeclaration[index] * 4;
1350
- }
1351
- }
1352
- }
1353
- this._bindIndexBufferWithCache(indexBuffer);
1354
- }
1355
- _unbindVertexArrayObject() {
1356
- if (!this._cachedVertexArrayObject) {
1357
- return;
1358
- }
1359
- this._cachedVertexArrayObject = null;
1360
- this._gl.bindVertexArray(null);
1361
- }
1362
- /**
1363
- * Bind a list of vertex buffers to the webGL context
1364
- * @param vertexBuffers defines the list of vertex buffers to bind
1365
- * @param indexBuffer defines the index buffer to bind
1366
- * @param effect defines the effect associated with the vertex buffers
1367
- * @param overrideVertexBuffers defines optional list of avertex buffers that overrides the entries in vertexBuffers
1368
- */
1369
- bindBuffers(vertexBuffers, indexBuffer, effect, overrideVertexBuffers) {
1370
- if (this._cachedVertexBuffers !== vertexBuffers || this._cachedEffectForVertexBuffers !== effect) {
1371
- this._cachedVertexBuffers = vertexBuffers;
1372
- this._cachedEffectForVertexBuffers = effect;
1373
- this._bindVertexBuffersAttributes(vertexBuffers, effect, overrideVertexBuffers);
1374
- }
1375
- this._bindIndexBufferWithCache(indexBuffer);
1376
- }
1377
- /**
1378
- * Unbind all instance attributes
1379
- */
1380
- unbindInstanceAttributes() {
1381
- let boundBuffer;
1382
- for (let i = 0, ul = this._currentInstanceLocations.length; i < ul; i++) {
1383
- const instancesBuffer = this._currentInstanceBuffers[i];
1384
- if (boundBuffer != instancesBuffer && instancesBuffer.references) {
1385
- boundBuffer = instancesBuffer;
1386
- this.bindArrayBuffer(instancesBuffer);
1387
- }
1388
- const offsetLocation = this._currentInstanceLocations[i];
1389
- this._gl.vertexAttribDivisor(offsetLocation, 0);
1390
- }
1391
- this._currentInstanceBuffers.length = 0;
1392
- this._currentInstanceLocations.length = 0;
1393
- }
1394
- /**
1395
- * Release and free the memory of a vertex array object
1396
- * @param vao defines the vertex array object to delete
1397
- */
1398
- releaseVertexArrayObject(vao) {
1399
- this._gl.deleteVertexArray(vao);
1400
- }
1401
- /**
1402
- * @internal
1403
- */
1404
- _releaseBuffer(buffer) {
1405
- buffer.references--;
1406
- if (buffer.references === 0) {
1407
- this._deleteBuffer(buffer);
1408
- return true;
1409
- }
1410
- return false;
1411
- }
1412
- _deleteBuffer(buffer) {
1413
- this._gl.deleteBuffer(buffer.underlyingResource);
1414
- }
1415
- /**
1416
- * Update the content of a webGL buffer used with instantiation and bind it to the webGL context
1417
- * @param instancesBuffer defines the webGL buffer to update and bind
1418
- * @param data defines the data to store in the buffer
1419
- * @param offsetLocations defines the offsets or attributes information used to determine where data must be stored in the buffer
1420
- */
1421
- updateAndBindInstancesBuffer(instancesBuffer, data, offsetLocations) {
1422
- this.bindArrayBuffer(instancesBuffer);
1423
- if (data) {
1424
- this._gl.bufferSubData(this._gl.ARRAY_BUFFER, 0, data);
1425
- }
1426
- if (offsetLocations[0].index !== undefined) {
1427
- this.bindInstancesBuffer(instancesBuffer, offsetLocations, true);
1428
- }
1429
- else {
1430
- for (let index = 0; index < 4; index++) {
1431
- const offsetLocation = offsetLocations[index];
1432
- if (!this._vertexAttribArraysEnabled[offsetLocation]) {
1433
- this._gl.enableVertexAttribArray(offsetLocation);
1434
- this._vertexAttribArraysEnabled[offsetLocation] = true;
1435
- }
1436
- this._vertexAttribPointer(instancesBuffer, offsetLocation, 4, this._gl.FLOAT, false, 64, index * 16);
1437
- this._gl.vertexAttribDivisor(offsetLocation, 1);
1438
- this._currentInstanceLocations.push(offsetLocation);
1439
- this._currentInstanceBuffers.push(instancesBuffer);
1440
- }
1441
- }
1442
- }
1443
- /**
1444
- * Bind the content of a webGL buffer used with instantiation
1445
- * @param instancesBuffer defines the webGL buffer to bind
1446
- * @param attributesInfo defines the offsets or attributes information used to determine where data must be stored in the buffer
1447
- * @param computeStride defines Whether to compute the strides from the info or use the default 0
1448
- */
1449
- bindInstancesBuffer(instancesBuffer, attributesInfo, computeStride = true) {
1450
- this.bindArrayBuffer(instancesBuffer);
1451
- let stride = 0;
1452
- if (computeStride) {
1453
- for (let i = 0; i < attributesInfo.length; i++) {
1454
- const ai = attributesInfo[i];
1455
- stride += ai.attributeSize * 4;
1456
- }
1457
- }
1458
- for (let i = 0; i < attributesInfo.length; i++) {
1459
- const ai = attributesInfo[i];
1460
- if (ai.index === undefined) {
1461
- ai.index = this._currentEffect.getAttributeLocationByName(ai.attributeName);
1462
- }
1463
- if (ai.index < 0) {
1464
- continue;
1465
- }
1466
- if (!this._vertexAttribArraysEnabled[ai.index]) {
1467
- this._gl.enableVertexAttribArray(ai.index);
1468
- this._vertexAttribArraysEnabled[ai.index] = true;
1469
- }
1470
- this._vertexAttribPointer(instancesBuffer, ai.index, ai.attributeSize, ai.attributeType || this._gl.FLOAT, ai.normalized || false, stride, ai.offset);
1471
- this._gl.vertexAttribDivisor(ai.index, ai.divisor === undefined ? 1 : ai.divisor);
1472
- this._currentInstanceLocations.push(ai.index);
1473
- this._currentInstanceBuffers.push(instancesBuffer);
1474
- }
1475
- }
1476
- /**
1477
- * Disable the instance attribute corresponding to the name in parameter
1478
- * @param name defines the name of the attribute to disable
1479
- */
1480
- disableInstanceAttributeByName(name) {
1481
- if (!this._currentEffect) {
1482
- return;
1483
- }
1484
- const attributeLocation = this._currentEffect.getAttributeLocationByName(name);
1485
- this.disableInstanceAttribute(attributeLocation);
1486
- }
1487
- /**
1488
- * Disable the instance attribute corresponding to the location in parameter
1489
- * @param attributeLocation defines the attribute location of the attribute to disable
1490
- */
1491
- disableInstanceAttribute(attributeLocation) {
1492
- let shouldClean = false;
1493
- let index;
1494
- while ((index = this._currentInstanceLocations.indexOf(attributeLocation)) !== -1) {
1495
- this._currentInstanceLocations.splice(index, 1);
1496
- this._currentInstanceBuffers.splice(index, 1);
1497
- shouldClean = true;
1498
- index = this._currentInstanceLocations.indexOf(attributeLocation);
1499
- }
1500
- if (shouldClean) {
1501
- this._gl.vertexAttribDivisor(attributeLocation, 0);
1502
- this.disableAttributeByIndex(attributeLocation);
1503
- }
1504
- }
1505
- /**
1506
- * Disable the attribute corresponding to the location in parameter
1507
- * @param attributeLocation defines the attribute location of the attribute to disable
1508
- */
1509
- disableAttributeByIndex(attributeLocation) {
1510
- this._gl.disableVertexAttribArray(attributeLocation);
1511
- this._vertexAttribArraysEnabled[attributeLocation] = false;
1512
- this._currentBufferPointers[attributeLocation].active = false;
1513
- }
1514
- /**
1515
- * Send a draw order
1516
- * @param useTriangles defines if triangles must be used to draw (else wireframe will be used)
1517
- * @param indexStart defines the starting index
1518
- * @param indexCount defines the number of index to draw
1519
- * @param instancesCount defines the number of instances to draw (if instantiation is enabled)
1520
- */
1521
- draw(useTriangles, indexStart, indexCount, instancesCount) {
1522
- this.drawElementsType(useTriangles ? Constants.MATERIAL_TriangleFillMode : Constants.MATERIAL_WireFrameFillMode, indexStart, indexCount, instancesCount);
1523
- }
1524
- /**
1525
- * Draw a list of points
1526
- * @param verticesStart defines the index of first vertex to draw
1527
- * @param verticesCount defines the count of vertices to draw
1528
- * @param instancesCount defines the number of instances to draw (if instantiation is enabled)
1529
- */
1530
- drawPointClouds(verticesStart, verticesCount, instancesCount) {
1531
- this.drawArraysType(Constants.MATERIAL_PointFillMode, verticesStart, verticesCount, instancesCount);
1532
- }
1533
- /**
1534
- * Draw a list of unindexed primitives
1535
- * @param useTriangles defines if triangles must be used to draw (else wireframe will be used)
1536
- * @param verticesStart defines the index of first vertex to draw
1537
- * @param verticesCount defines the count of vertices to draw
1538
- * @param instancesCount defines the number of instances to draw (if instantiation is enabled)
1539
- */
1540
- drawUnIndexed(useTriangles, verticesStart, verticesCount, instancesCount) {
1541
- this.drawArraysType(useTriangles ? Constants.MATERIAL_TriangleFillMode : Constants.MATERIAL_WireFrameFillMode, verticesStart, verticesCount, instancesCount);
1542
- }
1543
- /**
1544
- * Draw a list of indexed primitives
1545
- * @param fillMode defines the primitive to use
1546
- * @param indexStart defines the starting index
1547
- * @param indexCount defines the number of index to draw
1548
- * @param instancesCount defines the number of instances to draw (if instantiation is enabled)
1549
- */
1550
- drawElementsType(fillMode, indexStart, indexCount, instancesCount) {
1551
- // Apply states
1552
- this.applyStates();
1553
- this._reportDrawCall();
1554
- // Render
1555
- const drawMode = this._drawMode(fillMode);
1556
- const indexFormat = this._uintIndicesCurrentlySet ? this._gl.UNSIGNED_INT : this._gl.UNSIGNED_SHORT;
1557
- const mult = this._uintIndicesCurrentlySet ? 4 : 2;
1558
- if (instancesCount) {
1559
- this._gl.drawElementsInstanced(drawMode, indexCount, indexFormat, indexStart * mult, instancesCount);
1560
- }
1561
- else {
1562
- this._gl.drawElements(drawMode, indexCount, indexFormat, indexStart * mult);
1563
- }
1564
- }
1565
- /**
1566
- * Draw a list of unindexed primitives
1567
- * @param fillMode defines the primitive to use
1568
- * @param verticesStart defines the index of first vertex to draw
1569
- * @param verticesCount defines the count of vertices to draw
1570
- * @param instancesCount defines the number of instances to draw (if instantiation is enabled)
1571
- */
1572
- drawArraysType(fillMode, verticesStart, verticesCount, instancesCount) {
1573
- // Apply states
1574
- this.applyStates();
1575
- this._reportDrawCall();
1576
- const drawMode = this._drawMode(fillMode);
1577
- if (instancesCount) {
1578
- this._gl.drawArraysInstanced(drawMode, verticesStart, verticesCount, instancesCount);
1579
- }
1580
- else {
1581
- this._gl.drawArrays(drawMode, verticesStart, verticesCount);
1582
- }
1583
- }
1584
- _drawMode(fillMode) {
1585
- switch (fillMode) {
1586
- // Triangle views
1587
- case Constants.MATERIAL_TriangleFillMode:
1588
- return this._gl.TRIANGLES;
1589
- case Constants.MATERIAL_PointFillMode:
1590
- return this._gl.POINTS;
1591
- case Constants.MATERIAL_WireFrameFillMode:
1592
- return this._gl.LINES;
1593
- // Draw modes
1594
- case Constants.MATERIAL_PointListDrawMode:
1595
- return this._gl.POINTS;
1596
- case Constants.MATERIAL_LineListDrawMode:
1597
- return this._gl.LINES;
1598
- case Constants.MATERIAL_LineLoopDrawMode:
1599
- return this._gl.LINE_LOOP;
1600
- case Constants.MATERIAL_LineStripDrawMode:
1601
- return this._gl.LINE_STRIP;
1602
- case Constants.MATERIAL_TriangleStripDrawMode:
1603
- return this._gl.TRIANGLE_STRIP;
1604
- case Constants.MATERIAL_TriangleFanDrawMode:
1605
- return this._gl.TRIANGLE_FAN;
1606
- default:
1607
- return this._gl.TRIANGLES;
1608
- }
1609
- }
1610
- // Shaders
1611
- /**
1612
- * @internal
1613
- */
1614
- _releaseEffect(effect) {
1615
- if (this._compiledEffects[effect._key]) {
1616
- delete this._compiledEffects[effect._key];
1617
- }
1618
- const pipelineContext = effect.getPipelineContext();
1619
- if (pipelineContext) {
1620
- this._deletePipelineContext(pipelineContext);
1621
- }
1622
- }
1623
- /**
1624
- * @internal
1625
- */
1626
- _deletePipelineContext(pipelineContext) {
1627
- const webGLPipelineContext = pipelineContext;
1628
- if (webGLPipelineContext && webGLPipelineContext.program) {
1629
- webGLPipelineContext.program.__SPECTOR_rebuildProgram = null;
1630
- resetCachedPipeline(webGLPipelineContext);
1631
- if (this._gl) {
1632
- this._gl.deleteProgram(webGLPipelineContext.program);
1633
- }
1634
- }
1635
- }
1636
- /**
1637
- * @internal
1638
- */
1639
- _getGlobalDefines(defines) {
1640
- return _getGlobalDefines(defines, this.isNDCHalfZRange, this.useReverseDepthBuffer, this.useExactSrgbConversions);
1641
- }
1642
- /**
1643
- * Create a new effect (used to store vertex/fragment shaders)
1644
- * @param baseName defines the base name of the effect (The name of file without .fragment.fx or .vertex.fx)
1645
- * @param attributesNamesOrOptions defines either a list of attribute names or an IEffectCreationOptions object
1646
- * @param uniformsNamesOrEngine defines either a list of uniform names or the engine to use
1647
- * @param samplers defines an array of string used to represent textures
1648
- * @param defines defines the string containing the defines to use to compile the shaders
1649
- * @param fallbacks defines the list of potential fallbacks to use if shader compilation fails
1650
- * @param onCompiled defines a function to call when the effect creation is successful
1651
- * @param onError defines a function to call when the effect creation has failed
1652
- * @param indexParameters defines an object containing the index values to use to compile shaders (like the maximum number of simultaneous lights)
1653
- * @param shaderLanguage the language the shader is written in (default: GLSL)
1654
- * @param extraInitializationsAsync additional async code to run before preparing the effect
1655
- * @returns the new Effect
1656
- */
1657
- createEffect(baseName, attributesNamesOrOptions, uniformsNamesOrEngine, samplers, defines, fallbacks, onCompiled, onError, indexParameters, shaderLanguage = 0 /* ShaderLanguage.GLSL */, extraInitializationsAsync) {
1658
- const vertex = typeof baseName === "string" ? baseName : baseName.vertexToken || baseName.vertexSource || baseName.vertexElement || baseName.vertex;
1659
- const fragment = typeof baseName === "string" ? baseName : baseName.fragmentToken || baseName.fragmentSource || baseName.fragmentElement || baseName.fragment;
1660
- const globalDefines = this._getGlobalDefines();
1661
- let fullDefines = defines ?? attributesNamesOrOptions.defines ?? "";
1662
- if (globalDefines) {
1663
- fullDefines += globalDefines;
1664
- }
1665
- const name = vertex + "+" + fragment + "@" + fullDefines;
1666
- if (this._compiledEffects[name]) {
1667
- const compiledEffect = this._compiledEffects[name];
1668
- if (onCompiled && compiledEffect.isReady()) {
1669
- onCompiled(compiledEffect);
1670
- }
1671
- compiledEffect._refCount++;
1672
- return compiledEffect;
1673
- }
1674
- if (this._gl) {
1675
- getStateObject(this._gl);
1676
- }
1677
- const effect = new Effect(baseName, attributesNamesOrOptions, uniformsNamesOrEngine, samplers, this, defines, fallbacks, onCompiled, onError, indexParameters, name, attributesNamesOrOptions.shaderLanguage ?? shaderLanguage, attributesNamesOrOptions.extraInitializationsAsync ?? extraInitializationsAsync);
1678
- this._compiledEffects[name] = effect;
1679
- return effect;
1680
- }
1681
- /**
1682
- * @internal
1683
- */
1684
- _getShaderSource(shader) {
1685
- return this._gl.getShaderSource(shader);
1686
- }
1687
- /**
1688
- * Directly creates a webGL program
1689
- * @param pipelineContext defines the pipeline context to attach to
1690
- * @param vertexCode defines the vertex shader code to use
1691
- * @param fragmentCode defines the fragment shader code to use
1692
- * @param context defines the webGL context to use (if not set, the current one will be used)
1693
- * @param transformFeedbackVaryings defines the list of transform feedback varyings to use
1694
- * @returns the new webGL program
1695
- */
1696
- createRawShaderProgram(pipelineContext, vertexCode, fragmentCode, context, transformFeedbackVaryings = null) {
1697
- const stateObject = getStateObject(this._gl);
1698
- stateObject._contextWasLost = this._contextWasLost;
1699
- stateObject.validateShaderPrograms = this.validateShaderPrograms;
1700
- return createRawShaderProgram(pipelineContext, vertexCode, fragmentCode, context || this._gl, transformFeedbackVaryings);
1701
- }
1702
- /**
1703
- * Creates a webGL program
1704
- * @param pipelineContext defines the pipeline context to attach to
1705
- * @param vertexCode defines the vertex shader code to use
1706
- * @param fragmentCode defines the fragment shader code to use
1707
- * @param defines defines the string containing the defines to use to compile the shaders
1708
- * @param context defines the webGL context to use (if not set, the current one will be used)
1709
- * @param transformFeedbackVaryings defines the list of transform feedback varyings to use
1710
- * @returns the new webGL program
1711
- */
1712
- createShaderProgram(pipelineContext, vertexCode, fragmentCode, defines, context, transformFeedbackVaryings = null) {
1713
- const stateObject = getStateObject(this._gl);
1714
- // assure the state object is correct
1715
- stateObject._contextWasLost = this._contextWasLost;
1716
- stateObject.validateShaderPrograms = this.validateShaderPrograms;
1717
- return createShaderProgram(pipelineContext, vertexCode, fragmentCode, defines, context || this._gl, transformFeedbackVaryings);
1718
- }
1719
- /**
1720
- * Inline functions in shader code that are marked to be inlined
1721
- * @param code code to inline
1722
- * @returns inlined code
1723
- */
1724
- inlineShaderCode(code) {
1725
- // no inlining needed in the WebGL engine
1726
- return code;
1727
- }
1728
- /**
1729
- * Creates a new pipeline context
1730
- * @param shaderProcessingContext defines the shader processing context used during the processing if available
1731
- * @returns the new pipeline
1732
- */
1733
- createPipelineContext(shaderProcessingContext) {
1734
- if (this._gl) {
1735
- const stateObject = getStateObject(this._gl);
1736
- stateObject.parallelShaderCompile = this._caps.parallelShaderCompile;
1737
- }
1738
- const context = createPipelineContext(this._gl);
1739
- context.engine = this;
1740
- return context;
1741
- }
1742
- /**
1743
- * Creates a new material context
1744
- * @returns the new context
1745
- */
1746
- createMaterialContext() {
1747
- return undefined;
1748
- }
1749
- /**
1750
- * Creates a new draw context
1751
- * @returns the new context
1752
- */
1753
- createDrawContext() {
1754
- return undefined;
1755
- }
1756
- _finalizePipelineContext(pipelineContext) {
1757
- return _finalizePipelineContext(pipelineContext, this._gl, this.validateShaderPrograms);
1758
- }
1759
- /**
1760
- * @internal
1761
- */
1762
- _preparePipelineContext(pipelineContext, vertexSourceCode, fragmentSourceCode, createAsRaw, rawVertexSourceCode, rawFragmentSourceCode, rebuildRebind, defines, transformFeedbackVaryings, key, onReady) {
1763
- const stateObject = getStateObject(this._gl);
1764
- stateObject._contextWasLost = this._contextWasLost;
1765
- stateObject.validateShaderPrograms = this.validateShaderPrograms;
1766
- stateObject._createShaderProgramInjection = this._createShaderProgram.bind(this);
1767
- stateObject.createRawShaderProgramInjection = this.createRawShaderProgram.bind(this);
1768
- stateObject.createShaderProgramInjection = this.createShaderProgram.bind(this);
1769
- stateObject.loadFileInjection = this._loadFile.bind(this);
1770
- return _preparePipelineContext(pipelineContext, vertexSourceCode, fragmentSourceCode, createAsRaw, rawVertexSourceCode, rawFragmentSourceCode, rebuildRebind, defines, transformFeedbackVaryings, key, onReady);
1771
- }
1772
- _createShaderProgram(pipelineContext, vertexShader, fragmentShader, context, transformFeedbackVaryings = null) {
1773
- return _createShaderProgram(pipelineContext, vertexShader, fragmentShader, context, transformFeedbackVaryings);
1774
- }
1775
- /**
1776
- * @internal
1777
- */
1778
- _isRenderingStateCompiled(pipelineContext) {
1779
- const webGLPipelineContext = pipelineContext;
1780
- if (this._isDisposed || webGLPipelineContext._isDisposed) {
1781
- return false;
1782
- }
1783
- if (this._gl.getProgramParameter(webGLPipelineContext.program, this._caps.parallelShaderCompile.COMPLETION_STATUS_KHR)) {
1784
- this._finalizePipelineContext(webGLPipelineContext);
1785
- return true;
1786
- }
1787
- return false;
1788
- }
1789
- /**
1790
- * @internal
1791
- */
1792
- _executeWhenRenderingStateIsCompiled(pipelineContext, action) {
1793
- _executeWhenRenderingStateIsCompiled(pipelineContext, action);
1794
- }
1795
- /**
1796
- * Gets the list of webGL uniform locations associated with a specific program based on a list of uniform names
1797
- * @param pipelineContext defines the pipeline context to use
1798
- * @param uniformsNames defines the list of uniform names
1799
- * @returns an array of webGL uniform locations
1800
- */
1801
- getUniforms(pipelineContext, uniformsNames) {
1802
- const results = new Array();
1803
- const webGLPipelineContext = pipelineContext;
1804
- for (let index = 0; index < uniformsNames.length; index++) {
1805
- results.push(this._gl.getUniformLocation(webGLPipelineContext.program, uniformsNames[index]));
1806
- }
1807
- return results;
1808
- }
1809
- /**
1810
- * Gets the list of active attributes for a given webGL program
1811
- * @param pipelineContext defines the pipeline context to use
1812
- * @param attributesNames defines the list of attribute names to get
1813
- * @returns an array of indices indicating the offset of each attribute
1814
- */
1815
- getAttributes(pipelineContext, attributesNames) {
1816
- const results = [];
1817
- const webGLPipelineContext = pipelineContext;
1818
- for (let index = 0; index < attributesNames.length; index++) {
1819
- try {
1820
- results.push(this._gl.getAttribLocation(webGLPipelineContext.program, attributesNames[index]));
1821
- }
1822
- catch (e) {
1823
- results.push(-1);
1824
- }
1825
- }
1826
- return results;
1827
- }
1828
- /**
1829
- * Activates an effect, making it the current one (ie. the one used for rendering)
1830
- * @param effect defines the effect to activate
1831
- */
1832
- enableEffect(effect) {
1833
- effect = effect !== null && IsWrapper(effect) ? effect.effect : effect; // get only the effect, we don't need a Wrapper in the WebGL engine
1834
- if (!effect || effect === this._currentEffect) {
1835
- return;
1836
- }
1837
- this._stencilStateComposer.stencilMaterial = undefined;
1838
- effect = effect;
1839
- // Use program
1840
- this.bindSamplers(effect);
1841
- this._currentEffect = effect;
1842
- if (effect.onBind) {
1843
- effect.onBind(effect);
1844
- }
1845
- if (effect._onBindObservable) {
1846
- effect._onBindObservable.notifyObservers(effect);
1847
- }
1848
- }
1849
- /**
1850
- * Set the value of an uniform to a number (int)
1851
- * @param uniform defines the webGL uniform location where to store the value
1852
- * @param value defines the int number to store
1853
- * @returns true if the value was set
1854
- */
1855
- setInt(uniform, value) {
1856
- if (!uniform) {
1857
- return false;
1858
- }
1859
- this._gl.uniform1i(uniform, value);
1860
- return true;
1861
- }
1862
- /**
1863
- * Set the value of an uniform to a int2
1864
- * @param uniform defines the webGL uniform location where to store the value
1865
- * @param x defines the 1st component of the value
1866
- * @param y defines the 2nd component of the value
1867
- * @returns true if the value was set
1868
- */
1869
- setInt2(uniform, x, y) {
1870
- if (!uniform) {
1871
- return false;
1872
- }
1873
- this._gl.uniform2i(uniform, x, y);
1874
- return true;
1875
- }
1876
- /**
1877
- * Set the value of an uniform to a int3
1878
- * @param uniform defines the webGL uniform location where to store the value
1879
- * @param x defines the 1st component of the value
1880
- * @param y defines the 2nd component of the value
1881
- * @param z defines the 3rd component of the value
1882
- * @returns true if the value was set
1883
- */
1884
- setInt3(uniform, x, y, z) {
1885
- if (!uniform) {
1886
- return false;
1887
- }
1888
- this._gl.uniform3i(uniform, x, y, z);
1889
- return true;
1890
- }
1891
- /**
1892
- * Set the value of an uniform to a int4
1893
- * @param uniform defines the webGL uniform location where to store the value
1894
- * @param x defines the 1st component of the value
1895
- * @param y defines the 2nd component of the value
1896
- * @param z defines the 3rd component of the value
1897
- * @param w defines the 4th component of the value
1898
- * @returns true if the value was set
1899
- */
1900
- setInt4(uniform, x, y, z, w) {
1901
- if (!uniform) {
1902
- return false;
1903
- }
1904
- this._gl.uniform4i(uniform, x, y, z, w);
1905
- return true;
1906
- }
1907
- /**
1908
- * Set the value of an uniform to an array of int32
1909
- * @param uniform defines the webGL uniform location where to store the value
1910
- * @param array defines the array of int32 to store
1911
- * @returns true if the value was set
1912
- */
1913
- setIntArray(uniform, array) {
1914
- if (!uniform) {
1915
- return false;
1916
- }
1917
- this._gl.uniform1iv(uniform, array);
1918
- return true;
1919
- }
1920
- /**
1921
- * Set the value of an uniform to an array of int32 (stored as vec2)
1922
- * @param uniform defines the webGL uniform location where to store the value
1923
- * @param array defines the array of int32 to store
1924
- * @returns true if the value was set
1925
- */
1926
- setIntArray2(uniform, array) {
1927
- if (!uniform || array.length % 2 !== 0) {
1928
- return false;
1929
- }
1930
- this._gl.uniform2iv(uniform, array);
1931
- return true;
1932
- }
1933
- /**
1934
- * Set the value of an uniform to an array of int32 (stored as vec3)
1935
- * @param uniform defines the webGL uniform location where to store the value
1936
- * @param array defines the array of int32 to store
1937
- * @returns true if the value was set
1938
- */
1939
- setIntArray3(uniform, array) {
1940
- if (!uniform || array.length % 3 !== 0) {
1941
- return false;
1942
- }
1943
- this._gl.uniform3iv(uniform, array);
1944
- return true;
1945
- }
1946
- /**
1947
- * Set the value of an uniform to an array of int32 (stored as vec4)
1948
- * @param uniform defines the webGL uniform location where to store the value
1949
- * @param array defines the array of int32 to store
1950
- * @returns true if the value was set
1951
- */
1952
- setIntArray4(uniform, array) {
1953
- if (!uniform || array.length % 4 !== 0) {
1954
- return false;
1955
- }
1956
- this._gl.uniform4iv(uniform, array);
1957
- return true;
1958
- }
1959
- /**
1960
- * Set the value of an uniform to a number (unsigned int)
1961
- * @param uniform defines the webGL uniform location where to store the value
1962
- * @param value defines the unsigned int number to store
1963
- * @returns true if the value was set
1964
- */
1965
- setUInt(uniform, value) {
1966
- if (!uniform) {
1967
- return false;
1968
- }
1969
- this._gl.uniform1ui(uniform, value);
1970
- return true;
1971
- }
1972
- /**
1973
- * Set the value of an uniform to a unsigned int2
1974
- * @param uniform defines the webGL uniform location where to store the value
1975
- * @param x defines the 1st component of the value
1976
- * @param y defines the 2nd component of the value
1977
- * @returns true if the value was set
1978
- */
1979
- setUInt2(uniform, x, y) {
1980
- if (!uniform) {
1981
- return false;
1982
- }
1983
- this._gl.uniform2ui(uniform, x, y);
1984
- return true;
1985
- }
1986
- /**
1987
- * Set the value of an uniform to a unsigned int3
1988
- * @param uniform defines the webGL uniform location where to store the value
1989
- * @param x defines the 1st component of the value
1990
- * @param y defines the 2nd component of the value
1991
- * @param z defines the 3rd component of the value
1992
- * @returns true if the value was set
1993
- */
1994
- setUInt3(uniform, x, y, z) {
1995
- if (!uniform) {
1996
- return false;
1997
- }
1998
- this._gl.uniform3ui(uniform, x, y, z);
1999
- return true;
2000
- }
2001
- /**
2002
- * Set the value of an uniform to a unsigned int4
2003
- * @param uniform defines the webGL uniform location where to store the value
2004
- * @param x defines the 1st component of the value
2005
- * @param y defines the 2nd component of the value
2006
- * @param z defines the 3rd component of the value
2007
- * @param w defines the 4th component of the value
2008
- * @returns true if the value was set
2009
- */
2010
- setUInt4(uniform, x, y, z, w) {
2011
- if (!uniform) {
2012
- return false;
2013
- }
2014
- this._gl.uniform4ui(uniform, x, y, z, w);
2015
- return true;
2016
- }
2017
- /**
2018
- * Set the value of an uniform to an array of unsigned int32
2019
- * @param uniform defines the webGL uniform location where to store the value
2020
- * @param array defines the array of unsigned int32 to store
2021
- * @returns true if the value was set
2022
- */
2023
- setUIntArray(uniform, array) {
2024
- if (!uniform) {
2025
- return false;
2026
- }
2027
- this._gl.uniform1uiv(uniform, array);
2028
- return true;
2029
- }
2030
- /**
2031
- * Set the value of an uniform to an array of unsigned int32 (stored as vec2)
2032
- * @param uniform defines the webGL uniform location where to store the value
2033
- * @param array defines the array of unsigned int32 to store
2034
- * @returns true if the value was set
2035
- */
2036
- setUIntArray2(uniform, array) {
2037
- if (!uniform || array.length % 2 !== 0) {
2038
- return false;
2039
- }
2040
- this._gl.uniform2uiv(uniform, array);
2041
- return true;
2042
- }
2043
- /**
2044
- * Set the value of an uniform to an array of unsigned int32 (stored as vec3)
2045
- * @param uniform defines the webGL uniform location where to store the value
2046
- * @param array defines the array of unsigned int32 to store
2047
- * @returns true if the value was set
2048
- */
2049
- setUIntArray3(uniform, array) {
2050
- if (!uniform || array.length % 3 !== 0) {
2051
- return false;
2052
- }
2053
- this._gl.uniform3uiv(uniform, array);
2054
- return true;
2055
- }
2056
- /**
2057
- * Set the value of an uniform to an array of unsigned int32 (stored as vec4)
2058
- * @param uniform defines the webGL uniform location where to store the value
2059
- * @param array defines the array of unsigned int32 to store
2060
- * @returns true if the value was set
2061
- */
2062
- setUIntArray4(uniform, array) {
2063
- if (!uniform || array.length % 4 !== 0) {
2064
- return false;
2065
- }
2066
- this._gl.uniform4uiv(uniform, array);
2067
- return true;
2068
- }
2069
- /**
2070
- * Set the value of an uniform to an array of number
2071
- * @param uniform defines the webGL uniform location where to store the value
2072
- * @param array defines the array of number to store
2073
- * @returns true if the value was set
2074
- */
2075
- setArray(uniform, array) {
2076
- if (!uniform) {
2077
- return false;
2078
- }
2079
- if (array.length < 1) {
2080
- return false;
2081
- }
2082
- this._gl.uniform1fv(uniform, array);
2083
- return true;
2084
- }
2085
- /**
2086
- * Set the value of an uniform to an array of number (stored as vec2)
2087
- * @param uniform defines the webGL uniform location where to store the value
2088
- * @param array defines the array of number to store
2089
- * @returns true if the value was set
2090
- */
2091
- setArray2(uniform, array) {
2092
- if (!uniform || array.length % 2 !== 0) {
2093
- return false;
2094
- }
2095
- this._gl.uniform2fv(uniform, array);
2096
- return true;
2097
- }
2098
- /**
2099
- * Set the value of an uniform to an array of number (stored as vec3)
2100
- * @param uniform defines the webGL uniform location where to store the value
2101
- * @param array defines the array of number to store
2102
- * @returns true if the value was set
2103
- */
2104
- setArray3(uniform, array) {
2105
- if (!uniform || array.length % 3 !== 0) {
2106
- return false;
2107
- }
2108
- this._gl.uniform3fv(uniform, array);
2109
- return true;
2110
- }
2111
- /**
2112
- * Set the value of an uniform to an array of number (stored as vec4)
2113
- * @param uniform defines the webGL uniform location where to store the value
2114
- * @param array defines the array of number to store
2115
- * @returns true if the value was set
2116
- */
2117
- setArray4(uniform, array) {
2118
- if (!uniform || array.length % 4 !== 0) {
2119
- return false;
2120
- }
2121
- this._gl.uniform4fv(uniform, array);
2122
- return true;
2123
- }
2124
- /**
2125
- * Set the value of an uniform to an array of float32 (stored as matrices)
2126
- * @param uniform defines the webGL uniform location where to store the value
2127
- * @param matrices defines the array of float32 to store
2128
- * @returns true if the value was set
2129
- */
2130
- setMatrices(uniform, matrices) {
2131
- if (!uniform) {
2132
- return false;
2133
- }
2134
- this._gl.uniformMatrix4fv(uniform, false, matrices);
2135
- return true;
2136
- }
2137
- /**
2138
- * Set the value of an uniform to a matrix (3x3)
2139
- * @param uniform defines the webGL uniform location where to store the value
2140
- * @param matrix defines the Float32Array representing the 3x3 matrix to store
2141
- * @returns true if the value was set
2142
- */
2143
- setMatrix3x3(uniform, matrix) {
2144
- if (!uniform) {
2145
- return false;
2146
- }
2147
- this._gl.uniformMatrix3fv(uniform, false, matrix);
2148
- return true;
2149
- }
2150
- /**
2151
- * Set the value of an uniform to a matrix (2x2)
2152
- * @param uniform defines the webGL uniform location where to store the value
2153
- * @param matrix defines the Float32Array representing the 2x2 matrix to store
2154
- * @returns true if the value was set
2155
- */
2156
- setMatrix2x2(uniform, matrix) {
2157
- if (!uniform) {
2158
- return false;
2159
- }
2160
- this._gl.uniformMatrix2fv(uniform, false, matrix);
2161
- return true;
2162
- }
2163
- /**
2164
- * Set the value of an uniform to a number (float)
2165
- * @param uniform defines the webGL uniform location where to store the value
2166
- * @param value defines the float number to store
2167
- * @returns true if the value was transferred
2168
- */
2169
- setFloat(uniform, value) {
2170
- if (!uniform) {
2171
- return false;
2172
- }
2173
- this._gl.uniform1f(uniform, value);
2174
- return true;
2175
- }
2176
- /**
2177
- * Set the value of an uniform to a vec2
2178
- * @param uniform defines the webGL uniform location where to store the value
2179
- * @param x defines the 1st component of the value
2180
- * @param y defines the 2nd component of the value
2181
- * @returns true if the value was set
2182
- */
2183
- setFloat2(uniform, x, y) {
2184
- if (!uniform) {
2185
- return false;
2186
- }
2187
- this._gl.uniform2f(uniform, x, y);
2188
- return true;
2189
- }
2190
- /**
2191
- * Set the value of an uniform to a vec3
2192
- * @param uniform defines the webGL uniform location where to store the value
2193
- * @param x defines the 1st component of the value
2194
- * @param y defines the 2nd component of the value
2195
- * @param z defines the 3rd component of the value
2196
- * @returns true if the value was set
2197
- */
2198
- setFloat3(uniform, x, y, z) {
2199
- if (!uniform) {
2200
- return false;
2201
- }
2202
- this._gl.uniform3f(uniform, x, y, z);
2203
- return true;
2204
- }
2205
- /**
2206
- * Set the value of an uniform to a vec4
2207
- * @param uniform defines the webGL uniform location where to store the value
2208
- * @param x defines the 1st component of the value
2209
- * @param y defines the 2nd component of the value
2210
- * @param z defines the 3rd component of the value
2211
- * @param w defines the 4th component of the value
2212
- * @returns true if the value was set
2213
- */
2214
- setFloat4(uniform, x, y, z, w) {
2215
- if (!uniform) {
2216
- return false;
2217
- }
2218
- this._gl.uniform4f(uniform, x, y, z, w);
2219
- return true;
2220
- }
2221
- // States
2222
- /**
2223
- * Apply all cached states (depth, culling, stencil and alpha)
2224
- */
2225
- applyStates() {
2226
- this._depthCullingState.apply(this._gl);
2227
- this._stencilStateComposer.apply(this._gl);
2228
- this._alphaState.apply(this._gl);
2229
- if (this._colorWriteChanged) {
2230
- this._colorWriteChanged = false;
2231
- const enable = this._colorWrite;
2232
- this._gl.colorMask(enable, enable, enable, enable);
2233
- }
2234
- }
2235
- // Textures
2236
- /**
2237
- * Force the entire cache to be cleared
2238
- * You should not have to use this function unless your engine needs to share the webGL context with another engine
2239
- * @param bruteForce defines a boolean to force clearing ALL caches (including stencil, detoh and alpha states)
2240
- */
2241
- wipeCaches(bruteForce) {
2242
- if (this.preventCacheWipeBetweenFrames && !bruteForce) {
2243
- return;
2244
- }
2245
- this._currentEffect = null;
2246
- this._viewportCached.x = 0;
2247
- this._viewportCached.y = 0;
2248
- this._viewportCached.z = 0;
2249
- this._viewportCached.w = 0;
2250
- // Done before in case we clean the attributes
2251
- this._unbindVertexArrayObject();
2252
- if (bruteForce) {
2253
- this._currentProgram = null;
2254
- this.resetTextureCache();
2255
- this._stencilStateComposer.reset();
2256
- this._depthCullingState.reset();
2257
- this._depthCullingState.depthFunc = this._gl.LEQUAL;
2258
- this._alphaState.reset();
2259
- this._alphaMode = Constants.ALPHA_ADD;
2260
- this._alphaEquation = Constants.ALPHA_DISABLE;
2261
- this._colorWrite = true;
2262
- this._colorWriteChanged = true;
2263
- this._unpackFlipYCached = null;
2264
- this._gl.pixelStorei(this._gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, this._gl.NONE);
2265
- this._gl.pixelStorei(this._gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0);
2266
- this._mustWipeVertexAttributes = true;
2267
- this.unbindAllAttributes();
2268
- }
2269
- this._resetVertexBufferBinding();
2270
- this._cachedIndexBuffer = null;
2271
- this._cachedEffectForVertexBuffers = null;
2272
- this.bindIndexBuffer(null);
2273
- }
2274
- /**
2275
- * @internal
2276
- */
2277
- _getSamplingParameters(samplingMode, generateMipMaps) {
2278
- const gl = this._gl;
2279
- let magFilter = gl.NEAREST;
2280
- let minFilter = gl.NEAREST;
2281
- switch (samplingMode) {
2282
- case Constants.TEXTURE_LINEAR_LINEAR_MIPNEAREST:
2283
- magFilter = gl.LINEAR;
2284
- if (generateMipMaps) {
2285
- minFilter = gl.LINEAR_MIPMAP_NEAREST;
2286
- }
2287
- else {
2288
- minFilter = gl.LINEAR;
2289
- }
2290
- break;
2291
- case Constants.TEXTURE_LINEAR_LINEAR_MIPLINEAR:
2292
- magFilter = gl.LINEAR;
2293
- if (generateMipMaps) {
2294
- minFilter = gl.LINEAR_MIPMAP_LINEAR;
2295
- }
2296
- else {
2297
- minFilter = gl.LINEAR;
2298
- }
2299
- break;
2300
- case Constants.TEXTURE_NEAREST_NEAREST_MIPLINEAR:
2301
- magFilter = gl.NEAREST;
2302
- if (generateMipMaps) {
2303
- minFilter = gl.NEAREST_MIPMAP_LINEAR;
2304
- }
2305
- else {
2306
- minFilter = gl.NEAREST;
2307
- }
2308
- break;
2309
- case Constants.TEXTURE_NEAREST_NEAREST_MIPNEAREST:
2310
- magFilter = gl.NEAREST;
2311
- if (generateMipMaps) {
2312
- minFilter = gl.NEAREST_MIPMAP_NEAREST;
2313
- }
2314
- else {
2315
- minFilter = gl.NEAREST;
2316
- }
2317
- break;
2318
- case Constants.TEXTURE_NEAREST_LINEAR_MIPNEAREST:
2319
- magFilter = gl.NEAREST;
2320
- if (generateMipMaps) {
2321
- minFilter = gl.LINEAR_MIPMAP_NEAREST;
2322
- }
2323
- else {
2324
- minFilter = gl.LINEAR;
2325
- }
2326
- break;
2327
- case Constants.TEXTURE_NEAREST_LINEAR_MIPLINEAR:
2328
- magFilter = gl.NEAREST;
2329
- if (generateMipMaps) {
2330
- minFilter = gl.LINEAR_MIPMAP_LINEAR;
2331
- }
2332
- else {
2333
- minFilter = gl.LINEAR;
2334
- }
2335
- break;
2336
- case Constants.TEXTURE_NEAREST_LINEAR:
2337
- magFilter = gl.NEAREST;
2338
- minFilter = gl.LINEAR;
2339
- break;
2340
- case Constants.TEXTURE_NEAREST_NEAREST:
2341
- magFilter = gl.NEAREST;
2342
- minFilter = gl.NEAREST;
2343
- break;
2344
- case Constants.TEXTURE_LINEAR_NEAREST_MIPNEAREST:
2345
- magFilter = gl.LINEAR;
2346
- if (generateMipMaps) {
2347
- minFilter = gl.NEAREST_MIPMAP_NEAREST;
2348
- }
2349
- else {
2350
- minFilter = gl.NEAREST;
2351
- }
2352
- break;
2353
- case Constants.TEXTURE_LINEAR_NEAREST_MIPLINEAR:
2354
- magFilter = gl.LINEAR;
2355
- if (generateMipMaps) {
2356
- minFilter = gl.NEAREST_MIPMAP_LINEAR;
2357
- }
2358
- else {
2359
- minFilter = gl.NEAREST;
2360
- }
2361
- break;
2362
- case Constants.TEXTURE_LINEAR_LINEAR:
2363
- magFilter = gl.LINEAR;
2364
- minFilter = gl.LINEAR;
2365
- break;
2366
- case Constants.TEXTURE_LINEAR_NEAREST:
2367
- magFilter = gl.LINEAR;
2368
- minFilter = gl.NEAREST;
2369
- break;
2370
- }
2371
- return {
2372
- min: minFilter,
2373
- mag: magFilter,
2374
- };
2375
- }
2376
- /** @internal */
2377
- _createTexture() {
2378
- const texture = this._gl.createTexture();
2379
- if (!texture) {
2380
- throw new Error("Unable to create texture");
2381
- }
2382
- return texture;
2383
- }
2384
- /** @internal */
2385
- _createHardwareTexture() {
2386
- return new WebGLHardwareTexture(this._createTexture(), this._gl);
2387
- }
2388
- /**
2389
- * Creates an internal texture without binding it to a framebuffer
2390
- * @internal
2391
- * @param size defines the size of the texture
2392
- * @param options defines the options used to create the texture
2393
- * @param delayGPUTextureCreation true to delay the texture creation the first time it is really needed. false to create it right away
2394
- * @param source source type of the texture
2395
- * @returns a new internal texture
2396
- */
2397
- _createInternalTexture(size, options, delayGPUTextureCreation = true, source = 0 /* InternalTextureSource.Unknown */) {
2398
- let generateMipMaps = false;
2399
- let type = Constants.TEXTURETYPE_UNSIGNED_INT;
2400
- let samplingMode = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE;
2401
- let format = Constants.TEXTUREFORMAT_RGBA;
2402
- let useSRGBBuffer = false;
2403
- let samples = 1;
2404
- let label;
2405
- if (options !== undefined && typeof options === "object") {
2406
- generateMipMaps = !!options.generateMipMaps;
2407
- type = options.type === undefined ? Constants.TEXTURETYPE_UNSIGNED_INT : options.type;
2408
- samplingMode = options.samplingMode === undefined ? Constants.TEXTURE_TRILINEAR_SAMPLINGMODE : options.samplingMode;
2409
- format = options.format === undefined ? Constants.TEXTUREFORMAT_RGBA : options.format;
2410
- useSRGBBuffer = options.useSRGBBuffer === undefined ? false : options.useSRGBBuffer;
2411
- samples = options.samples ?? 1;
2412
- label = options.label;
2413
- }
2414
- else {
2415
- generateMipMaps = !!options;
2416
- }
2417
- useSRGBBuffer &&= this._caps.supportSRGBBuffers && (this.webGLVersion > 1 || this.isWebGPU);
2418
- if (type === Constants.TEXTURETYPE_FLOAT && !this._caps.textureFloatLinearFiltering) {
2419
- // if floating point linear (gl.FLOAT) then force to NEAREST_SAMPLINGMODE
2420
- samplingMode = Constants.TEXTURE_NEAREST_SAMPLINGMODE;
2421
- }
2422
- else if (type === Constants.TEXTURETYPE_HALF_FLOAT && !this._caps.textureHalfFloatLinearFiltering) {
2423
- // if floating point linear (HALF_FLOAT) then force to NEAREST_SAMPLINGMODE
2424
- samplingMode = Constants.TEXTURE_NEAREST_SAMPLINGMODE;
2425
- }
2426
- if (type === Constants.TEXTURETYPE_FLOAT && !this._caps.textureFloat) {
2427
- type = Constants.TEXTURETYPE_UNSIGNED_INT;
2428
- Logger.Warn("Float textures are not supported. Type forced to TEXTURETYPE_UNSIGNED_BYTE");
2429
- }
2430
- const gl = this._gl;
2431
- const texture = new InternalTexture(this, source);
2432
- const width = size.width || size;
2433
- const height = size.height || size;
2434
- const depth = size.depth || 0;
2435
- const layers = size.layers || 0;
2436
- const filters = this._getSamplingParameters(samplingMode, generateMipMaps);
2437
- const target = layers !== 0 ? gl.TEXTURE_2D_ARRAY : depth !== 0 ? gl.TEXTURE_3D : gl.TEXTURE_2D;
2438
- const sizedFormat = this._getRGBABufferInternalSizedFormat(type, format, useSRGBBuffer);
2439
- const internalFormat = this._getInternalFormat(format);
2440
- const textureType = this._getWebGLTextureType(type);
2441
- // Bind
2442
- this._bindTextureDirectly(target, texture);
2443
- if (layers !== 0) {
2444
- texture.is2DArray = true;
2445
- gl.texImage3D(target, 0, sizedFormat, width, height, layers, 0, internalFormat, textureType, null);
2446
- }
2447
- else if (depth !== 0) {
2448
- texture.is3D = true;
2449
- gl.texImage3D(target, 0, sizedFormat, width, height, depth, 0, internalFormat, textureType, null);
2450
- }
2451
- else {
2452
- gl.texImage2D(target, 0, sizedFormat, width, height, 0, internalFormat, textureType, null);
2453
- }
2454
- gl.texParameteri(target, gl.TEXTURE_MAG_FILTER, filters.mag);
2455
- gl.texParameteri(target, gl.TEXTURE_MIN_FILTER, filters.min);
2456
- gl.texParameteri(target, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
2457
- gl.texParameteri(target, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
2458
- // MipMaps
2459
- if (generateMipMaps) {
2460
- this._gl.generateMipmap(target);
2461
- }
2462
- this._bindTextureDirectly(target, null);
2463
- texture._useSRGBBuffer = useSRGBBuffer;
2464
- texture.baseWidth = width;
2465
- texture.baseHeight = height;
2466
- texture.width = width;
2467
- texture.height = height;
2468
- texture.depth = layers;
2469
- texture.isReady = true;
2470
- texture.samples = samples;
2471
- texture.generateMipMaps = generateMipMaps;
2472
- texture.samplingMode = samplingMode;
2473
- texture.type = type;
2474
- texture.format = format;
2475
- texture.label = label;
2476
- this._internalTexturesCache.push(texture);
2477
- return texture;
2478
- }
2479
- /**
2480
- * @internal
2481
- */
2482
- _getUseSRGBBuffer(useSRGBBuffer, noMipmap) {
2483
- // Generating mipmaps for sRGB textures is not supported in WebGL1 so we must disable the support if mipmaps is enabled
2484
- return useSRGBBuffer && this._caps.supportSRGBBuffers && (this.webGLVersion > 1 || noMipmap);
2485
- }
2486
- /**
2487
- * Usually called from Texture.ts.
2488
- * Passed information to create a WebGLTexture
2489
- * @param url defines a value which contains one of the following:
2490
- * * A conventional http URL, e.g. 'http://...' or 'file://...'
2491
- * * A base64 string of in-line texture data, e.g. 'data:image/jpg;base64,/...'
2492
- * * An indicator that data being passed using the buffer parameter, e.g. 'data:mytexture.jpg'
2493
- * @param noMipmap defines a boolean indicating that no mipmaps shall be generated. Ignored for compressed textures. They must be in the file
2494
- * @param invertY when true, image is flipped when loaded. You probably want true. Certain compressed textures may invert this if their default is inverted (eg. ktx)
2495
- * @param scene needed for loading to the correct scene
2496
- * @param samplingMode mode with should be used sample / access the texture (Default: Texture.TRILINEAR_SAMPLINGMODE)
2497
- * @param onLoad optional callback to be called upon successful completion
2498
- * @param onError optional callback to be called upon failure
2499
- * @param buffer a source of a file previously fetched as either a base64 string, an ArrayBuffer (compressed or image format), HTMLImageElement (image format), or a Blob
2500
- * @param fallback an internal argument in case the function must be called again, due to etc1 not having alpha capabilities
2501
- * @param format internal format. Default: RGB when extension is '.jpg' else RGBA. Ignored for compressed textures
2502
- * @param forcedExtension defines the extension to use to pick the right loader
2503
- * @param mimeType defines an optional mime type
2504
- * @param loaderOptions options to be passed to the loader
2505
- * @param creationFlags specific flags to use when creating the texture (Constants.TEXTURE_CREATIONFLAG_STORAGE for storage textures, for eg)
2506
- * @param useSRGBBuffer defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU).
2507
- * @returns a InternalTexture for assignment back into BABYLON.Texture
2508
- */
2509
- createTexture(url, noMipmap, invertY, scene, samplingMode = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE, onLoad = null, onError = null, buffer = null, fallback = null, format = null, forcedExtension = null, mimeType, loaderOptions, creationFlags, useSRGBBuffer) {
2510
- return this._createTextureBase(url, noMipmap, invertY, scene, samplingMode, onLoad, onError, (...args) => this._prepareWebGLTexture(...args, format), (potWidth, potHeight, img, extension, texture, continuationCallback) => {
2511
- const gl = this._gl;
2512
- const isPot = img.width === potWidth && img.height === potHeight;
2513
- texture._creationFlags = creationFlags ?? 0;
2514
- const tip = this._getTexImageParametersForCreateTexture(texture.format, texture._useSRGBBuffer);
2515
- if (isPot) {
2516
- gl.texImage2D(gl.TEXTURE_2D, 0, tip.internalFormat, tip.format, tip.type, img);
2517
- return false;
2518
- }
2519
- const maxTextureSize = this._caps.maxTextureSize;
2520
- if (img.width > maxTextureSize || img.height > maxTextureSize || !this._supportsHardwareTextureRescaling) {
2521
- this._prepareWorkingCanvas();
2522
- if (!this._workingCanvas || !this._workingContext) {
2523
- return false;
2524
- }
2525
- this._workingCanvas.width = potWidth;
2526
- this._workingCanvas.height = potHeight;
2527
- this._workingContext.drawImage(img, 0, 0, img.width, img.height, 0, 0, potWidth, potHeight);
2528
- gl.texImage2D(gl.TEXTURE_2D, 0, tip.internalFormat, tip.format, tip.type, this._workingCanvas);
2529
- texture.width = potWidth;
2530
- texture.height = potHeight;
2531
- return false;
2532
- }
2533
- else {
2534
- // Using shaders when possible to rescale because canvas.drawImage is lossy
2535
- const source = new InternalTexture(this, 2 /* InternalTextureSource.Temp */);
2536
- this._bindTextureDirectly(gl.TEXTURE_2D, source, true);
2537
- gl.texImage2D(gl.TEXTURE_2D, 0, tip.internalFormat, tip.format, tip.type, img);
2538
- this._rescaleTexture(source, texture, scene, tip.format, () => {
2539
- this._releaseTexture(source);
2540
- this._bindTextureDirectly(gl.TEXTURE_2D, texture, true);
2541
- continuationCallback();
2542
- });
2543
- }
2544
- return true;
2545
- }, buffer, fallback, format, forcedExtension, mimeType, loaderOptions, useSRGBBuffer);
2546
- }
2547
- /**
2548
- * Calls to the GL texImage2D and texImage3D functions require three arguments describing the pixel format of the texture.
2549
- * createTexture derives these from the babylonFormat and useSRGBBuffer arguments and also the file extension of the URL it's working with.
2550
- * This function encapsulates that derivation for easy unit testing.
2551
- * @param babylonFormat Babylon's format enum, as specified in ITextureCreationOptions.
2552
- * @param fileExtension The file extension including the dot, e.g. .jpg.
2553
- * @param useSRGBBuffer Use SRGB not linear.
2554
- * @returns The options to pass to texImage2D or texImage3D calls.
2555
- * @internal
2556
- */
2557
- _getTexImageParametersForCreateTexture(babylonFormat, useSRGBBuffer) {
2558
- let format, internalFormat;
2559
- if (this.webGLVersion === 1) {
2560
- // In WebGL 1, format and internalFormat must be the same and taken from a limited set of values, see https://docs.gl/es2/glTexImage2D.
2561
- // The SRGB extension (https://developer.mozilla.org/en-US/docs/Web/API/EXT_sRGB) adds some extra values, hence passing useSRGBBuffer
2562
- // to getInternalFormat.
2563
- format = this._getInternalFormat(babylonFormat, useSRGBBuffer);
2564
- internalFormat = format;
2565
- }
2566
- else {
2567
- // In WebGL 2, format has a wider range of values and internal format can be one of the sized formats, see
2568
- // https://registry.khronos.org/OpenGL-Refpages/es3.0/html/glTexImage2D.xhtml.
2569
- // SRGB is included in the sized format and should not be passed in "format", hence always passing useSRGBBuffer as false.
2570
- format = this._getInternalFormat(babylonFormat, false);
2571
- internalFormat = this._getRGBABufferInternalSizedFormat(Constants.TEXTURETYPE_UNSIGNED_BYTE, babylonFormat, useSRGBBuffer);
2572
- }
2573
- return {
2574
- internalFormat,
2575
- format,
2576
- type: this._gl.UNSIGNED_BYTE,
2577
- };
2578
- }
2579
- /**
2580
- * @internal
2581
- */
2582
- _rescaleTexture(source, destination, scene, internalFormat, onComplete) { }
2583
- /**
2584
- * @internal
2585
- */
2586
- _unpackFlipY(value) {
2587
- if (this._unpackFlipYCached !== value) {
2588
- this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, value ? 1 : 0);
2589
- if (this.enableUnpackFlipYCached) {
2590
- this._unpackFlipYCached = value;
2591
- }
2592
- }
2593
- }
2594
- /** @internal */
2595
- _getUnpackAlignement() {
2596
- return this._gl.getParameter(this._gl.UNPACK_ALIGNMENT);
2597
- }
2598
- /** @internal */
2599
- _getTextureTarget(texture) {
2600
- if (texture.isCube) {
2601
- return this._gl.TEXTURE_CUBE_MAP;
2602
- }
2603
- else if (texture.is3D) {
2604
- return this._gl.TEXTURE_3D;
2605
- }
2606
- else if (texture.is2DArray || texture.isMultiview) {
2607
- return this._gl.TEXTURE_2D_ARRAY;
2608
- }
2609
- return this._gl.TEXTURE_2D;
2610
- }
2611
- /**
2612
- * Update the sampling mode of a given texture
2613
- * @param samplingMode defines the required sampling mode
2614
- * @param texture defines the texture to update
2615
- * @param generateMipMaps defines whether to generate mipmaps for the texture
2616
- */
2617
- updateTextureSamplingMode(samplingMode, texture, generateMipMaps = false) {
2618
- const target = this._getTextureTarget(texture);
2619
- const filters = this._getSamplingParameters(samplingMode, texture.useMipMaps || generateMipMaps);
2620
- this._setTextureParameterInteger(target, this._gl.TEXTURE_MAG_FILTER, filters.mag, texture);
2621
- this._setTextureParameterInteger(target, this._gl.TEXTURE_MIN_FILTER, filters.min);
2622
- if (generateMipMaps) {
2623
- texture.generateMipMaps = true;
2624
- this._gl.generateMipmap(target);
2625
- }
2626
- this._bindTextureDirectly(target, null);
2627
- texture.samplingMode = samplingMode;
2628
- }
2629
- /**
2630
- * Update the dimensions of a texture
2631
- * @param texture texture to update
2632
- * @param width new width of the texture
2633
- * @param height new height of the texture
2634
- * @param depth new depth of the texture
2635
- */
2636
- updateTextureDimensions(texture, width, height, depth = 1) { }
2637
- /**
2638
- * Update the sampling mode of a given texture
2639
- * @param texture defines the texture to update
2640
- * @param wrapU defines the texture wrap mode of the u coordinates
2641
- * @param wrapV defines the texture wrap mode of the v coordinates
2642
- * @param wrapR defines the texture wrap mode of the r coordinates
2643
- */
2644
- updateTextureWrappingMode(texture, wrapU, wrapV = null, wrapR = null) {
2645
- const target = this._getTextureTarget(texture);
2646
- if (wrapU !== null) {
2647
- this._setTextureParameterInteger(target, this._gl.TEXTURE_WRAP_S, this._getTextureWrapMode(wrapU), texture);
2648
- texture._cachedWrapU = wrapU;
2649
- }
2650
- if (wrapV !== null) {
2651
- this._setTextureParameterInteger(target, this._gl.TEXTURE_WRAP_T, this._getTextureWrapMode(wrapV), texture);
2652
- texture._cachedWrapV = wrapV;
2653
- }
2654
- if ((texture.is2DArray || texture.is3D) && wrapR !== null) {
2655
- this._setTextureParameterInteger(target, this._gl.TEXTURE_WRAP_R, this._getTextureWrapMode(wrapR), texture);
2656
- texture._cachedWrapR = wrapR;
2657
- }
2658
- this._bindTextureDirectly(target, null);
2659
- }
2660
- /**
2661
- * @internal
2662
- */
2663
- _uploadCompressedDataToTextureDirectly(texture, internalFormat, width, height, data, faceIndex = 0, lod = 0) {
2664
- const gl = this._gl;
2665
- let target = gl.TEXTURE_2D;
2666
- if (texture.isCube) {
2667
- target = gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex;
2668
- }
2669
- if (texture._useSRGBBuffer) {
2670
- switch (internalFormat) {
2671
- case Constants.TEXTUREFORMAT_COMPRESSED_RGB8_ETC2:
2672
- case Constants.TEXTUREFORMAT_COMPRESSED_RGB_ETC1_WEBGL:
2673
- // Note, if using ETC1 and sRGB is requested, this will use ETC2 if available.
2674
- if (this._caps.etc2) {
2675
- internalFormat = gl.COMPRESSED_SRGB8_ETC2;
2676
- }
2677
- else {
2678
- texture._useSRGBBuffer = false;
2679
- }
2680
- break;
2681
- case Constants.TEXTUREFORMAT_COMPRESSED_RGBA8_ETC2_EAC:
2682
- if (this._caps.etc2) {
2683
- internalFormat = gl.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
2684
- }
2685
- else {
2686
- texture._useSRGBBuffer = false;
2687
- }
2688
- break;
2689
- case Constants.TEXTUREFORMAT_COMPRESSED_RGBA_BPTC_UNORM:
2690
- internalFormat = gl.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT;
2691
- break;
2692
- case Constants.TEXTUREFORMAT_COMPRESSED_RGBA_ASTC_4x4:
2693
- internalFormat = gl.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
2694
- break;
2695
- case Constants.TEXTUREFORMAT_COMPRESSED_RGB_S3TC_DXT1:
2696
- if (this._caps.s3tc_srgb) {
2697
- internalFormat = gl.COMPRESSED_SRGB_S3TC_DXT1_EXT;
2698
- }
2699
- else {
2700
- // S3TC sRGB extension not supported
2701
- texture._useSRGBBuffer = false;
2702
- }
2703
- break;
2704
- case Constants.TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT1:
2705
- if (this._caps.s3tc_srgb) {
2706
- internalFormat = gl.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
2707
- }
2708
- else {
2709
- // S3TC sRGB extension not supported
2710
- texture._useSRGBBuffer = false;
2711
- }
2712
- break;
2713
- case Constants.TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT5:
2714
- if (this._caps.s3tc_srgb) {
2715
- internalFormat = gl.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
2716
- }
2717
- else {
2718
- // S3TC sRGB extension not supported
2719
- texture._useSRGBBuffer = false;
2720
- }
2721
- break;
2722
- default:
2723
- // We don't support a sRGB format corresponding to internalFormat, so revert to non sRGB format
2724
- texture._useSRGBBuffer = false;
2725
- break;
2726
- }
2727
- }
2728
- this._gl.compressedTexImage2D(target, lod, internalFormat, width, height, 0, data);
2729
- }
2730
- /**
2731
- * @internal
2732
- */
2733
- _uploadDataToTextureDirectly(texture, imageData, faceIndex = 0, lod = 0, babylonInternalFormat, useTextureWidthAndHeight = false) {
2734
- const gl = this._gl;
2735
- const textureType = this._getWebGLTextureType(texture.type);
2736
- const format = this._getInternalFormat(texture.format);
2737
- const internalFormat = babylonInternalFormat === undefined
2738
- ? this._getRGBABufferInternalSizedFormat(texture.type, texture.format, texture._useSRGBBuffer)
2739
- : this._getInternalFormat(babylonInternalFormat, texture._useSRGBBuffer);
2740
- this._unpackFlipY(texture.invertY);
2741
- let target = gl.TEXTURE_2D;
2742
- if (texture.isCube) {
2743
- target = gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex;
2744
- }
2745
- const lodMaxWidth = Math.round(Math.log(texture.width) * Math.LOG2E);
2746
- const lodMaxHeight = Math.round(Math.log(texture.height) * Math.LOG2E);
2747
- const width = useTextureWidthAndHeight ? texture.width : Math.pow(2, Math.max(lodMaxWidth - lod, 0));
2748
- const height = useTextureWidthAndHeight ? texture.height : Math.pow(2, Math.max(lodMaxHeight - lod, 0));
2749
- gl.texImage2D(target, lod, internalFormat, width, height, 0, format, textureType, imageData);
2750
- }
2751
- /**
2752
- * Update a portion of an internal texture
2753
- * @param texture defines the texture to update
2754
- * @param imageData defines the data to store into the texture
2755
- * @param xOffset defines the x coordinates of the update rectangle
2756
- * @param yOffset defines the y coordinates of the update rectangle
2757
- * @param width defines the width of the update rectangle
2758
- * @param height defines the height of the update rectangle
2759
- * @param faceIndex defines the face index if texture is a cube (0 by default)
2760
- * @param lod defines the lod level to update (0 by default)
2761
- * @param generateMipMaps defines whether to generate mipmaps or not
2762
- */
2763
- updateTextureData(texture, imageData, xOffset, yOffset, width, height, faceIndex = 0, lod = 0, generateMipMaps = false) {
2764
- const gl = this._gl;
2765
- const textureType = this._getWebGLTextureType(texture.type);
2766
- const format = this._getInternalFormat(texture.format);
2767
- this._unpackFlipY(texture.invertY);
2768
- let targetForBinding = gl.TEXTURE_2D;
2769
- let target = gl.TEXTURE_2D;
2770
- if (texture.isCube) {
2771
- target = gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex;
2772
- targetForBinding = gl.TEXTURE_CUBE_MAP;
2773
- }
2774
- this._bindTextureDirectly(targetForBinding, texture, true);
2775
- gl.texSubImage2D(target, lod, xOffset, yOffset, width, height, format, textureType, imageData);
2776
- if (generateMipMaps) {
2777
- this._gl.generateMipmap(target);
2778
- }
2779
- this._bindTextureDirectly(targetForBinding, null);
2780
- }
2781
- /**
2782
- * @internal
2783
- */
2784
- _uploadArrayBufferViewToTexture(texture, imageData, faceIndex = 0, lod = 0) {
2785
- const gl = this._gl;
2786
- const bindTarget = texture.isCube ? gl.TEXTURE_CUBE_MAP : gl.TEXTURE_2D;
2787
- this._bindTextureDirectly(bindTarget, texture, true);
2788
- this._uploadDataToTextureDirectly(texture, imageData, faceIndex, lod);
2789
- this._bindTextureDirectly(bindTarget, null, true);
2790
- }
2791
- _prepareWebGLTextureContinuation(texture, scene, noMipmap, isCompressed, samplingMode) {
2792
- const gl = this._gl;
2793
- if (!gl) {
2794
- return;
2795
- }
2796
- const filters = this._getSamplingParameters(samplingMode, !noMipmap);
2797
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filters.mag);
2798
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filters.min);
2799
- if (!noMipmap && !isCompressed) {
2800
- gl.generateMipmap(gl.TEXTURE_2D);
2801
- }
2802
- this._bindTextureDirectly(gl.TEXTURE_2D, null);
2803
- // this.resetTextureCache();
2804
- if (scene) {
2805
- scene.removePendingData(texture);
2806
- }
2807
- texture.onLoadedObservable.notifyObservers(texture);
2808
- texture.onLoadedObservable.clear();
2809
- }
2810
- _prepareWebGLTexture(texture, extension, scene, img, invertY, noMipmap, isCompressed, processFunction, samplingMode, format) {
2811
- const maxTextureSize = this.getCaps().maxTextureSize;
2812
- const potWidth = Math.min(maxTextureSize, this.needPOTTextures ? GetExponentOfTwo(img.width, maxTextureSize) : img.width);
2813
- const potHeight = Math.min(maxTextureSize, this.needPOTTextures ? GetExponentOfTwo(img.height, maxTextureSize) : img.height);
2814
- const gl = this._gl;
2815
- if (!gl) {
2816
- return;
2817
- }
2818
- if (!texture._hardwareTexture) {
2819
- // this.resetTextureCache();
2820
- if (scene) {
2821
- scene.removePendingData(texture);
2822
- }
2823
- return;
2824
- }
2825
- this._bindTextureDirectly(gl.TEXTURE_2D, texture, true);
2826
- this._unpackFlipY(invertY === undefined ? true : invertY ? true : false);
2827
- texture.baseWidth = img.width;
2828
- texture.baseHeight = img.height;
2829
- texture.width = potWidth;
2830
- texture.height = potHeight;
2831
- texture.isReady = true;
2832
- texture.type = texture.type !== -1 ? texture.type : Constants.TEXTURETYPE_UNSIGNED_BYTE;
2833
- texture.format =
2834
- texture.format !== -1 ? texture.format : (format ?? (extension === ".jpg" && !texture._useSRGBBuffer ? Constants.TEXTUREFORMAT_RGB : Constants.TEXTUREFORMAT_RGBA));
2835
- if (processFunction(potWidth, potHeight, img, extension, texture, () => {
2836
- this._prepareWebGLTextureContinuation(texture, scene, noMipmap, isCompressed, samplingMode);
2837
- })) {
2838
- // Returning as texture needs extra async steps
2839
- return;
2840
- }
2841
- this._prepareWebGLTextureContinuation(texture, scene, noMipmap, isCompressed, samplingMode);
2842
- }
2843
- _getInternalFormatFromDepthTextureFormat(textureFormat, hasDepth, hasStencil) {
2844
- const gl = this._gl;
2845
- if (!hasDepth) {
2846
- return gl.STENCIL_INDEX8;
2847
- }
2848
- const format = hasStencil ? gl.DEPTH_STENCIL : gl.DEPTH_COMPONENT;
2849
- let internalFormat = format;
2850
- if (this.webGLVersion > 1) {
2851
- if (textureFormat === Constants.TEXTUREFORMAT_DEPTH16) {
2852
- internalFormat = gl.DEPTH_COMPONENT16;
2853
- }
2854
- else if (textureFormat === Constants.TEXTUREFORMAT_DEPTH24) {
2855
- internalFormat = gl.DEPTH_COMPONENT24;
2856
- }
2857
- else if (textureFormat === Constants.TEXTUREFORMAT_DEPTH24UNORM_STENCIL8 || textureFormat === Constants.TEXTUREFORMAT_DEPTH24_STENCIL8) {
2858
- internalFormat = hasStencil ? gl.DEPTH24_STENCIL8 : gl.DEPTH_COMPONENT24;
2859
- }
2860
- else if (textureFormat === Constants.TEXTUREFORMAT_DEPTH32_FLOAT) {
2861
- internalFormat = gl.DEPTH_COMPONENT32F;
2862
- }
2863
- else if (textureFormat === Constants.TEXTUREFORMAT_DEPTH32FLOAT_STENCIL8) {
2864
- internalFormat = hasStencil ? gl.DEPTH32F_STENCIL8 : gl.DEPTH_COMPONENT32F;
2865
- }
2866
- }
2867
- else {
2868
- internalFormat = gl.DEPTH_COMPONENT16;
2869
- }
2870
- return internalFormat;
2871
- }
2872
- /**
2873
- * @internal
2874
- */
2875
- _setupFramebufferDepthAttachments(generateStencilBuffer, generateDepthBuffer, width, height, samples = 1, depthTextureFormat) {
2876
- const gl = this._gl;
2877
- depthTextureFormat = depthTextureFormat ?? (generateStencilBuffer ? Constants.TEXTUREFORMAT_DEPTH24_STENCIL8 : Constants.TEXTUREFORMAT_DEPTH32_FLOAT);
2878
- const internalFormat = this._getInternalFormatFromDepthTextureFormat(depthTextureFormat, generateDepthBuffer, generateStencilBuffer);
2879
- // Create the depth/stencil buffer
2880
- if (generateStencilBuffer && generateDepthBuffer) {
2881
- return this._createRenderBuffer(width, height, samples, gl.DEPTH_STENCIL, internalFormat, gl.DEPTH_STENCIL_ATTACHMENT);
2882
- }
2883
- if (generateDepthBuffer) {
2884
- return this._createRenderBuffer(width, height, samples, internalFormat, internalFormat, gl.DEPTH_ATTACHMENT);
2885
- }
2886
- if (generateStencilBuffer) {
2887
- return this._createRenderBuffer(width, height, samples, internalFormat, internalFormat, gl.STENCIL_ATTACHMENT);
2888
- }
2889
- return null;
2890
- }
2891
- /**
2892
- * @internal
2893
- */
2894
- _createRenderBuffer(width, height, samples, internalFormat, msInternalFormat, attachment, unbindBuffer = true) {
2895
- const gl = this._gl;
2896
- const renderBuffer = gl.createRenderbuffer();
2897
- return this._updateRenderBuffer(renderBuffer, width, height, samples, internalFormat, msInternalFormat, attachment, unbindBuffer);
2898
- }
2899
- _updateRenderBuffer(renderBuffer, width, height, samples, internalFormat, msInternalFormat, attachment, unbindBuffer = true) {
2900
- const gl = this._gl;
2901
- gl.bindRenderbuffer(gl.RENDERBUFFER, renderBuffer);
2902
- if (samples > 1 && gl.renderbufferStorageMultisample) {
2903
- gl.renderbufferStorageMultisample(gl.RENDERBUFFER, samples, msInternalFormat, width, height);
2904
- }
2905
- else {
2906
- gl.renderbufferStorage(gl.RENDERBUFFER, internalFormat, width, height);
2907
- }
2908
- gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment, gl.RENDERBUFFER, renderBuffer);
2909
- if (unbindBuffer) {
2910
- gl.bindRenderbuffer(gl.RENDERBUFFER, null);
2911
- }
2912
- return renderBuffer;
2913
- }
2914
- /**
2915
- * @internal
2916
- */
2917
- _releaseTexture(texture) {
2918
- this._deleteTexture(texture._hardwareTexture);
2919
- // Unbind channels
2920
- this.unbindAllTextures();
2921
- const index = this._internalTexturesCache.indexOf(texture);
2922
- if (index !== -1) {
2923
- this._internalTexturesCache.splice(index, 1);
2924
- }
2925
- // Integrated fixed lod samplers.
2926
- if (texture._lodTextureHigh) {
2927
- texture._lodTextureHigh.dispose();
2928
- }
2929
- if (texture._lodTextureMid) {
2930
- texture._lodTextureMid.dispose();
2931
- }
2932
- if (texture._lodTextureLow) {
2933
- texture._lodTextureLow.dispose();
2934
- }
2935
- // Integrated irradiance map.
2936
- if (texture._irradianceTexture) {
2937
- texture._irradianceTexture.dispose();
2938
- }
2939
- }
2940
- _deleteTexture(texture) {
2941
- texture?.release();
2942
- }
2943
- _setProgram(program) {
2944
- if (this._currentProgram !== program) {
2945
- _setProgram(program, this._gl);
2946
- this._currentProgram = program;
2947
- }
2948
- }
2949
- /**
2950
- * Binds an effect to the webGL context
2951
- * @param effect defines the effect to bind
2952
- */
2953
- bindSamplers(effect) {
2954
- const webGLPipelineContext = effect.getPipelineContext();
2955
- this._setProgram(webGLPipelineContext.program);
2956
- const samplers = effect.getSamplers();
2957
- for (let index = 0; index < samplers.length; index++) {
2958
- const uniform = effect.getUniform(samplers[index]);
2959
- if (uniform) {
2960
- this._boundUniforms[index] = uniform;
2961
- }
2962
- }
2963
- this._currentEffect = null;
2964
- }
2965
- _activateCurrentTexture() {
2966
- if (this._currentTextureChannel !== this._activeChannel) {
2967
- this._gl.activeTexture(this._gl.TEXTURE0 + this._activeChannel);
2968
- this._currentTextureChannel = this._activeChannel;
2969
- }
2970
- }
2971
- /**
2972
- * @internal
2973
- */
2974
- _bindTextureDirectly(target, texture, forTextureDataUpdate = false, force = false) {
2975
- let wasPreviouslyBound = false;
2976
- const isTextureForRendering = texture && texture._associatedChannel > -1;
2977
- if (forTextureDataUpdate && isTextureForRendering) {
2978
- this._activeChannel = texture._associatedChannel;
2979
- }
2980
- const currentTextureBound = this._boundTexturesCache[this._activeChannel];
2981
- if (currentTextureBound !== texture || force) {
2982
- this._activateCurrentTexture();
2983
- if (texture && texture.isMultiview) {
2984
- //this._gl.bindTexture(target, texture ? texture._colorTextureArray : null);
2985
- Logger.Error(["_bindTextureDirectly called with a multiview texture!", target, texture]);
2986
- // eslint-disable-next-line no-throw-literal
2987
- throw "_bindTextureDirectly called with a multiview texture!";
2988
- }
2989
- else {
2990
- this._gl.bindTexture(target, texture?._hardwareTexture?.underlyingResource ?? null);
2991
- }
2992
- this._boundTexturesCache[this._activeChannel] = texture;
2993
- if (texture) {
2994
- texture._associatedChannel = this._activeChannel;
2995
- }
2996
- }
2997
- else if (forTextureDataUpdate) {
2998
- wasPreviouslyBound = true;
2999
- this._activateCurrentTexture();
3000
- }
3001
- if (isTextureForRendering && !forTextureDataUpdate) {
3002
- this._bindSamplerUniformToChannel(texture._associatedChannel, this._activeChannel);
3003
- }
3004
- return wasPreviouslyBound;
3005
- }
3006
- /**
3007
- * @internal
3008
- */
3009
- _bindTexture(channel, texture, name) {
3010
- if (channel === undefined) {
3011
- return;
3012
- }
3013
- if (texture) {
3014
- texture._associatedChannel = channel;
3015
- }
3016
- this._activeChannel = channel;
3017
- const target = texture ? this._getTextureTarget(texture) : this._gl.TEXTURE_2D;
3018
- this._bindTextureDirectly(target, texture);
3019
- }
3020
- /**
3021
- * Unbind all textures from the webGL context
3022
- */
3023
- unbindAllTextures() {
3024
- for (let channel = 0; channel < this._maxSimultaneousTextures; channel++) {
3025
- this._activeChannel = channel;
3026
- this._bindTextureDirectly(this._gl.TEXTURE_2D, null);
3027
- this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, null);
3028
- if (this.webGLVersion > 1) {
3029
- this._bindTextureDirectly(this._gl.TEXTURE_3D, null);
3030
- this._bindTextureDirectly(this._gl.TEXTURE_2D_ARRAY, null);
3031
- }
3032
- }
3033
- }
3034
- /**
3035
- * Sets a texture to the according uniform.
3036
- * @param channel The texture channel
3037
- * @param uniform The uniform to set
3038
- * @param texture The texture to apply
3039
- * @param name The name of the uniform in the effect
3040
- */
3041
- setTexture(channel, uniform, texture, name) {
3042
- if (channel === undefined) {
3043
- return;
3044
- }
3045
- if (uniform) {
3046
- this._boundUniforms[channel] = uniform;
3047
- }
3048
- this._setTexture(channel, texture);
3049
- }
3050
- _bindSamplerUniformToChannel(sourceSlot, destination) {
3051
- const uniform = this._boundUniforms[sourceSlot];
3052
- if (!uniform || uniform._currentState === destination) {
3053
- return;
3054
- }
3055
- this._gl.uniform1i(uniform, destination);
3056
- uniform._currentState = destination;
3057
- }
3058
- _getTextureWrapMode(mode) {
3059
- switch (mode) {
3060
- case Constants.TEXTURE_WRAP_ADDRESSMODE:
3061
- return this._gl.REPEAT;
3062
- case Constants.TEXTURE_CLAMP_ADDRESSMODE:
3063
- return this._gl.CLAMP_TO_EDGE;
3064
- case Constants.TEXTURE_MIRROR_ADDRESSMODE:
3065
- return this._gl.MIRRORED_REPEAT;
3066
- }
3067
- return this._gl.REPEAT;
3068
- }
3069
- _setTexture(channel, texture, isPartOfTextureArray = false, depthStencilTexture = false, name = "") {
3070
- // Not ready?
3071
- if (!texture) {
3072
- if (this._boundTexturesCache[channel] != null) {
3073
- this._activeChannel = channel;
3074
- this._bindTextureDirectly(this._gl.TEXTURE_2D, null);
3075
- this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, null);
3076
- if (this.webGLVersion > 1) {
3077
- this._bindTextureDirectly(this._gl.TEXTURE_3D, null);
3078
- this._bindTextureDirectly(this._gl.TEXTURE_2D_ARRAY, null);
3079
- }
3080
- }
3081
- return false;
3082
- }
3083
- // Video
3084
- if (texture.video) {
3085
- this._activeChannel = channel;
3086
- const videoInternalTexture = texture.getInternalTexture();
3087
- if (videoInternalTexture) {
3088
- videoInternalTexture._associatedChannel = channel;
3089
- }
3090
- texture.update();
3091
- }
3092
- else if (texture.delayLoadState === Constants.DELAYLOADSTATE_NOTLOADED) {
3093
- // Delay loading
3094
- texture.delayLoad();
3095
- return false;
3096
- }
3097
- let internalTexture;
3098
- if (depthStencilTexture) {
3099
- internalTexture = texture.depthStencilTexture;
3100
- }
3101
- else if (texture.isReady()) {
3102
- internalTexture = texture.getInternalTexture();
3103
- }
3104
- else if (texture.isCube) {
3105
- internalTexture = this.emptyCubeTexture;
3106
- }
3107
- else if (texture.is3D) {
3108
- internalTexture = this.emptyTexture3D;
3109
- }
3110
- else if (texture.is2DArray) {
3111
- internalTexture = this.emptyTexture2DArray;
3112
- }
3113
- else {
3114
- internalTexture = this.emptyTexture;
3115
- }
3116
- if (!isPartOfTextureArray && internalTexture) {
3117
- internalTexture._associatedChannel = channel;
3118
- }
3119
- let needToBind = true;
3120
- if (this._boundTexturesCache[channel] === internalTexture) {
3121
- if (!isPartOfTextureArray) {
3122
- this._bindSamplerUniformToChannel(internalTexture._associatedChannel, channel);
3123
- }
3124
- needToBind = false;
3125
- }
3126
- this._activeChannel = channel;
3127
- const target = this._getTextureTarget(internalTexture);
3128
- if (needToBind) {
3129
- this._bindTextureDirectly(target, internalTexture, isPartOfTextureArray);
3130
- }
3131
- if (internalTexture && !internalTexture.isMultiview) {
3132
- // CUBIC_MODE and SKYBOX_MODE both require CLAMP_TO_EDGE. All other modes use REPEAT.
3133
- if (internalTexture.isCube && internalTexture._cachedCoordinatesMode !== texture.coordinatesMode) {
3134
- internalTexture._cachedCoordinatesMode = texture.coordinatesMode;
3135
- const textureWrapMode = texture.coordinatesMode !== Constants.TEXTURE_CUBIC_MODE && texture.coordinatesMode !== Constants.TEXTURE_SKYBOX_MODE
3136
- ? Constants.TEXTURE_WRAP_ADDRESSMODE
3137
- : Constants.TEXTURE_CLAMP_ADDRESSMODE;
3138
- texture.wrapU = textureWrapMode;
3139
- texture.wrapV = textureWrapMode;
3140
- }
3141
- if (internalTexture._cachedWrapU !== texture.wrapU) {
3142
- internalTexture._cachedWrapU = texture.wrapU;
3143
- this._setTextureParameterInteger(target, this._gl.TEXTURE_WRAP_S, this._getTextureWrapMode(texture.wrapU), internalTexture);
3144
- }
3145
- if (internalTexture._cachedWrapV !== texture.wrapV) {
3146
- internalTexture._cachedWrapV = texture.wrapV;
3147
- this._setTextureParameterInteger(target, this._gl.TEXTURE_WRAP_T, this._getTextureWrapMode(texture.wrapV), internalTexture);
3148
- }
3149
- if (internalTexture.is3D && internalTexture._cachedWrapR !== texture.wrapR) {
3150
- internalTexture._cachedWrapR = texture.wrapR;
3151
- this._setTextureParameterInteger(target, this._gl.TEXTURE_WRAP_R, this._getTextureWrapMode(texture.wrapR), internalTexture);
3152
- }
3153
- this._setAnisotropicLevel(target, internalTexture, texture.anisotropicFilteringLevel);
3154
- }
3155
- return true;
3156
- }
3157
- /**
3158
- * Sets an array of texture to the webGL context
3159
- * @param channel defines the channel where the texture array must be set
3160
- * @param uniform defines the associated uniform location
3161
- * @param textures defines the array of textures to bind
3162
- * @param name name of the channel
3163
- */
3164
- setTextureArray(channel, uniform, textures, name) {
3165
- if (channel === undefined || !uniform) {
3166
- return;
3167
- }
3168
- if (!this._textureUnits || this._textureUnits.length !== textures.length) {
3169
- this._textureUnits = new Int32Array(textures.length);
3170
- }
3171
- for (let i = 0; i < textures.length; i++) {
3172
- const texture = textures[i].getInternalTexture();
3173
- if (texture) {
3174
- this._textureUnits[i] = channel + i;
3175
- texture._associatedChannel = channel + i;
3176
- }
3177
- else {
3178
- this._textureUnits[i] = -1;
3179
- }
3180
- }
3181
- this._gl.uniform1iv(uniform, this._textureUnits);
3182
- for (let index = 0; index < textures.length; index++) {
3183
- this._setTexture(this._textureUnits[index], textures[index], true);
3184
- }
3185
- }
3186
- /**
3187
- * @internal
3188
- */
3189
- _setAnisotropicLevel(target, internalTexture, anisotropicFilteringLevel) {
3190
- const anisotropicFilterExtension = this._caps.textureAnisotropicFilterExtension;
3191
- if (internalTexture.samplingMode !== Constants.TEXTURE_LINEAR_LINEAR_MIPNEAREST &&
3192
- internalTexture.samplingMode !== Constants.TEXTURE_LINEAR_LINEAR_MIPLINEAR &&
3193
- internalTexture.samplingMode !== Constants.TEXTURE_LINEAR_LINEAR) {
3194
- anisotropicFilteringLevel = 1; // Forcing the anisotropic to 1 because else webgl will force filters to linear
3195
- }
3196
- if (anisotropicFilterExtension && internalTexture._cachedAnisotropicFilteringLevel !== anisotropicFilteringLevel) {
3197
- this._setTextureParameterFloat(target, anisotropicFilterExtension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(anisotropicFilteringLevel, this._caps.maxAnisotropy), internalTexture);
3198
- internalTexture._cachedAnisotropicFilteringLevel = anisotropicFilteringLevel;
3199
- }
3200
- }
3201
- _setTextureParameterFloat(target, parameter, value, texture) {
3202
- this._bindTextureDirectly(target, texture, true, true);
3203
- this._gl.texParameterf(target, parameter, value);
3204
- }
3205
- _setTextureParameterInteger(target, parameter, value, texture) {
3206
- if (texture) {
3207
- this._bindTextureDirectly(target, texture, true, true);
3208
- }
3209
- this._gl.texParameteri(target, parameter, value);
3210
- }
3211
- /**
3212
- * Unbind all vertex attributes from the webGL context
3213
- */
3214
- unbindAllAttributes() {
3215
- if (this._mustWipeVertexAttributes) {
3216
- this._mustWipeVertexAttributes = false;
3217
- for (let i = 0; i < this._caps.maxVertexAttribs; i++) {
3218
- this.disableAttributeByIndex(i);
3219
- }
3220
- return;
3221
- }
3222
- for (let i = 0, ul = this._vertexAttribArraysEnabled.length; i < ul; i++) {
3223
- if (i >= this._caps.maxVertexAttribs || !this._vertexAttribArraysEnabled[i]) {
3224
- continue;
3225
- }
3226
- this.disableAttributeByIndex(i);
3227
- }
3228
- }
3229
- /**
3230
- * Force the engine to release all cached effects. This means that next effect compilation will have to be done completely even if a similar effect was already compiled
3231
- */
3232
- releaseEffects() {
3233
- const keys = Object.keys(this._compiledEffects);
3234
- for (const name of keys) {
3235
- const effect = this._compiledEffects[name];
3236
- effect.dispose();
3237
- }
3238
- this._compiledEffects = {};
3239
- }
3240
- /**
3241
- * Dispose and release all associated resources
3242
- */
3243
- dispose() {
3244
- // Events
3245
- if (IsWindowObjectExist()) {
3246
- if (this._renderingCanvas) {
3247
- if (!this._doNotHandleContextLost) {
3248
- this._renderingCanvas.removeEventListener("webglcontextlost", this._onContextLost);
3249
- this._renderingCanvas.removeEventListener("webglcontextrestored", this._onContextRestored);
3250
- }
3251
- }
3252
- }
3253
- // Should not be moved up of renderingCanvas will be null.
3254
- super.dispose();
3255
- if (this._dummyFramebuffer) {
3256
- this._gl.deleteFramebuffer(this._dummyFramebuffer);
3257
- }
3258
- // Unbind
3259
- this.unbindAllAttributes();
3260
- this._boundUniforms = {};
3261
- this._workingCanvas = null;
3262
- this._workingContext = null;
3263
- this._currentBufferPointers.length = 0;
3264
- this._currentProgram = null;
3265
- if (this._creationOptions.loseContextOnDispose) {
3266
- this._gl.getExtension("WEBGL_lose_context")?.loseContext();
3267
- }
3268
- // clear the state object
3269
- deleteStateObject(this._gl);
3270
- }
3271
- /**
3272
- * Attach a new callback raised when context lost event is fired
3273
- * @param callback defines the callback to call
3274
- */
3275
- attachContextLostEvent(callback) {
3276
- if (this._renderingCanvas) {
3277
- this._renderingCanvas.addEventListener("webglcontextlost", callback, false);
3278
- }
3279
- }
3280
- /**
3281
- * Attach a new callback raised when context restored event is fired
3282
- * @param callback defines the callback to call
3283
- */
3284
- attachContextRestoredEvent(callback) {
3285
- if (this._renderingCanvas) {
3286
- this._renderingCanvas.addEventListener("webglcontextrestored", callback, false);
3287
- }
3288
- }
3289
- /**
3290
- * Get the current error code of the webGL context
3291
- * @returns the error code
3292
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/getError
3293
- */
3294
- getError() {
3295
- return this._gl.getError();
3296
- }
3297
- _canRenderToFloatFramebuffer() {
3298
- if (this._webGLVersion > 1) {
3299
- return this._caps.colorBufferFloat;
3300
- }
3301
- return this._canRenderToFramebuffer(Constants.TEXTURETYPE_FLOAT);
3302
- }
3303
- _canRenderToHalfFloatFramebuffer() {
3304
- if (this._webGLVersion > 1) {
3305
- return this._caps.colorBufferFloat;
3306
- }
3307
- return this._canRenderToFramebuffer(Constants.TEXTURETYPE_HALF_FLOAT);
3308
- }
3309
- // Thank you : http://stackoverflow.com/questions/28827511/webgl-ios-render-to-floating-point-texture
3310
- _canRenderToFramebuffer(type) {
3311
- const gl = this._gl;
3312
- //clear existing errors
3313
- // eslint-disable-next-line no-empty
3314
- while (gl.getError() !== gl.NO_ERROR) { }
3315
- let successful = true;
3316
- const texture = gl.createTexture();
3317
- gl.bindTexture(gl.TEXTURE_2D, texture);
3318
- gl.texImage2D(gl.TEXTURE_2D, 0, this._getRGBABufferInternalSizedFormat(type), 1, 1, 0, gl.RGBA, this._getWebGLTextureType(type), null);
3319
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
3320
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
3321
- const fb = gl.createFramebuffer();
3322
- gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
3323
- gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
3324
- const status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
3325
- successful = successful && status === gl.FRAMEBUFFER_COMPLETE;
3326
- successful = successful && gl.getError() === gl.NO_ERROR;
3327
- //try render by clearing frame buffer's color buffer
3328
- if (successful) {
3329
- gl.clear(gl.COLOR_BUFFER_BIT);
3330
- successful = successful && gl.getError() === gl.NO_ERROR;
3331
- }
3332
- //try reading from frame to ensure render occurs (just creating the FBO is not sufficient to determine if rendering is supported)
3333
- if (successful) {
3334
- //in practice it's sufficient to just read from the backbuffer rather than handle potentially issues reading from the texture
3335
- gl.bindFramebuffer(gl.FRAMEBUFFER, null);
3336
- const readFormat = gl.RGBA;
3337
- const readType = gl.UNSIGNED_BYTE;
3338
- const buffer = new Uint8Array(4);
3339
- gl.readPixels(0, 0, 1, 1, readFormat, readType, buffer);
3340
- successful = successful && gl.getError() === gl.NO_ERROR;
3341
- }
3342
- //clean up
3343
- gl.deleteTexture(texture);
3344
- gl.deleteFramebuffer(fb);
3345
- gl.bindFramebuffer(gl.FRAMEBUFFER, null);
3346
- //clear accumulated errors
3347
- // eslint-disable-next-line no-empty
3348
- while (!successful && gl.getError() !== gl.NO_ERROR) { }
3349
- return successful;
3350
- }
3351
- /**
3352
- * @internal
3353
- */
3354
- _getWebGLTextureType(type) {
3355
- if (this._webGLVersion === 1) {
3356
- switch (type) {
3357
- case Constants.TEXTURETYPE_FLOAT:
3358
- return this._gl.FLOAT;
3359
- case Constants.TEXTURETYPE_HALF_FLOAT:
3360
- return this._gl.HALF_FLOAT_OES;
3361
- case Constants.TEXTURETYPE_UNSIGNED_BYTE:
3362
- return this._gl.UNSIGNED_BYTE;
3363
- case Constants.TEXTURETYPE_UNSIGNED_SHORT_4_4_4_4:
3364
- return this._gl.UNSIGNED_SHORT_4_4_4_4;
3365
- case Constants.TEXTURETYPE_UNSIGNED_SHORT_5_5_5_1:
3366
- return this._gl.UNSIGNED_SHORT_5_5_5_1;
3367
- case Constants.TEXTURETYPE_UNSIGNED_SHORT_5_6_5:
3368
- return this._gl.UNSIGNED_SHORT_5_6_5;
3369
- }
3370
- return this._gl.UNSIGNED_BYTE;
3371
- }
3372
- switch (type) {
3373
- case Constants.TEXTURETYPE_BYTE:
3374
- return this._gl.BYTE;
3375
- case Constants.TEXTURETYPE_UNSIGNED_BYTE:
3376
- return this._gl.UNSIGNED_BYTE;
3377
- case Constants.TEXTURETYPE_SHORT:
3378
- return this._gl.SHORT;
3379
- case Constants.TEXTURETYPE_UNSIGNED_SHORT:
3380
- return this._gl.UNSIGNED_SHORT;
3381
- case Constants.TEXTURETYPE_INT:
3382
- return this._gl.INT;
3383
- case Constants.TEXTURETYPE_UNSIGNED_INTEGER: // Refers to UNSIGNED_INT
3384
- return this._gl.UNSIGNED_INT;
3385
- case Constants.TEXTURETYPE_FLOAT:
3386
- return this._gl.FLOAT;
3387
- case Constants.TEXTURETYPE_HALF_FLOAT:
3388
- return this._gl.HALF_FLOAT;
3389
- case Constants.TEXTURETYPE_UNSIGNED_SHORT_4_4_4_4:
3390
- return this._gl.UNSIGNED_SHORT_4_4_4_4;
3391
- case Constants.TEXTURETYPE_UNSIGNED_SHORT_5_5_5_1:
3392
- return this._gl.UNSIGNED_SHORT_5_5_5_1;
3393
- case Constants.TEXTURETYPE_UNSIGNED_SHORT_5_6_5:
3394
- return this._gl.UNSIGNED_SHORT_5_6_5;
3395
- case Constants.TEXTURETYPE_UNSIGNED_INT_2_10_10_10_REV:
3396
- return this._gl.UNSIGNED_INT_2_10_10_10_REV;
3397
- case Constants.TEXTURETYPE_UNSIGNED_INT_24_8:
3398
- return this._gl.UNSIGNED_INT_24_8;
3399
- case Constants.TEXTURETYPE_UNSIGNED_INT_10F_11F_11F_REV:
3400
- return this._gl.UNSIGNED_INT_10F_11F_11F_REV;
3401
- case Constants.TEXTURETYPE_UNSIGNED_INT_5_9_9_9_REV:
3402
- return this._gl.UNSIGNED_INT_5_9_9_9_REV;
3403
- case Constants.TEXTURETYPE_FLOAT_32_UNSIGNED_INT_24_8_REV:
3404
- return this._gl.FLOAT_32_UNSIGNED_INT_24_8_REV;
3405
- }
3406
- return this._gl.UNSIGNED_BYTE;
3407
- }
3408
- /**
3409
- * @internal
3410
- */
3411
- _getInternalFormat(format, useSRGBBuffer = false) {
3412
- let internalFormat = useSRGBBuffer ? this._glSRGBExtensionValues.SRGB8_ALPHA8 : this._gl.RGBA;
3413
- switch (format) {
3414
- case Constants.TEXTUREFORMAT_ALPHA:
3415
- internalFormat = this._gl.ALPHA;
3416
- break;
3417
- case Constants.TEXTUREFORMAT_LUMINANCE:
3418
- internalFormat = this._gl.LUMINANCE;
3419
- break;
3420
- case Constants.TEXTUREFORMAT_LUMINANCE_ALPHA:
3421
- internalFormat = this._gl.LUMINANCE_ALPHA;
3422
- break;
3423
- case Constants.TEXTUREFORMAT_RED:
3424
- internalFormat = this._gl.RED;
3425
- break;
3426
- case Constants.TEXTUREFORMAT_RG:
3427
- internalFormat = this._gl.RG;
3428
- break;
3429
- case Constants.TEXTUREFORMAT_RGB:
3430
- internalFormat = useSRGBBuffer ? this._glSRGBExtensionValues.SRGB : this._gl.RGB;
3431
- break;
3432
- case Constants.TEXTUREFORMAT_RGBA:
3433
- internalFormat = useSRGBBuffer ? this._glSRGBExtensionValues.SRGB8_ALPHA8 : this._gl.RGBA;
3434
- break;
3435
- }
3436
- if (this._webGLVersion > 1) {
3437
- switch (format) {
3438
- case Constants.TEXTUREFORMAT_RED_INTEGER:
3439
- internalFormat = this._gl.RED_INTEGER;
3440
- break;
3441
- case Constants.TEXTUREFORMAT_RG_INTEGER:
3442
- internalFormat = this._gl.RG_INTEGER;
3443
- break;
3444
- case Constants.TEXTUREFORMAT_RGB_INTEGER:
3445
- internalFormat = this._gl.RGB_INTEGER;
3446
- break;
3447
- case Constants.TEXTUREFORMAT_RGBA_INTEGER:
3448
- internalFormat = this._gl.RGBA_INTEGER;
3449
- break;
3450
- }
3451
- }
3452
- return internalFormat;
3453
- }
3454
- /**
3455
- * @internal
3456
- */
3457
- _getRGBABufferInternalSizedFormat(type, format, useSRGBBuffer = false) {
3458
- if (this._webGLVersion === 1) {
3459
- if (format !== undefined) {
3460
- switch (format) {
3461
- case Constants.TEXTUREFORMAT_ALPHA:
3462
- return this._gl.ALPHA;
3463
- case Constants.TEXTUREFORMAT_LUMINANCE:
3464
- return this._gl.LUMINANCE;
3465
- case Constants.TEXTUREFORMAT_LUMINANCE_ALPHA:
3466
- return this._gl.LUMINANCE_ALPHA;
3467
- case Constants.TEXTUREFORMAT_RGB:
3468
- return useSRGBBuffer ? this._glSRGBExtensionValues.SRGB : this._gl.RGB;
3469
- }
3470
- }
3471
- return this._gl.RGBA;
3472
- }
3473
- switch (type) {
3474
- case Constants.TEXTURETYPE_BYTE:
3475
- switch (format) {
3476
- case Constants.TEXTUREFORMAT_RED:
3477
- return this._gl.R8_SNORM;
3478
- case Constants.TEXTUREFORMAT_RG:
3479
- return this._gl.RG8_SNORM;
3480
- case Constants.TEXTUREFORMAT_RGB:
3481
- return this._gl.RGB8_SNORM;
3482
- case Constants.TEXTUREFORMAT_RED_INTEGER:
3483
- return this._gl.R8I;
3484
- case Constants.TEXTUREFORMAT_RG_INTEGER:
3485
- return this._gl.RG8I;
3486
- case Constants.TEXTUREFORMAT_RGB_INTEGER:
3487
- return this._gl.RGB8I;
3488
- case Constants.TEXTUREFORMAT_RGBA_INTEGER:
3489
- return this._gl.RGBA8I;
3490
- default:
3491
- return this._gl.RGBA8_SNORM;
3492
- }
3493
- case Constants.TEXTURETYPE_UNSIGNED_BYTE:
3494
- switch (format) {
3495
- case Constants.TEXTUREFORMAT_RED:
3496
- return this._gl.R8;
3497
- case Constants.TEXTUREFORMAT_RG:
3498
- return this._gl.RG8;
3499
- case Constants.TEXTUREFORMAT_RGB:
3500
- return useSRGBBuffer ? this._glSRGBExtensionValues.SRGB8 : this._gl.RGB8; // By default. Other possibilities are RGB565, SRGB8.
3501
- case Constants.TEXTUREFORMAT_RGBA:
3502
- return useSRGBBuffer ? this._glSRGBExtensionValues.SRGB8_ALPHA8 : this._gl.RGBA8; // By default. Other possibilities are RGB5_A1, RGBA4, SRGB8_ALPHA8.
3503
- case Constants.TEXTUREFORMAT_RED_INTEGER:
3504
- return this._gl.R8UI;
3505
- case Constants.TEXTUREFORMAT_RG_INTEGER:
3506
- return this._gl.RG8UI;
3507
- case Constants.TEXTUREFORMAT_RGB_INTEGER:
3508
- return this._gl.RGB8UI;
3509
- case Constants.TEXTUREFORMAT_RGBA_INTEGER:
3510
- return this._gl.RGBA8UI;
3511
- case Constants.TEXTUREFORMAT_ALPHA:
3512
- return this._gl.ALPHA;
3513
- case Constants.TEXTUREFORMAT_LUMINANCE:
3514
- return this._gl.LUMINANCE;
3515
- case Constants.TEXTUREFORMAT_LUMINANCE_ALPHA:
3516
- return this._gl.LUMINANCE_ALPHA;
3517
- default:
3518
- return this._gl.RGBA8;
3519
- }
3520
- case Constants.TEXTURETYPE_SHORT:
3521
- switch (format) {
3522
- case Constants.TEXTUREFORMAT_RED_INTEGER:
3523
- return this._gl.R16I;
3524
- case Constants.TEXTUREFORMAT_RG_INTEGER:
3525
- return this._gl.RG16I;
3526
- case Constants.TEXTUREFORMAT_RGB_INTEGER:
3527
- return this._gl.RGB16I;
3528
- case Constants.TEXTUREFORMAT_RGBA_INTEGER:
3529
- return this._gl.RGBA16I;
3530
- default:
3531
- return this._gl.RGBA16I;
3532
- }
3533
- case Constants.TEXTURETYPE_UNSIGNED_SHORT:
3534
- switch (format) {
3535
- case Constants.TEXTUREFORMAT_RED_INTEGER:
3536
- return this._gl.R16UI;
3537
- case Constants.TEXTUREFORMAT_RG_INTEGER:
3538
- return this._gl.RG16UI;
3539
- case Constants.TEXTUREFORMAT_RGB_INTEGER:
3540
- return this._gl.RGB16UI;
3541
- case Constants.TEXTUREFORMAT_RGBA_INTEGER:
3542
- return this._gl.RGBA16UI;
3543
- default:
3544
- return this._gl.RGBA16UI;
3545
- }
3546
- case Constants.TEXTURETYPE_INT:
3547
- switch (format) {
3548
- case Constants.TEXTUREFORMAT_RED_INTEGER:
3549
- return this._gl.R32I;
3550
- case Constants.TEXTUREFORMAT_RG_INTEGER:
3551
- return this._gl.RG32I;
3552
- case Constants.TEXTUREFORMAT_RGB_INTEGER:
3553
- return this._gl.RGB32I;
3554
- case Constants.TEXTUREFORMAT_RGBA_INTEGER:
3555
- return this._gl.RGBA32I;
3556
- default:
3557
- return this._gl.RGBA32I;
3558
- }
3559
- case Constants.TEXTURETYPE_UNSIGNED_INTEGER: // Refers to UNSIGNED_INT
3560
- switch (format) {
3561
- case Constants.TEXTUREFORMAT_RED_INTEGER:
3562
- return this._gl.R32UI;
3563
- case Constants.TEXTUREFORMAT_RG_INTEGER:
3564
- return this._gl.RG32UI;
3565
- case Constants.TEXTUREFORMAT_RGB_INTEGER:
3566
- return this._gl.RGB32UI;
3567
- case Constants.TEXTUREFORMAT_RGBA_INTEGER:
3568
- return this._gl.RGBA32UI;
3569
- default:
3570
- return this._gl.RGBA32UI;
3571
- }
3572
- case Constants.TEXTURETYPE_FLOAT:
3573
- switch (format) {
3574
- case Constants.TEXTUREFORMAT_RED:
3575
- return this._gl.R32F; // By default. Other possibility is R16F.
3576
- case Constants.TEXTUREFORMAT_RG:
3577
- return this._gl.RG32F; // By default. Other possibility is RG16F.
3578
- case Constants.TEXTUREFORMAT_RGB:
3579
- return this._gl.RGB32F; // By default. Other possibilities are RGB16F, R11F_G11F_B10F, RGB9_E5.
3580
- case Constants.TEXTUREFORMAT_RGBA:
3581
- return this._gl.RGBA32F; // By default. Other possibility is RGBA16F.
3582
- default:
3583
- return this._gl.RGBA32F;
3584
- }
3585
- case Constants.TEXTURETYPE_HALF_FLOAT:
3586
- switch (format) {
3587
- case Constants.TEXTUREFORMAT_RED:
3588
- return this._gl.R16F;
3589
- case Constants.TEXTUREFORMAT_RG:
3590
- return this._gl.RG16F;
3591
- case Constants.TEXTUREFORMAT_RGB:
3592
- return this._gl.RGB16F; // By default. Other possibilities are R11F_G11F_B10F, RGB9_E5.
3593
- case Constants.TEXTUREFORMAT_RGBA:
3594
- return this._gl.RGBA16F;
3595
- default:
3596
- return this._gl.RGBA16F;
3597
- }
3598
- case Constants.TEXTURETYPE_UNSIGNED_SHORT_5_6_5:
3599
- return this._gl.RGB565;
3600
- case Constants.TEXTURETYPE_UNSIGNED_INT_10F_11F_11F_REV:
3601
- return this._gl.R11F_G11F_B10F;
3602
- case Constants.TEXTURETYPE_UNSIGNED_INT_5_9_9_9_REV:
3603
- return this._gl.RGB9_E5;
3604
- case Constants.TEXTURETYPE_UNSIGNED_SHORT_4_4_4_4:
3605
- return this._gl.RGBA4;
3606
- case Constants.TEXTURETYPE_UNSIGNED_SHORT_5_5_5_1:
3607
- return this._gl.RGB5_A1;
3608
- case Constants.TEXTURETYPE_UNSIGNED_INT_2_10_10_10_REV:
3609
- switch (format) {
3610
- case Constants.TEXTUREFORMAT_RGBA:
3611
- return this._gl.RGB10_A2; // By default. Other possibility is RGB5_A1.
3612
- case Constants.TEXTUREFORMAT_RGBA_INTEGER:
3613
- return this._gl.RGB10_A2UI;
3614
- default:
3615
- return this._gl.RGB10_A2;
3616
- }
3617
- }
3618
- return useSRGBBuffer ? this._glSRGBExtensionValues.SRGB8_ALPHA8 : this._gl.RGBA8;
3619
- }
3620
- /**
3621
- * Reads pixels from the current frame buffer. Please note that this function can be slow
3622
- * @param x defines the x coordinate of the rectangle where pixels must be read
3623
- * @param y defines the y coordinate of the rectangle where pixels must be read
3624
- * @param width defines the width of the rectangle where pixels must be read
3625
- * @param height defines the height of the rectangle where pixels must be read
3626
- * @param hasAlpha defines whether the output should have alpha or not (defaults to true)
3627
- * @param flushRenderer true to flush the renderer from the pending commands before reading the pixels
3628
- * @returns a ArrayBufferView promise (Uint8Array) containing RGBA colors
3629
- */
3630
- readPixels(x, y, width, height, hasAlpha = true, flushRenderer = true) {
3631
- const numChannels = hasAlpha ? 4 : 3;
3632
- const format = hasAlpha ? this._gl.RGBA : this._gl.RGB;
3633
- const data = new Uint8Array(height * width * numChannels);
3634
- if (flushRenderer) {
3635
- this.flushFramebuffer();
3636
- }
3637
- this._gl.readPixels(x, y, width, height, format, this._gl.UNSIGNED_BYTE, data);
3638
- return Promise.resolve(data);
3639
- }
3640
- /**
3641
- * Gets a Promise<boolean> indicating if the engine can be instantiated (ie. if a webGL context can be found)
3642
- */
3643
- static get IsSupportedAsync() {
3644
- return Promise.resolve(this.isSupported());
3645
- }
3646
- /**
3647
- * Gets a boolean indicating if the engine can be instantiated (ie. if a webGL context can be found)
3648
- */
3649
- static get IsSupported() {
3650
- return this.isSupported(); // Backward compat
3651
- }
3652
- /**
3653
- * Gets a boolean indicating if the engine can be instantiated (ie. if a webGL context can be found)
3654
- * @returns true if the engine can be created
3655
- * @ignorenaming
3656
- */
3657
- // eslint-disable-next-line @typescript-eslint/naming-convention
3658
- static isSupported() {
3659
- if (this._HasMajorPerformanceCaveat !== null) {
3660
- return !this._HasMajorPerformanceCaveat; // We know it is performant so WebGL is supported
3661
- }
3662
- if (this._IsSupported === null) {
3663
- try {
3664
- const tempcanvas = AbstractEngine._CreateCanvas(1, 1);
3665
- const gl = tempcanvas.getContext("webgl") || tempcanvas.getContext("experimental-webgl");
3666
- this._IsSupported = gl != null && !!window.WebGLRenderingContext;
3667
- }
3668
- catch (e) {
3669
- this._IsSupported = false;
3670
- }
3671
- }
3672
- return this._IsSupported;
3673
- }
3674
- /**
3675
- * Gets a boolean indicating if the engine can be instantiated on a performant device (ie. if a webGL context can be found and it does not use a slow implementation)
3676
- */
3677
- static get HasMajorPerformanceCaveat() {
3678
- if (this._HasMajorPerformanceCaveat === null) {
3679
- try {
3680
- const tempcanvas = AbstractEngine._CreateCanvas(1, 1);
3681
- const gl = tempcanvas.getContext("webgl", { failIfMajorPerformanceCaveat: true }) ||
3682
- tempcanvas.getContext("experimental-webgl", { failIfMajorPerformanceCaveat: true });
3683
- this._HasMajorPerformanceCaveat = !gl;
3684
- }
3685
- catch (e) {
3686
- this._HasMajorPerformanceCaveat = false;
3687
- }
3688
- }
3689
- return this._HasMajorPerformanceCaveat;
3690
- }
3691
- }
3692
- ThinEngine._TempClearColorUint32 = new Uint32Array(4);
3693
- ThinEngine._TempClearColorInt32 = new Int32Array(4);
3694
- /** Use this array to turn off some WebGL2 features on known buggy browsers version */
3695
- ThinEngine.ExceptionList = [
3696
- { key: "Chrome/63.0", capture: "63\\.0\\.3239\\.(\\d+)", captureConstraint: 108, targets: ["uniformBuffer"] },
3697
- { key: "Firefox/58", capture: null, captureConstraint: null, targets: ["uniformBuffer"] },
3698
- { key: "Firefox/59", capture: null, captureConstraint: null, targets: ["uniformBuffer"] },
3699
- { key: "Chrome/72.+?Mobile", capture: null, captureConstraint: null, targets: ["vao"] },
3700
- { key: "Chrome/73.+?Mobile", capture: null, captureConstraint: null, targets: ["vao"] },
3701
- { key: "Chrome/74.+?Mobile", capture: null, captureConstraint: null, targets: ["vao"] },
3702
- { key: "Mac OS.+Chrome/71", capture: null, captureConstraint: null, targets: ["vao"] },
3703
- { key: "Mac OS.+Chrome/72", capture: null, captureConstraint: null, targets: ["vao"] },
3704
- { key: "Mac OS.+Chrome", capture: null, captureConstraint: null, targets: ["uniformBuffer"] },
3705
- { key: "Chrome/12\\d\\..+?Mobile", capture: null, captureConstraint: null, targets: ["uniformBuffer"] },
3706
- // desktop osx safari 15.4
3707
- { key: ".*AppleWebKit.*(15.4).*Safari", capture: null, captureConstraint: null, targets: ["antialias", "maxMSAASamples"] },
3708
- // mobile browsers using safari 15.4 on ios
3709
- { key: ".*(15.4).*AppleWebKit.*Safari", capture: null, captureConstraint: null, targets: ["antialias", "maxMSAASamples"] },
3710
- ];
3711
- // eslint-disable-next-line @typescript-eslint/naming-convention
3712
- ThinEngine._ConcatenateShader = _ConcatenateShader;
3713
- // Statics
3714
- ThinEngine._IsSupported = null;
3715
- ThinEngine._HasMajorPerformanceCaveat = null;
3716
-
3717
- var thinEngine = /*#__PURE__*/Object.freeze({
3718
- __proto__: null,
3719
- ThinEngine: ThinEngine
3720
- });
3721
-
3722
- export { ThinEngine as T, WebGLDataBuffer as W, WebGLHardwareTexture as a, thinEngine as t };
3723
- //# sourceMappingURL=thinEngine-CvGTeAY9.esm.js.map