@vived/component-abb-6700 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. package/.todo.md +13 -0
  2. package/README.md +122 -0
  3. package/dist/.gitkeep +0 -0
  4. package/dist/Adapters/aBB6700PMAdapter.d.ts +10 -0
  5. package/dist/Adapters/aBB6700PMAdapter.d.ts.map +1 -0
  6. package/dist/Controllers/createABB6700.d.ts +12 -0
  7. package/dist/Controllers/createABB6700.d.ts.map +1 -0
  8. package/dist/Controllers/getPose.d.ts +11 -0
  9. package/dist/Controllers/getPose.d.ts.map +1 -0
  10. package/dist/Controllers/setJointAngle.d.ts +12 -0
  11. package/dist/Controllers/setJointAngle.d.ts.map +1 -0
  12. package/dist/Controllers/setPose.d.ts +11 -0
  13. package/dist/Controllers/setPose.d.ts.map +1 -0
  14. package/dist/Entities/ABB6700Entity.d.ts +35 -0
  15. package/dist/Entities/ABB6700Entity.d.ts.map +1 -0
  16. package/dist/Entities/ABB6700Repo.d.ts +32 -0
  17. package/dist/Entities/ABB6700Repo.d.ts.map +1 -0
  18. package/dist/Factory/ABB6700FeatureFactory.d.ts +26 -0
  19. package/dist/Factory/ABB6700FeatureFactory.d.ts.map +1 -0
  20. package/dist/Mocks/MockABB6700PM.d.ts +11 -0
  21. package/dist/Mocks/MockABB6700PM.d.ts.map +1 -0
  22. package/dist/Mocks/MockSetJointAngleUC.d.ts +7 -0
  23. package/dist/Mocks/MockSetJointAngleUC.d.ts.map +1 -0
  24. package/dist/Mocks/MockSetPoseUC.d.ts +7 -0
  25. package/dist/Mocks/MockSetPoseUC.d.ts.map +1 -0
  26. package/dist/PMs/ABB6700PM.d.ts +32 -0
  27. package/dist/PMs/ABB6700PM.d.ts.map +1 -0
  28. package/dist/UCs/CalcStabilizerUC.d.ts +7 -0
  29. package/dist/UCs/CalcStabilizerUC.d.ts.map +1 -0
  30. package/dist/UCs/SetJointAngleUC.d.ts +15 -0
  31. package/dist/UCs/SetJointAngleUC.d.ts.map +1 -0
  32. package/dist/UCs/SetPoseUC.d.ts +22 -0
  33. package/dist/UCs/SetPoseUC.d.ts.map +1 -0
  34. package/dist/Views/ABB6700BabylonView.d.ts +27 -0
  35. package/dist/Views/ABB6700BabylonView.d.ts.map +1 -0
  36. package/dist/abb_6700.glb +0 -0
  37. package/dist/abstractAudioBus-CyBWsmuN.js +14 -0
  38. package/dist/animationGroup-BhNThqQe.js +1454 -0
  39. package/dist/basisTextureLoader-BT391BsV.js +310 -0
  40. package/dist/brdfTextureTools-DUyKBAXf.js +79 -0
  41. package/dist/bumpFragment-Dd-ojPA1.js +134 -0
  42. package/dist/bumpFragment-KE1_PuMl.js +287 -0
  43. package/dist/bumpVertex-BcdvVFVx.js +8 -0
  44. package/dist/bumpVertexDeclaration-B5Uvs-RS.js +8 -0
  45. package/dist/bumpVertexDeclaration-ixSg-yGI.js +8 -0
  46. package/dist/clipPlaneFragment-DJwQynjA.js +136 -0
  47. package/dist/clipPlaneVertex-D4Wk50XG.js +376 -0
  48. package/dist/clipPlaneVertex-eQ147Tn2.js +350 -0
  49. package/dist/component.config.d.ts +17 -0
  50. package/dist/component.config.d.ts.map +1 -0
  51. package/dist/ddsTextureLoader-DeoF3iGO.js +331 -0
  52. package/dist/default.fragment-DKnTR9nY.js +548 -0
  53. package/dist/default.fragment-rIGWrUS5.js +486 -0
  54. package/dist/default.vertex-Bt5y1VyA.js +212 -0
  55. package/dist/default.vertex-Dext1liJ.js +224 -0
  56. package/dist/defaultUboDeclaration-BwslQZX8.js +11 -0
  57. package/dist/defaultUboDeclaration-DSXACgip.js +9 -0
  58. package/dist/easing-BAt0SO-B.js +163 -0
  59. package/dist/envTextureLoader-CBiW_Q-U.js +40 -0
  60. package/dist/exrTextureLoader-5SC6PKIA.js +740 -0
  61. package/dist/flowGraphApplyForceBlock-6e8-wcaw.js +32 -0
  62. package/dist/flowGraphApplyImpulseBlock-B27EZQow.js +32 -0
  63. package/dist/flowGraphArrayIndexBlock-DIUn5e4i.js +31 -0
  64. package/dist/flowGraphBezierCurveEasingBlock-BJmiHk40.js +25 -0
  65. package/dist/flowGraphBinaryOperationBlock-Bj7TANCc.js +25 -0
  66. package/dist/flowGraphBranchBlock-7CRvIKWc.js +19 -0
  67. package/dist/flowGraphCachedOperationBlock-CP1ZiuIB.js +26 -0
  68. package/dist/flowGraphCancelDelayBlock-DqtgzBGm.js +20 -0
  69. package/dist/flowGraphCodeExecutionBlock-CaYXCGqo.js +23 -0
  70. package/dist/flowGraphConditionalDataBlock-DJ7evX8_.js +28 -0
  71. package/dist/flowGraphConsoleLogBlock-cMkpqLzO.js +68 -0
  72. package/dist/flowGraphConstantBlock-JWybwT0A.js +28 -0
  73. package/dist/flowGraphContextBlock-CFDXHcbn.js +19 -0
  74. package/dist/flowGraphCounterBlock-B0uPkgw9.js +24 -0
  75. package/dist/flowGraphDataSwitchBlock-B0GSifvJ.js +27 -0
  76. package/dist/flowGraphDebounceBlock-CSw8zKym.js +24 -0
  77. package/dist/flowGraphDebugBlock-DiSR6Ahn.js +65 -0
  78. package/dist/flowGraphDoNBlock-C-48oQ2H.js +24 -0
  79. package/dist/flowGraphEasingBlock-DKUaE7Rp.js +50 -0
  80. package/dist/flowGraphFlipFlopBlock-DX5BGhMV.js +20 -0
  81. package/dist/flowGraphForLoopBlock-Di-Qwg23.js +27 -0
  82. package/dist/flowGraphFunctionReferenceBlock-D8X5TFsO.js +20 -0
  83. package/dist/flowGraphGLTFDataProvider-C4j7nPQv.js +16 -0
  84. package/dist/flowGraphGetAngularVelocityBlock-Cq-yTQ4D.js +31 -0
  85. package/dist/flowGraphGetAssetBlock-B36eioor.js +21 -0
  86. package/dist/flowGraphGetLinearVelocityBlock-MdrV0eUD.js +31 -0
  87. package/dist/flowGraphGetPhysicsMassPropertiesBlock-wXDZP1wM.js +30 -0
  88. package/dist/flowGraphGetPropertyBlock-eP0badwf.js +46 -0
  89. package/dist/flowGraphGetSoundVolumeBlock-D3gXGHXa.js +29 -0
  90. package/dist/flowGraphGetVariableBlock-C7-qZAec.js +31 -0
  91. package/dist/flowGraphIndexOfBlock-CC5l9n9P.js +31 -0
  92. package/dist/flowGraphInterpolationBlock-B6922jzt.js +50 -0
  93. package/dist/flowGraphIsKeyPressedBlock-X_iuiUOX.js +31 -0
  94. package/dist/flowGraphIsSoundPlayingBlock-DONQX8N8.js +29 -0
  95. package/dist/flowGraphJsonPointerParserBlock-DBH_gN8I.js +95 -0
  96. package/dist/flowGraphKeyDownEventBlock-D5T1Uyfv.js +26 -0
  97. package/dist/flowGraphKeyUpEventBlock-BPY_Kgkm.js +21 -0
  98. package/dist/flowGraphKeyboardEventBlock-C49fx3TC.js +20 -0
  99. package/dist/flowGraphMathBlocks-CkvrN3VJ.js +864 -0
  100. package/dist/flowGraphMathCombineExtractBlocks-QSjGlnoz.js +248 -0
  101. package/dist/flowGraphMatrixMathBlocks-B3D7Cz9p.js +117 -0
  102. package/dist/flowGraphMeshPickEventBlock-BBTz-taa.js +35 -0
  103. package/dist/flowGraphMultiGateBlock-BhY1y5BG.js +50 -0
  104. package/dist/flowGraphPauseAnimationBlock-CHZZXMbg.js +19 -0
  105. package/dist/flowGraphPauseSoundBlock-B7hMmJ0c.js +31 -0
  106. package/dist/flowGraphPhysicsCollisionEventBlock-CxoPpT-q.js +56 -0
  107. package/dist/flowGraphPlayAnimationBlock-DVAvIFux.js +99 -0
  108. package/dist/flowGraphPlaySoundBlock-DjHGrqbC.js +32 -0
  109. package/dist/flowGraphPointerDownEventBlock-qI-H0JST.js +31 -0
  110. package/dist/flowGraphPointerMoveEventBlock-DAi4VUyy.js +31 -0
  111. package/dist/flowGraphPointerOutEventBlock-CFtj68aC.js +21 -0
  112. package/dist/flowGraphPointerOverEventBlock-VxdHhFuu.js +23 -0
  113. package/dist/flowGraphPointerUpEventBlock-DRR1f07q.js +31 -0
  114. package/dist/flowGraphReceiveCustomEventBlock-B3bwdB66.js +52 -0
  115. package/dist/flowGraphSceneReadyEventBlock-Dy6lDT3j.js +23 -0
  116. package/dist/flowGraphSceneTickEventBlock-Bl9BF_Xw.js +32 -0
  117. package/dist/flowGraphSendCustomEventBlock-BAR4PGFq.js +35 -0
  118. package/dist/flowGraphSequenceBlock-veqU32ZZ.js +32 -0
  119. package/dist/flowGraphSetAngularVelocityBlock-Dj9b-zu6.js +31 -0
  120. package/dist/flowGraphSetDelayBlock-CMjudtvk.js +131 -0
  121. package/dist/flowGraphSetLinearVelocityBlock-DVDhhJBd.js +31 -0
  122. package/dist/flowGraphSetPhysicsMotionTypeBlock-CL3cxNCO.js +36 -0
  123. package/dist/flowGraphSetPropertyBlock-D3sWL3Ss.js +47 -0
  124. package/dist/flowGraphSetSoundVolumeBlock-CxVk45yR.js +32 -0
  125. package/dist/flowGraphSetVariableBlock-D1oJiwLj.js +47 -0
  126. package/dist/flowGraphSoundEndedEventBlock-CubEwii0.js +47 -0
  127. package/dist/flowGraphStopAnimationBlock-B9inwIQx.js +48 -0
  128. package/dist/flowGraphStopSoundBlock-BijIX2jC.js +31 -0
  129. package/dist/flowGraphSwitchBlock-BMhPb4OX.js +54 -0
  130. package/dist/flowGraphThrottleBlock-C7vrnkb1.js +37 -0
  131. package/dist/flowGraphTransformCoordinatesSystemBlock-DoISqaUG.js +29 -0
  132. package/dist/flowGraphTypeToTypeBlocks-CSML6QWx.js +57 -0
  133. package/dist/flowGraphUnaryOperationBlock-B0Shf-lJ.js +24 -0
  134. package/dist/flowGraphVectorMathBlocks-DoTRR_E0.js +178 -0
  135. package/dist/flowGraphWaitAllBlock-BvmDMc24.js +54 -0
  136. package/dist/flowGraphWhileLoopBlock-BaIq4-K2.js +27 -0
  137. package/dist/geometry.fragment-Bsis3UG2.js +275 -0
  138. package/dist/geometry.vertex-DskQ5b8j.js +222 -0
  139. package/dist/harmonicsFunctions-CtNrRfir.js +193 -0
  140. package/dist/harmonicsFunctions-PEz6APC7.js +18 -0
  141. package/dist/hdrTextureLoader-D9rYxJ9q.js +112 -0
  142. package/dist/helperFunctions-Bt7Zfkrp.js +89 -0
  143. package/dist/helperFunctions-CPmRxd37.js +121 -0
  144. package/dist/iesTextureLoader-BGUFjVhI.js +93 -0
  145. package/dist/index-CS3Icp_r.js +67657 -0
  146. package/dist/index.d.ts +23 -0
  147. package/dist/index.d.ts.map +1 -0
  148. package/dist/index.js +27 -0
  149. package/dist/ktxTextureLoader-cUaGg9_L.js +459 -0
  150. package/dist/lightFragment-BRDibDKG.js +404 -0
  151. package/dist/lightFragment-DCqtGMp_.js +402 -0
  152. package/dist/logDepthDeclaration-Bwm-3KyB.js +16 -0
  153. package/dist/logDepthDeclaration-gUfeSnXX.js +20 -0
  154. package/dist/logDepthVertex-CKeuJ6ae.js +213 -0
  155. package/dist/logDepthVertex-CXkmZels.js +459 -0
  156. package/dist/mesh.vertexData.functions-Bc9lJlrU.js +74 -0
  157. package/dist/oitFragment-B8zuQigp.js +792 -0
  158. package/dist/oitFragment-DH3h3T6x.js +657 -0
  159. package/dist/openpbr.fragment-BglYS6LA.js +1405 -0
  160. package/dist/openpbr.fragment-DrOTZs4m.js +1553 -0
  161. package/dist/openpbr.vertex-B-PaLFOR.js +384 -0
  162. package/dist/openpbr.vertex-DMdFRTnX.js +268 -0
  163. package/dist/openpbrMaterial-HCU0aOca.js +2880 -0
  164. package/dist/openpbrMaterialLoadingAdapter-CWRAa-7S.js +1122 -0
  165. package/dist/openpbrTransmissionLayerData-CfDVObj5.js +352 -0
  166. package/dist/openpbrUboDeclaration-CA2pvSbt.js +9 -0
  167. package/dist/openpbrUboDeclaration-xU8VOaib.js +10 -0
  168. package/dist/pass.fragment-1mMP54bb.js +10 -0
  169. package/dist/pass.fragment-DzaUp_jk.js +10 -0
  170. package/dist/passCube.fragment-CQaXS7g3.js +29 -0
  171. package/dist/passCube.fragment-QJGPwAXI.js +29 -0
  172. package/dist/pbr.fragment-BnaAAGxb.js +2775 -0
  173. package/dist/pbr.fragment-CYZk_EGU.js +2619 -0
  174. package/dist/pbr.vertex-CyvdCw91.js +372 -0
  175. package/dist/pbr.vertex-DJMAkDxs.js +270 -0
  176. package/dist/pbrBRDFFunctions-EugoWm6O.js +175 -0
  177. package/dist/pbrDebug-Bk3sPoEG.js +719 -0
  178. package/dist/pbrDebug-Cdalzb1I.js +614 -0
  179. package/dist/pbrIBLFunctions-B0bVAXCF.js +47 -0
  180. package/dist/pbrIBLFunctions-C06z-ouZ.js +51 -0
  181. package/dist/pbrMaterial-C4FCKBZQ.js +1660 -0
  182. package/dist/pbrMaterialLoadingAdapter-BGHlS_ZN.js +1032 -0
  183. package/dist/pbrUboDeclaration-1lN5_-Bw.js +9 -0
  184. package/dist/pbrUboDeclaration-BJOUUOZ2.js +10 -0
  185. package/dist/procedural.vertex-CFPKczKj.js +14 -0
  186. package/dist/procedural.vertex-DUW7bYZt.js +13 -0
  187. package/dist/rgbdDecode.fragment-CEGgE4tL.js +8 -0
  188. package/dist/rgbdDecode.fragment-FT0wkgah.js +8 -0
  189. package/dist/rgbdEncode.fragment-CLnJJf6E.js +8 -0
  190. package/dist/rgbdEncode.fragment-CaAcMsY9.js +8 -0
  191. package/dist/sceneUboDeclaration-B6oxsfcj.js +8 -0
  192. package/dist/sceneUboDeclaration-JByfVKik.js +13 -0
  193. package/dist/setupABB6700InstanceFactory.d.ts +7 -0
  194. package/dist/setupABB6700InstanceFactory.d.ts.map +1 -0
  195. package/dist/studio.env +0 -0
  196. package/dist/textureProcessor.fragment-BYPw6SMQ.js +152 -0
  197. package/dist/textureProcessor.fragment-Ciw9-F3w.js +157 -0
  198. package/dist/textureTools-Cct_bGgp.js +40 -0
  199. package/dist/tgaTextureLoader-BJOIdnFr.js +198 -0
  200. package/dist/thinEngine-Bt9FW4dD.js +2425 -0
  201. package/dist/webAudioBus-BUzRHSxr.js +88 -0
  202. package/dist/webAudioMainBus-Dds1TgJG.js +49 -0
  203. package/package.json +49 -0
