@babylonjs/viewer 7.40.0-alpha → 7.40.0

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