@babylonjs/core 7.4.0 → 7.6.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 (235) hide show
  1. package/Audio/sound.js +3 -0
  2. package/Audio/sound.js.map +1 -1
  3. package/Buffers/storageBuffer.d.ts +2 -2
  4. package/Buffers/storageBuffer.js.map +1 -1
  5. package/Cameras/arcRotateCamera.js +3 -0
  6. package/Cameras/arcRotateCamera.js.map +1 -1
  7. package/Cameras/flyCamera.js +3 -0
  8. package/Cameras/flyCamera.js.map +1 -1
  9. package/Cameras/followCamera.js +4 -0
  10. package/Cameras/followCamera.js.map +1 -1
  11. package/Cameras/freeCamera.js +3 -0
  12. package/Cameras/freeCamera.js.map +1 -1
  13. package/Engines/Extensions/index.d.ts +0 -3
  14. package/Engines/Extensions/index.js +0 -3
  15. package/Engines/Extensions/index.js.map +1 -1
  16. package/Engines/WebGPU/Extensions/index.d.ts +0 -3
  17. package/Engines/WebGPU/Extensions/index.js +0 -3
  18. package/Engines/WebGPU/Extensions/index.js.map +1 -1
  19. package/Engines/abstractEngine.d.ts +11 -63
  20. package/Engines/abstractEngine.js +7 -7
  21. package/Engines/abstractEngine.js.map +1 -1
  22. package/Engines/nativeEngine.js +2 -2
  23. package/Engines/nativeEngine.js.map +1 -1
  24. package/Engines/thinEngine.d.ts +2 -2
  25. package/Engines/thinEngine.functions.d.ts +2 -10
  26. package/Engines/thinEngine.functions.js +1 -20
  27. package/Engines/thinEngine.functions.js.map +1 -1
  28. package/Engines/thinEngine.js +27 -11
  29. package/Engines/thinEngine.js.map +1 -1
  30. package/Engines/webgpuEngine.d.ts +54 -2
  31. package/Engines/webgpuEngine.js +147 -0
  32. package/Engines/webgpuEngine.js.map +1 -1
  33. package/Inputs/scene.inputManager.d.ts +1 -0
  34. package/Inputs/scene.inputManager.js +1 -0
  35. package/Inputs/scene.inputManager.js.map +1 -1
  36. package/Lights/directionalLight.js +3 -0
  37. package/Lights/directionalLight.js.map +1 -1
  38. package/Lights/hemisphericLight.js +3 -0
  39. package/Lights/hemisphericLight.js.map +1 -1
  40. package/Lights/pointLight.js +3 -0
  41. package/Lights/pointLight.js.map +1 -1
  42. package/Lights/spotLight.js +3 -0
  43. package/Lights/spotLight.js.map +1 -1
  44. package/Loading/Plugins/babylonFileLoader.js +25 -14
  45. package/Loading/Plugins/babylonFileLoader.js.map +1 -1
  46. package/Materials/Background/backgroundMaterial.js +1 -2
  47. package/Materials/Background/backgroundMaterial.js.map +1 -1
  48. package/Materials/GreasedLine/greasedLinePluginMaterial.js +7 -3
  49. package/Materials/GreasedLine/greasedLinePluginMaterial.js.map +1 -1
  50. package/Materials/Node/Blocks/Dual/clipPlanesBlock.d.ts +1 -1
  51. package/Materials/Node/Blocks/Dual/clipPlanesBlock.js.map +1 -1
  52. package/Materials/Node/Blocks/Dual/currentScreenBlock.d.ts +1 -1
  53. package/Materials/Node/Blocks/Dual/currentScreenBlock.js.map +1 -1
  54. package/Materials/Node/Blocks/Dual/fogBlock.d.ts +1 -1
  55. package/Materials/Node/Blocks/Dual/fogBlock.js.map +1 -1
  56. package/Materials/Node/Blocks/Dual/reflectionTextureBaseBlock.d.ts +1 -1
  57. package/Materials/Node/Blocks/Dual/reflectionTextureBaseBlock.js.map +1 -1
  58. package/Materials/Node/Blocks/Dual/sceneDepthBlock.d.ts +1 -1
  59. package/Materials/Node/Blocks/Dual/sceneDepthBlock.js.map +1 -1
  60. package/Materials/Node/Blocks/Dual/textureBlock.d.ts +1 -1
  61. package/Materials/Node/Blocks/Dual/textureBlock.js +5 -1
  62. package/Materials/Node/Blocks/Dual/textureBlock.js.map +1 -1
  63. package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.d.ts +1 -1
  64. package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js.map +1 -1
  65. package/Materials/Node/Blocks/Fragment/perturbNormalBlock.d.ts +1 -1
  66. package/Materials/Node/Blocks/Fragment/perturbNormalBlock.js.map +1 -1
  67. package/Materials/Node/Blocks/Fragment/screenSizeBlock.d.ts +1 -1
  68. package/Materials/Node/Blocks/Fragment/screenSizeBlock.js.map +1 -1
  69. package/Materials/Node/Blocks/Fragment/shadowMapBlock.d.ts +1 -1
  70. package/Materials/Node/Blocks/Fragment/shadowMapBlock.js.map +1 -1
  71. package/Materials/Node/Blocks/Input/animatedInputBlockTypes.d.ts +2 -1
  72. package/Materials/Node/Blocks/Input/animatedInputBlockTypes.js +1 -0
  73. package/Materials/Node/Blocks/Input/animatedInputBlockTypes.js.map +1 -1
  74. package/Materials/Node/Blocks/Input/inputBlock.d.ts +1 -1
  75. package/Materials/Node/Blocks/Input/inputBlock.js +16 -0
  76. package/Materials/Node/Blocks/Input/inputBlock.js.map +1 -1
  77. package/Materials/Node/Blocks/PBR/anisotropyBlock.d.ts +1 -1
  78. package/Materials/Node/Blocks/PBR/anisotropyBlock.js.map +1 -1
  79. package/Materials/Node/Blocks/PBR/clearCoatBlock.d.ts +1 -1
  80. package/Materials/Node/Blocks/PBR/clearCoatBlock.js.map +1 -1
  81. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.d.ts +1 -1
  82. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js.map +1 -1
  83. package/Materials/Node/Blocks/PBR/reflectionBlock.d.ts +1 -1
  84. package/Materials/Node/Blocks/PBR/reflectionBlock.js.map +1 -1
  85. package/Materials/Node/Blocks/PBR/refractionBlock.d.ts +1 -1
  86. package/Materials/Node/Blocks/PBR/refractionBlock.js.map +1 -1
  87. package/Materials/Node/Blocks/Vertex/lightInformationBlock.d.ts +1 -1
  88. package/Materials/Node/Blocks/Vertex/lightInformationBlock.js.map +1 -1
  89. package/Materials/Node/Blocks/Vertex/vertexOutputBlock.d.ts +1 -1
  90. package/Materials/Node/Blocks/Vertex/vertexOutputBlock.js.map +1 -1
  91. package/Materials/Node/Blocks/baseMathBlock.js +2 -4
  92. package/Materials/Node/Blocks/baseMathBlock.js.map +1 -1
  93. package/Materials/Node/Blocks/modBlock.js +7 -1
  94. package/Materials/Node/Blocks/modBlock.js.map +1 -1
  95. package/Materials/Node/Blocks/triPlanarBlock.d.ts +1 -1
  96. package/Materials/Node/Blocks/triPlanarBlock.js.map +1 -1
  97. package/Materials/Node/nodeMaterial.d.ts +2 -4
  98. package/Materials/Node/nodeMaterial.js +1 -3
  99. package/Materials/Node/nodeMaterial.js.map +1 -1
  100. package/Materials/Node/nodeMaterialBlockConnectionPoint.d.ts +34 -14
  101. package/Materials/Node/nodeMaterialBlockConnectionPoint.js +87 -9
  102. package/Materials/Node/nodeMaterialBlockConnectionPoint.js.map +1 -1
  103. package/Materials/Node/nodeMaterialBuildState.d.ts +1 -1
  104. package/Materials/Node/nodeMaterialBuildState.js.map +1 -1
  105. package/Materials/PBR/pbrBaseMaterial.d.ts +1 -2
  106. package/Materials/PBR/pbrBaseMaterial.js +1 -2
  107. package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
  108. package/Materials/Textures/Loaders/ktxTextureLoader.js +1 -1
  109. package/Materials/Textures/Loaders/ktxTextureLoader.js.map +1 -1
  110. package/Materials/Textures/htmlElementTexture.d.ts +0 -1
  111. package/Materials/Textures/htmlElementTexture.js +7 -2
  112. package/Materials/Textures/htmlElementTexture.js.map +1 -1
  113. package/Materials/Textures/videoTexture.js +4 -2
  114. package/Materials/Textures/videoTexture.js.map +1 -1
  115. package/Materials/effect.d.ts +4 -0
  116. package/Materials/effect.functions.d.ts +1 -1
  117. package/Materials/effect.functions.js +6 -4
  118. package/Materials/effect.functions.js.map +1 -1
  119. package/Materials/effect.js +1 -1
  120. package/Materials/effect.js.map +1 -1
  121. package/Materials/effect.webgl.functions.js +3 -3
  122. package/Materials/effect.webgl.functions.js.map +1 -1
  123. package/Materials/imageProcessingConfiguration.d.ts +5 -0
  124. package/Materials/imageProcessingConfiguration.defines.d.ts +2 -4
  125. package/Materials/imageProcessingConfiguration.defines.js +1 -2
  126. package/Materials/imageProcessingConfiguration.defines.js.map +1 -1
  127. package/Materials/imageProcessingConfiguration.js +26 -11
  128. package/Materials/imageProcessingConfiguration.js.map +1 -1
  129. package/Materials/materialPluginBase.js +3 -0
  130. package/Materials/materialPluginBase.js.map +1 -1
  131. package/Materials/meshDebugPluginMaterial.js +2 -2
  132. package/Materials/meshDebugPluginMaterial.js.map +1 -1
  133. package/Materials/shaderMaterial.js +18 -8
  134. package/Materials/shaderMaterial.js.map +1 -1
  135. package/Materials/standardMaterial.d.ts +1 -2
  136. package/Materials/standardMaterial.js +1 -2
  137. package/Materials/standardMaterial.js.map +1 -1
  138. package/Maths/math.color.d.ts +85 -82
  139. package/Maths/math.color.js +34 -27
  140. package/Maths/math.color.js.map +1 -1
  141. package/Maths/math.vector.d.ts +202 -202
  142. package/Maths/math.vector.js +133 -130
  143. package/Maths/math.vector.js.map +1 -1
  144. package/Maths/tensor.d.ts +44 -42
  145. package/Maths/tensor.js.map +1 -1
  146. package/Meshes/Compression/dracoCompression.d.ts +7 -0
  147. package/Meshes/Compression/dracoCompression.js +14 -0
  148. package/Meshes/Compression/dracoCompression.js.map +1 -1
  149. package/Meshes/Node/nodeGeometryBlockConnectionPoint.js +6 -0
  150. package/Meshes/Node/nodeGeometryBlockConnectionPoint.js.map +1 -1
  151. package/Meshes/instancedMesh.js +3 -0
  152. package/Meshes/instancedMesh.js.map +1 -1
  153. package/Misc/dumpTools.js +11 -0
  154. package/Misc/dumpTools.js.map +1 -1
  155. package/Misc/fileTools.d.ts +9 -3
  156. package/Misc/fileTools.js +17 -14
  157. package/Misc/fileTools.js.map +1 -1
  158. package/Misc/greasedLineTools.js +7 -1
  159. package/Misc/greasedLineTools.js.map +1 -1
  160. package/Misc/sceneSerializer.js +9 -1
  161. package/Misc/sceneSerializer.js.map +1 -1
  162. package/Misc/textureTools.d.ts +2 -0
  163. package/Misc/textureTools.js +2 -0
  164. package/Misc/textureTools.js.map +1 -1
  165. package/Misc/tools.d.ts +5 -6
  166. package/Misc/tools.js +9 -9
  167. package/Misc/tools.js.map +1 -1
  168. package/Misc/typeStore.d.ts +4 -0
  169. package/Misc/typeStore.js +11 -0
  170. package/Misc/typeStore.js.map +1 -1
  171. package/NOTICE.md +8 -0
  172. package/Particles/baseParticleSystem.js +3 -0
  173. package/Particles/baseParticleSystem.js.map +1 -1
  174. package/Particles/computeShaderParticleSystem.d.ts +2 -2
  175. package/Particles/computeShaderParticleSystem.js.map +1 -1
  176. package/Physics/v1/Plugins/ammoJSPlugin.js +39 -10
  177. package/Physics/v1/Plugins/ammoJSPlugin.js.map +1 -1
  178. package/PostProcesses/RenderPipeline/Pipelines/ssrRenderingPipeline.js +4 -0
  179. package/PostProcesses/RenderPipeline/Pipelines/ssrRenderingPipeline.js.map +1 -1
  180. package/PostProcesses/imageProcessingPostProcess.js +14 -5
  181. package/PostProcesses/imageProcessingPostProcess.js.map +1 -1
  182. package/Rendering/GlobalIllumination/giRSMManager.d.ts +6 -0
  183. package/Rendering/GlobalIllumination/giRSMManager.js +15 -1
  184. package/Rendering/GlobalIllumination/giRSMManager.js.map +1 -1
  185. package/Rendering/fluidRenderer/fluidRenderingTargetRenderer.js +22 -20
  186. package/Rendering/fluidRenderer/fluidRenderingTargetRenderer.js.map +1 -1
  187. package/Rendering/renderingGroup.js +1 -1
  188. package/Rendering/renderingGroup.js.map +1 -1
  189. package/Shaders/ShadersInclude/imageProcessingFunctions.js +8 -5
  190. package/Shaders/ShadersInclude/imageProcessingFunctions.js.map +1 -1
  191. package/Shaders/ShadersInclude/screenSpaceRayTrace.js +8 -0
  192. package/Shaders/ShadersInclude/screenSpaceRayTrace.js.map +1 -1
  193. package/Shaders/lod.fragment.d.ts +5 -0
  194. package/Shaders/lod.fragment.js +12 -0
  195. package/Shaders/lod.fragment.js.map +1 -0
  196. package/Shaders/lodCube.fragment.d.ts +5 -0
  197. package/Shaders/lodCube.fragment.js +30 -0
  198. package/Shaders/lodCube.fragment.js.map +1 -0
  199. package/Shaders/screenSpaceReflection2.fragment.js +7 -1
  200. package/Shaders/screenSpaceReflection2.fragment.js.map +1 -1
  201. package/Shaders/ssao2.fragment.js +1 -1
  202. package/Shaders/ssao2.fragment.js.map +1 -1
  203. package/XR/features/WebXRNearInteraction.d.ts +6 -0
  204. package/XR/features/WebXRNearInteraction.js +14 -2
  205. package/XR/features/WebXRNearInteraction.js.map +1 -1
  206. package/XR/webXRManagedOutputCanvas.d.ts +2 -0
  207. package/XR/webXRManagedOutputCanvas.js +14 -6
  208. package/XR/webXRManagedOutputCanvas.js.map +1 -1
  209. package/abstractScene.js +3 -0
  210. package/abstractScene.js.map +1 -1
  211. package/assets/glslang/glslang.js +113 -0
  212. package/assets/glslang/glslang.wasm +0 -0
  213. package/assets/twgsl/twgsl.js +53 -0
  214. package/assets/twgsl/twgsl.wasm +0 -0
  215. package/package.json +1 -1
  216. package/scene.js +3 -0
  217. package/scene.js.map +1 -1
  218. package/Engines/Extensions/engine.externalTexture.d.ts +0 -18
  219. package/Engines/Extensions/engine.externalTexture.js +0 -10
  220. package/Engines/Extensions/engine.externalTexture.js.map +0 -1
  221. package/Engines/Extensions/engine.storageBuffer.d.ts +0 -39
  222. package/Engines/Extensions/engine.storageBuffer.js +0 -16
  223. package/Engines/Extensions/engine.storageBuffer.js.map +0 -1
  224. package/Engines/Extensions/engine.textureSampler.d.ts +0 -12
  225. package/Engines/Extensions/engine.textureSampler.js +0 -6
  226. package/Engines/Extensions/engine.textureSampler.js.map +0 -1
  227. package/Engines/WebGPU/Extensions/engine.externalTexture.d.ts +0 -28
  228. package/Engines/WebGPU/Extensions/engine.externalTexture.js +0 -18
  229. package/Engines/WebGPU/Extensions/engine.externalTexture.js.map +0 -1
  230. package/Engines/WebGPU/Extensions/engine.storageBuffer.d.ts +0 -50
  231. package/Engines/WebGPU/Extensions/engine.storageBuffer.js +0 -88
  232. package/Engines/WebGPU/Extensions/engine.storageBuffer.js.map +0 -1
  233. package/Engines/WebGPU/Extensions/engine.textureSampler.d.ts +0 -22
  234. package/Engines/WebGPU/Extensions/engine.textureSampler.js +0 -9
  235. package/Engines/WebGPU/Extensions/engine.textureSampler.js.map +0 -1