@@ -0,0 +1,2425 @@
1
+ import { G as X, f as w, I as O, bR as U, a7 as I, bY as L, h as W, c5 as k, bn as K, bO as j, bP as Y, bN as z, bF as Q, bH as Z, bD as $, bG as q, bE as J, a4 as ee, a1 as y, X as N, bI as te, a3 as re, bl as se } from "./index-CS3Icp_r.js";
2
+ class ie {
3
+ constructor() {
4
+ this.shaderLanguage = 0;
5
+ }
6
+ postProcessor(e, t, r, s, i) {
7
+ if (i.drawBuffersExtensionDisabled) {
8
+ const n = /#extension.+GL_EXT_draw_buffers.+(enable|require)/g;
9
+ e = e.replace(n, "");
10
+ }
11
+ return e;
12
+ }
13
+ }
14
+ const ne = /(flat\s)?\s*varying\s*.*/;
15
+ class ae {
16
+ constructor() {
17
+ this.shaderLanguage = 0;
18
+ }
19
+ attributeProcessor(e) {
20
+ return e.replace("attribute", "in");
21
+ }
22
+ varyingCheck(e, t) {
23
+ return ne.test(e);
24
+ }
25
+ varyingProcessor(e, t) {
26
+ return e.replace("varying", t ? "in" : "out");
27
+ }
28
+ postProcessor(e, t, r) {
29
+ const s = e.search(/#extension.+GL_EXT_draw_buffers.+require/) !== -1, i = /#extension.+(GL_OVR_multiview2|GL_OES_standard_derivatives|GL_EXT_shader_texture_lod|GL_EXT_frag_depth|GL_EXT_draw_buffers).+(enable|require)/g;
30
+ if (e = e.replace(i, ""), e = e.replace(/texture2D\s*\(/g, "texture("), r) {
31
+ const n = e.search(/layout *\(location *= *0\) *out/g) !== -1, l = t.indexOf("#define DUAL_SOURCE_BLENDING") !== -1, a = l ? `layout(location = 0, index = 0) out vec4 glFragColor;
32
+ layout(location = 0, index = 1) out vec4 glFragColor2;
33
+ ` : `layout(location = 0) out vec4 glFragColor;
34
+ `;
35
+ l && (e = `#extension GL_EXT_blend_func_extended : require
36
+ ` + e), e = e.replace(/texture2DLodEXT\s*\(/g, "textureLod("), e = e.replace(/textureCubeLodEXT\s*\(/g, "textureLod("), e = e.replace(/textureCube\s*\(/g, "texture("), e = e.replace(/gl_FragDepthEXT/g, "gl_FragDepth"), e = e.replace(/gl_FragColor/g, "glFragColor"), e = e.replace(/gl_FragData/g, "glFragData"), e = e.replace(/void\s+?main\s*\(/g, (s || n ? "" : a) + "void main(");
37
+ } else if (t.indexOf("#define VERTEXOUTPUT_INVARIANT") >= 0 && (e = `invariant gl_Position;
38
+ ` + e), t.indexOf("#define MULTIVIEW") !== -1)
39
+ return `#extension GL_OVR_multiview2 : require
40
+ layout (num_views = 2) in;
41
+ ` + e;
42
+ return e;
43
+ }
44
+ }
45
+ class v extends X {
46
+ /** @internal */
47
+ constructor(e) {
48
+ super(), this._buffer = e;
49
+ }
50
+ /** @internal */
51
+ get underlyingResource() {
52
+ return this._buffer;
53
+ }
54
+ }
55
+ class _e {
56
+ get underlyingResource() {
57
+ return this._webGLTexture;
58
+ }
59
+ constructor(e = null, t) {
60
+ if (this._MSAARenderBuffers = null, this._context = t, !e && (e = t.createTexture(), !e))
61
+ throw new Error("Unable to create webGL texture");
62
+ this.set(e);
63
+ }
64
+ setUsage() {
65
+ }
66
+ set(e) {
67
+ this._webGLTexture = e;
68
+ }
69
+ reset() {
70
+ this._webGLTexture = null, this._MSAARenderBuffers = null;
71
+ }
72
+ addMSAARenderBuffer(e) {
73
+ this._MSAARenderBuffers || (this._MSAARenderBuffers = []), this._MSAARenderBuffers.push(e);
74
+ }
75
+ releaseMSAARenderBuffers() {
76
+ if (this._MSAARenderBuffers) {
77
+ for (const e of this._MSAARenderBuffers)
78
+ this._context.deleteRenderbuffer(e);
79
+ this._MSAARenderBuffers = null;
80
+ }
81
+ }
82
+ getMSAARenderBuffer(e = 0) {
83
+ return this._MSAARenderBuffers?.[e] ?? null;
84
+ }
85
+ release() {
86
+ this.releaseMSAARenderBuffers(), this._webGLTexture && this._context.deleteTexture(this._webGLTexture), this.reset();
87
+ }
88
+ }
89
+ function H(R) {
90
+ return R === 13 || R === 14 || R === 15 || R === 16 || R === 17 || R === 18 || R === 19;
91
+ }
92
+ function V(R) {
93
+ return R === 13 || R === 17 || R === 18 || R === 19;
94
+ }
95
+ class le {
96
+ }
97
+ class T extends w {
98
+ /**
99
+ * Gets or sets the name of the engine
100
+ */
101
+ get name() {
102
+ return this._name;
103
+ }
104
+ set name(e) {
105
+ this._name = e;
106
+ }
107
+ /**
108
+ * Returns the version of the engine
109
+ */
110
+ get version() {
111
+ return this._webGLVersion;
112
+ }
113
+ /**
114
+ * Gets or sets the relative url used to load shaders if using the engine in non-minified mode
115
+ */
116
+ static get ShadersRepository() {
117
+ return O.ShadersRepository;
118
+ }
119
+ static set ShadersRepository(e) {
120
+ O.ShadersRepository = e;
121
+ }
122
+ /**
123
+ * Gets a boolean indicating that the engine supports uniform buffers
124
+ * @see https://doc.babylonjs.com/setup/support/webGL2#uniform-buffer-objets
125
+ */
126
+ get supportsUniformBuffers() {
127
+ return this.webGLVersion > 1 && !this.disableUniformBuffers;
128
+ }
129
+ /**
130
+ * Gets a boolean indicating that only power of 2 textures are supported
131
+ * Please note that you can still use non power of 2 textures but in this case the engine will forcefully convert them
132
+ */
133
+ get needPOTTextures() {
134
+ return this._webGLVersion < 2 || this.forcePOTTextures;
135
+ }
136
+ get _supportsHardwareTextureRescaling() {
137
+ return !1;
138
+ }
139
+ /**
140
+ * sets the object from which width and height will be taken from when getting render width and height
141
+ * Will fallback to the gl object
142
+ * @param dimensions the framebuffer width and height that will be used.
143
+ */
144
+ set framebufferDimensionsObject(e) {
145
+ this._framebufferDimensionsObject = e;
146
+ }
147
+ /**
148
+ * Creates a new snapshot at the next frame using the current snapshotRenderingMode
149
+ */
150
+ snapshotRenderingReset() {
151
+ this.snapshotRendering = !1;
152
+ }
153
+ /**
154
+ * Creates a new engine
155
+ * @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
156
+ * @param antialias defines whether anti-aliasing should be enabled (default value is "undefined", meaning that the browser may or may not enable it)
157
+ * @param options defines further options to be sent to the getContext() function
158
+ * @param adaptToDeviceRatio defines whether to adapt to the device's viewport characteristics (default: false)
159
+ */
160
+ constructor(e, t, r, s) {
161
+ if (r = r || {}, super(t ?? r.antialias, r, s), this._name = "WebGL", this.forcePOTTextures = !1, this.validateShaderPrograms = !1, this.disableUniformBuffers = !1, this._webGLVersion = 1, this._vertexAttribArraysEnabled = [], this._uintIndicesCurrentlySet = !1, this._currentBoundBuffer = new Array(), this._currentFramebuffer = null, this._dummyFramebuffer = null, this._currentBufferPointers = new Array(), this._currentInstanceLocations = new Array(), this._currentInstanceBuffers = new Array(), this._vaoRecordInProgress = !1, this._mustWipeVertexAttributes = !1, this._nextFreeTextureSlots = new Array(), this._maxSimultaneousTextures = 0, this._maxMSAASamplesOverride = null, this._unpackFlipYCached = null, this.enableUnpackFlipYCached = !0, this._boundUniforms = {}, !e)
162
+ return;
163
+ let i;
164
+ if (e.getContext) {
165
+ if (i = e, r.preserveDrawingBuffer === void 0 && (r.preserveDrawingBuffer = !1), r.xrCompatible === void 0 && (r.xrCompatible = !1), navigator && navigator.userAgent) {
166
+ this._setupMobileChecks();
167
+ const a = navigator.userAgent;
168
+ for (const _ of T.ExceptionList) {
169
+ const u = _.key, f = _.targets;
170
+ if (new RegExp(u).test(a)) {
171
+ if (_.capture && _.captureConstraint) {
172
+ const d = _.capture, g = _.captureConstraint, E = new RegExp(d).exec(a);
173
+ if (E && E.length > 0 && parseInt(E[E.length - 1]) >= g)
174
+ continue;
175
+ }
176
+ for (const d of f)
177
+ switch (d) {
178
+ case "uniformBuffer":
179
+ this.disableUniformBuffers = !0;
180
+ break;
181
+ case "vao":
182
+ this.disableVertexArrayObjects = !0;
183
+ break;
184
+ case "antialias":
185
+ r.antialias = !1;
186
+ break;
187
+ case "maxMSAASamples":
188
+ this._maxMSAASamplesOverride = 1;
189
+ break;
190
+ }
191
+ }
192
+ }
193
+ }
194
+ if (this._doNotHandleContextLost ? this._onContextLost = () => {
195
+ U(this._gl);
196
+ } : (this._onContextLost = (a) => {
197
+ a.preventDefault(), this._contextWasLost = !0, U(this._gl), I.Warn("WebGL context lost."), this.onContextLostObservable.notifyObservers(this);
198
+ }, this._onContextRestored = () => {
199
+ this._restoreEngineAfterContextLost(() => this._initGLContext());
200
+ }, i.addEventListener("webglcontextrestored", this._onContextRestored, !1), r.powerPreference = r.powerPreference || "high-performance"), i.addEventListener("webglcontextlost", this._onContextLost, !1), this._badDesktopOS && (r.xrCompatible = !1), !r.disableWebGL2Support)
201
+ try {
202
+ this._gl = i.getContext("webgl2", r) || i.getContext("experimental-webgl2", r), this._gl && (this._webGLVersion = 2, this._shaderPlatformName = "WEBGL2", this._gl.deleteQuery || (this._webGLVersion = 1, this._shaderPlatformName = "WEBGL1"));
203
+ } catch {
204
+ }
205
+ if (!this._gl) {
206
+ if (!i)
207
+ throw new Error("The provided canvas is null or undefined.");
208
+ try {
209
+ this._gl = i.getContext("webgl", r) || i.getContext("experimental-webgl", r);
210
+ } catch (a) {
211
+ throw new Error("WebGL not supported", { cause: a });
212
+ }
213
+ }
214
+ if (!this._gl)
215
+ throw new Error("WebGL not supported");
216
+ } else {
217
+ this._gl = e, i = this._gl.canvas, this._gl.renderbufferStorageMultisample ? (this._webGLVersion = 2, this._shaderPlatformName = "WEBGL2") : this._shaderPlatformName = "WEBGL1";
218
+ const a = this._gl.getContextAttributes();
219
+ a && (r.stencil = a.stencil);
220
+ }
221
+ this._sharedInit(i), this._gl.pixelStorei(this._gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, this._gl.NONE), r.useHighPrecisionFloats !== void 0 && (this._highPrecisionShadersAllowed = r.useHighPrecisionFloats), this.resize(), this._initGLContext(), this._initFeatures();
222
+ for (let a = 0; a < this._caps.maxVertexAttribs; a++)
223
+ this._currentBufferPointers[a] = new le();
224
+ this._shaderProcessor = this.webGLVersion > 1 ? new ae() : new ie();
225
+ const n = `Babylon.js v${T.Version}`;
226
+ I.Log(n + ` - ${this.description}`), this._renderingCanvas && this._renderingCanvas.setAttribute && this._renderingCanvas.setAttribute("data-engine", n);
227
+ const l = L(this._gl);
228
+ l.validateShaderPrograms = this.validateShaderPrograms, l.parallelShaderCompile = this._caps.parallelShaderCompile;
229
+ }
230
+ _clearEmptyResources() {
231
+ this._dummyFramebuffer = null, super._clearEmptyResources();
232
+ }
233
+ /**
234
+ * @internal
235
+ */
236
+ _getShaderProcessingContext(e) {
237
+ return null;
238
+ }
239
+ /**
240
+ * Gets a boolean indicating if all created effects are ready
241
+ * @returns true if all effects are ready
242
+ */
243
+ areAllEffectsReady() {
244
+ for (const e in this._compiledEffects)
245
+ if (!this._compiledEffects[e].isReady())
246
+ return !1;
247
+ return !0;
248
+ }
249
+ _initGLContext() {
250
+ this._caps = {
251
+ maxTexturesImageUnits: this._gl.getParameter(this._gl.MAX_TEXTURE_IMAGE_UNITS),
252
+ maxCombinedTexturesImageUnits: this._gl.getParameter(this._gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS),
253
+ maxVertexTextureImageUnits: this._gl.getParameter(this._gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS),
254
+ maxTextureSize: this._gl.getParameter(this._gl.MAX_TEXTURE_SIZE),
255
+ maxSamples: this._webGLVersion > 1 ? this._gl.getParameter(this._gl.MAX_SAMPLES) : 1,
256
+ maxCubemapTextureSize: this._gl.getParameter(this._gl.MAX_CUBE_MAP_TEXTURE_SIZE),
257
+ maxRenderTextureSize: this._gl.getParameter(this._gl.MAX_RENDERBUFFER_SIZE),
258
+ maxVertexAttribs: this._gl.getParameter(this._gl.MAX_VERTEX_ATTRIBS),
259
+ maxVaryingVectors: this._gl.getParameter(this._gl.MAX_VARYING_VECTORS),
260
+ maxFragmentUniformVectors: this._gl.getParameter(this._gl.MAX_FRAGMENT_UNIFORM_VECTORS),
261
+ maxVertexUniformVectors: this._gl.getParameter(this._gl.MAX_VERTEX_UNIFORM_VECTORS),
262
+ shaderFloatPrecision: 0,
263
+ parallelShaderCompile: this._gl.getExtension("KHR_parallel_shader_compile") || void 0,
264
+ standardDerivatives: this._webGLVersion > 1 || this._gl.getExtension("OES_standard_derivatives") !== null,
265
+ maxAnisotropy: 1,
266
+ astc: this._gl.getExtension("WEBGL_compressed_texture_astc") || this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_astc"),
267
+ bptc: this._gl.getExtension("EXT_texture_compression_bptc") || this._gl.getExtension("WEBKIT_EXT_texture_compression_bptc"),
268
+ s3tc: this._gl.getExtension("WEBGL_compressed_texture_s3tc") || this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc"),
269
+ // eslint-disable-next-line @typescript-eslint/naming-convention
270
+ s3tc_srgb: this._gl.getExtension("WEBGL_compressed_texture_s3tc_srgb") || this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc_srgb"),
271
+ pvrtc: this._gl.getExtension("WEBGL_compressed_texture_pvrtc") || this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),
272
+ etc1: this._gl.getExtension("WEBGL_compressed_texture_etc1") || this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_etc1"),
273
+ etc2: this._gl.getExtension("WEBGL_compressed_texture_etc") || this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_etc") || this._gl.getExtension("WEBGL_compressed_texture_es3_0"),
274
+ // also a requirement of OpenGL ES 3
275
+ textureAnisotropicFilterExtension: this._gl.getExtension("EXT_texture_filter_anisotropic") || this._gl.getExtension("WEBKIT_EXT_texture_filter_anisotropic") || this._gl.getExtension("MOZ_EXT_texture_filter_anisotropic"),
276
+ uintIndices: this._webGLVersion > 1 || this._gl.getExtension("OES_element_index_uint") !== null,
277
+ fragmentDepthSupported: this._webGLVersion > 1 || this._gl.getExtension("EXT_frag_depth") !== null,
278
+ highPrecisionShaderSupported: !1,
279
+ timerQuery: this._gl.getExtension("EXT_disjoint_timer_query_webgl2") || this._gl.getExtension("EXT_disjoint_timer_query"),
280
+ supportOcclusionQuery: this._webGLVersion > 1,
281
+ canUseTimestampForTimerQuery: !1,
282
+ drawBuffersExtension: !1,
283
+ maxMSAASamples: 1,
284
+ colorBufferFloat: !!(this._webGLVersion > 1 && this._gl.getExtension("EXT_color_buffer_float")),
285
+ blendFloat: this._gl.getExtension("EXT_float_blend") !== null,
286
+ supportFloatTexturesResolve: !1,
287
+ rg11b10ufColorRenderable: !1,
288
+ colorBufferHalfFloat: !!(this._webGLVersion > 1 && this._gl.getExtension("EXT_color_buffer_half_float")),
289
+ textureFloat: !!(this._webGLVersion > 1 || this._gl.getExtension("OES_texture_float")),
290
+ textureHalfFloat: !!(this._webGLVersion > 1 || this._gl.getExtension("OES_texture_half_float")),
291
+ textureHalfFloatRender: !1,
292
+ textureFloatLinearFiltering: !1,
293
+ textureFloatRender: !1,
294
+ textureHalfFloatLinearFiltering: !1,
295
+ vertexArrayObject: !1,
296
+ instancedArrays: !1,
297
+ textureLOD: !!(this._webGLVersion > 1 || this._gl.getExtension("EXT_shader_texture_lod")),
298
+ texelFetch: this._webGLVersion !== 1,
299
+ blendMinMax: !1,
300
+ multiview: this._gl.getExtension("OVR_multiview2"),
301
+ oculusMultiview: this._gl.getExtension("OCULUS_multiview"),
302
+ depthTextureExtension: !1,
303
+ canUseGLInstanceID: this._webGLVersion > 1,
304
+ canUseGLVertexID: this._webGLVersion > 1,
305
+ supportComputeShaders: !1,
306
+ supportSRGBBuffers: !1,
307
+ supportTransformFeedbacks: this._webGLVersion > 1,
308
+ textureMaxLevel: this._webGLVersion > 1,
309
+ texture2DArrayMaxLayerCount: this._webGLVersion > 1 ? this._gl.getParameter(this._gl.MAX_ARRAY_TEXTURE_LAYERS) : 128,
310
+ disableMorphTargetTexture: !1,
311
+ textureNorm16: !!this._gl.getExtension("EXT_texture_norm16"),
312
+ blendParametersPerTarget: !1,
313
+ dualSourceBlending: !1,
314
+ supportReadWriteStorageTextures: !1
315
+ }, this._caps.supportFloatTexturesResolve = this._caps.colorBufferFloat, this._caps.rg11b10ufColorRenderable = this._caps.colorBufferFloat, this._glVersion = this._gl.getParameter(this._gl.VERSION);
316
+ const e = this._gl.getExtension("WEBGL_debug_renderer_info");
317
+ e != null && (this._glRenderer = this._gl.getParameter(e.UNMASKED_RENDERER_WEBGL), this._glVendor = this._gl.getParameter(e.UNMASKED_VENDOR_WEBGL)), this._glVendor || (this._glVendor = this._gl.getParameter(this._gl.VENDOR) || "Unknown vendor"), this._glRenderer || (this._glRenderer = this._gl.getParameter(this._gl.RENDERER) || "Unknown renderer"), this._gl.HALF_FLOAT_OES !== 36193 && (this._gl.HALF_FLOAT_OES = 36193), this._gl.RGBA16F !== 34842 && (this._gl.RGBA16F = 34842), this._gl.RGBA32F !== 34836 && (this._gl.RGBA32F = 34836), this._gl.DEPTH24_STENCIL8 !== 35056 && (this._gl.DEPTH24_STENCIL8 = 35056), this._caps.timerQuery && (this._webGLVersion === 1 && (this._gl.getQuery = this._caps.timerQuery.getQueryEXT.bind(this._caps.timerQuery)), this._caps.canUseTimestampForTimerQuery = (this._gl.getQuery(this._caps.timerQuery.TIMESTAMP_EXT, this._caps.timerQuery.QUERY_COUNTER_BITS_EXT) ?? 0) > 0), this._caps.maxAnisotropy = this._caps.textureAnisotropicFilterExtension ? this._gl.getParameter(this._caps.textureAnisotropicFilterExtension.MAX_TEXTURE_MAX_ANISOTROPY_EXT) : 0, this._caps.textureFloatLinearFiltering = !!(this._caps.textureFloat && this._gl.getExtension("OES_texture_float_linear")), this._caps.textureFloatRender = !!(this._caps.textureFloat && this._canRenderToFloatFramebuffer()), this._caps.textureHalfFloatLinearFiltering = !!(this._webGLVersion > 1 || this._caps.textureHalfFloat && this._gl.getExtension("OES_texture_half_float_linear")), this._caps.textureNorm16 && (this._gl.R16_EXT = 33322, this._gl.RG16_EXT = 33324, this._gl.RGB16_EXT = 32852, this._gl.RGBA16_EXT = 32859, this._gl.R16_SNORM_EXT = 36760, this._gl.RG16_SNORM_EXT = 36761, this._gl.RGB16_SNORM_EXT = 36762, this._gl.RGBA16_SNORM_EXT = 36763);
318
+ const t = this._gl.getExtension("OES_draw_buffers_indexed");
319
+ if (this._caps.blendParametersPerTarget = !!t, this._alphaState = new W(this._caps.blendParametersPerTarget), t && (this._gl.blendEquationSeparateIndexed = t.blendEquationSeparateiOES.bind(t), this._gl.blendEquationIndexed = t.blendEquationiOES.bind(t), this._gl.blendFuncSeparateIndexed = t.blendFuncSeparateiOES.bind(t), this._gl.blendFuncIndexed = t.blendFunciOES.bind(t), this._gl.colorMaskIndexed = t.colorMaskiOES.bind(t), this._gl.disableIndexed = t.disableiOES.bind(t), this._gl.enableIndexed = t.enableiOES.bind(t)), this._caps.dualSourceBlending = !!this._gl.getExtension("WEBGL_blend_func_extended"), this._caps.astc && (this._gl.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR = this._caps.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, this._gl.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR = this._caps.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, this._gl.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR = this._caps.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, this._gl.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR = this._caps.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, this._gl.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR = this._caps.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, this._gl.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR = this._caps.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, this._gl.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR = this._caps.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, this._gl.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR = this._caps.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, this._gl.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR = this._caps.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, this._gl.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR = this._caps.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, this._gl.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR = this._caps.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, this._gl.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR = this._caps.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, this._gl.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR = this._caps.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, this._gl.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR = this._caps.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR), this._caps.bptc && (this._gl.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT = this._caps.bptc.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT), this._caps.s3tc_srgb && (this._gl.COMPRESSED_SRGB_S3TC_DXT1_EXT = this._caps.s3tc_srgb.COMPRESSED_SRGB_S3TC_DXT1_EXT, this._gl.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT = this._caps.s3tc_srgb.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, this._gl.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT = this._caps.s3tc_srgb.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT), this._caps.etc2 && (this._gl.COMPRESSED_SRGB8_ETC2 = this._caps.etc2.COMPRESSED_SRGB8_ETC2, this._gl.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = this._caps.etc2.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC), this._webGLVersion > 1 && this._gl.HALF_FLOAT_OES !== 5131 && (this._gl.HALF_FLOAT_OES = 5131), this._caps.textureHalfFloatRender = this._caps.textureHalfFloat && this._canRenderToHalfFloatFramebuffer(), this._webGLVersion > 1)
320
+ this._caps.drawBuffersExtension = !0, this._caps.maxMSAASamples = this._maxMSAASamplesOverride !== null ? this._maxMSAASamplesOverride : this._gl.getParameter(this._gl.MAX_SAMPLES), this._caps.maxDrawBuffers = this._gl.getParameter(this._gl.MAX_DRAW_BUFFERS);
321
+ else {
322
+ const r = this._gl.getExtension("WEBGL_draw_buffers");
323
+ if (r !== null) {
324
+ this._caps.drawBuffersExtension = !0, this._gl.drawBuffers = r.drawBuffersWEBGL.bind(r), this._caps.maxDrawBuffers = this._gl.getParameter(r.MAX_DRAW_BUFFERS_WEBGL), this._gl.DRAW_FRAMEBUFFER = this._gl.FRAMEBUFFER;
325
+ for (let s = 0; s < 16; s++)
326
+ this._gl["COLOR_ATTACHMENT" + s + "_WEBGL"] = r["COLOR_ATTACHMENT" + s + "_WEBGL"];
327
+ }
328
+ }
329
+ if (this._webGLVersion > 1)
330
+ this._caps.depthTextureExtension = !0;
331
+ else {
332
+ const r = this._gl.getExtension("WEBGL_depth_texture");
333
+ r != null && (this._caps.depthTextureExtension = !0, this._gl.UNSIGNED_INT_24_8 = r.UNSIGNED_INT_24_8_WEBGL);
334
+ }
335
+ if (this.disableVertexArrayObjects)
336
+ this._caps.vertexArrayObject = !1;
337
+ else if (this._webGLVersion > 1)
338
+ this._caps.vertexArrayObject = !0;
339
+ else {
340
+ const r = this._gl.getExtension("OES_vertex_array_object");
341
+ r != null && (this._caps.vertexArrayObject = !0, this._gl.createVertexArray = r.createVertexArrayOES.bind(r), this._gl.bindVertexArray = r.bindVertexArrayOES.bind(r), this._gl.deleteVertexArray = r.deleteVertexArrayOES.bind(r));
342
+ }
343
+ if (this._webGLVersion > 1)
344
+ this._caps.instancedArrays = !0;
345
+ else {
346
+ const r = this._gl.getExtension("ANGLE_instanced_arrays");
347
+ r != null ? (this._caps.instancedArrays = !0, this._gl.drawArraysInstanced = r.drawArraysInstancedANGLE.bind(r), this._gl.drawElementsInstanced = r.drawElementsInstancedANGLE.bind(r), this._gl.vertexAttribDivisor = r.vertexAttribDivisorANGLE.bind(r)) : this._caps.instancedArrays = !1;
348
+ }
349
+ if (this._gl.getShaderPrecisionFormat) {
350
+ const r = this._gl.getShaderPrecisionFormat(this._gl.VERTEX_SHADER, this._gl.HIGH_FLOAT), s = this._gl.getShaderPrecisionFormat(this._gl.FRAGMENT_SHADER, this._gl.HIGH_FLOAT);
351
+ if (r && s && (this._caps.highPrecisionShaderSupported = r.precision !== 0 && s.precision !== 0, this._caps.shaderFloatPrecision = Math.min(r.precision, s.precision)), !this._shouldUseHighPrecisionShader) {
352
+ const i = this._gl.getShaderPrecisionFormat(this._gl.VERTEX_SHADER, this._gl.MEDIUM_FLOAT), n = this._gl.getShaderPrecisionFormat(this._gl.FRAGMENT_SHADER, this._gl.MEDIUM_FLOAT);
353
+ i && n && (this._caps.shaderFloatPrecision = Math.min(i.precision, n.precision));
354
+ }
355
+ this._caps.shaderFloatPrecision < 10 && (this._caps.shaderFloatPrecision = 10);
356
+ }
357
+ if (this._webGLVersion > 1)
358
+ this._caps.blendMinMax = !0;
359
+ else {
360
+ const r = this._gl.getExtension("EXT_blend_minmax");
361
+ r != null && (this._caps.blendMinMax = !0, this._gl.MAX = r.MAX_EXT, this._gl.MIN = r.MIN_EXT);
362
+ }
363
+ if (!this._caps.supportSRGBBuffers) {
364
+ if (this._webGLVersion > 1)
365
+ this._caps.supportSRGBBuffers = !0, this._glSRGBExtensionValues = {
366
+ SRGB: WebGL2RenderingContext.SRGB,
367
+ SRGB8: WebGL2RenderingContext.SRGB8,
368
+ SRGB8_ALPHA8: WebGL2RenderingContext.SRGB8_ALPHA8
369
+ };
370
+ else {
371
+ const r = this._gl.getExtension("EXT_sRGB");
372
+ r != null && (this._caps.supportSRGBBuffers = !0, this._glSRGBExtensionValues = {
373
+ SRGB: r.SRGB_EXT,
374
+ SRGB8: r.SRGB_ALPHA_EXT,
375
+ SRGB8_ALPHA8: r.SRGB_ALPHA_EXT
376
+ });
377
+ }
378
+ if (this._creationOptions) {
379
+ const r = this._creationOptions.forceSRGBBufferSupportState;
380
+ r !== void 0 && (this._caps.supportSRGBBuffers = this._caps.supportSRGBBuffers && r);
381
+ }
382
+ }
383
+ this._depthCullingState.depthTest = !0, this._depthCullingState.depthFunc = this._gl.LEQUAL, this._depthCullingState.depthMask = !0, this._maxSimultaneousTextures = this._caps.maxCombinedTexturesImageUnits;
384
+ for (let r = 0; r < this._maxSimultaneousTextures; r++)
385
+ this._nextFreeTextureSlots.push(r);
386
+ this._glRenderer === "Mali-G72" && (this._caps.disableMorphTargetTexture = !0);
387
+ }
388
+ _initFeatures() {
389
+ this._features = {
390
+ forceBitmapOverHTMLImageElement: typeof HTMLImageElement > "u",
391
+ supportRenderAndCopyToLodForFloatTextures: this._webGLVersion !== 1,
392
+ supportDepthStencilTexture: this._webGLVersion !== 1,
393
+ supportShadowSamplers: this._webGLVersion !== 1,
394
+ uniformBufferHardCheckMatrix: !1,
395
+ allowTexturePrefiltering: this._webGLVersion !== 1,
396
+ trackUbosInFrame: !1,
397
+ checkUbosContentBeforeUpload: !1,
398
+ supportCSM: this._webGLVersion !== 1,
399
+ basisNeedsPOT: this._webGLVersion === 1,
400
+ support3DTextures: this._webGLVersion !== 1,
401
+ needTypeSuffixInShaderConstants: this._webGLVersion !== 1,
402
+ supportMSAA: this._webGLVersion !== 1,
403
+ supportSSAO2: this._webGLVersion !== 1,
404
+ supportIBLShadows: this._webGLVersion !== 1,
405
+ supportExtendedTextureFormats: this._webGLVersion !== 1,
406
+ supportSwitchCaseInShader: this._webGLVersion !== 1,
407
+ supportSyncTextureRead: !0,
408
+ needsInvertingBitmap: !0,
409
+ useUBOBindingCache: !0,
410
+ needShaderCodeInlining: !1,
411
+ needToAlwaysBindUniformBuffers: !1,
412
+ supportRenderPasses: !1,
413
+ supportSpriteInstancing: !0,
414
+ forceVertexBufferStrideAndOffsetMultiple4Bytes: !1,
415
+ _checkNonFloatVertexBuffersDontRecreatePipelineContext: !1
416
+ };
417
+ }
418
+ /**
419
+ * Gets version of the current webGL context
420
+ * Keep it for back compat - use version instead
421
+ */
422
+ get webGLVersion() {
423
+ return this._webGLVersion;
424
+ }
425
+ /**
426
+ * Gets a string identifying the name of the class
427
+ * @returns "Engine" string
428
+ */
429
+ getClassName() {
430
+ return "ThinEngine";
431
+ }
432
+ /** @internal */
433
+ _prepareWorkingCanvas() {
434
+ if (this._workingCanvas)
435
+ return;
436
+ this._workingCanvas = this.createCanvas(1, 1);
437
+ const e = this._workingCanvas.getContext("2d");
438
+ e && (this._workingContext = e);
439
+ }
440
+ /**
441
+ * Gets an object containing information about the current engine context
442
+ * @returns an object containing the vendor, the renderer and the version of the current engine context
443
+ */
444
+ getInfo() {
445
+ return this.getGlInfo();
446
+ }
447
+ /**
448
+ * Gets an object containing information about the current webGL context
449
+ * @returns an object containing the vendor, the renderer and the version of the current webGL context
450
+ */
451
+ getGlInfo() {
452
+ return {
453
+ vendor: this._glVendor,
454
+ renderer: this._glRenderer,
455
+ version: this._glVersion
456
+ };
457
+ }
458
+ /**Gets driver info if available */
459
+ extractDriverInfo() {
460
+ const e = this.getGlInfo();
461
+ return e && e.renderer ? e.renderer : "";
462
+ }
463
+ /**
464
+ * Gets the current render width
465
+ * @param useScreen defines if screen size must be used (or the current render target if any)
466
+ * @returns a number defining the current render width
467
+ */
468
+ getRenderWidth(e = !1) {
469
+ return !e && this._currentRenderTarget ? this._currentRenderTarget.width : this._framebufferDimensionsObject ? this._framebufferDimensionsObject.framebufferWidth : this._gl.drawingBufferWidth;
470
+ }
471
+ /**
472
+ * Gets the current render height
473
+ * @param useScreen defines if screen size must be used (or the current render target if any)
474
+ * @returns a number defining the current render height
475
+ */
476
+ getRenderHeight(e = !1) {
477
+ return !e && this._currentRenderTarget ? this._currentRenderTarget.height : this._framebufferDimensionsObject ? this._framebufferDimensionsObject.framebufferHeight : this._gl.drawingBufferHeight;
478
+ }
479
+ /**
480
+ * Clear the current render buffer or the current render target (if any is set up)
481
+ * @param color defines the color to use
482
+ * @param backBuffer defines if the back buffer must be cleared
483
+ * @param depth defines if the depth buffer must be cleared
484
+ * @param stencil defines if the stencil buffer must be cleared
485
+ * @param stencilClearValue defines the value to use to clear the stencil buffer (default is 0)
486
+ */
487
+ clear(e, t, r, s = !1, i = 0) {
488
+ const n = this.stencilStateComposer.useStencilGlobalOnly;
489
+ this.stencilStateComposer.useStencilGlobalOnly = !0, this.applyStates(), this.stencilStateComposer.useStencilGlobalOnly = n;
490
+ let l = 0;
491
+ if (t && e) {
492
+ let a = !0;
493
+ if (this._currentRenderTarget) {
494
+ const _ = this._currentRenderTarget.texture?.format;
495
+ if (_ === 8 || _ === 9 || _ === 10 || _ === 11) {
496
+ const u = this._currentRenderTarget.texture?.type;
497
+ u === 7 || u === 5 ? (T._TempClearColorUint32[0] = e.r * 255, T._TempClearColorUint32[1] = e.g * 255, T._TempClearColorUint32[2] = e.b * 255, T._TempClearColorUint32[3] = e.a * 255, this._gl.clearBufferuiv(this._gl.COLOR, 0, T._TempClearColorUint32), a = !1) : (T._TempClearColorInt32[0] = e.r * 255, T._TempClearColorInt32[1] = e.g * 255, T._TempClearColorInt32[2] = e.b * 255, T._TempClearColorInt32[3] = e.a * 255, this._gl.clearBufferiv(this._gl.COLOR, 0, T._TempClearColorInt32), a = !1);
498
+ }
499
+ }
500
+ a && (this._gl.clearColor(e.r, e.g, e.b, e.a !== void 0 ? e.a : 1), l |= this._gl.COLOR_BUFFER_BIT);
501
+ }
502
+ r && (this.useReverseDepthBuffer ? (this._depthCullingState.depthFunc = this._gl.GEQUAL, this._gl.clearDepth(0)) : this._gl.clearDepth(1), l |= this._gl.DEPTH_BUFFER_BIT), s && (this._gl.clearStencil(i), l |= this._gl.STENCIL_BUFFER_BIT), this._gl.clear(l);
503
+ }
504
+ /**
505
+ * @internal
506
+ */
507
+ _viewport(e, t, r, s) {
508
+ (e !== this._viewportCached.x || t !== this._viewportCached.y || r !== this._viewportCached.z || s !== this._viewportCached.w) && (this._viewportCached.x = e, this._viewportCached.y = t, this._viewportCached.z = r, this._viewportCached.w = s, this._gl.viewport(e, t, r, s));
509
+ }
510
+ /**
511
+ * End the current frame
512
+ */
513
+ endFrame() {
514
+ super.endFrame(), this._badOS && this.flushFramebuffer();
515
+ }
516
+ /**
517
+ * Gets the performance monitor attached to this engine
518
+ * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimize_your_scene#engineinstrumentation
519
+ */
520
+ get performanceMonitor() {
521
+ throw new Error("Not Supported by ThinEngine");
522
+ }
523
+ /**
524
+ * Binds the frame buffer to the specified texture.
525
+ * @param rtWrapper The render target wrapper to render to
526
+ * @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
527
+ * @param requiredWidth The width of the target to render to
528
+ * @param requiredHeight The height of the target to render to
529
+ * @param forceFullscreenViewport Forces the viewport to be the entire texture/screen if true
530
+ * @param lodLevel Defines the lod level to bind to the frame buffer
531
+ * @param layer Defines the 2d array index to bind to the frame buffer if the render target wrapper is not a multi render target
532
+ */
533
+ bindFramebuffer(e, t = 0, r, s, i, n = 0, l = 0) {
534
+ const a = e;
535
+ this._currentRenderTarget && this._resolveAndGenerateMipMapsFramebuffer(this._currentRenderTarget), this._currentRenderTarget = e, this._bindUnboundFramebuffer(a._framebuffer);
536
+ const _ = this._gl;
537
+ e.isMulti || (e.is2DArray || e.is3D ? (_.framebufferTextureLayer(_.FRAMEBUFFER, _.COLOR_ATTACHMENT0, e.texture._hardwareTexture?.underlyingResource, n, l), a._currentLOD = n) : e.isCube ? _.framebufferTexture2D(_.FRAMEBUFFER, _.COLOR_ATTACHMENT0, _.TEXTURE_CUBE_MAP_POSITIVE_X + t, e.texture._hardwareTexture?.underlyingResource, n) : a._currentLOD !== n && (_.framebufferTexture2D(_.FRAMEBUFFER, _.COLOR_ATTACHMENT0, _.TEXTURE_2D, e.texture._hardwareTexture?.underlyingResource, n), a._currentLOD = n));
538
+ const u = e._depthStencilTexture;
539
+ if (u) {
540
+ e.is3D && (e.texture.width !== u.width || e.texture.height !== u.height || e.texture.depth !== u.depth) && I.Warn("Depth/Stencil attachment for 3D target must have same dimensions as color attachment");
541
+ const f = e._depthStencilTextureWithStencil ? _.DEPTH_STENCIL_ATTACHMENT : _.DEPTH_ATTACHMENT;
542
+ e.is2DArray || e.is3D ? _.framebufferTextureLayer(_.FRAMEBUFFER, f, u._hardwareTexture?.underlyingResource, n, l) : e.isCube ? _.framebufferTexture2D(_.FRAMEBUFFER, f, _.TEXTURE_CUBE_MAP_POSITIVE_X + t, u._hardwareTexture?.underlyingResource, n) : _.framebufferTexture2D(_.FRAMEBUFFER, f, _.TEXTURE_2D, u._hardwareTexture?.underlyingResource, n);
543
+ }
544
+ a._MSAAFramebuffer && this._bindUnboundFramebuffer(a._MSAAFramebuffer), this._cachedViewport && !i ? this.setViewport(this._cachedViewport, r, s) : (r || (r = e.width, n && (r = r / Math.pow(2, n))), s || (s = e.height, n && (s = s / Math.pow(2, n))), this._viewport(0, 0, r, s)), this.wipeCaches();
545
+ }
546
+ setStateCullFaceType(e, t) {
547
+ const r = this.cullBackFaces ?? e ?? !0 ? this._gl.BACK : this._gl.FRONT;
548
+ (this._depthCullingState.cullFace !== r || t) && (this._depthCullingState.cullFace = r);
549
+ }
550
+ /**
551
+ * Set various states to the webGL context
552
+ * @param culling defines culling state: true to enable culling, false to disable it
553
+ * @param zOffset defines the value to apply to zOffset (0 by default)
554
+ * @param force defines if states must be applied even if cache is up to date
555
+ * @param reverseSide defines if culling must be reversed (CCW if false, CW if true)
556
+ * @param cullBackFaces true to cull back faces, false to cull front faces (if culling is enabled)
557
+ * @param stencil stencil states to set
558
+ * @param zOffsetUnits defines the value to apply to zOffsetUnits (0 by default)
559
+ */
560
+ setState(e, t = 0, r, s = !1, i, n, l = 0) {
561
+ (this._depthCullingState.cull !== e || r) && (this._depthCullingState.cull = e), this.setStateCullFaceType(i, r), this.setZOffset(t), this.setZOffsetUnits(l);
562
+ const a = s ? this._gl.CW : this._gl.CCW;
563
+ (this._depthCullingState.frontFace !== a || r) && (this._depthCullingState.frontFace = a), this._stencilStateComposer.stencilMaterial = n;
564
+ }
565
+ _resolveAndGenerateMipMapsFramebuffer(e, t = !1) {
566
+ e.disableAutomaticMSAAResolve || (e.isMulti ? this.resolveMultiFramebuffer(e) : this.resolveFramebuffer(e)), t || (e.isMulti ? this.generateMipMapsMultiFramebuffer(e) : this.generateMipMapsFramebuffer(e));
567
+ }
568
+ /**
569
+ * @internal
570
+ */
571
+ _bindUnboundFramebuffer(e) {
572
+ this._currentFramebuffer !== e && (this._gl.bindFramebuffer(this._gl.FRAMEBUFFER, e), this._currentFramebuffer = e);
573
+ }
574
+ /** @internal */
575
+ _currentFrameBufferIsDefaultFrameBuffer() {
576
+ return this._currentFramebuffer === null;
577
+ }
578
+ /**
579
+ * Generates the mipmaps for a texture
580
+ * @param texture texture to generate the mipmaps for
581
+ */
582
+ generateMipmaps(e) {
583
+ const t = this._getTextureTarget(e);
584
+ this._bindTextureDirectly(t, e, !0), this._gl.generateMipmap(t), this._bindTextureDirectly(t, null);
585
+ }
586
+ /**
587
+ * Unbind the current render target texture from the webGL context
588
+ * @param texture defines the render target wrapper to unbind
589
+ * @param disableGenerateMipMaps defines a boolean indicating that mipmaps must not be generated
590
+ * @param onBeforeUnbind defines a function which will be called before the effective unbind
591
+ */
592
+ unBindFramebuffer(e, t, r) {
593
+ const s = e;
594
+ this._currentRenderTarget = null, this._resolveAndGenerateMipMapsFramebuffer(e, t), r && (s._MSAAFramebuffer && this._bindUnboundFramebuffer(s._framebuffer), r()), this._bindUnboundFramebuffer(null);
595
+ }
596
+ /**
597
+ * Generates mipmaps for the texture of the (single) render target
598
+ * @param texture The render target containing the texture to generate the mipmaps for
599
+ */
600
+ generateMipMapsFramebuffer(e) {
601
+ !e.isMulti && e.texture?.generateMipMaps && !e.isCube && this.generateMipmaps(e.texture);
602
+ }
603
+ /**
604
+ * Resolves the MSAA texture of the (single) render target into its non-MSAA version.
605
+ * Note that if "texture" is not a MSAA render target, no resolve is performed.
606
+ * @param texture The render target texture containing the MSAA textures to resolve
607
+ */
608
+ resolveFramebuffer(e) {
609
+ const t = e, r = this._gl;
610
+ if (!t._MSAAFramebuffer || t.isMulti)
611
+ return;
612
+ let s = t.resolveMSAAColors ? r.COLOR_BUFFER_BIT : 0;
613
+ s |= t._generateDepthBuffer && t.resolveMSAADepth ? r.DEPTH_BUFFER_BIT : 0, s |= t._generateStencilBuffer && t.resolveMSAAStencil ? r.STENCIL_BUFFER_BIT : 0, r.bindFramebuffer(r.READ_FRAMEBUFFER, t._MSAAFramebuffer), r.bindFramebuffer(r.DRAW_FRAMEBUFFER, t._framebuffer), r.blitFramebuffer(0, 0, e.width, e.height, 0, 0, e.width, e.height, s, r.NEAREST);
614
+ }
615
+ /**
616
+ * Force a webGL flush (ie. a flush of all waiting webGL commands)
617
+ */
618
+ flushFramebuffer() {
619
+ this._gl.flush();
620
+ }
621
+ /**
622
+ * Unbind the current render target and bind the default framebuffer
623
+ */
624
+ restoreDefaultFramebuffer() {
625
+ this._currentRenderTarget ? this.unBindFramebuffer(this._currentRenderTarget) : this._bindUnboundFramebuffer(null), this._cachedViewport && this.setViewport(this._cachedViewport), this.wipeCaches();
626
+ }
627
+ // VBOs
628
+ /** @internal */
629
+ _resetVertexBufferBinding() {
630
+ this.bindArrayBuffer(null), this._cachedVertexBuffers = null;
631
+ }
632
+ /**
633
+ * Creates a vertex buffer
634
+ * @param data the data or size for the vertex buffer
635
+ * @param _updatable whether the buffer should be created as updatable
636
+ * @param _label defines the label of the buffer (for debug purpose)
637
+ * @returns the new WebGL static buffer
638
+ */
639
+ createVertexBuffer(e, t, r) {
640
+ return this._createVertexBuffer(e, this._gl.STATIC_DRAW);
641
+ }
642
+ _createVertexBuffer(e, t) {
643
+ const r = this._gl.createBuffer();
644
+ if (!r)
645
+ throw new Error("Unable to create vertex buffer");
646
+ const s = new v(r);
647
+ return this.bindArrayBuffer(s), typeof e != "number" ? e instanceof Array ? (this._gl.bufferData(this._gl.ARRAY_BUFFER, new Float32Array(e), t), s.capacity = e.length * 4) : (this._gl.bufferData(this._gl.ARRAY_BUFFER, e, t), s.capacity = e.byteLength) : (this._gl.bufferData(this._gl.ARRAY_BUFFER, new Uint8Array(e), t), s.capacity = e), this._resetVertexBufferBinding(), s.references = 1, s;
648
+ }
649
+ /**
650
+ * Creates a dynamic vertex buffer
651
+ * @param data the data for the dynamic vertex buffer
652
+ * @param _label defines the label of the buffer (for debug purpose)
653
+ * @returns the new WebGL dynamic buffer
654
+ */
655
+ createDynamicVertexBuffer(e, t) {
656
+ return this._createVertexBuffer(e, this._gl.DYNAMIC_DRAW);
657
+ }
658
+ _resetIndexBufferBinding() {
659
+ this.bindIndexBuffer(null), this._cachedIndexBuffer = null;
660
+ }
661
+ /**
662
+ * Creates a new index buffer
663
+ * @param indices defines the content of the index buffer
664
+ * @param updatable defines if the index buffer must be updatable
665
+ * @param _label defines the label of the buffer (for debug purpose)
666
+ * @returns a new webGL buffer
667
+ */
668
+ createIndexBuffer(e, t, r) {
669
+ const s = this._gl.createBuffer(), i = new v(s);
670
+ if (!s)
671
+ throw new Error("Unable to create index buffer");
672
+ this.bindIndexBuffer(i);
673
+ const n = this._normalizeIndexData(e);
674
+ return this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER, n, t ? this._gl.DYNAMIC_DRAW : this._gl.STATIC_DRAW), this._resetIndexBufferBinding(), i.references = 1, i.is32Bits = n.BYTES_PER_ELEMENT === 4, i;
675
+ }
676
+ _normalizeIndexData(e) {
677
+ if (e.BYTES_PER_ELEMENT === 2)
678
+ return e;
679
+ if (this._caps.uintIndices) {
680
+ if (e instanceof Uint32Array)
681
+ return e;
682
+ for (let r = 0; r < e.length; r++)
683
+ if (e[r] >= 65535)
684
+ return new Uint32Array(e);
685
+ return new Uint16Array(e);
686
+ }
687
+ return new Uint16Array(e);
688
+ }
689
+ /**
690
+ * Bind a webGL buffer to the webGL context
691
+ * @param buffer defines the buffer to bind
692
+ */
693
+ bindArrayBuffer(e) {
694
+ this._vaoRecordInProgress || this._unbindVertexArrayObject(), this._bindBuffer(e, this._gl.ARRAY_BUFFER);
695
+ }
696
+ /**
697
+ * Bind a specific block at a given index in a specific shader program
698
+ * @param pipelineContext defines the pipeline context to use
699
+ * @param blockName defines the block name
700
+ * @param index defines the index where to bind the block
701
+ */
702
+ bindUniformBlock(e, t, r) {
703
+ const s = e.program, i = this._gl.getUniformBlockIndex(s, t);
704
+ this._gl.uniformBlockBinding(s, i, r);
705
+ }
706
+ // eslint-disable-next-line @typescript-eslint/naming-convention
707
+ bindIndexBuffer(e) {
708
+ this._vaoRecordInProgress || this._unbindVertexArrayObject(), this._bindBuffer(e, this._gl.ELEMENT_ARRAY_BUFFER);
709
+ }
710
+ _bindBuffer(e, t) {
711
+ (this._vaoRecordInProgress || this._currentBoundBuffer[t] !== e) && (this._gl.bindBuffer(t, e ? e.underlyingResource : null), this._currentBoundBuffer[t] = e);
712
+ }
713
+ /**
714
+ * update the bound buffer with the given data
715
+ * @param data defines the data to update
716
+ */
717
+ updateArrayBuffer(e) {
718
+ this._gl.bufferSubData(this._gl.ARRAY_BUFFER, 0, e);
719
+ }
720
+ _vertexAttribPointer(e, t, r, s, i, n, l) {
721
+ const a = this._currentBufferPointers[t];
722
+ if (!a)
723
+ return;
724
+ let _ = !1;
725
+ a.active ? (a.buffer !== e && (a.buffer = e, _ = !0), a.size !== r && (a.size = r, _ = !0), a.type !== s && (a.type = s, _ = !0), a.normalized !== i && (a.normalized = i, _ = !0), a.stride !== n && (a.stride = n, _ = !0), a.offset !== l && (a.offset = l, _ = !0)) : (_ = !0, a.active = !0, a.index = t, a.size = r, a.type = s, a.normalized = i, a.stride = n, a.offset = l, a.buffer = e), (_ || this._vaoRecordInProgress) && (this.bindArrayBuffer(e), s === this._gl.UNSIGNED_INT || s === this._gl.INT ? this._gl.vertexAttribIPointer(t, r, s, n, l) : this._gl.vertexAttribPointer(t, r, s, i, n, l));
726
+ }
727
+ /**
728
+ * @internal
729
+ */
730
+ _bindIndexBufferWithCache(e) {
731
+ e != null && this._cachedIndexBuffer !== e && (this._cachedIndexBuffer = e, this.bindIndexBuffer(e), this._uintIndicesCurrentlySet = e.is32Bits);
732
+ }
733
+ _bindVertexBuffersAttributes(e, t, r) {
734
+ const s = t.getAttributesNames();
735
+ this._vaoRecordInProgress || this._unbindVertexArrayObject(), this.unbindAllAttributes();
736
+ for (let i = 0; i < s.length; i++) {
737
+ const n = t.getAttributeLocation(i);
738
+ if (n >= 0) {
739
+ const l = s[i];
740
+ let a = null;
741
+ if (r && (a = r[l]), a || (a = e[l]), !a)
742
+ continue;
743
+ this._gl.enableVertexAttribArray(n), this._vaoRecordInProgress || (this._vertexAttribArraysEnabled[n] = !0);
744
+ const _ = a.getBuffer();
745
+ _ && (this._vertexAttribPointer(_, n, a.getSize(), a.type, a.normalized, a.byteStride, a.byteOffset), a.getIsInstanced() && (this._gl.vertexAttribDivisor(n, a.getInstanceDivisor()), this._vaoRecordInProgress || (this._currentInstanceLocations.push(n), this._currentInstanceBuffers.push(_))));
746
+ }
747
+ }
748
+ }
749
+ /**
750
+ * Records a vertex array object
751
+ * @see https://doc.babylonjs.com/setup/support/webGL2#vertex-array-objects
752
+ * @param vertexBuffers defines the list of vertex buffers to store
753
+ * @param indexBuffer defines the index buffer to store
754
+ * @param effect defines the effect to store
755
+ * @param overrideVertexBuffers defines optional list of avertex buffers that overrides the entries in vertexBuffers
756
+ * @returns the new vertex array object
757
+ */
758
+ recordVertexArrayObject(e, t, r, s) {
759
+ const i = this._gl.createVertexArray();
760
+ if (!i)
761
+ throw new Error("Unable to create VAO");
762
+ return this._vaoRecordInProgress = !0, this._gl.bindVertexArray(i), this._mustWipeVertexAttributes = !0, this._bindVertexBuffersAttributes(e, r, s), this.bindIndexBuffer(t), this._vaoRecordInProgress = !1, this._gl.bindVertexArray(null), i;
763
+ }
764
+ /**
765
+ * Bind a specific vertex array object
766
+ * @see https://doc.babylonjs.com/setup/support/webGL2#vertex-array-objects
767
+ * @param vertexArrayObject defines the vertex array object to bind
768
+ * @param indexBuffer defines the index buffer to bind
769
+ */
770
+ bindVertexArrayObject(e, t) {
771
+ this._cachedVertexArrayObject !== e && (this._cachedVertexArrayObject = e, this._gl.bindVertexArray(e), this._cachedVertexBuffers = null, this._cachedIndexBuffer = null, this._uintIndicesCurrentlySet = t != null && t.is32Bits, this._mustWipeVertexAttributes = !0);
772
+ }
773
+ /**
774
+ * Bind webGl buffers directly to the webGL context
775
+ * @param vertexBuffer defines the vertex buffer to bind
776
+ * @param indexBuffer defines the index buffer to bind
777
+ * @param vertexDeclaration defines the vertex declaration to use with the vertex buffer
778
+ * @param vertexStrideSize defines the vertex stride of the vertex buffer
779
+ * @param effect defines the effect associated with the vertex buffer
780
+ */
781
+ bindBuffersDirectly(e, t, r, s, i) {
782
+ if (this._cachedVertexBuffers !== e || this._cachedEffectForVertexBuffers !== i) {
783
+ this._cachedVertexBuffers = e, this._cachedEffectForVertexBuffers = i;
784
+ const n = i.getAttributesCount();
785
+ this._unbindVertexArrayObject(), this.unbindAllAttributes();
786
+ let l = 0;
787
+ for (let a = 0; a < n; a++)
788
+ if (a < r.length) {
789
+ const _ = i.getAttributeLocation(a);
790
+ _ >= 0 && (this._gl.enableVertexAttribArray(_), this._vertexAttribArraysEnabled[_] = !0, this._vertexAttribPointer(e, _, r[a], this._gl.FLOAT, !1, s, l)), l += r[a] * 4;
791
+ }
792
+ }
793
+ this._bindIndexBufferWithCache(t);
794
+ }
795
+ _unbindVertexArrayObject() {
796
+ this._cachedVertexArrayObject && (this._cachedVertexArrayObject = null, this._gl.bindVertexArray(null));
797
+ }
798
+ /**
799
+ * Bind a list of vertex buffers to the webGL context
800
+ * @param vertexBuffers defines the list of vertex buffers to bind
801
+ * @param indexBuffer defines the index buffer to bind
802
+ * @param effect defines the effect associated with the vertex buffers
803
+ * @param overrideVertexBuffers defines optional list of avertex buffers that overrides the entries in vertexBuffers
804
+ */
805
+ bindBuffers(e, t, r, s) {
806
+ (this._cachedVertexBuffers !== e || this._cachedEffectForVertexBuffers !== r) && (this._cachedVertexBuffers = e, this._cachedEffectForVertexBuffers = r, this._bindVertexBuffersAttributes(e, r, s)), this._bindIndexBufferWithCache(t);
807
+ }
808
+ /**
809
+ * Unbind all instance attributes
810
+ */
811
+ unbindInstanceAttributes() {
812
+ let e;
813
+ for (let t = 0, r = this._currentInstanceLocations.length; t < r; t++) {
814
+ const s = this._currentInstanceBuffers[t];
815
+ e != s && s.references && (e = s, this.bindArrayBuffer(s));
816
+ const i = this._currentInstanceLocations[t];
817
+ this._gl.vertexAttribDivisor(i, 0);
818
+ }
819
+ this._currentInstanceBuffers.length = 0, this._currentInstanceLocations.length = 0;
820
+ }
821
+ /**
822
+ * Release and free the memory of a vertex array object
823
+ * @param vao defines the vertex array object to delete
824
+ */
825
+ releaseVertexArrayObject(e) {
826
+ this._gl.deleteVertexArray(e);
827
+ }
828
+ /**
829
+ * @internal
830
+ */
831
+ _releaseBuffer(e) {
832
+ return e.references--, e.references === 0 ? (this._deleteBuffer(e), !0) : !1;
833
+ }
834
+ _deleteBuffer(e) {
835
+ this._gl.deleteBuffer(e.underlyingResource);
836
+ }
837
+ /**
838
+ * Update the content of a webGL buffer used with instantiation and bind it to the webGL context
839
+ * @param instancesBuffer defines the webGL buffer to update and bind
840
+ * @param data defines the data to store in the buffer
841
+ * @param offsetLocations defines the offsets or attributes information used to determine where data must be stored in the buffer
842
+ */
843
+ updateAndBindInstancesBuffer(e, t, r) {
844
+ if (this.bindArrayBuffer(e), t && this._gl.bufferSubData(this._gl.ARRAY_BUFFER, 0, t), r[0].index !== void 0)
845
+ this.bindInstancesBuffer(e, r, !0);
846
+ else
847
+ for (let s = 0; s < 4; s++) {
848
+ const i = r[s];
849
+ this._vertexAttribArraysEnabled[i] || (this._gl.enableVertexAttribArray(i), this._vertexAttribArraysEnabled[i] = !0), this._vertexAttribPointer(e, i, 4, this._gl.FLOAT, !1, 64, s * 16), this._gl.vertexAttribDivisor(i, 1), this._currentInstanceLocations.push(i), this._currentInstanceBuffers.push(e);
850
+ }
851
+ }
852
+ /**
853
+ * Bind the content of a webGL buffer used with instantiation
854
+ * @param instancesBuffer defines the webGL buffer to bind
855
+ * @param attributesInfo defines the offsets or attributes information used to determine where data must be stored in the buffer
856
+ * @param computeStride defines Whether to compute the strides from the info or use the default 0
857
+ */
858
+ bindInstancesBuffer(e, t, r = !0) {
859
+ this.bindArrayBuffer(e);
860
+ let s = 0;
861
+ if (r)
862
+ for (let i = 0; i < t.length; i++) {
863
+ const n = t[i];
864
+ s += n.attributeSize * 4;
865
+ }
866
+ for (let i = 0; i < t.length; i++) {
867
+ const n = t[i];
868
+ n.index === void 0 && (n.index = this._currentEffect.getAttributeLocationByName(n.attributeName)), !(n.index < 0) && (this._vertexAttribArraysEnabled[n.index] || (this._gl.enableVertexAttribArray(n.index), this._vertexAttribArraysEnabled[n.index] = !0), this._vertexAttribPointer(e, n.index, n.attributeSize, n.attributeType || this._gl.FLOAT, n.normalized || !1, s, n.offset), this._gl.vertexAttribDivisor(n.index, n.divisor === void 0 ? 1 : n.divisor), this._currentInstanceLocations.push(n.index), this._currentInstanceBuffers.push(e));
869
+ }
870
+ }
871
+ /**
872
+ * Disable the instance attribute corresponding to the name in parameter
873
+ * @param name defines the name of the attribute to disable
874
+ */
875
+ disableInstanceAttributeByName(e) {
876
+ if (!this._currentEffect)
877
+ return;
878
+ const t = this._currentEffect.getAttributeLocationByName(e);
879
+ this.disableInstanceAttribute(t);
880
+ }
881
+ /**
882
+ * Disable the instance attribute corresponding to the location in parameter
883
+ * @param attributeLocation defines the attribute location of the attribute to disable
884
+ */
885
+ disableInstanceAttribute(e) {
886
+ let t = !1, r;
887
+ for (; (r = this._currentInstanceLocations.indexOf(e)) !== -1; )
888
+ this._currentInstanceLocations.splice(r, 1), this._currentInstanceBuffers.splice(r, 1), t = !0;
889
+ t && (this._gl.vertexAttribDivisor(e, 0), this.disableAttributeByIndex(e));
890
+ }
891
+ /**
892
+ * Disable the attribute corresponding to the location in parameter
893
+ * @param attributeLocation defines the attribute location of the attribute to disable
894
+ */
895
+ disableAttributeByIndex(e) {
896
+ this._gl.disableVertexAttribArray(e), this._vertexAttribArraysEnabled[e] = !1, this._currentBufferPointers[e].active = !1;
897
+ }
898
+ /**
899
+ * Send a draw order
900
+ * @param useTriangles defines if triangles must be used to draw (else wireframe will be used)
901
+ * @param indexStart defines the starting index
902
+ * @param indexCount defines the number of index to draw
903
+ * @param instancesCount defines the number of instances to draw (if instantiation is enabled)
904
+ */
905
+ draw(e, t, r, s) {
906
+ this.drawElementsType(e ? 0 : 1, t, r, s);
907
+ }
908
+ /**
909
+ * Draw a list of points
910
+ * @param verticesStart defines the index of first vertex to draw
911
+ * @param verticesCount defines the count of vertices to draw
912
+ * @param instancesCount defines the number of instances to draw (if instantiation is enabled)
913
+ */
914
+ drawPointClouds(e, t, r) {
915
+ this.drawArraysType(2, e, t, r);
916
+ }
917
+ /**
918
+ * Draw a list of unindexed primitives
919
+ * @param useTriangles defines if triangles must be used to draw (else wireframe will be used)
920
+ * @param verticesStart defines the index of first vertex to draw
921
+ * @param verticesCount defines the count of vertices to draw
922
+ * @param instancesCount defines the number of instances to draw (if instantiation is enabled)
923
+ */
924
+ drawUnIndexed(e, t, r, s) {
925
+ this.drawArraysType(e ? 0 : 1, t, r, s);
926
+ }
927
+ /**
928
+ * Draw a list of indexed primitives
929
+ * @param fillMode defines the primitive to use
930
+ * @param indexStart defines the starting index
931
+ * @param indexCount defines the number of index to draw
932
+ * @param instancesCount defines the number of instances to draw (if instantiation is enabled)
933
+ */
934
+ drawElementsType(e, t, r, s) {
935
+ this.applyStates(), this._reportDrawCall();
936
+ const i = this._drawMode(e), n = this._uintIndicesCurrentlySet ? this._gl.UNSIGNED_INT : this._gl.UNSIGNED_SHORT, l = this._uintIndicesCurrentlySet ? 4 : 2;
937
+ s ? this._gl.drawElementsInstanced(i, r, n, t * l, s) : this._gl.drawElements(i, r, n, t * l);
938
+ }
939
+ /**
940
+ * Draw a list of unindexed primitives
941
+ * @param fillMode defines the primitive to use
942
+ * @param verticesStart defines the index of first vertex to draw
943
+ * @param verticesCount defines the count of vertices to draw
944
+ * @param instancesCount defines the number of instances to draw (if instantiation is enabled)
945
+ */
946
+ drawArraysType(e, t, r, s) {
947
+ this.applyStates(), this._reportDrawCall();
948
+ const i = this._drawMode(e);
949
+ s ? this._gl.drawArraysInstanced(i, t, r, s) : this._gl.drawArrays(i, t, r);
950
+ }
951
+ _drawMode(e) {
952
+ switch (e) {
953
+ // Triangle views
954
+ case 0:
955
+ return this._gl.TRIANGLES;
956
+ case 2:
957
+ return this._gl.POINTS;
958
+ case 1:
959
+ return this._gl.LINES;
960
+ // Draw modes
961
+ case 3:
962
+ return this._gl.POINTS;
963
+ case 4:
964
+ return this._gl.LINES;
965
+ case 5:
966
+ return this._gl.LINE_LOOP;
967
+ case 6:
968
+ return this._gl.LINE_STRIP;
969
+ case 7:
970
+ return this._gl.TRIANGLE_STRIP;
971
+ case 8:
972
+ return this._gl.TRIANGLE_FAN;
973
+ default:
974
+ return this._gl.TRIANGLES;
975
+ }
976
+ }
977
+ // Shaders
978
+ /**
979
+ * @internal
980
+ */
981
+ _releaseEffect(e) {
982
+ this._compiledEffects[e._key] && delete this._compiledEffects[e._key];
983
+ const t = e.getPipelineContext();
984
+ t && this._deletePipelineContext(t);
985
+ }
986
+ /**
987
+ * @internal
988
+ */
989
+ _deletePipelineContext(e) {
990
+ const t = e;
991
+ t && t.program && (t.program.__SPECTOR_rebuildProgram = null, k(t), this._gl && (this._currentProgram === t.program && this._setProgram(null), this._gl.deleteProgram(t.program)));
992
+ }
993
+ /**
994
+ * @internal
995
+ */
996
+ _getGlobalDefines(e) {
997
+ return K(e, this.isNDCHalfZRange, this.useReverseDepthBuffer, this.useExactSrgbConversions);
998
+ }
999
+ /**
1000
+ * Create a new effect (used to store vertex/fragment shaders)
1001
+ * @param baseName defines the base name of the effect (The name of file without .fragment.fx or .vertex.fx)
1002
+ * @param attributesNamesOrOptions defines either a list of attribute names or an IEffectCreationOptions object
1003
+ * @param uniformsNamesOrEngine defines either a list of uniform names or the engine to use
1004
+ * @param samplers defines an array of string used to represent textures
1005
+ * @param defines defines the string containing the defines to use to compile the shaders
1006
+ * @param fallbacks defines the list of potential fallbacks to use if shader compilation fails
1007
+ * @param onCompiled defines a function to call when the effect creation is successful
1008
+ * @param onError defines a function to call when the effect creation has failed
1009
+ * @param indexParameters defines an object containing the index values to use to compile shaders (like the maximum number of simultaneous lights)
1010
+ * @param shaderLanguage the language the shader is written in (default: GLSL)
1011
+ * @param extraInitializationsAsync additional async code to run before preparing the effect
1012
+ * @returns the new Effect
1013
+ */
1014
+ createEffect(e, t, r, s, i, n, l, a, _, u = 0, f) {
1015
+ const c = typeof e == "string" ? e : e.vertexToken || e.vertexSource || e.vertexElement || e.vertex, d = typeof e == "string" ? e : e.fragmentToken || e.fragmentSource || e.fragmentElement || e.fragment, g = this._getGlobalDefines(), m = t.attributes !== void 0;
1016
+ let E = i ?? t.defines ?? "";
1017
+ g && (E += g);
1018
+ const p = c + "+" + d + "@" + E;
1019
+ if (this._compiledEffects[p]) {
1020
+ const o = this._compiledEffects[p];
1021
+ return l && o.isReady() && l(o), o._refCount++, o;
1022
+ }
1023
+ this._gl && L(this._gl);
1024
+ const h = new O(e, t, m ? this : r, s, this, i, n, l, a, _, p, t.shaderLanguage ?? u, t.extraInitializationsAsync ?? f);
1025
+ return this._compiledEffects[p] = h, h;
1026
+ }
1027
+ /**
1028
+ * @internal
1029
+ */
1030
+ _getShaderSource(e) {
1031
+ return this._gl.getShaderSource(e);
1032
+ }
1033
+ /**
1034
+ * Directly creates a webGL program
1035
+ * @param pipelineContext defines the pipeline context to attach to
1036
+ * @param vertexCode defines the vertex shader code to use
1037
+ * @param fragmentCode defines the fragment shader code to use
1038
+ * @param context defines the webGL context to use (if not set, the current one will be used)
1039
+ * @param transformFeedbackVaryings defines the list of transform feedback varyings to use
1040
+ * @returns the new webGL program
1041
+ */
1042
+ createRawShaderProgram(e, t, r, s, i = null) {
1043
+ const n = L(this._gl);
1044
+ return n._contextWasLost = this._contextWasLost, n.validateShaderPrograms = this.validateShaderPrograms, j(e, t, r, s || this._gl, i);
1045
+ }
1046
+ /**
1047
+ * Creates a webGL program
1048
+ * @param pipelineContext defines the pipeline context to attach to
1049
+ * @param vertexCode defines the vertex shader code to use
1050
+ * @param fragmentCode defines the fragment shader code to use
1051
+ * @param defines defines the string containing the defines to use to compile the shaders
1052
+ * @param context defines the webGL context to use (if not set, the current one will be used)
1053
+ * @param transformFeedbackVaryings defines the list of transform feedback varyings to use
1054
+ * @returns the new webGL program
1055
+ */
1056
+ createShaderProgram(e, t, r, s, i, n = null) {
1057
+ const l = L(this._gl);
1058
+ return l._contextWasLost = this._contextWasLost, l.validateShaderPrograms = this.validateShaderPrograms, Y(e, t, r, s, i || this._gl, n);
1059
+ }
1060
+ /**
1061
+ * Inline functions in shader code that are marked to be inlined
1062
+ * @param code code to inline
1063
+ * @returns inlined code
1064
+ */
1065
+ inlineShaderCode(e) {
1066
+ return e;
1067
+ }
1068
+ /**
1069
+ * Creates a new pipeline context
1070
+ * @param shaderProcessingContext defines the shader processing context used during the processing if available
1071
+ * @returns the new pipeline
1072
+ */
1073
+ createPipelineContext(e) {
1074
+ if (this._gl) {
1075
+ const r = L(this._gl);
1076
+ r.parallelShaderCompile = this._caps.parallelShaderCompile;
1077
+ }
1078
+ const t = z(this._gl);
1079
+ return t.engine = this, t;
1080
+ }
1081
+ /**
1082
+ * Creates a new material context
1083
+ * @returns the new context
1084
+ */
1085
+ createMaterialContext() {
1086
+ }
1087
+ /**
1088
+ * Creates a new draw context
1089
+ * @returns the new context
1090
+ */
1091
+ createDrawContext() {
1092
+ }
1093
+ _finalizePipelineContext(e) {
1094
+ return Q(e, this._gl, this.validateShaderPrograms);
1095
+ }
1096
+ /**
1097
+ * @internal
1098
+ */
1099
+ // named async but not actually an async function
1100
+ // eslint-disable-next-line no-restricted-syntax
1101
+ _preparePipelineContextAsync(e, t, r, s, i, n, l, a, _, u, f) {
1102
+ const c = L(this._gl);
1103
+ return c._contextWasLost = this._contextWasLost, c.validateShaderPrograms = this.validateShaderPrograms, c._createShaderProgramInjection = this._createShaderProgram.bind(this), c.createRawShaderProgramInjection = this.createRawShaderProgram.bind(this), c.createShaderProgramInjection = this.createShaderProgram.bind(this), c.loadFileInjection = this._loadFile.bind(this), Z(e, t, r, s, i, n, l, a, _, u, f);
1104
+ }
1105
+ _createShaderProgram(e, t, r, s, i = null) {
1106
+ return $(e, t, r, s, i);
1107
+ }
1108
+ /**
1109
+ * @internal
1110
+ */
1111
+ _isRenderingStateCompiled(e) {
1112
+ return this._isDisposed ? !1 : q(e, this._gl, this.validateShaderPrograms);
1113
+ }
1114
+ /**
1115
+ * @internal
1116
+ */
1117
+ _executeWhenRenderingStateIsCompiled(e, t) {
1118
+ J(e, t);
1119
+ }
1120
+ /**
1121
+ * Gets the list of webGL uniform locations associated with a specific program based on a list of uniform names
1122
+ * @param pipelineContext defines the pipeline context to use
1123
+ * @param uniformsNames defines the list of uniform names
1124
+ * @returns an array of webGL uniform locations
1125
+ */
1126
+ getUniforms(e, t) {
1127
+ const r = new Array(), s = e;
1128
+ for (let i = 0; i < t.length; i++)
1129
+ r.push(this._gl.getUniformLocation(s.program, t[i]));
1130
+ return r;
1131
+ }
1132
+ /**
1133
+ * Gets the list of active attributes for a given webGL program
1134
+ * @param pipelineContext defines the pipeline context to use
1135
+ * @param attributesNames defines the list of attribute names to get
1136
+ * @returns an array of indices indicating the offset of each attribute
1137
+ */
1138
+ getAttributes(e, t) {
1139
+ const r = [], s = e;
1140
+ for (let i = 0; i < t.length; i++)
1141
+ try {
1142
+ r.push(this._gl.getAttribLocation(s.program, t[i]));
1143
+ } catch {
1144
+ r.push(-1);
1145
+ }
1146
+ return r;
1147
+ }
1148
+ /**
1149
+ * Activates an effect, making it the current one (ie. the one used for rendering)
1150
+ * @param effect defines the effect to activate
1151
+ */
1152
+ enableEffect(e) {
1153
+ e = e !== null && ee(e) ? e.effect : e, !(!e || e === this._currentEffect) && (this._stencilStateComposer.stencilMaterial = void 0, this.bindSamplers(e), this._currentEffect = e, e.onBind && e.onBind(e), e._onBindObservable && e._onBindObservable.notifyObservers(e));
1154
+ }
1155
+ /**
1156
+ * Set the value of an uniform to a number (int)
1157
+ * @param uniform defines the webGL uniform location where to store the value
1158
+ * @param value defines the int number to store
1159
+ * @returns true if the value was set
1160
+ */
1161
+ setInt(e, t) {
1162
+ return e ? (this._gl.uniform1i(e, t), !0) : !1;
1163
+ }
1164
+ /**
1165
+ * Set the value of an uniform to a int2
1166
+ * @param uniform defines the webGL uniform location where to store the value
1167
+ * @param x defines the 1st component of the value
1168
+ * @param y defines the 2nd component of the value
1169
+ * @returns true if the value was set
1170
+ */
1171
+ setInt2(e, t, r) {
1172
+ return e ? (this._gl.uniform2i(e, t, r), !0) : !1;
1173
+ }
1174
+ /**
1175
+ * Set the value of an uniform to a int3
1176
+ * @param uniform defines the webGL uniform location where to store the value
1177
+ * @param x defines the 1st component of the value
1178
+ * @param y defines the 2nd component of the value
1179
+ * @param z defines the 3rd component of the value
1180
+ * @returns true if the value was set
1181
+ */
1182
+ setInt3(e, t, r, s) {
1183
+ return e ? (this._gl.uniform3i(e, t, r, s), !0) : !1;
1184
+ }
1185
+ /**
1186
+ * Set the value of an uniform to a int4
1187
+ * @param uniform defines the webGL uniform location where to store the value
1188
+ * @param x defines the 1st component of the value
1189
+ * @param y defines the 2nd component of the value
1190
+ * @param z defines the 3rd component of the value
1191
+ * @param w defines the 4th component of the value
1192
+ * @returns true if the value was set
1193
+ */
1194
+ setInt4(e, t, r, s, i) {
1195
+ return e ? (this._gl.uniform4i(e, t, r, s, i), !0) : !1;
1196
+ }
1197
+ /**
1198
+ * Set the value of an uniform to an array of int32
1199
+ * @param uniform defines the webGL uniform location where to store the value
1200
+ * @param array defines the array of int32 to store
1201
+ * @returns true if the value was set
1202
+ */
1203
+ setIntArray(e, t) {
1204
+ return e ? (this._gl.uniform1iv(e, t), !0) : !1;
1205
+ }
1206
+ /**
1207
+ * Set the value of an uniform to an array of int32 (stored as vec2)
1208
+ * @param uniform defines the webGL uniform location where to store the value
1209
+ * @param array defines the array of int32 to store
1210
+ * @returns true if the value was set
1211
+ */
1212
+ setIntArray2(e, t) {
1213
+ return !e || t.length % 2 !== 0 ? !1 : (this._gl.uniform2iv(e, t), !0);
1214
+ }
1215
+ /**
1216
+ * Set the value of an uniform to an array of int32 (stored as vec3)
1217
+ * @param uniform defines the webGL uniform location where to store the value
1218
+ * @param array defines the array of int32 to store
1219
+ * @returns true if the value was set
1220
+ */
1221
+ setIntArray3(e, t) {
1222
+ return !e || t.length % 3 !== 0 ? !1 : (this._gl.uniform3iv(e, t), !0);
1223
+ }
1224
+ /**
1225
+ * Set the value of an uniform to an array of int32 (stored as vec4)
1226
+ * @param uniform defines the webGL uniform location where to store the value
1227
+ * @param array defines the array of int32 to store
1228
+ * @returns true if the value was set
1229
+ */
1230
+ setIntArray4(e, t) {
1231
+ return !e || t.length % 4 !== 0 ? !1 : (this._gl.uniform4iv(e, t), !0);
1232
+ }
1233
+ /**
1234
+ * Set the value of an uniform to a number (unsigned int)
1235
+ * @param uniform defines the webGL uniform location where to store the value
1236
+ * @param value defines the unsigned int number to store
1237
+ * @returns true if the value was set
1238
+ */
1239
+ setUInt(e, t) {
1240
+ return e ? (this._gl.uniform1ui(e, t), !0) : !1;
1241
+ }
1242
+ /**
1243
+ * Set the value of an uniform to a unsigned int2
1244
+ * @param uniform defines the webGL uniform location where to store the value
1245
+ * @param x defines the 1st component of the value
1246
+ * @param y defines the 2nd component of the value
1247
+ * @returns true if the value was set
1248
+ */
1249
+ setUInt2(e, t, r) {
1250
+ return e ? (this._gl.uniform2ui(e, t, r), !0) : !1;
1251
+ }
1252
+ /**
1253
+ * Set the value of an uniform to a unsigned int3
1254
+ * @param uniform defines the webGL uniform location where to store the value
1255
+ * @param x defines the 1st component of the value
1256
+ * @param y defines the 2nd component of the value
1257
+ * @param z defines the 3rd component of the value
1258
+ * @returns true if the value was set
1259
+ */
1260
+ setUInt3(e, t, r, s) {
1261
+ return e ? (this._gl.uniform3ui(e, t, r, s), !0) : !1;
1262
+ }
1263
+ /**
1264
+ * Set the value of an uniform to a unsigned int4
1265
+ * @param uniform defines the webGL uniform location where to store the value
1266
+ * @param x defines the 1st component of the value
1267
+ * @param y defines the 2nd component of the value
1268
+ * @param z defines the 3rd component of the value
1269
+ * @param w defines the 4th component of the value
1270
+ * @returns true if the value was set
1271
+ */
1272
+ setUInt4(e, t, r, s, i) {
1273
+ return e ? (this._gl.uniform4ui(e, t, r, s, i), !0) : !1;
1274
+ }
1275
+ /**
1276
+ * Set the value of an uniform to an array of unsigned int32
1277
+ * @param uniform defines the webGL uniform location where to store the value
1278
+ * @param array defines the array of unsigned int32 to store
1279
+ * @returns true if the value was set
1280
+ */
1281
+ setUIntArray(e, t) {
1282
+ return e ? (this._gl.uniform1uiv(e, t), !0) : !1;
1283
+ }
1284
+ /**
1285
+ * Set the value of an uniform to an array of unsigned int32 (stored as vec2)
1286
+ * @param uniform defines the webGL uniform location where to store the value
1287
+ * @param array defines the array of unsigned int32 to store
1288
+ * @returns true if the value was set
1289
+ */
1290
+ setUIntArray2(e, t) {
1291
+ return !e || t.length % 2 !== 0 ? !1 : (this._gl.uniform2uiv(e, t), !0);
1292
+ }
1293
+ /**
1294
+ * Set the value of an uniform to an array of unsigned int32 (stored as vec3)
1295
+ * @param uniform defines the webGL uniform location where to store the value
1296
+ * @param array defines the array of unsigned int32 to store
1297
+ * @returns true if the value was set
1298
+ */
1299
+ setUIntArray3(e, t) {
1300
+ return !e || t.length % 3 !== 0 ? !1 : (this._gl.uniform3uiv(e, t), !0);
1301
+ }
1302
+ /**
1303
+ * Set the value of an uniform to an array of unsigned int32 (stored as vec4)
1304
+ * @param uniform defines the webGL uniform location where to store the value
1305
+ * @param array defines the array of unsigned int32 to store
1306
+ * @returns true if the value was set
1307
+ */
1308
+ setUIntArray4(e, t) {
1309
+ return !e || t.length % 4 !== 0 ? !1 : (this._gl.uniform4uiv(e, t), !0);
1310
+ }
1311
+ /**
1312
+ * Set the value of an uniform to an array of number
1313
+ * @param uniform defines the webGL uniform location where to store the value
1314
+ * @param array defines the array of number to store
1315
+ * @returns true if the value was set
1316
+ */
1317
+ setArray(e, t) {
1318
+ return !e || t.length < 1 ? !1 : (this._gl.uniform1fv(e, t), !0);
1319
+ }
1320
+ /**
1321
+ * Set the value of an uniform to an array of number (stored as vec2)
1322
+ * @param uniform defines the webGL uniform location where to store the value
1323
+ * @param array defines the array of number to store
1324
+ * @returns true if the value was set
1325
+ */
1326
+ setArray2(e, t) {
1327
+ return !e || t.length % 2 !== 0 ? !1 : (this._gl.uniform2fv(e, t), !0);
1328
+ }
1329
+ /**
1330
+ * Set the value of an uniform to an array of number (stored as vec3)
1331
+ * @param uniform defines the webGL uniform location where to store the value
1332
+ * @param array defines the array of number to store
1333
+ * @returns true if the value was set
1334
+ */
1335
+ setArray3(e, t) {
1336
+ return !e || t.length % 3 !== 0 ? !1 : (this._gl.uniform3fv(e, t), !0);
1337
+ }
1338
+ /**
1339
+ * Set the value of an uniform to an array of number (stored as vec4)
1340
+ * @param uniform defines the webGL uniform location where to store the value
1341
+ * @param array defines the array of number to store
1342
+ * @returns true if the value was set
1343
+ */
1344
+ setArray4(e, t) {
1345
+ return !e || t.length % 4 !== 0 ? !1 : (this._gl.uniform4fv(e, t), !0);
1346
+ }
1347
+ /**
1348
+ * Set the value of an uniform to an array of float32 (stored as matrices)
1349
+ * @param uniform defines the webGL uniform location where to store the value
1350
+ * @param matrices defines the array of float32 to store
1351
+ * @returns true if the value was set
1352
+ */
1353
+ setMatrices(e, t) {
1354
+ return e ? (this._gl.uniformMatrix4fv(e, !1, t), !0) : !1;
1355
+ }
1356
+ /**
1357
+ * Set the value of an uniform to a matrix (3x3)
1358
+ * @param uniform defines the webGL uniform location where to store the value
1359
+ * @param matrix defines the Float32Array representing the 3x3 matrix to store
1360
+ * @returns true if the value was set
1361
+ */
1362
+ setMatrix3x3(e, t) {
1363
+ return e ? (this._gl.uniformMatrix3fv(e, !1, t), !0) : !1;
1364
+ }
1365
+ /**
1366
+ * Set the value of an uniform to a matrix (2x2)
1367
+ * @param uniform defines the webGL uniform location where to store the value
1368
+ * @param matrix defines the Float32Array representing the 2x2 matrix to store
1369
+ * @returns true if the value was set
1370
+ */
1371
+ setMatrix2x2(e, t) {
1372
+ return e ? (this._gl.uniformMatrix2fv(e, !1, t), !0) : !1;
1373
+ }
1374
+ /**
1375
+ * Set the value of an uniform to a number (float)
1376
+ * @param uniform defines the webGL uniform location where to store the value
1377
+ * @param value defines the float number to store
1378
+ * @returns true if the value was transferred
1379
+ */
1380
+ setFloat(e, t) {
1381
+ return e ? (this._gl.uniform1f(e, t), !0) : !1;
1382
+ }
1383
+ /**
1384
+ * Set the value of an uniform to a vec2
1385
+ * @param uniform defines the webGL uniform location where to store the value
1386
+ * @param x defines the 1st component of the value
1387
+ * @param y defines the 2nd component of the value
1388
+ * @returns true if the value was set
1389
+ */
1390
+ setFloat2(e, t, r) {
1391
+ return e ? (this._gl.uniform2f(e, t, r), !0) : !1;
1392
+ }
1393
+ /**
1394
+ * Set the value of an uniform to a vec3
1395
+ * @param uniform defines the webGL uniform location where to store the value
1396
+ * @param x defines the 1st component of the value
1397
+ * @param y defines the 2nd component of the value
1398
+ * @param z defines the 3rd component of the value
1399
+ * @returns true if the value was set
1400
+ */
1401
+ setFloat3(e, t, r, s) {
1402
+ return e ? (this._gl.uniform3f(e, t, r, s), !0) : !1;
1403
+ }
1404
+ /**
1405
+ * Set the value of an uniform to a vec4
1406
+ * @param uniform defines the webGL uniform location where to store the value
1407
+ * @param x defines the 1st component of the value
1408
+ * @param y defines the 2nd component of the value
1409
+ * @param z defines the 3rd component of the value
1410
+ * @param w defines the 4th component of the value
1411
+ * @returns true if the value was set
1412
+ */
1413
+ setFloat4(e, t, r, s, i) {
1414
+ return e ? (this._gl.uniform4f(e, t, r, s, i), !0) : !1;
1415
+ }
1416
+ // States
1417
+ /**
1418
+ * Apply all cached states (depth, culling, stencil and alpha)
1419
+ */
1420
+ applyStates() {
1421
+ if (this._depthCullingState.apply(this._gl), this._stencilStateComposer.apply(this._gl), this._alphaState.apply(this._gl, this._currentRenderTarget && this._currentRenderTarget.textures ? this._currentRenderTarget.textures.length : 1), this._colorWriteChanged) {
1422
+ this._colorWriteChanged = !1;
1423
+ const e = this._colorWrite;
1424
+ this._gl.colorMask(e, e, e, e);
1425
+ }
1426
+ }
1427
+ // Textures
1428
+ /**
1429
+ * Force the entire cache to be cleared
1430
+ * You should not have to use this function unless your engine needs to share the webGL context with another engine
1431
+ * @param bruteForce defines a boolean to force clearing ALL caches (including stencil, detoh and alpha states)
1432
+ */
1433
+ wipeCaches(e) {
1434
+ this.preventCacheWipeBetweenFrames && !e || (this._currentEffect = null, this._viewportCached.x = 0, this._viewportCached.y = 0, this._viewportCached.z = 0, this._viewportCached.w = 0, this._unbindVertexArrayObject(), e && (this._currentProgram = null, this.resetTextureCache(), this._stencilStateComposer.reset(), this._depthCullingState.reset(), this._depthCullingState.depthFunc = this._gl.LEQUAL, this._alphaState.reset(), this._resetAlphaMode(), this._colorWrite = !0, this._colorWriteChanged = !0, this._unpackFlipYCached = null, this._gl.pixelStorei(this._gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, this._gl.NONE), this._gl.pixelStorei(this._gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0), this._mustWipeVertexAttributes = !0, this.unbindAllAttributes()), this._resetVertexBufferBinding(), this._cachedIndexBuffer = null, this._cachedEffectForVertexBuffers = null, this.bindIndexBuffer(null));
1435
+ }
1436
+ /**
1437
+ * @internal
1438
+ */
1439
+ _getSamplingParameters(e, t) {
1440
+ const r = this._gl;
1441
+ let s = r.NEAREST, i = r.NEAREST, n = !1;
1442
+ switch (e) {
1443
+ case 11:
1444
+ s = r.LINEAR, t ? i = r.LINEAR_MIPMAP_NEAREST : i = r.LINEAR;
1445
+ break;
1446
+ case 3:
1447
+ s = r.LINEAR, n = !0, t ? i = r.LINEAR_MIPMAP_LINEAR : i = r.LINEAR;
1448
+ break;
1449
+ case 8:
1450
+ n = !0, s = r.NEAREST, t ? i = r.NEAREST_MIPMAP_LINEAR : i = r.NEAREST;
1451
+ break;
1452
+ case 4:
1453
+ s = r.NEAREST, t ? i = r.NEAREST_MIPMAP_NEAREST : i = r.NEAREST;
1454
+ break;
1455
+ case 5:
1456
+ s = r.NEAREST, t ? i = r.LINEAR_MIPMAP_NEAREST : i = r.LINEAR;
1457
+ break;
1458
+ case 6:
1459
+ n = !0, s = r.NEAREST, t ? i = r.LINEAR_MIPMAP_LINEAR : i = r.LINEAR;
1460
+ break;
1461
+ case 7:
1462
+ s = r.NEAREST, i = r.LINEAR;
1463
+ break;
1464
+ case 1:
1465
+ s = r.NEAREST, i = r.NEAREST;
1466
+ break;
1467
+ case 9:
1468
+ s = r.LINEAR, t ? i = r.NEAREST_MIPMAP_NEAREST : i = r.NEAREST;
1469
+ break;
1470
+ case 10:
1471
+ n = !0, s = r.LINEAR, t ? i = r.NEAREST_MIPMAP_LINEAR : i = r.NEAREST;
1472
+ break;
1473
+ case 2:
1474
+ s = r.LINEAR, i = r.LINEAR;
1475
+ break;
1476
+ case 12:
1477
+ s = r.LINEAR, i = r.NEAREST;
1478
+ break;
1479
+ }
1480
+ return {
1481
+ min: i,
1482
+ mag: s,
1483
+ hasMipMaps: n
1484
+ };
1485
+ }
1486
+ /** @internal */
1487
+ _createTexture() {
1488
+ const e = this._gl.createTexture();
1489
+ if (!e)
1490
+ throw new Error("Unable to create texture");
1491
+ return e;
1492
+ }
1493
+ /** @internal */
1494
+ _createHardwareTexture() {
1495
+ return new _e(this._createTexture(), this._gl);
1496
+ }
1497
+ /**
1498
+ * Creates an internal texture without binding it to a framebuffer
1499
+ * @internal
1500
+ * @param size defines the size of the texture
1501
+ * @param options defines the options used to create the texture
1502
+ * @param delayGPUTextureCreation true to delay the texture creation the first time it is really needed. false to create it right away
1503
+ * @param source source type of the texture
1504
+ * @returns a new internal texture
1505
+ */
1506
+ _createInternalTexture(e, t, r = !0, s = 0) {
1507
+ let i, n = !1, l = 0, a = 3, _ = 5, u = !1, f = 1, c, d = !1, g = 0, m = !1;
1508
+ t !== void 0 && typeof t == "object" ? (i = !!t.generateMipMaps, n = !!t.createMipMaps, l = t.type === void 0 ? 0 : t.type, a = t.samplingMode === void 0 ? 3 : t.samplingMode, _ = t.format === void 0 ? 5 : t.format, u = t.useSRGBBuffer === void 0 ? !1 : t.useSRGBBuffer, f = t.samples ?? 1, c = t.label, d = !!t.createMSAATexture, g = t.comparisonFunction || 0, m = !!t.isCube) : i = !!t, u && (u = this._caps.supportSRGBBuffers && (this.webGLVersion > 1 || this.isWebGPU)), (l === 1 && !this._caps.textureFloatLinearFiltering || l === 2 && !this._caps.textureHalfFloatLinearFiltering) && (a = 1), l === 1 && !this._caps.textureFloat && (l = 0, I.Warn("Float textures are not supported. Type forced to TEXTURETYPE_UNSIGNED_BYTE"));
1509
+ const E = H(_), p = V(_), h = this._gl, o = new y(this, s), S = e.width || e, C = e.height || e, b = e.depth || 0, G = e.layers || 0, x = this._getSamplingParameters(a, (i || n) && !E), A = G !== 0 ? h.TEXTURE_2D_ARRAY : b !== 0 ? h.TEXTURE_3D : m ? h.TEXTURE_CUBE_MAP : h.TEXTURE_2D, B = E ? this._getInternalFormatFromDepthTextureFormat(_, !0, p) : this._getRGBABufferInternalSizedFormat(l, _, u), M = E ? p ? h.DEPTH_STENCIL : h.DEPTH_COMPONENT : this._getInternalFormat(_), F = E ? this._getWebGLTextureTypeFromDepthTextureFormat(_) : this._getWebGLTextureType(l);
1510
+ if (this._bindTextureDirectly(A, o), G !== 0)
1511
+ o.is2DArray = !0, h.texImage3D(A, 0, B, S, C, G, 0, M, F, null);
1512
+ else if (b !== 0)
1513
+ o.is3D = !0, h.texImage3D(A, 0, B, S, C, b, 0, M, F, null);
1514
+ else if (m) {
1515
+ o.isCube = !0;
1516
+ for (let P = 0; P < 6; P++)
1517
+ h.texImage2D(h.TEXTURE_CUBE_MAP_POSITIVE_X + P, 0, B, S, C, 0, M, F, null);
1518
+ } else
1519
+ h.texImage2D(A, 0, B, S, C, 0, M, F, null);
1520
+ if (h.texParameteri(A, h.TEXTURE_MAG_FILTER, x.mag), h.texParameteri(A, h.TEXTURE_MIN_FILTER, x.min), h.texParameteri(A, h.TEXTURE_WRAP_S, h.CLAMP_TO_EDGE), h.texParameteri(A, h.TEXTURE_WRAP_T, h.CLAMP_TO_EDGE), E && this.webGLVersion > 1 && (g === 0 ? (h.texParameteri(A, h.TEXTURE_COMPARE_FUNC, 515), h.texParameteri(A, h.TEXTURE_COMPARE_MODE, h.NONE)) : (h.texParameteri(A, h.TEXTURE_COMPARE_FUNC, g), h.texParameteri(A, h.TEXTURE_COMPARE_MODE, h.COMPARE_REF_TO_TEXTURE))), (i || n) && this._gl.generateMipmap(A), this._bindTextureDirectly(A, null), o._useSRGBBuffer = u, o.baseWidth = S, o.baseHeight = C, o.width = S, o.height = C, o.depth = G || b, o.isReady = !0, o.samples = f, o.generateMipMaps = i, o.samplingMode = a, o.type = l, o.format = _, o.label = c, o.comparisonFunction = g, this._internalTexturesCache.push(o), d) {
1521
+ let P;
1522
+ if (H(o.format) ? P = this._setupFramebufferDepthAttachments(V(o.format), o.format !== 19, o.width, o.height, f, o.format, !0) : P = this._createRenderBuffer(
1523
+ o.width,
1524
+ o.height,
1525
+ f,
1526
+ -1,
1527
+ this._getRGBABufferInternalSizedFormat(o.type, o.format, o._useSRGBBuffer),
1528
+ -1
1529
+ /* attachment */
1530
+ ), !P)
1531
+ throw new Error("Unable to create render buffer");
1532
+ o._autoMSAAManagement = !0;
1533
+ let D = o._hardwareTexture;
1534
+ D || (D = o._hardwareTexture = this._createHardwareTexture()), D.addMSAARenderBuffer(P);
1535
+ }
1536
+ return o;
1537
+ }
1538
+ /**
1539
+ * @internal
1540
+ */
1541
+ _getUseSRGBBuffer(e, t) {
1542
+ return e && this._caps.supportSRGBBuffers && (this.webGLVersion > 1 || t);
1543
+ }
1544
+ /**
1545
+ * Usually called from Texture.ts.
1546
+ * Passed information to create a WebGLTexture
1547
+ * @param url defines a value which contains one of the following:
1548
+ * * A conventional http URL, e.g. 'http://...' or 'file://...'
1549
+ * * A base64 string of in-line texture data, e.g. 'data:image/jpg;base64,/...'
1550
+ * * An indicator that data being passed using the buffer parameter, e.g. 'data:mytexture.jpg'
1551
+ * @param noMipmap defines a boolean indicating that no mipmaps shall be generated. Ignored for compressed textures. They must be in the file
1552
+ * @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)
1553
+ * @param scene needed for loading to the correct scene
1554
+ * @param samplingMode mode with should be used sample / access the texture (Default: Texture.TRILINEAR_SAMPLINGMODE)
1555
+ * @param onLoad optional callback to be called upon successful completion
1556
+ * @param onError optional callback to be called upon failure
1557
+ * @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
1558
+ * @param fallback an internal argument in case the function must be called again, due to etc1 not having alpha capabilities
1559
+ * @param format internal format. Default: RGB when extension is '.jpg' else RGBA. Ignored for compressed textures
1560
+ * @param forcedExtension defines the extension to use to pick the right loader
1561
+ * @param mimeType defines an optional mime type
1562
+ * @param loaderOptions options to be passed to the loader
1563
+ * @param creationFlags specific flags to use when creating the texture (1 for storage textures, for eg)
1564
+ * @param useSRGBBuffer defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU).
1565
+ * @returns a InternalTexture for assignment back into BABYLON.Texture
1566
+ */
1567
+ createTexture(e, t, r, s, i = 3, n = null, l = null, a = null, _ = null, u = null, f = null, c, d, g, m) {
1568
+ return this._createTextureBase(e, t, r, s, i, n, l, (...E) => this._prepareWebGLTexture(...E, u), (E, p, h, o, S, C) => {
1569
+ const b = this._gl, G = h.width === E && h.height === p;
1570
+ S._creationFlags = g ?? 0;
1571
+ const x = this._getTexImageParametersForCreateTexture(S.format, S._useSRGBBuffer);
1572
+ if (G)
1573
+ return b.texImage2D(b.TEXTURE_2D, 0, x.internalFormat, x.format, x.type, h), !1;
1574
+ const A = this._caps.maxTextureSize;
1575
+ if (h.width > A || h.height > A || !this._supportsHardwareTextureRescaling)
1576
+ return this._prepareWorkingCanvas(), !this._workingCanvas || !this._workingContext || (this._workingCanvas.width = E, this._workingCanvas.height = p, this._workingContext.drawImage(h, 0, 0, h.width, h.height, 0, 0, E, p), b.texImage2D(b.TEXTURE_2D, 0, x.internalFormat, x.format, x.type, this._workingCanvas), S.width = E, S.height = p), !1;
1577
+ {
1578
+ const B = new y(
1579
+ this,
1580
+ 2
1581
+ /* InternalTextureSource.Temp */
1582
+ );
1583
+ this._bindTextureDirectly(b.TEXTURE_2D, B, !0), b.texImage2D(b.TEXTURE_2D, 0, x.internalFormat, x.format, x.type, h), this._rescaleTexture(B, S, s, x.format, () => {
1584
+ this._releaseTexture(B), this._bindTextureDirectly(b.TEXTURE_2D, S, !0), C();
1585
+ });
1586
+ }
1587
+ return !0;
1588
+ }, a, _, u, f, c, d, m);
1589
+ }
1590
+ /**
1591
+ * Calls to the GL texImage2D and texImage3D functions require three arguments describing the pixel format of the texture.
1592
+ * createTexture derives these from the babylonFormat and useSRGBBuffer arguments and also the file extension of the URL it's working with.
1593
+ * This function encapsulates that derivation for easy unit testing.
1594
+ * @param babylonFormat Babylon's format enum, as specified in ITextureCreationOptions.
1595
+ * @param fileExtension The file extension including the dot, e.g. .jpg.
1596
+ * @param useSRGBBuffer Use SRGB not linear.
1597
+ * @returns The options to pass to texImage2D or texImage3D calls.
1598
+ * @internal
1599
+ */
1600
+ _getTexImageParametersForCreateTexture(e, t) {
1601
+ let r, s;
1602
+ return this.webGLVersion === 1 ? (r = this._getInternalFormat(e, t), s = r) : (r = this._getInternalFormat(e, !1), s = this._getRGBABufferInternalSizedFormat(0, e, t)), {
1603
+ internalFormat: s,
1604
+ format: r,
1605
+ type: this._gl.UNSIGNED_BYTE
1606
+ };
1607
+ }
1608
+ /**
1609
+ * @internal
1610
+ */
1611
+ _rescaleTexture(e, t, r, s, i) {
1612
+ }
1613
+ /**
1614
+ * @internal
1615
+ */
1616
+ _unpackFlipY(e) {
1617
+ this._unpackFlipYCached !== e && (this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, e ? 1 : 0), this.enableUnpackFlipYCached && (this._unpackFlipYCached = e));
1618
+ }
1619
+ /** @internal */
1620
+ _getUnpackAlignement() {
1621
+ return this._gl.getParameter(this._gl.UNPACK_ALIGNMENT);
1622
+ }
1623
+ /** @internal */
1624
+ _getTextureTarget(e) {
1625
+ return e.isCube ? this._gl.TEXTURE_CUBE_MAP : e.is3D ? this._gl.TEXTURE_3D : e.is2DArray || e.isMultiview ? this._gl.TEXTURE_2D_ARRAY : this._gl.TEXTURE_2D;
1626
+ }
1627
+ /**
1628
+ * Update the sampling mode of a given texture
1629
+ * @param samplingMode defines the required sampling mode
1630
+ * @param texture defines the texture to update
1631
+ * @param generateMipMaps defines whether to generate mipmaps for the texture
1632
+ */
1633
+ updateTextureSamplingMode(e, t, r = !1) {
1634
+ const s = this._getTextureTarget(t), i = this._getSamplingParameters(e, t.useMipMaps || r);
1635
+ this._setTextureParameterInteger(s, this._gl.TEXTURE_MAG_FILTER, i.mag, t), this._setTextureParameterInteger(s, this._gl.TEXTURE_MIN_FILTER, i.min), r && i.hasMipMaps && (t.generateMipMaps = !0, this._gl.generateMipmap(s)), this._bindTextureDirectly(s, null), t.samplingMode = e;
1636
+ }
1637
+ /**
1638
+ * Update the dimensions of a texture
1639
+ * @param texture texture to update
1640
+ * @param width new width of the texture
1641
+ * @param height new height of the texture
1642
+ * @param depth new depth of the texture
1643
+ */
1644
+ updateTextureDimensions(e, t, r, s = 1) {
1645
+ }
1646
+ /**
1647
+ * Update the sampling mode of a given texture
1648
+ * @param texture defines the texture to update
1649
+ * @param wrapU defines the texture wrap mode of the u coordinates
1650
+ * @param wrapV defines the texture wrap mode of the v coordinates
1651
+ * @param wrapR defines the texture wrap mode of the r coordinates
1652
+ */
1653
+ updateTextureWrappingMode(e, t, r = null, s = null) {
1654
+ const i = this._getTextureTarget(e);
1655
+ t !== null && (this._setTextureParameterInteger(i, this._gl.TEXTURE_WRAP_S, this._getTextureWrapMode(t), e), e._cachedWrapU = t), r !== null && (this._setTextureParameterInteger(i, this._gl.TEXTURE_WRAP_T, this._getTextureWrapMode(r), e), e._cachedWrapV = r), (e.is2DArray || e.is3D) && s !== null && (this._setTextureParameterInteger(i, this._gl.TEXTURE_WRAP_R, this._getTextureWrapMode(s), e), e._cachedWrapR = s), this._bindTextureDirectly(i, null);
1656
+ }
1657
+ /**
1658
+ * @internal
1659
+ */
1660
+ _uploadCompressedDataToTextureDirectly(e, t, r, s, i, n = 0, l = 0) {
1661
+ const a = this._gl;
1662
+ let _ = a.TEXTURE_2D;
1663
+ if (e.isCube && (_ = a.TEXTURE_CUBE_MAP_POSITIVE_X + n), e._useSRGBBuffer)
1664
+ switch (t) {
1665
+ case 37492:
1666
+ case 36196:
1667
+ this._caps.etc2 ? t = a.COMPRESSED_SRGB8_ETC2 : e._useSRGBBuffer = !1;
1668
+ break;
1669
+ case 37496:
1670
+ this._caps.etc2 ? t = a.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC : e._useSRGBBuffer = !1;
1671
+ break;
1672
+ case 36492:
1673
+ t = a.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT;
1674
+ break;
1675
+ case 37808:
1676
+ t = a.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
1677
+ break;
1678
+ case 37809:
1679
+ t = a.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR;
1680
+ break;
1681
+ case 37810:
1682
+ t = a.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR;
1683
+ break;
1684
+ case 37811:
1685
+ t = a.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR;
1686
+ break;
1687
+ case 37812:
1688
+ t = a.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR;
1689
+ break;
1690
+ case 37813:
1691
+ t = a.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR;
1692
+ break;
1693
+ case 37814:
1694
+ t = a.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR;
1695
+ break;
1696
+ case 37815:
1697
+ t = a.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR;
1698
+ break;
1699
+ case 37816:
1700
+ t = a.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR;
1701
+ break;
1702
+ case 37817:
1703
+ t = a.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR;
1704
+ break;
1705
+ case 37818:
1706
+ t = a.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR;
1707
+ break;
1708
+ case 37819:
1709
+ t = a.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR;
1710
+ break;
1711
+ case 37820:
1712
+ t = a.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR;
1713
+ break;
1714
+ case 37821:
1715
+ t = a.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR;
1716
+ break;
1717
+ case 33776:
1718
+ this._caps.s3tc_srgb ? t = a.COMPRESSED_SRGB_S3TC_DXT1_EXT : e._useSRGBBuffer = !1;
1719
+ break;
1720
+ case 33777:
1721
+ this._caps.s3tc_srgb ? t = a.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT : e._useSRGBBuffer = !1;
1722
+ break;
1723
+ case 33779:
1724
+ this._caps.s3tc_srgb ? t = a.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT : e._useSRGBBuffer = !1;
1725
+ break;
1726
+ default:
1727
+ e._useSRGBBuffer = !1;
1728
+ break;
1729
+ }
1730
+ if (e.generateMipMaps) {
1731
+ const u = e._hardwareTexture;
1732
+ u.memoryAllocated || (a.texStorage2D(e.isCube ? a.TEXTURE_CUBE_MAP : a.TEXTURE_2D, Math.floor(Math.log2(Math.max(r, s))) + 1, t, e.width, e.height), u.memoryAllocated = !0), this._gl.compressedTexSubImage2D(_, l, 0, 0, r, s, t, i);
1733
+ } else
1734
+ this._gl.compressedTexImage2D(_, l, t, r, s, 0, i);
1735
+ }
1736
+ /**
1737
+ * @internal
1738
+ */
1739
+ _uploadDataToTextureDirectly(e, t, r = 0, s = 0, i, n = !1) {
1740
+ const l = this._gl, a = this._getWebGLTextureType(e.type), _ = this._getInternalFormat(e.format), u = i === void 0 ? this._getRGBABufferInternalSizedFormat(e.type, e.format, e._useSRGBBuffer) : this._getInternalFormat(i, e._useSRGBBuffer);
1741
+ this._unpackFlipY(e.invertY);
1742
+ let f = l.TEXTURE_2D;
1743
+ e.isCube && (f = l.TEXTURE_CUBE_MAP_POSITIVE_X + r);
1744
+ const c = Math.round(Math.log(e.width) * Math.LOG2E), d = Math.round(Math.log(e.height) * Math.LOG2E), g = n ? e.width : Math.pow(2, Math.max(c - s, 0)), m = n ? e.height : Math.pow(2, Math.max(d - s, 0));
1745
+ l.texImage2D(f, s, u, g, m, 0, _, a, t);
1746
+ }
1747
+ /**
1748
+ * Update a portion of an internal texture
1749
+ * @param texture defines the texture to update
1750
+ * @param imageData defines the data to store into the texture
1751
+ * @param xOffset defines the x coordinates of the update rectangle
1752
+ * @param yOffset defines the y coordinates of the update rectangle
1753
+ * @param width defines the width of the update rectangle
1754
+ * @param height defines the height of the update rectangle
1755
+ * @param faceIndex defines the face index if texture is a cube (0 by default)
1756
+ * @param lod defines the lod level to update (0 by default)
1757
+ * @param generateMipMaps defines whether to generate mipmaps or not
1758
+ */
1759
+ updateTextureData(e, t, r, s, i, n, l = 0, a = 0, _ = !1) {
1760
+ const u = this._gl, f = this._getWebGLTextureType(e.type), c = this._getInternalFormat(e.format);
1761
+ this._unpackFlipY(e.invertY);
1762
+ let d = u.TEXTURE_2D, g = u.TEXTURE_2D;
1763
+ e.isCube && (g = u.TEXTURE_CUBE_MAP_POSITIVE_X + l, d = u.TEXTURE_CUBE_MAP), this._bindTextureDirectly(d, e, !0), u.texSubImage2D(g, a, r, s, i, n, c, f, t), _ && this._gl.generateMipmap(g), this._bindTextureDirectly(d, null);
1764
+ }
1765
+ /**
1766
+ * @internal
1767
+ */
1768
+ _uploadArrayBufferViewToTexture(e, t, r = 0, s = 0) {
1769
+ const i = this._gl, n = e.isCube ? i.TEXTURE_CUBE_MAP : i.TEXTURE_2D;
1770
+ this._bindTextureDirectly(n, e, !0), this._uploadDataToTextureDirectly(e, t, r, s), this._bindTextureDirectly(n, null, !0);
1771
+ }
1772
+ _prepareWebGLTextureContinuation(e, t, r, s, i) {
1773
+ const n = this._gl;
1774
+ if (!n)
1775
+ return;
1776
+ const l = this._getSamplingParameters(i, !r);
1777
+ n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MAG_FILTER, l.mag), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MIN_FILTER, l.min), !r && !s && n.generateMipmap(n.TEXTURE_2D), this._bindTextureDirectly(n.TEXTURE_2D, null), t && t.removePendingData(e), e.onLoadedObservable.notifyObservers(e), e.onLoadedObservable.clear();
1778
+ }
1779
+ _prepareWebGLTexture(e, t, r, s, i, n, l, a, _, u) {
1780
+ const f = this.getCaps().maxTextureSize, c = Math.min(f, this.needPOTTextures ? N(s.width, f) : s.width), d = Math.min(f, this.needPOTTextures ? N(s.height, f) : s.height), g = this._gl;
1781
+ if (g) {
1782
+ if (!e._hardwareTexture) {
1783
+ r && r.removePendingData(e);
1784
+ return;
1785
+ }
1786
+ this._bindTextureDirectly(g.TEXTURE_2D, e, !0), this._unpackFlipY(i === void 0 ? !0 : !!i), e.baseWidth = s.width, e.baseHeight = s.height, e.width = c, e.height = d, e.isReady = !0, e.type = e.type !== -1 ? e.type : 0, e.format = e.format !== -1 ? e.format : u ?? (t === ".jpg" && !e._useSRGBBuffer ? 4 : 5), !a(c, d, s, t, e, () => {
1787
+ this._prepareWebGLTextureContinuation(e, r, n, l, _);
1788
+ }) && this._prepareWebGLTextureContinuation(e, r, n, l, _);
1789
+ }
1790
+ }
1791
+ _getInternalFormatFromDepthTextureFormat(e, t, r) {
1792
+ const s = this._gl;
1793
+ if (!t)
1794
+ return s.STENCIL_INDEX8;
1795
+ let n = r ? s.DEPTH_STENCIL : s.DEPTH_COMPONENT;
1796
+ return this.webGLVersion > 1 ? e === 15 ? n = s.DEPTH_COMPONENT16 : e === 16 ? n = s.DEPTH_COMPONENT24 : e === 17 || e === 13 ? n = r ? s.DEPTH24_STENCIL8 : s.DEPTH_COMPONENT24 : e === 14 ? n = s.DEPTH_COMPONENT32F : e === 18 && (n = r ? s.DEPTH32F_STENCIL8 : s.DEPTH_COMPONENT32F) : n = s.DEPTH_COMPONENT16, n;
1797
+ }
1798
+ _getWebGLTextureTypeFromDepthTextureFormat(e) {
1799
+ const t = this._gl;
1800
+ let r = t.UNSIGNED_INT;
1801
+ return e === 15 ? r = t.UNSIGNED_SHORT : e === 17 || e === 13 ? r = t.UNSIGNED_INT_24_8 : e === 14 ? r = t.FLOAT : e === 18 ? r = t.FLOAT_32_UNSIGNED_INT_24_8_REV : e === 19 && (r = t.UNSIGNED_BYTE), r;
1802
+ }
1803
+ /**
1804
+ * @internal
1805
+ */
1806
+ _setupFramebufferDepthAttachments(e, t, r, s, i = 1, n, l = !1) {
1807
+ const a = this._gl;
1808
+ n = n ?? (e ? 13 : 14);
1809
+ const _ = this._getInternalFormatFromDepthTextureFormat(n, t, e);
1810
+ return e && t ? this._createRenderBuffer(r, s, i, a.DEPTH_STENCIL, _, l ? -1 : a.DEPTH_STENCIL_ATTACHMENT) : t ? this._createRenderBuffer(r, s, i, _, _, l ? -1 : a.DEPTH_ATTACHMENT) : e ? this._createRenderBuffer(r, s, i, _, _, l ? -1 : a.STENCIL_ATTACHMENT) : null;
1811
+ }
1812
+ /**
1813
+ * @internal
1814
+ */
1815
+ _createRenderBuffer(e, t, r, s, i, n, l = !0) {
1816
+ const _ = this._gl.createRenderbuffer();
1817
+ return this._updateRenderBuffer(_, e, t, r, s, i, n, l);
1818
+ }
1819
+ _updateRenderBuffer(e, t, r, s, i, n, l, a = !0) {
1820
+ const _ = this._gl;
1821
+ return _.bindRenderbuffer(_.RENDERBUFFER, e), s > 1 && _.renderbufferStorageMultisample ? _.renderbufferStorageMultisample(_.RENDERBUFFER, s, n, t, r) : _.renderbufferStorage(_.RENDERBUFFER, i, t, r), l !== -1 && _.framebufferRenderbuffer(_.FRAMEBUFFER, l, _.RENDERBUFFER, e), a && _.bindRenderbuffer(_.RENDERBUFFER, null), e;
1822
+ }
1823
+ /**
1824
+ * @internal
1825
+ */
1826
+ _releaseTexture(e) {
1827
+ this._deleteTexture(e._hardwareTexture), this.unbindAllTextures();
1828
+ const t = this._internalTexturesCache.indexOf(e);
1829
+ t !== -1 && this._internalTexturesCache.splice(t, 1), e._lodTextureHigh && e._lodTextureHigh.dispose(), e._lodTextureMid && e._lodTextureMid.dispose(), e._lodTextureLow && e._lodTextureLow.dispose(), e._irradianceTexture && e._irradianceTexture.dispose();
1830
+ }
1831
+ _deleteTexture(e) {
1832
+ e?.release();
1833
+ }
1834
+ _setProgram(e) {
1835
+ this._currentProgram !== e && (te(e, this._gl), this._currentProgram = e);
1836
+ }
1837
+ /**
1838
+ * Binds an effect to the webGL context
1839
+ * @param effect defines the effect to bind
1840
+ */
1841
+ bindSamplers(e) {
1842
+ const t = e.getPipelineContext();
1843
+ this._setProgram(t.program);
1844
+ const r = e.getSamplers();
1845
+ for (let s = 0; s < r.length; s++) {
1846
+ const i = e.getUniform(r[s]);
1847
+ i && (this._boundUniforms[s] = i);
1848
+ }
1849
+ this._currentEffect = null;
1850
+ }
1851
+ _activateCurrentTexture() {
1852
+ this._currentTextureChannel !== this._activeChannel && (this._gl.activeTexture(this._gl.TEXTURE0 + this._activeChannel), this._currentTextureChannel = this._activeChannel);
1853
+ }
1854
+ /**
1855
+ * @internal
1856
+ */
1857
+ _bindTextureDirectly(e, t, r = !1, s = !1) {
1858
+ let i = !1;
1859
+ const n = t && t._associatedChannel > -1;
1860
+ if (r && n && (this._activeChannel = t._associatedChannel), this._boundTexturesCache[this._activeChannel] !== t || s) {
1861
+ if (this._activateCurrentTexture(), t && t.isMultiview)
1862
+ throw I.Error(["_bindTextureDirectly called with a multiview texture!", e, t]), "_bindTextureDirectly called with a multiview texture!";
1863
+ this._gl.bindTexture(e, t?._hardwareTexture?.underlyingResource ?? null), this._boundTexturesCache[this._activeChannel] = t, t && (t._associatedChannel = this._activeChannel);
1864
+ } else r && (i = !0, this._activateCurrentTexture());
1865
+ return n && !r && this._bindSamplerUniformToChannel(t._associatedChannel, this._activeChannel), i;
1866
+ }
1867
+ /**
1868
+ * @internal
1869
+ */
1870
+ _bindTexture(e, t, r) {
1871
+ if (e === void 0)
1872
+ return;
1873
+ t && (t._associatedChannel = e), this._activeChannel = e;
1874
+ const s = t ? this._getTextureTarget(t) : this._gl.TEXTURE_2D;
1875
+ this._bindTextureDirectly(s, t);
1876
+ }
1877
+ /**
1878
+ * Unbind all textures from the webGL context
1879
+ */
1880
+ unbindAllTextures() {
1881
+ for (let e = 0; e < this._maxSimultaneousTextures; e++)
1882
+ this._activeChannel = e, this._bindTextureDirectly(this._gl.TEXTURE_2D, null), this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, null), this.webGLVersion > 1 && (this._bindTextureDirectly(this._gl.TEXTURE_3D, null), this._bindTextureDirectly(this._gl.TEXTURE_2D_ARRAY, null));
1883
+ }
1884
+ /**
1885
+ * Sets a texture to the according uniform.
1886
+ * @param channel The texture channel
1887
+ * @param uniform The uniform to set
1888
+ * @param texture The texture to apply
1889
+ * @param name The name of the uniform in the effect
1890
+ */
1891
+ setTexture(e, t, r, s) {
1892
+ e !== void 0 && (t && (this._boundUniforms[e] = t), this._setTexture(e, r));
1893
+ }
1894
+ _bindSamplerUniformToChannel(e, t) {
1895
+ const r = this._boundUniforms[e];
1896
+ !r || r._currentState === t || (this._gl.uniform1i(r, t), r._currentState = t);
1897
+ }
1898
+ _getTextureWrapMode(e) {
1899
+ switch (e) {
1900
+ case 1:
1901
+ return this._gl.REPEAT;
1902
+ case 0:
1903
+ return this._gl.CLAMP_TO_EDGE;
1904
+ case 2:
1905
+ return this._gl.MIRRORED_REPEAT;
1906
+ }
1907
+ return this._gl.REPEAT;
1908
+ }
1909
+ _setTexture(e, t, r = !1, s = !1, i = "") {
1910
+ if (!t)
1911
+ return this._boundTexturesCache[e] != null && (this._activeChannel = e, this._bindTextureDirectly(this._gl.TEXTURE_2D, null), this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, null), this.webGLVersion > 1 && (this._bindTextureDirectly(this._gl.TEXTURE_3D, null), this._bindTextureDirectly(this._gl.TEXTURE_2D_ARRAY, null))), !1;
1912
+ if (t.video) {
1913
+ this._activeChannel = e;
1914
+ const _ = t.getInternalTexture();
1915
+ _ && (_._associatedChannel = e), t.update();
1916
+ } else if (t.delayLoadState === 4)
1917
+ return t.delayLoad(), !1;
1918
+ let n;
1919
+ s ? n = t.depthStencilTexture : t.isReady() ? n = t.getInternalTexture() : t.isCube ? n = this.emptyCubeTexture : t.is3D ? n = this.emptyTexture3D : t.is2DArray ? n = this.emptyTexture2DArray : n = this.emptyTexture, !r && n && (n._associatedChannel = e);
1920
+ let l = !0;
1921
+ this._boundTexturesCache[e] === n && (r || this._bindSamplerUniformToChannel(n._associatedChannel, e), l = !1), this._activeChannel = e;
1922
+ const a = this._getTextureTarget(n);
1923
+ if (l && this._bindTextureDirectly(a, n, r), n && !n.isMultiview) {
1924
+ if (n.isCube && n._cachedCoordinatesMode !== t.coordinatesMode) {
1925
+ n._cachedCoordinatesMode = t.coordinatesMode;
1926
+ const _ = t.coordinatesMode !== 3 && t.coordinatesMode !== 5 ? 1 : 0;
1927
+ t.wrapU = _, t.wrapV = _;
1928
+ }
1929
+ n._cachedWrapU !== t.wrapU && (n._cachedWrapU = t.wrapU, this._setTextureParameterInteger(a, this._gl.TEXTURE_WRAP_S, this._getTextureWrapMode(t.wrapU), n)), n._cachedWrapV !== t.wrapV && (n._cachedWrapV = t.wrapV, this._setTextureParameterInteger(a, this._gl.TEXTURE_WRAP_T, this._getTextureWrapMode(t.wrapV), n)), n.is3D && n._cachedWrapR !== t.wrapR && (n._cachedWrapR = t.wrapR, this._setTextureParameterInteger(a, this._gl.TEXTURE_WRAP_R, this._getTextureWrapMode(t.wrapR), n)), this._setAnisotropicLevel(a, n, t.anisotropicFilteringLevel);
1930
+ }
1931
+ return !0;
1932
+ }
1933
+ /**
1934
+ * Sets an array of texture to the webGL context
1935
+ * @param channel defines the channel where the texture array must be set
1936
+ * @param uniform defines the associated uniform location
1937
+ * @param textures defines the array of textures to bind
1938
+ * @param name name of the channel
1939
+ */
1940
+ setTextureArray(e, t, r, s) {
1941
+ if (!(e === void 0 || !t)) {
1942
+ (!this._textureUnits || this._textureUnits.length !== r.length) && (this._textureUnits = new Int32Array(r.length));
1943
+ for (let i = 0; i < r.length; i++) {
1944
+ const n = r[i].getInternalTexture();
1945
+ n ? (this._textureUnits[i] = e + i, n._associatedChannel = e + i) : this._textureUnits[i] = -1;
1946
+ }
1947
+ this._gl.uniform1iv(t, this._textureUnits);
1948
+ for (let i = 0; i < r.length; i++)
1949
+ this._setTexture(this._textureUnits[i], r[i], !0);
1950
+ }
1951
+ }
1952
+ /**
1953
+ * @internal
1954
+ */
1955
+ _setAnisotropicLevel(e, t, r) {
1956
+ const s = this._caps.textureAnisotropicFilterExtension;
1957
+ t.samplingMode !== 11 && t.samplingMode !== 3 && t.samplingMode !== 2 && (r = 1), s && t._cachedAnisotropicFilteringLevel !== r && (this._setTextureParameterFloat(e, s.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(r, this._caps.maxAnisotropy), t), t._cachedAnisotropicFilteringLevel = r);
1958
+ }
1959
+ _setTextureParameterFloat(e, t, r, s) {
1960
+ this._bindTextureDirectly(e, s, !0, !0), this._gl.texParameterf(e, t, r);
1961
+ }
1962
+ _setTextureParameterInteger(e, t, r, s) {
1963
+ s && this._bindTextureDirectly(e, s, !0, !0), this._gl.texParameteri(e, t, r);
1964
+ }
1965
+ /**
1966
+ * Unbind all vertex attributes from the webGL context
1967
+ */
1968
+ unbindAllAttributes() {
1969
+ if (this._mustWipeVertexAttributes) {
1970
+ this._mustWipeVertexAttributes = !1;
1971
+ for (let e = 0; e < this._caps.maxVertexAttribs; e++)
1972
+ this.disableAttributeByIndex(e);
1973
+ return;
1974
+ }
1975
+ for (let e = 0, t = this._vertexAttribArraysEnabled.length; e < t; e++)
1976
+ e >= this._caps.maxVertexAttribs || !this._vertexAttribArraysEnabled[e] || this.disableAttributeByIndex(e);
1977
+ }
1978
+ /**
1979
+ * 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
1980
+ */
1981
+ releaseEffects() {
1982
+ this._compiledEffects = {}, this.onReleaseEffectsObservable.notifyObservers(this);
1983
+ }
1984
+ /**
1985
+ * Dispose and release all associated resources
1986
+ */
1987
+ dispose() {
1988
+ re() && this._renderingCanvas && (this._renderingCanvas.removeEventListener("webglcontextlost", this._onContextLost), this._onContextRestored && this._renderingCanvas.removeEventListener("webglcontextrestored", this._onContextRestored)), super.dispose(), this._dummyFramebuffer && this._gl.deleteFramebuffer(this._dummyFramebuffer), this.unbindAllAttributes(), this._boundUniforms = {}, this._workingCanvas = null, this._workingContext = null, this._currentBufferPointers.length = 0, this._currentProgram = null, this._creationOptions.loseContextOnDispose && this._gl.getExtension("WEBGL_lose_context")?.loseContext(), U(this._gl);
1989
+ }
1990
+ /**
1991
+ * Attach a new callback raised when context lost event is fired
1992
+ * @param callback defines the callback to call
1993
+ */
1994
+ attachContextLostEvent(e) {
1995
+ this._renderingCanvas && this._renderingCanvas.addEventListener("webglcontextlost", e, !1);
1996
+ }
1997
+ /**
1998
+ * Attach a new callback raised when context restored event is fired
1999
+ * @param callback defines the callback to call
2000
+ */
2001
+ attachContextRestoredEvent(e) {
2002
+ this._renderingCanvas && this._renderingCanvas.addEventListener("webglcontextrestored", e, !1);
2003
+ }
2004
+ /**
2005
+ * Get the current error code of the webGL context
2006
+ * @returns the error code
2007
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/getError
2008
+ */
2009
+ getError() {
2010
+ return this._gl.getError();
2011
+ }
2012
+ _canRenderToFloatFramebuffer() {
2013
+ return this._webGLVersion > 1 ? this._caps.colorBufferFloat : this._canRenderToFramebuffer(1);
2014
+ }
2015
+ _canRenderToHalfFloatFramebuffer() {
2016
+ return this._webGLVersion > 1 ? this._caps.colorBufferFloat : this._canRenderToFramebuffer(2);
2017
+ }
2018
+ // Thank you : http://stackoverflow.com/questions/28827511/webgl-ios-render-to-floating-point-texture
2019
+ _canRenderToFramebuffer(e) {
2020
+ const t = this._gl;
2021
+ for (; t.getError() !== t.NO_ERROR; )
2022
+ ;
2023
+ let r = !0;
2024
+ const s = t.createTexture();
2025
+ t.bindTexture(t.TEXTURE_2D, s), t.texImage2D(t.TEXTURE_2D, 0, this._getRGBABufferInternalSizedFormat(e), 1, 1, 0, t.RGBA, this._getWebGLTextureType(e), null), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_MIN_FILTER, t.NEAREST), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_MAG_FILTER, t.NEAREST);
2026
+ const i = t.createFramebuffer();
2027
+ t.bindFramebuffer(t.FRAMEBUFFER, i), t.framebufferTexture2D(t.FRAMEBUFFER, t.COLOR_ATTACHMENT0, t.TEXTURE_2D, s, 0);
2028
+ const n = t.checkFramebufferStatus(t.FRAMEBUFFER);
2029
+ if (r = r && n === t.FRAMEBUFFER_COMPLETE, r = r && t.getError() === t.NO_ERROR, r && (t.clear(t.COLOR_BUFFER_BIT), r = r && t.getError() === t.NO_ERROR), r) {
2030
+ t.bindFramebuffer(t.FRAMEBUFFER, null);
2031
+ const l = t.RGBA, a = t.UNSIGNED_BYTE, _ = new Uint8Array(4);
2032
+ t.readPixels(0, 0, 1, 1, l, a, _), r = r && t.getError() === t.NO_ERROR;
2033
+ }
2034
+ for (t.deleteTexture(s), t.deleteFramebuffer(i), t.bindFramebuffer(t.FRAMEBUFFER, null); !r && t.getError() !== t.NO_ERROR; )
2035
+ ;
2036
+ return r;
2037
+ }
2038
+ /**
2039
+ * @internal
2040
+ */
2041
+ _getWebGLTextureType(e) {
2042
+ if (this._webGLVersion === 1) {
2043
+ switch (e) {
2044
+ case 1:
2045
+ return this._gl.FLOAT;
2046
+ case 2:
2047
+ return this._gl.HALF_FLOAT_OES;
2048
+ case 0:
2049
+ return this._gl.UNSIGNED_BYTE;
2050
+ case 8:
2051
+ return this._gl.UNSIGNED_SHORT_4_4_4_4;
2052
+ case 9:
2053
+ return this._gl.UNSIGNED_SHORT_5_5_5_1;
2054
+ case 10:
2055
+ return this._gl.UNSIGNED_SHORT_5_6_5;
2056
+ }
2057
+ return this._gl.UNSIGNED_BYTE;
2058
+ }
2059
+ switch (e) {
2060
+ case 3:
2061
+ return this._gl.BYTE;
2062
+ case 0:
2063
+ return this._gl.UNSIGNED_BYTE;
2064
+ case 4:
2065
+ return this._gl.SHORT;
2066
+ case 5:
2067
+ return this._gl.UNSIGNED_SHORT;
2068
+ case 6:
2069
+ return this._gl.INT;
2070
+ case 7:
2071
+ return this._gl.UNSIGNED_INT;
2072
+ case 1:
2073
+ return this._gl.FLOAT;
2074
+ case 2:
2075
+ return this._gl.HALF_FLOAT;
2076
+ case 8:
2077
+ return this._gl.UNSIGNED_SHORT_4_4_4_4;
2078
+ case 9:
2079
+ return this._gl.UNSIGNED_SHORT_5_5_5_1;
2080
+ case 10:
2081
+ return this._gl.UNSIGNED_SHORT_5_6_5;
2082
+ case 11:
2083
+ return this._gl.UNSIGNED_INT_2_10_10_10_REV;
2084
+ case 12:
2085
+ return this._gl.UNSIGNED_INT_24_8;
2086
+ case 13:
2087
+ return this._gl.UNSIGNED_INT_10F_11F_11F_REV;
2088
+ case 14:
2089
+ return this._gl.UNSIGNED_INT_5_9_9_9_REV;
2090
+ case 15:
2091
+ return this._gl.FLOAT_32_UNSIGNED_INT_24_8_REV;
2092
+ }
2093
+ return this._gl.UNSIGNED_BYTE;
2094
+ }
2095
+ /**
2096
+ * @internal
2097
+ */
2098
+ _getInternalFormat(e, t = !1) {
2099
+ let r = t ? this._glSRGBExtensionValues.SRGB8_ALPHA8 : this._gl.RGBA;
2100
+ switch (e) {
2101
+ case 0:
2102
+ r = this._gl.ALPHA;
2103
+ break;
2104
+ case 1:
2105
+ r = this._gl.LUMINANCE;
2106
+ break;
2107
+ case 2:
2108
+ r = this._gl.LUMINANCE_ALPHA;
2109
+ break;
2110
+ case 6:
2111
+ case 33322:
2112
+ case 36760:
2113
+ r = this._gl.RED;
2114
+ break;
2115
+ case 7:
2116
+ case 33324:
2117
+ case 36761:
2118
+ r = this._gl.RG;
2119
+ break;
2120
+ case 4:
2121
+ case 32852:
2122
+ case 36762:
2123
+ r = t ? this._glSRGBExtensionValues.SRGB : this._gl.RGB;
2124
+ break;
2125
+ case 5:
2126
+ case 32859:
2127
+ case 36763:
2128
+ r = t ? this._glSRGBExtensionValues.SRGB8_ALPHA8 : this._gl.RGBA;
2129
+ break;
2130
+ }
2131
+ if (this._webGLVersion > 1)
2132
+ switch (e) {
2133
+ case 8:
2134
+ r = this._gl.RED_INTEGER;
2135
+ break;
2136
+ case 9:
2137
+ r = this._gl.RG_INTEGER;
2138
+ break;
2139
+ case 10:
2140
+ r = this._gl.RGB_INTEGER;
2141
+ break;
2142
+ case 11:
2143
+ r = this._gl.RGBA_INTEGER;
2144
+ break;
2145
+ }
2146
+ return r;
2147
+ }
2148
+ /**
2149
+ * @internal
2150
+ */
2151
+ _getRGBABufferInternalSizedFormat(e, t, r = !1) {
2152
+ if (this._webGLVersion === 1) {
2153
+ if (t !== void 0)
2154
+ switch (t) {
2155
+ case 0:
2156
+ return this._gl.ALPHA;
2157
+ case 1:
2158
+ return this._gl.LUMINANCE;
2159
+ case 2:
2160
+ return this._gl.LUMINANCE_ALPHA;
2161
+ case 4:
2162
+ return r ? this._glSRGBExtensionValues.SRGB : this._gl.RGB;
2163
+ }
2164
+ return this._gl.RGBA;
2165
+ }
2166
+ switch (e) {
2167
+ case 3:
2168
+ switch (t) {
2169
+ case 6:
2170
+ return this._gl.R8_SNORM;
2171
+ case 7:
2172
+ return this._gl.RG8_SNORM;
2173
+ case 4:
2174
+ return this._gl.RGB8_SNORM;
2175
+ case 8:
2176
+ return this._gl.R8I;
2177
+ case 9:
2178
+ return this._gl.RG8I;
2179
+ case 10:
2180
+ return this._gl.RGB8I;
2181
+ case 11:
2182
+ return this._gl.RGBA8I;
2183
+ default:
2184
+ return this._gl.RGBA8_SNORM;
2185
+ }
2186
+ case 0:
2187
+ switch (t) {
2188
+ case 6:
2189
+ return this._gl.R8;
2190
+ case 7:
2191
+ return this._gl.RG8;
2192
+ case 4:
2193
+ return r ? this._glSRGBExtensionValues.SRGB8 : this._gl.RGB8;
2194
+ // By default. Other possibilities are RGB565, SRGB8.
2195
+ case 5:
2196
+ return r ? this._glSRGBExtensionValues.SRGB8_ALPHA8 : this._gl.RGBA8;
2197
+ // By default. Other possibilities are RGB5_A1, RGBA4, SRGB8_ALPHA8.
2198
+ case 8:
2199
+ return this._gl.R8UI;
2200
+ case 9:
2201
+ return this._gl.RG8UI;
2202
+ case 10:
2203
+ return this._gl.RGB8UI;
2204
+ case 11:
2205
+ return this._gl.RGBA8UI;
2206
+ case 0:
2207
+ return this._gl.ALPHA;
2208
+ case 1:
2209
+ return this._gl.LUMINANCE;
2210
+ case 2:
2211
+ return this._gl.LUMINANCE_ALPHA;
2212
+ default:
2213
+ return this._gl.RGBA8;
2214
+ }
2215
+ case 4:
2216
+ switch (t) {
2217
+ case 8:
2218
+ return this._gl.R16I;
2219
+ case 36760:
2220
+ return this._gl.R16_SNORM_EXT;
2221
+ case 36761:
2222
+ return this._gl.RG16_SNORM_EXT;
2223
+ case 36762:
2224
+ return this._gl.RGB16_SNORM_EXT;
2225
+ case 36763:
2226
+ return this._gl.RGBA16_SNORM_EXT;
2227
+ case 9:
2228
+ return this._gl.RG16I;
2229
+ case 10:
2230
+ return this._gl.RGB16I;
2231
+ case 11:
2232
+ return this._gl.RGBA16I;
2233
+ default:
2234
+ return this._gl.RGBA16I;
2235
+ }
2236
+ case 5:
2237
+ switch (t) {
2238
+ case 8:
2239
+ return this._gl.R16UI;
2240
+ case 33322:
2241
+ return this._gl.R16_EXT;
2242
+ case 33324:
2243
+ return this._gl.RG16_EXT;
2244
+ case 32852:
2245
+ return this._gl.RGB16_EXT;
2246
+ case 32859:
2247
+ return this._gl.RGBA16_EXT;
2248
+ case 9:
2249
+ return this._gl.RG16UI;
2250
+ case 10:
2251
+ return this._gl.RGB16UI;
2252
+ case 11:
2253
+ return this._gl.RGBA16UI;
2254
+ default:
2255
+ return this._gl.RGBA16UI;
2256
+ }
2257
+ case 6:
2258
+ switch (t) {
2259
+ case 8:
2260
+ return this._gl.R32I;
2261
+ case 9:
2262
+ return this._gl.RG32I;
2263
+ case 10:
2264
+ return this._gl.RGB32I;
2265
+ case 11:
2266
+ return this._gl.RGBA32I;
2267
+ default:
2268
+ return this._gl.RGBA32I;
2269
+ }
2270
+ case 7:
2271
+ switch (t) {
2272
+ case 8:
2273
+ return this._gl.R32UI;
2274
+ case 9:
2275
+ return this._gl.RG32UI;
2276
+ case 10:
2277
+ return this._gl.RGB32UI;
2278
+ case 11:
2279
+ return this._gl.RGBA32UI;
2280
+ default:
2281
+ return this._gl.RGBA32UI;
2282
+ }
2283
+ case 1:
2284
+ switch (t) {
2285
+ case 6:
2286
+ return this._gl.R32F;
2287
+ // By default. Other possibility is R16F.
2288
+ case 7:
2289
+ return this._gl.RG32F;
2290
+ // By default. Other possibility is RG16F.
2291
+ case 4:
2292
+ return this._gl.RGB32F;
2293
+ // By default. Other possibilities are RGB16F, R11F_G11F_B10F, RGB9_E5.
2294
+ case 5:
2295
+ return this._gl.RGBA32F;
2296
+ // By default. Other possibility is RGBA16F.
2297
+ default:
2298
+ return this._gl.RGBA32F;
2299
+ }
2300
+ case 2:
2301
+ switch (t) {
2302
+ case 6:
2303
+ return this._gl.R16F;
2304
+ case 7:
2305
+ return this._gl.RG16F;
2306
+ case 4:
2307
+ return this._gl.RGB16F;
2308
+ // By default. Other possibilities are R11F_G11F_B10F, RGB9_E5.
2309
+ case 5:
2310
+ return this._gl.RGBA16F;
2311
+ default:
2312
+ return this._gl.RGBA16F;
2313
+ }
2314
+ case 10:
2315
+ return this._gl.RGB565;
2316
+ case 13:
2317
+ return this._gl.R11F_G11F_B10F;
2318
+ case 14:
2319
+ return this._gl.RGB9_E5;
2320
+ case 8:
2321
+ return this._gl.RGBA4;
2322
+ case 9:
2323
+ return this._gl.RGB5_A1;
2324
+ case 11:
2325
+ switch (t) {
2326
+ case 5:
2327
+ return this._gl.RGB10_A2;
2328
+ // By default. Other possibility is RGB5_A1.
2329
+ case 11:
2330
+ return this._gl.RGB10_A2UI;
2331
+ default:
2332
+ return this._gl.RGB10_A2;
2333
+ }
2334
+ }
2335
+ return r ? this._glSRGBExtensionValues.SRGB8_ALPHA8 : this._gl.RGBA8;
2336
+ }
2337
+ /**
2338
+ * Reads pixels from the current frame buffer. Please note that this function can be slow
2339
+ * @param x defines the x coordinate of the rectangle where pixels must be read
2340
+ * @param y defines the y coordinate of the rectangle where pixels must be read
2341
+ * @param width defines the width of the rectangle where pixels must be read
2342
+ * @param height defines the height of the rectangle where pixels must be read
2343
+ * @param hasAlpha defines whether the output should have alpha or not (defaults to true)
2344
+ * @param flushRenderer true to flush the renderer from the pending commands before reading the pixels
2345
+ * @param data defines the data to fill with the read pixels (if not provided, a new one will be created)
2346
+ * @returns a ArrayBufferView promise (Uint8Array) containing RGBA colors
2347
+ */
2348
+ // Async function, not named Async and not marked as async to avoid breaking changes
2349
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
2350
+ readPixels(e, t, r, s, i = !0, n = !0, l = null) {
2351
+ const a = i ? 4 : 3, _ = i ? this._gl.RGBA : this._gl.RGB, u = r * s * a;
2352
+ if (!l)
2353
+ l = new Uint8Array(u);
2354
+ else if (l.length < u)
2355
+ return I.Error(`Data buffer is too small to store the read pixels (${l.length} should be more than ${u})`), Promise.resolve(l);
2356
+ return n && this.flushFramebuffer(), this._gl.readPixels(e, t, r, s, _, this._gl.UNSIGNED_BYTE, l), Promise.resolve(l);
2357
+ }
2358
+ /**
2359
+ * Gets a Promise<boolean> indicating if the engine can be instantiated (ie. if a webGL context can be found)
2360
+ */
2361
+ // eslint-disable-next-line no-restricted-syntax
2362
+ static get IsSupportedAsync() {
2363
+ return Promise.resolve(this.isSupported());
2364
+ }
2365
+ /**
2366
+ * Gets a boolean indicating if the engine can be instantiated (ie. if a webGL context can be found)
2367
+ */
2368
+ static get IsSupported() {
2369
+ return this.isSupported();
2370
+ }
2371
+ /**
2372
+ * Gets a boolean indicating if the engine can be instantiated (ie. if a webGL context can be found)
2373
+ * @returns true if the engine can be created
2374
+ */
2375
+ // eslint-disable-next-line @typescript-eslint/naming-convention
2376
+ static isSupported() {
2377
+ if (this._HasMajorPerformanceCaveat !== null)
2378
+ return !this._HasMajorPerformanceCaveat;
2379
+ if (this._IsSupported === null)
2380
+ try {
2381
+ const e = w._CreateCanvas(1, 1), t = e.getContext("webgl") || e.getContext("experimental-webgl");
2382
+ this._IsSupported = t != null && !!globalThis.WebGLRenderingContext;
2383
+ } catch {
2384
+ this._IsSupported = !1;
2385
+ }
2386
+ return this._IsSupported;
2387
+ }
2388
+ /**
2389
+ * 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)
2390
+ */
2391
+ static get HasMajorPerformanceCaveat() {
2392
+ if (this._HasMajorPerformanceCaveat === null)
2393
+ try {
2394
+ const e = w._CreateCanvas(1, 1), t = e.getContext("webgl", { failIfMajorPerformanceCaveat: !0 }) || e.getContext("experimental-webgl", { failIfMajorPerformanceCaveat: !0 });
2395
+ this._HasMajorPerformanceCaveat = !t;
2396
+ } catch {
2397
+ this._HasMajorPerformanceCaveat = !1;
2398
+ }
2399
+ return this._HasMajorPerformanceCaveat;
2400
+ }
2401
+ }
2402
+ T._TempClearColorUint32 = new Uint32Array(4);
2403
+ T._TempClearColorInt32 = new Int32Array(4);
2404
+ T.ExceptionList = [
2405
+ { key: "Chrome/63.0", capture: "63\\.0\\.3239\\.(\\d+)", captureConstraint: 108, targets: ["uniformBuffer"] },
2406
+ { key: "Firefox/58", capture: null, captureConstraint: null, targets: ["uniformBuffer"] },
2407
+ { key: "Firefox/59", capture: null, captureConstraint: null, targets: ["uniformBuffer"] },
2408
+ { key: "Chrome/72.+?Mobile", capture: null, captureConstraint: null, targets: ["vao"] },
2409
+ { key: "Chrome/73.+?Mobile", capture: null, captureConstraint: null, targets: ["vao"] },
2410
+ { key: "Chrome/74.+?Mobile", capture: null, captureConstraint: null, targets: ["vao"] },
2411
+ { key: "Mac OS.+Chrome/71", capture: null, captureConstraint: null, targets: ["vao"] },
2412
+ { key: "Mac OS.+Chrome/72", capture: null, captureConstraint: null, targets: ["vao"] },
2413
+ { key: "Mac OS.+Chrome", capture: null, captureConstraint: null, targets: ["uniformBuffer"] },
2414
+ { key: "Chrome/12\\d\\..+?Mobile", capture: null, captureConstraint: null, targets: ["uniformBuffer"] },
2415
+ // desktop osx safari 15.4
2416
+ { key: ".*AppleWebKit.*(15.4).*Safari", capture: null, captureConstraint: null, targets: ["antialias", "maxMSAASamples"] },
2417
+ // mobile browsers using safari 15.4 on ios
2418
+ { key: ".*(15.4).*AppleWebKit.*Safari", capture: null, captureConstraint: null, targets: ["antialias", "maxMSAASamples"] }
2419
+ ];
2420
+ T._ConcatenateShader = se;
2421
+ T._IsSupported = null;
2422
+ T._HasMajorPerformanceCaveat = null;
2423
+ export {
2424
+ T as ThinEngine
2425
+ };