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