@babylonjs/viewer 7.39.1-alpha → 7.39.1

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