@@ -174,7 +174,7 @@ export declare class ThinEngine extends AbstractEngine {
174
174
  /**
175
175
  * Creates a new engine
176
176
  * @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
177
- * @param antialias defines enable antialiasing (default: false)
177
+ * @param antialias defines whether anti-aliasing should be enabled (default value is "undefined", meaning that the browser may or may not enable it)
178
178
  * @param options defines further options to be sent to the getContext() function
179
179
  * @param adaptToDeviceRatio defines whether to adapt to the device's viewport characteristics (default: false)
180
180
  */
@@ -868,7 +868,7 @@ export declare class ThinEngine extends AbstractEngine {
868
868
  * @returns The options to pass to texImage2D or texImage3D calls.
869
869
  * @internal
870
870
  */
871
- _getTexImageParametersForCreateTexture(babylonFormat: Nullable<number>, fileExtension: string, useSRGBBuffer: boolean): TexImageParameters;
871
+ _getTexImageParametersForCreateTexture(babylonFormat: number, useSRGBBuffer: boolean): TexImageParameters;
872
872
  /**
873
873
  * @internal
874
874
  */
@@ -2,6 +2,7 @@ import type { Nullable } from "../types";
2
2
  import type { IPipelineContext } from "./IPipelineContext";
3
3
  import type { ShaderProcessingContext } from "./Processors/shaderProcessingOptions";
4
4
  import { WebGLPipelineContext } from "./WebGL/webGLPipelineContext";
5
+ import type { _loadFile } from "./abstractEngine.functions";
5
6
  /**
6
7
  * @internal
7
8
  */
@@ -16,6 +17,7 @@ export interface IThinEngineStateObject {
16
17
  _createShaderProgramInjection?: typeof _createShaderProgram;
17
18
  createRawShaderProgramInjection?: typeof createRawShaderProgram;
18
19
  createShaderProgramInjection?: typeof createShaderProgram;
20
+ loadFileInjection?: typeof _loadFile;
19
21
  cachedPipelines: {
20
22
  [name: string]: IPipelineContext;
21
23
  };
@@ -76,16 +78,6 @@ export declare function _finalizePipelineContext(pipelineContext: WebGLPipelineC
76
78
  * @internal
77
79
  */
78
80
  export declare function _preparePipelineContext(pipelineContext: IPipelineContext, vertexSourceCode: string, fragmentSourceCode: string, createAsRaw: boolean, _rawVertexSourceCode: string, _rawFragmentSourceCode: string, rebuildRebind: any, defines: Nullable<string>, transformFeedbackVaryings: Nullable<string[]>, _key?: string, createRawShaderProgramInjection?: typeof createRawShaderProgram, createShaderProgramInjection?: typeof createShaderProgram): void;
79
- /**
80
- * Binds an effect to the webGL context
81
- * @param pipelineContext defines the pipeline context to use
82
- * @param samplers defines the list of webGL samplers to bind
83
- * @param uniforms defines the list of webGL uniforms to bind
84
- * @returns the webGL program
85
- */
86
- export declare function bindSamplers(pipelineContext: IPipelineContext, samplers: string[], uniforms: {
87
- [key: string]: Nullable<WebGLUniformLocation>;
88
- }): Nullable<WebGLUniformLocation>[];
89
81
  /**
90
82
  * @internal
91
83
  */
@@ -128,7 +128,7 @@ export function _finalizePipelineContext(pipelineContext, gl, validateShaderProg
128
128
  if (!linked) {
129
129
  // Get more info
130
130
  // Vertex
131
- if (gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {
131
+ if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {
132
132
  const log = gl.getShaderInfoLog(vertexShader);
133
133
  if (log) {
134
134
  pipelineContext.vertexCompilationError = log;
@@ -206,25 +206,6 @@ function _compileRawShader(source, type, gl, _contextWasLost) {
206
206
  gl.compileShader(shader);
207
207
  return shader;
208
208
  }
209
- /**
210
- * Binds an effect to the webGL context
211
- * @param pipelineContext defines the pipeline context to use
212
- * @param samplers defines the list of webGL samplers to bind
213
- * @param uniforms defines the list of webGL uniforms to bind
214
- * @returns the webGL program
215
- */
216
- export function bindSamplers(pipelineContext, samplers, uniforms) {
217
- const webGLPipelineContext = pipelineContext;
218
- _setProgram(webGLPipelineContext.program, webGLPipelineContext.context);
219
- const _boundUniforms = [];
220
- for (let index = 0; index < samplers.length; index++) {
221
- const uniform = uniforms[samplers[index]];
222
- if (uniform) {
223
- _boundUniforms[index] = uniform;
224
- }
225
- }
226
- return _boundUniforms;
227
- }
228
209
  /**
229
210
  * @internal
230
211
  */
@@ -1 +1 @@
1
- {"version":3,"file":"thinEngine.functions.js","sourceRoot":"","sources":["../../../../dev/core/src/Engines/thinEngine.functions.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAgBhE;;GAEG;AACH,MAAM,YAAY,GAAkD,IAAI,OAAO,EAAE,CAAC;AAElF;;GAEG;AACH,MAAM,iBAAiB,GAA2B;IAC9C,aAAa,EAAE,CAAC;IAChB,eAAe,EAAE,EAAE;CACtB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,OAAqB;IAChD,IAAI,KAAK,GAAG,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACtC,IAAI,CAAC,KAAK,EAAE;QACR,IAAI,CAAC,OAAO,EAAE;YACV,OAAO,iBAAiB,CAAC;SAC5B;QACD,KAAK,GAAG;YACJ,sFAAsF;YACtF,aAAa,EAAG,OAAkC,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7E,QAAQ,EAAE,OAAO;YACjB,eAAe,EAAE,EAAE;SACtB,CAAC;QACF,YAAY,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;KACpC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AACD;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAqB;IACnD,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC;AAGD;;;;;;;;;GASG;AACH,MAAM,UAAU,sBAAsB,CAClC,eAAiC,EACjC,UAAkB,EAClB,YAAoB,EACpB,OAAqB,EACrB,yBAA6C,EAC7C,6BAA2D;IAE3D,MAAM,WAAW,GAAG,cAAc,CAAC,O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ChC,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IAEzB,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CACxB,eAAiC,EACjC,QAAkB,EAClB,QAEC;IAED,MAAM,oBAAoB,GAAG,eAAuC,CAAC;IACrE,WAAW,CAAC,oBAAoB,CAAC,OAAQ,EAAE,oBAAoB,CAAC,OAAQ,CAAC,CAAC;IAC1E,MAAM,cAAc,GAAqC,EAAE,CAAC;IAC5D,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QAClD,MAAM,OAAO,GAAG,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;QAE1C,IAAI,OAAO,EAAE;YACT,cAAc,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC;SACnC;KACJ;IACD,OAAO,cAAc,CAAC;AAC1B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,OAAqB,EAAE,EAAgB;IAC/D,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AAC3B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oCAAoC,CAAC,eAAiC,EAAE,MAAoD;IACxI,MAAM,oBAAoB,GAAG,eAAuC,CAAC;IAErE,IAAI,CAAC,oBAAoB,CAAC,kBAAkB,EAAE;QAC1C,MAAM,CAAC,eAAe,CAAC,CAAC;QACxB,OAAO;KACV;IAED,MAAM,UAAU,GAAG,oBAAoB,CAAC,UAAU,CAAC;IAEnD,oBAAoB,CAAC,UAAU,GAAG,GAAG,EAAE;QACnC,UAAU,EAAE,EAAE,CAAC;QACf,MAAM,CAAC,eAAe,CAAC,CAAC;IAC5B,CAAC,CAAC;AACN,CAAC","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport type { IPipelineContext } from \"./IPipelineContext\";\r\nimport type { ShaderProcessingContext } from \"./Processors/shaderProcessingOptions\";\r\nimport { WebGLPipelineContext } from \"./WebGL/webGLPipelineContext\";\r\nimport { _ConcatenateShader } from \"./abstractEngine.functions\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport interface IThinEngineStateObject {\r\n _contextWasLost?: boolean;\r\n validateShaderPrograms?: boolean;\r\n _webGLVersion: number;\r\n parallelShaderCompile?: { COMPLETION_STATUS_KHR: number };\r\n _context?: WebGLContext;\r\n _createShaderProgramInjection?: typeof _createShaderProgram;\r\n createRawShaderProgramInjection?: typeof createRawShaderProgram;\r\n createShaderProgramInjection?: typeof createShaderProgram;\r\n cachedPipelines: { [name: string]: IPipelineContext };\r\n}\r\n/**\r\n * @internal\r\n */\r\nconst _stateObject: WeakMap<WebGLContext, IThinEngineStateObject> = new WeakMap();\r\n\r\n/**\r\n * This will be used in cases where the engine doesn't have a context (like the nullengine)\r\n */\r\nconst singleStateObject: IThinEngineStateObject = {\r\n _webGLVersion: 2,\r\n cachedPipelines: {},\r\n};\r\n\r\n/**\r\n * get or create a state object for the given context\r\n * Note - Used in WebGL only at the moment.\r\n * @param context The context to get the state object from\r\n * @returns the state object\r\n * @internal\r\n */\r\nexport function getStateObject(context: WebGLContext): IThinEngineStateObject {\r\n let state = _stateObject.get(context);\r\n if (!state) {\r\n if (!context) {\r\n return singleStateObject;\r\n }\r\n state = {\r\n // use feature detection. instanceof returns false. This only exists on WebGL2 context\r\n _webGLVersion: (context as WebGL2RenderingContext).TEXTURE_BINDING_3D ? 2 : 1,\r\n _context: context,\r\n cachedPipelines: {},\r\n };\r\n _stateObject.set(context, state);\r\n }\r\n return state;\r\n}\r\n/**\r\n * Remove the state object that belongs to the specific context\r\n * @param context the context that is being\r\n */\r\nexport function deleteStateObject(context: WebGLContext): void {\r\n _stateObject.delete(context);\r\n}\r\n\r\nexport type WebGLContext = WebGLRenderingContext | WebGL2RenderingContext;\r\n/**\r\n * Directly creates a webGL program\r\n * @param pipelineContext defines the pipeline context to attach to\r\n * @param vertexCode defines the vertex shader code to use\r\n * @param fragmentCode defines the fragment shader code to use\r\n * @param context defines the webGL context to use (if not set, the current one will be used)\r\n * @param transformFeedbackVaryings defines the list of transform feedback varyings to use\r\n * @param _createShaderProgramInjection defines an optional injection to use to create the shader program\r\n * @returns the new webGL program\r\n */\r\nexport function createRawShaderProgram(\r\n pipelineContext: IPipelineContext,\r\n vertexCode: string,\r\n fragmentCode: string,\r\n context: WebGLContext,\r\n transformFeedbackVaryings: Nullable<string[]>,\r\n _createShaderProgramInjection?: typeof _createShaderProgram\r\n): WebGLProgram {\r\n const stateObject = getStateObject(context);\r\n if (!_createShaderProgramInjection) {\r\n _createShaderProgramInjection = stateObject._createShaderProgramInjection ?? _createShaderProgram;\r\n }\r\n\r\n const vertexShader = _compileRawShader(vertexCode, \"vertex\", context, stateObject._contextWasLost);\r\n const fragmentShader = _compileRawShader(fragmentCode, \"fragment\", context, stateObject._contextWasLost);\r\n\r\n return _createShaderProgramInjection(\r\n pipelineContext as WebGLPipelineContext,\r\n vertexShader,\r\n fragmentShader,\r\n context,\r\n transformFeedbackVaryings,\r\n stateObject.validateShaderPrograms\r\n );\r\n}\r\n\r\n/**\r\n * Creates a webGL program\r\n * @param pipelineContext defines the pipeline context to attach to\r\n * @param vertexCode defines the vertex shader code to use\r\n * @param fragmentCode defines the fragment shader code to use\r\n * @param defines defines the string containing the defines to use to compile the shaders\r\n * @param context defines the webGL context to use (if not set, the current one will be used)\r\n * @param transformFeedbackVaryings defines the list of transform feedback varyings to use\r\n * @param _createShaderProgramInjection defines an optional injection to use to create the shader program\r\n * @returns the new webGL program\r\n */\r\nexport function createShaderProgram(\r\n pipelineContext: IPipelineContext,\r\n vertexCode: string,\r\n fragmentCode: string,\r\n defines: Nullable<string>,\r\n context: WebGLContext,\r\n transformFeedbackVaryings: Nullable<string[]> = null,\r\n _createShaderProgramInjection?: typeof _createShaderProgram\r\n): WebGLProgram {\r\n const stateObject = getStateObject(context);\r\n if (!_createShaderProgramInjection) {\r\n _createShaderProgramInjection = stateObject._createShaderProgramInjection ?? _createShaderProgram;\r\n }\r\n const shaderVersion = stateObject._webGLVersion > 1 ? \"#version 300 es\\n#define WEBGL2 \\n\" : \"\";\r\n const vertexShader = _compileShader(vertexCode, \"vertex\", defines, shaderVersion, context, stateObject._contextWasLost);\r\n const fragmentShader = _compileShader(fragmentCode, \"fragment\", defines, shaderVersion, context, stateObject._contextWasLost);\r\n\r\n return _createShaderProgramInjection(\r\n pipelineContext as WebGLPipelineContext,\r\n vertexShader,\r\n fragmentShader,\r\n context,\r\n transformFeedbackVaryings,\r\n stateObject.validateShaderPrograms\r\n );\r\n}\r\n\r\n/**\r\n * Creates a new pipeline context. Note, make sure to attach an engine instance to the created context\r\n * @param context defines the webGL context to use (if not set, the current one will be used)\r\n * @param _shaderProcessingContext defines the shader processing context used during the processing if available\r\n * @returns the new pipeline\r\n */\r\nexport function createPipelineContext(context: WebGLContext, _shaderProcessingContext: Nullable<ShaderProcessingContext>): IPipelineContext {\r\n const pipelineContext = new WebGLPipelineContext();\r\n const stateObject = getStateObject(context);\r\n if (stateObject.parallelShaderCompile) {\r\n pipelineContext.isParallelCompiled = true;\r\n }\r\n pipelineContext.context = stateObject._context;\r\n return pipelineContext;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function _createShaderProgram(\r\n pipelineContext: WebGLPipelineContext,\r\n vertexShader: WebGLShader,\r\n fragmentShader: WebGLShader,\r\n context: WebGLContext,\r\n _transformFeedbackVaryings: Nullable<string[]> = null,\r\n validateShaderPrograms?: boolean\r\n): WebGLProgram {\r\n const shaderProgram = context.createProgram();\r\n pipelineContext.program = shaderProgram;\r\n\r\n if (!shaderProgram) {\r\n throw new Error(\"Unable to create program\");\r\n }\r\n\r\n context.attachShader(shaderProgram, vertexShader);\r\n context.attachShader(shaderProgram, fragmentShader);\r\n\r\n context.linkProgram(shaderProgram);\r\n\r\n pipelineContext.context = context;\r\n pipelineContext.vertexShader = vertexShader;\r\n pipelineContext.fragmentShader = fragmentShader;\r\n\r\n if (!pipelineContext.isParallelCompiled) {\r\n _finalizePipelineContext(pipelineContext, context, validateShaderPrograms);\r\n }\r\n\r\n return shaderProgram;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function _finalizePipelineContext(pipelineContext: WebGLPipelineContext, gl: WebGLContext, validateShaderPrograms?: boolean) {\r\n const context = pipelineContext.context!;\r\n const vertexShader = pipelineContext.vertexShader!;\r\n const fragmentShader = pipelineContext.fragmentShader!;\r\n const program = pipelineContext.program!;\r\n\r\n const linked = context.getProgramParameter(program, context.LINK_STATUS);\r\n if (!linked) {\r\n // Get more info\r\n // Vertex\r\n if (gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {\r\n const log = gl.getShaderInfoLog(vertexShader);\r\n if (log) {\r\n pipelineContext.vertexCompilationError = log;\r\n throw new Error(\"VERTEX SHADER \" + log);\r\n }\r\n }\r\n\r\n // Fragment\r\n if (!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS)) {\r\n const log = gl.getShaderInfoLog(fragmentShader);\r\n if (log) {\r\n pipelineContext.fragmentCompilationError = log;\r\n throw new Error(\"FRAGMENT SHADER \" + log);\r\n }\r\n }\r\n\r\n const error = context.getProgramInfoLog(program);\r\n if (error) {\r\n pipelineContext.programLinkError = error;\r\n throw new Error(error);\r\n }\r\n }\r\n\r\n if (/*this.*/ validateShaderPrograms) {\r\n context.validateProgram(program);\r\n const validated = context.getProgramParameter(program, context.VALIDATE_STATUS);\r\n\r\n if (!validated) {\r\n const error = context.getProgramInfoLog(program);\r\n if (error) {\r\n pipelineContext.programValidationError = error;\r\n throw new Error(error);\r\n }\r\n }\r\n }\r\n\r\n context.deleteShader(vertexShader);\r\n context.deleteShader(fragmentShader);\r\n\r\n pipelineContext.vertexShader = undefined;\r\n pipelineContext.fragmentShader = undefined;\r\n\r\n if (pipelineContext.onCompiled) {\r\n pipelineContext.onCompiled();\r\n pipelineContext.onCompiled = undefined;\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function _preparePipelineContext(\r\n pipelineContext: IPipelineContext,\r\n vertexSourceCode: string,\r\n fragmentSourceCode: string,\r\n createAsRaw: boolean,\r\n _rawVertexSourceCode: string,\r\n _rawFragmentSourceCode: string,\r\n rebuildRebind: any,\r\n defines: Nullable<string>,\r\n transformFeedbackVaryings: Nullable<string[]>,\r\n _key: string = \"\",\r\n createRawShaderProgramInjection?: typeof createRawShaderProgram,\r\n createShaderProgramInjection?: typeof createShaderProgram\r\n) {\r\n const stateObject = getStateObject((pipelineContext as WebGLPipelineContext).context!);\r\n if (!createRawShaderProgramInjection) {\r\n createRawShaderProgramInjection = stateObject.createRawShaderProgramInjection ?? createRawShaderProgram;\r\n }\r\n if (!createShaderProgramInjection) {\r\n createShaderProgramInjection = stateObject.createShaderProgramInjection ?? createShaderProgram;\r\n }\r\n const webGLRenderingState = pipelineContext as WebGLPipelineContext;\r\n\r\n if (createAsRaw) {\r\n webGLRenderingState.program = createRawShaderProgramInjection(\r\n webGLRenderingState,\r\n vertexSourceCode,\r\n fragmentSourceCode,\r\n webGLRenderingState.context!,\r\n transformFeedbackVaryings\r\n );\r\n } else {\r\n webGLRenderingState.program = createShaderProgramInjection(\r\n webGLRenderingState,\r\n vertexSourceCode,\r\n fragmentSourceCode,\r\n defines,\r\n webGLRenderingState.context!,\r\n transformFeedbackVaryings\r\n );\r\n }\r\n webGLRenderingState.program.__SPECTOR_rebuildProgram = rebuildRebind;\r\n}\r\n\r\nfunction _compileShader(source: string, type: string, defines: Nullable<string>, shaderVersion: string, gl: WebGLContext, _contextWasLost?: boolean): WebGLShader {\r\n return _compileRawShader(_ConcatenateShader(source, defines, shaderVersion), type, gl, _contextWasLost);\r\n}\r\n\r\nfunction _compileRawShader(source: string, type: string, gl: WebGLContext, _contextWasLost?: boolean): WebGLShader {\r\n const shader = gl.createShader(type === \"vertex\" ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER);\r\n\r\n if (!shader) {\r\n let error: GLenum = gl.NO_ERROR;\r\n let tempError: GLenum = gl.NO_ERROR;\r\n while ((tempError = gl.getError()) !== gl.NO_ERROR) {\r\n error = tempError;\r\n }\r\n\r\n throw new Error(\r\n `Something went wrong while creating a gl ${type} shader object. gl error=${error}, gl isContextLost=${gl.isContextLost()}, _contextWasLost=${_contextWasLost}`\r\n );\r\n }\r\n\r\n gl.shaderSource(shader, source);\r\n gl.compileShader(shader);\r\n\r\n return shader;\r\n}\r\n\r\n/**\r\n * Binds an effect to the webGL context\r\n * @param pipelineContext defines the pipeline context to use\r\n * @param samplers defines the list of webGL samplers to bind\r\n * @param uniforms defines the list of webGL uniforms to bind\r\n * @returns the webGL program\r\n */\r\nexport function bindSamplers(\r\n pipelineContext: IPipelineContext,\r\n samplers: string[],\r\n uniforms: {\r\n [key: string]: Nullable<WebGLUniformLocation>;\r\n }\r\n) {\r\n const webGLPipelineContext = pipelineContext as WebGLPipelineContext;\r\n _setProgram(webGLPipelineContext.program!, webGLPipelineContext.context!);\r\n const _boundUniforms: Nullable<WebGLUniformLocation>[] = [];\r\n for (let index = 0; index < samplers.length; index++) {\r\n const uniform = uniforms[samplers[index]];\r\n\r\n if (uniform) {\r\n _boundUniforms[index] = uniform;\r\n }\r\n }\r\n return _boundUniforms;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function _setProgram(program: WebGLProgram, gl: WebGLContext): void {\r\n gl.useProgram(program);\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function _executeWhenRenderingStateIsCompiled(pipelineContext: IPipelineContext, action: (pipelineContext?: IPipelineContext) => void) {\r\n const webGLPipelineContext = pipelineContext as WebGLPipelineContext;\r\n\r\n if (!webGLPipelineContext.isParallelCompiled) {\r\n action(pipelineContext);\r\n return;\r\n }\r\n\r\n const oldHandler = webGLPipelineContext.onCompiled;\r\n\r\n webGLPipelineContext.onCompiled = () => {\r\n oldHandler?.();\r\n action(pipelineContext);\r\n };\r\n}\r\n"]}
1
+ {"version":3,"file":"thinEngine.functions.js","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AAC,OAAqB,EAAE,EAAgB;IAC/D,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AAC3B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oCAAoC,CAAC,eAAiC,EAAE,MAAoD;IACxI,MAAM,oBAAoB,GAAG,eAAuC,CAAC;IAErE,IAAI,CAAC,oBAAoB,CAAC,kBAAkB,EAAE;QAC1C,MAAM,CAAC,eAAe,CAAC,CAAC;QACxB,OAAO;KACV;IAED,MAAM,UAAU,GAAG,oBAAoB,CAAC,UAAU,CAAC;IAEnD,oBAAoB,CAAC,UAAU,GAAG,GAAG,EAAE;QACnC,UAAU,EAAE,EAAE,CAAC;QACf,MAAM,CAAC,eAAe,CAAC,CAAC;IAC5B,CAAC,CAAC;AACN,CAAC","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport type { IPipelineContext } from \"./IPipelineContext\";\r\nimport type { ShaderProcessingContext } from \"./Processors/shaderProcessingOptions\";\r\nimport { WebGLPipelineContext } from \"./WebGL/webGLPipelineContext\";\r\nimport type { _loadFile } from \"./abstractEngine.functions\";\r\nimport { _ConcatenateShader } from \"./abstractEngine.functions\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport interface IThinEngineStateObject {\r\n _contextWasLost?: boolean;\r\n validateShaderPrograms?: boolean;\r\n _webGLVersion: number;\r\n parallelShaderCompile?: { COMPLETION_STATUS_KHR: number };\r\n _context?: WebGLContext;\r\n _createShaderProgramInjection?: typeof _createShaderProgram;\r\n createRawShaderProgramInjection?: typeof createRawShaderProgram;\r\n createShaderProgramInjection?: typeof createShaderProgram;\r\n loadFileInjection?: typeof _loadFile;\r\n cachedPipelines: { [name: string]: IPipelineContext };\r\n}\r\n/**\r\n * @internal\r\n */\r\nconst _stateObject: WeakMap<WebGLContext, IThinEngineStateObject> = new WeakMap();\r\n\r\n/**\r\n * This will be used in cases where the engine doesn't have a context (like the nullengine)\r\n */\r\nconst singleStateObject: IThinEngineStateObject = {\r\n _webGLVersion: 2,\r\n cachedPipelines: {},\r\n};\r\n\r\n/**\r\n * get or create a state object for the given context\r\n * Note - Used in WebGL only at the moment.\r\n * @param context The context to get the state object from\r\n * @returns the state object\r\n * @internal\r\n */\r\nexport function getStateObject(context: WebGLContext): IThinEngineStateObject {\r\n let state = _stateObject.get(context);\r\n if (!state) {\r\n if (!context) {\r\n return singleStateObject;\r\n }\r\n state = {\r\n // use feature detection. instanceof returns false. This only exists on WebGL2 context\r\n _webGLVersion: (context as WebGL2RenderingContext).TEXTURE_BINDING_3D ? 2 : 1,\r\n _context: context,\r\n cachedPipelines: {},\r\n };\r\n _stateObject.set(context, state);\r\n }\r\n return state;\r\n}\r\n/**\r\n * Remove the state object that belongs to the specific context\r\n * @param context the context that is being\r\n */\r\nexport function deleteStateObject(context: WebGLContext): void {\r\n _stateObject.delete(context);\r\n}\r\n\r\nexport type WebGLContext = WebGLRenderingContext | WebGL2RenderingContext;\r\n/**\r\n * Directly creates a webGL program\r\n * @param pipelineContext defines the pipeline context to attach to\r\n * @param vertexCode defines the vertex shader code to use\r\n * @param fragmentCode defines the fragment shader code to use\r\n * @param context defines the webGL context to use (if not set, the current one will be used)\r\n * @param transformFeedbackVaryings defines the list of transform feedback varyings to use\r\n * @param _createShaderProgramInjection defines an optional injection to use to create the shader program\r\n * @returns the new webGL program\r\n */\r\nexport function createRawShaderProgram(\r\n pipelineContext: IPipelineContext,\r\n vertexCode: string,\r\n fragmentCode: string,\r\n context: WebGLContext,\r\n transformFeedbackVaryings: Nullable<string[]>,\r\n _createShaderProgramInjection?: typeof _createShaderProgram\r\n): WebGLProgram {\r\n const stateObject = getStateObject(context);\r\n if (!_createShaderProgramInjection) {\r\n _createShaderProgramInjection = stateObject._createShaderProgramInjection ?? _createShaderProgram;\r\n }\r\n\r\n const vertexShader = _compileRawShader(vertexCode, \"vertex\", context, stateObject._contextWasLost);\r\n const fragmentShader = _compileRawShader(fragmentCode, \"fragment\", context, stateObject._contextWasLost);\r\n\r\n return _createShaderProgramInjection(\r\n pipelineContext as WebGLPipelineContext,\r\n vertexShader,\r\n fragmentShader,\r\n context,\r\n transformFeedbackVaryings,\r\n stateObject.validateShaderPrograms\r\n );\r\n}\r\n\r\n/**\r\n * Creates a webGL program\r\n * @param pipelineContext defines the pipeline context to attach to\r\n * @param vertexCode defines the vertex shader code to use\r\n * @param fragmentCode defines the fragment shader code to use\r\n * @param defines defines the string containing the defines to use to compile the shaders\r\n * @param context defines the webGL context to use (if not set, the current one will be used)\r\n * @param transformFeedbackVaryings defines the list of transform feedback varyings to use\r\n * @param _createShaderProgramInjection defines an optional injection to use to create the shader program\r\n * @returns the new webGL program\r\n */\r\nexport function createShaderProgram(\r\n pipelineContext: IPipelineContext,\r\n vertexCode: string,\r\n fragmentCode: string,\r\n defines: Nullable<string>,\r\n context: WebGLContext,\r\n transformFeedbackVaryings: Nullable<string[]> = null,\r\n _createShaderProgramInjection?: typeof _createShaderProgram\r\n): WebGLProgram {\r\n const stateObject = getStateObject(context);\r\n if (!_createShaderProgramInjection) {\r\n _createShaderProgramInjection = stateObject._createShaderProgramInjection ?? _createShaderProgram;\r\n }\r\n const shaderVersion = stateObject._webGLVersion > 1 ? \"#version 300 es\\n#define WEBGL2 \\n\" : \"\";\r\n const vertexShader = _compileShader(vertexCode, \"vertex\", defines, shaderVersion, context, stateObject._contextWasLost);\r\n const fragmentShader = _compileShader(fragmentCode, \"fragment\", defines, shaderVersion, context, stateObject._contextWasLost);\r\n\r\n return _createShaderProgramInjection(\r\n pipelineContext as WebGLPipelineContext,\r\n vertexShader,\r\n fragmentShader,\r\n context,\r\n transformFeedbackVaryings,\r\n stateObject.validateShaderPrograms\r\n );\r\n}\r\n\r\n/**\r\n * Creates a new pipeline context. Note, make sure to attach an engine instance to the created context\r\n * @param context defines the webGL context to use (if not set, the current one will be used)\r\n * @param _shaderProcessingContext defines the shader processing context used during the processing if available\r\n * @returns the new pipeline\r\n */\r\nexport function createPipelineContext(context: WebGLContext, _shaderProcessingContext: Nullable<ShaderProcessingContext>): IPipelineContext {\r\n const pipelineContext = new WebGLPipelineContext();\r\n const stateObject = getStateObject(context);\r\n if (stateObject.parallelShaderCompile) {\r\n pipelineContext.isParallelCompiled = true;\r\n }\r\n pipelineContext.context = stateObject._context;\r\n return pipelineContext;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function _createShaderProgram(\r\n pipelineContext: WebGLPipelineContext,\r\n vertexShader: WebGLShader,\r\n fragmentShader: WebGLShader,\r\n context: WebGLContext,\r\n _transformFeedbackVaryings: Nullable<string[]> = null,\r\n validateShaderPrograms?: boolean\r\n): WebGLProgram {\r\n const shaderProgram = context.createProgram();\r\n pipelineContext.program = shaderProgram;\r\n\r\n if (!shaderProgram) {\r\n throw new Error(\"Unable to create program\");\r\n }\r\n\r\n context.attachShader(shaderProgram, vertexShader);\r\n context.attachShader(shaderProgram, fragmentShader);\r\n\r\n context.linkProgram(shaderProgram);\r\n\r\n pipelineContext.context = context;\r\n pipelineContext.vertexShader = vertexShader;\r\n pipelineContext.fragmentShader = fragmentShader;\r\n\r\n if (!pipelineContext.isParallelCompiled) {\r\n _finalizePipelineContext(pipelineContext, context, validateShaderPrograms);\r\n }\r\n\r\n return shaderProgram;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function _finalizePipelineContext(pipelineContext: WebGLPipelineContext, gl: WebGLContext, validateShaderPrograms?: boolean) {\r\n const context = pipelineContext.context!;\r\n const vertexShader = pipelineContext.vertexShader!;\r\n const fragmentShader = pipelineContext.fragmentShader!;\r\n const program = pipelineContext.program!;\r\n\r\n const linked = context.getProgramParameter(program, context.LINK_STATUS);\r\n if (!linked) {\r\n // Get more info\r\n // Vertex\r\n if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {\r\n const log = gl.getShaderInfoLog(vertexShader);\r\n if (log) {\r\n pipelineContext.vertexCompilationError = log;\r\n throw new Error(\"VERTEX SHADER \" + log);\r\n }\r\n }\r\n\r\n // Fragment\r\n if (!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS)) {\r\n const log = gl.getShaderInfoLog(fragmentShader);\r\n if (log) {\r\n pipelineContext.fragmentCompilationError = log;\r\n throw new Error(\"FRAGMENT SHADER \" + log);\r\n }\r\n }\r\n\r\n const error = context.getProgramInfoLog(program);\r\n if (error) {\r\n pipelineContext.programLinkError = error;\r\n throw new Error(error);\r\n }\r\n }\r\n\r\n if (/*this.*/ validateShaderPrograms) {\r\n context.validateProgram(program);\r\n const validated = context.getProgramParameter(program, context.VALIDATE_STATUS);\r\n\r\n if (!validated) {\r\n const error = context.getProgramInfoLog(program);\r\n if (error) {\r\n pipelineContext.programValidationError = error;\r\n throw new Error(error);\r\n }\r\n }\r\n }\r\n\r\n context.deleteShader(vertexShader);\r\n context.deleteShader(fragmentShader);\r\n\r\n pipelineContext.vertexShader = undefined;\r\n pipelineContext.fragmentShader = undefined;\r\n\r\n if (pipelineContext.onCompiled) {\r\n pipelineContext.onCompiled();\r\n pipelineContext.onCompiled = undefined;\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function _preparePipelineContext(\r\n pipelineContext: IPipelineContext,\r\n vertexSourceCode: string,\r\n fragmentSourceCode: string,\r\n createAsRaw: boolean,\r\n _rawVertexSourceCode: string,\r\n _rawFragmentSourceCode: string,\r\n rebuildRebind: any,\r\n defines: Nullable<string>,\r\n transformFeedbackVaryings: Nullable<string[]>,\r\n _key: string = \"\",\r\n createRawShaderProgramInjection?: typeof createRawShaderProgram,\r\n createShaderProgramInjection?: typeof createShaderProgram\r\n) {\r\n const stateObject = getStateObject((pipelineContext as WebGLPipelineContext).context!);\r\n if (!createRawShaderProgramInjection) {\r\n createRawShaderProgramInjection = stateObject.createRawShaderProgramInjection ?? createRawShaderProgram;\r\n }\r\n if (!createShaderProgramInjection) {\r\n createShaderProgramInjection = stateObject.createShaderProgramInjection ?? createShaderProgram;\r\n }\r\n const webGLRenderingState = pipelineContext as WebGLPipelineContext;\r\n\r\n if (createAsRaw) {\r\n webGLRenderingState.program = createRawShaderProgramInjection(\r\n webGLRenderingState,\r\n vertexSourceCode,\r\n fragmentSourceCode,\r\n webGLRenderingState.context!,\r\n transformFeedbackVaryings\r\n );\r\n } else {\r\n webGLRenderingState.program = createShaderProgramInjection(\r\n webGLRenderingState,\r\n vertexSourceCode,\r\n fragmentSourceCode,\r\n defines,\r\n webGLRenderingState.context!,\r\n transformFeedbackVaryings\r\n );\r\n }\r\n webGLRenderingState.program.__SPECTOR_rebuildProgram = rebuildRebind;\r\n}\r\n\r\nfunction _compileShader(source: string, type: string, defines: Nullable<string>, shaderVersion: string, gl: WebGLContext, _contextWasLost?: boolean): WebGLShader {\r\n return _compileRawShader(_ConcatenateShader(source, defines, shaderVersion), type, gl, _contextWasLost);\r\n}\r\n\r\nfunction _compileRawShader(source: string, type: string, gl: WebGLContext, _contextWasLost?: boolean): WebGLShader {\r\n const shader = gl.createShader(type === \"vertex\" ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER);\r\n\r\n if (!shader) {\r\n let error: GLenum = gl.NO_ERROR;\r\n let tempError: GLenum = gl.NO_ERROR;\r\n while ((tempError = gl.getError()) !== gl.NO_ERROR) {\r\n error = tempError;\r\n }\r\n\r\n throw new Error(\r\n `Something went wrong while creating a gl ${type} shader object. gl error=${error}, gl isContextLost=${gl.isContextLost()}, _contextWasLost=${_contextWasLost}`\r\n );\r\n }\r\n\r\n gl.shaderSource(shader, source);\r\n gl.compileShader(shader);\r\n\r\n return shader;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function _setProgram(program: WebGLProgram, gl: WebGLContext): void {\r\n gl.useProgram(program);\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function _executeWhenRenderingStateIsCompiled(pipelineContext: IPipelineContext, action: (pipelineContext?: IPipelineContext) => void) {\r\n const webGLPipelineContext = pipelineContext as WebGLPipelineContext;\r\n\r\n if (!webGLPipelineContext.isParallelCompiled) {\r\n action(pipelineContext);\r\n return;\r\n }\r\n\r\n const oldHandler = webGLPipelineContext.onCompiled;\r\n\r\n webGLPipelineContext.onCompiled = () => {\r\n oldHandler?.();\r\n action(pipelineContext);\r\n };\r\n}\r\n"]}
@@ -82,13 +82,13 @@ export class ThinEngine extends AbstractEngine {
82
82
  /**
83
83
  * Creates a new engine
84
84
  * @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
85
- * @param antialias defines enable antialiasing (default: false)
85
+ * @param antialias defines whether anti-aliasing should be enabled (default value is "undefined", meaning that the browser may or may not enable it)
86
86
  * @param options defines further options to be sent to the getContext() function
87
87
  * @param adaptToDeviceRatio defines whether to adapt to the device's viewport characteristics (default: false)
88
88
  */
89
89
  constructor(canvasOrContext, antialias, options, adaptToDeviceRatio) {
90
90
  options = options || {};
91
- super((antialias ?? options.antialias) || false, options, adaptToDeviceRatio);
91
+ super(antialias ?? options.antialias, options, adaptToDeviceRatio);
92
92
  /** @internal */
93
93
  this._name = "WebGL";
94
94
  /**
@@ -137,7 +137,7 @@ export class ThinEngine extends AbstractEngine {
137
137
  options.preserveDrawingBuffer = false;
138
138
  }
139
139
  if (options.xrCompatible === undefined) {
140
- options.xrCompatible = true;
140
+ options.xrCompatible = false;
141
141
  }
142
142
  // Exceptions
143
143
  if (navigator && navigator.userAgent) {
@@ -1639,6 +1639,7 @@ export class ThinEngine extends AbstractEngine {
1639
1639
  stateObject._createShaderProgramInjection = this._createShaderProgram.bind(this);
1640
1640
  stateObject.createRawShaderProgramInjection = this.createRawShaderProgram.bind(this);
1641
1641
  stateObject.createShaderProgramInjection = this.createShaderProgram.bind(this);
1642
+ stateObject.loadFileInjection = this._loadFile.bind(this);
1642
1643
  return _preparePipelineContext(pipelineContext, vertexSourceCode, fragmentSourceCode, createAsRaw, _rawVertexSourceCode, _rawFragmentSourceCode, rebuildRebind, defines, transformFeedbackVaryings, _key);
1643
1644
  }
1644
1645
  _createShaderProgram(pipelineContext, vertexShader, fragmentShader, context, transformFeedbackVaryings = null) {
@@ -2388,11 +2389,11 @@ export class ThinEngine extends AbstractEngine {
2388
2389
  * @returns a InternalTexture for assignment back into BABYLON.Texture
2389
2390
  */
2390
2391
  createTexture(url, noMipmap, invertY, scene, samplingMode = 3, onLoad = null, onError = null, buffer = null, fallback = null, format = null, forcedExtension = null, mimeType, loaderOptions, creationFlags, useSRGBBuffer) {
2391
- return this._createTextureBase(url, noMipmap, invertY, scene, samplingMode, onLoad, onError, this._prepareWebGLTexture.bind(this), (potWidth, potHeight, img, extension, texture, continuationCallback) => {
2392
+ return this._createTextureBase(url, noMipmap, invertY, scene, samplingMode, onLoad, onError, (...args) => this._prepareWebGLTexture(...args, format), (potWidth, potHeight, img, extension, texture, continuationCallback) => {
2392
2393
  const gl = this._gl;
2393
2394
  const isPot = img.width === potWidth && img.height === potHeight;
2394
2395
  texture._creationFlags = creationFlags ?? 0;
2395
- const tip = this._getTexImageParametersForCreateTexture(format, extension, texture._useSRGBBuffer);
2396
+ const tip = this._getTexImageParametersForCreateTexture(texture.format, texture._useSRGBBuffer);
2396
2397
  if (isPot) {
2397
2398
  gl.texImage2D(gl.TEXTURE_2D, 0, tip.internalFormat, tip.format, tip.type, img);
2398
2399
  return false;
@@ -2435,10 +2436,7 @@ export class ThinEngine extends AbstractEngine {
2435
2436
  * @returns The options to pass to texImage2D or texImage3D calls.
2436
2437
  * @internal
2437
2438
  */
2438
- _getTexImageParametersForCreateTexture(babylonFormat, fileExtension, useSRGBBuffer) {
2439
- if (babylonFormat === undefined || babylonFormat === null) {
2440
- babylonFormat = fileExtension === ".jpg" && !useSRGBBuffer ? 4 : 5;
2441
- }
2439
+ _getTexImageParametersForCreateTexture(babylonFormat, useSRGBBuffer) {
2442
2440
  let format, internalFormat;
2443
2441
  if (this.webGLVersion === 1) {
2444
2442
  // In WebGL 1, format and internalFormat must be the same and taken from a limited set of values, see https://docs.gl/es2/glTexImage2D.
@@ -2535,6 +2533,23 @@ export class ThinEngine extends AbstractEngine {
2535
2533
  createRawTexture2DArray(data, width, height, depth, format, generateMipMaps, invertY, samplingMode, compression = null, textureType = 0) {
2536
2534
  throw _WarnImport("Engine.RawTexture");
2537
2535
  }
2536
+ // eslint-disable-next-line jsdoc/require-returns-check
2537
+ /**
2538
+ * Create a cube texture from prefiltered data (ie. the mipmaps contain ready to use data for PBR reflection)
2539
+ * @param rootUrl defines the url where the file to load is located
2540
+ * @param scene defines the current scene
2541
+ * @param lodScale defines scale to apply to the mip map selection
2542
+ * @param lodOffset defines offset to apply to the mip map selection
2543
+ * @param onLoad defines an optional callback raised when the texture is loaded
2544
+ * @param onError defines an optional callback raised if there is an issue to load the texture
2545
+ * @param format defines the format of the data
2546
+ * @param forcedExtension defines the extension to use to pick the right loader
2547
+ * @param createPolynomials defines wheter or not to create polynomails harmonics for the texture
2548
+ * @returns the cube texture as an InternalTexture
2549
+ */
2550
+ createPrefilteredCubeTexture(rootUrl, scene, lodScale, lodOffset, onLoad, onError, format, forcedExtension, createPolynomials) {
2551
+ throw _WarnImport("Misc/dds");
2552
+ }
2538
2553
  /**
2539
2554
  * @internal
2540
2555
  */
@@ -2800,7 +2815,7 @@ export class ThinEngine extends AbstractEngine {
2800
2815
  texture.onLoadedObservable.notifyObservers(texture);
2801
2816
  texture.onLoadedObservable.clear();
2802
2817
  }
2803
- _prepareWebGLTexture(texture, extension, scene, img, invertY, noMipmap, isCompressed, processFunction, samplingMode = 3) {
2818
+ _prepareWebGLTexture(texture, extension, scene, img, invertY, noMipmap, isCompressed, processFunction, samplingMode, format) {
2804
2819
  const maxTextureSize = this.getCaps().maxTextureSize;
2805
2820
  const potWidth = Math.min(maxTextureSize, this.needPOTTextures ? GetExponentOfTwo(img.width, maxTextureSize) : img.width);
2806
2821
  const potHeight = Math.min(maxTextureSize, this.needPOTTextures ? GetExponentOfTwo(img.height, maxTextureSize) : img.height);
@@ -2823,7 +2838,8 @@ export class ThinEngine extends AbstractEngine {
2823
2838
  texture.height = potHeight;
2824
2839
  texture.isReady = true;
2825
2840
  texture.type = texture.type !== -1 ? texture.type : 0;
2826
- texture.format = texture.format !== -1 ? texture.format : extension === ".jpg" && !texture._useSRGBBuffer ? 4 : 5;
2841
+ texture.format =
2842
+ texture.format !== -1 ? texture.format : format ?? (extension === ".jpg" && !texture._useSRGBBuffer ? 4 : 5);
2827
2843
  if (processFunction(potWidth, potHeight, img, extension, texture, () => {
2828
2844
  this._prepareWebGLTextureContinuation(texture, scene, noMipmap, isCompressed, samplingMode);
2829
2845
  })) {