@babylonjs/core 6.48.1 → 7.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 (78) hide show
  1. package/Behaviors/Meshes/baseSixDofDragBehavior.js +6 -6
  2. package/Behaviors/Meshes/baseSixDofDragBehavior.js.map +1 -1
  3. package/Behaviors/Meshes/sixDofDragBehavior.d.ts +1 -0
  4. package/Behaviors/Meshes/sixDofDragBehavior.js +5 -1
  5. package/Behaviors/Meshes/sixDofDragBehavior.js.map +1 -1
  6. package/Compute/computeEffect.d.ts +24 -2
  7. package/Compute/computeEffect.js +5 -9
  8. package/Compute/computeEffect.js.map +1 -1
  9. package/Compute/computeShader.d.ts +4 -4
  10. package/Compute/computeShader.js +1 -1
  11. package/Compute/computeShader.js.map +1 -1
  12. package/Engines/Extensions/engine.computeShader.d.ts +7 -2
  13. package/Engines/Extensions/engine.computeShader.js.map +1 -1
  14. package/Engines/ICanvas.d.ts +10 -0
  15. package/Engines/ICanvas.js.map +1 -1
  16. package/Engines/Native/nativeDataStream.d.ts +2 -1
  17. package/Engines/Native/nativeDataStream.js.map +1 -1
  18. package/Engines/Native/nativePipelineContext.js.map +1 -1
  19. package/Engines/WebGL/webGLPipelineContext.js.map +1 -1
  20. package/Engines/WebGPU/Extensions/engine.computeShader.js +1 -1
  21. package/Engines/WebGPU/Extensions/engine.computeShader.js.map +1 -1
  22. package/Engines/WebGPU/webgpuShaderProcessorsWGSL.js +6 -4
  23. package/Engines/WebGPU/webgpuShaderProcessorsWGSL.js.map +1 -1
  24. package/Engines/nativeEngine.d.ts +2 -2
  25. package/Engines/nativeEngine.js.map +1 -1
  26. package/Engines/thinEngine.d.ts +7 -4
  27. package/Engines/thinEngine.js +4 -4
  28. package/Engines/thinEngine.js.map +1 -1
  29. package/Engines/webgpuEngine.d.ts +5 -2
  30. package/Engines/webgpuEngine.js +3 -3
  31. package/Engines/webgpuEngine.js.map +1 -1
  32. package/Materials/Node/nodeMaterialBuildState.js +1 -1
  33. package/Materials/Node/nodeMaterialBuildState.js.map +1 -1
  34. package/Materials/PBR/pbrSubSurfaceConfiguration.js +6 -0
  35. package/Materials/PBR/pbrSubSurfaceConfiguration.js.map +1 -1
  36. package/Materials/effect.d.ts +37 -2
  37. package/Materials/effect.js +10 -14
  38. package/Materials/effect.js.map +1 -1
  39. package/Materials/shaderMaterial.d.ts +5 -9
  40. package/Materials/shaderMaterial.js +2 -6
  41. package/Materials/shaderMaterial.js.map +1 -1
  42. package/Maths/math.like.d.ts +2 -2
  43. package/Maths/math.like.js.map +1 -1
  44. package/Maths/math.vector.d.ts +1 -1
  45. package/Maths/math.vector.js.map +1 -1
  46. package/Maths/tensor.d.ts +12 -8
  47. package/Maths/tensor.js.map +1 -1
  48. package/Meshes/Node/Blocks/geometryDistanceBlock.js +1 -0
  49. package/Meshes/Node/Blocks/geometryDistanceBlock.js.map +1 -1
  50. package/Meshes/Node/Blocks/geometryDotBlock.js +1 -0
  51. package/Meshes/Node/Blocks/geometryDotBlock.js.map +1 -1
  52. package/Meshes/Node/Blocks/geometryLengthBlock.js +1 -0
  53. package/Meshes/Node/Blocks/geometryLengthBlock.js.map +1 -1
  54. package/Meshes/Node/Blocks/geometryTrigonometryBlock.js +1 -0
  55. package/Meshes/Node/Blocks/geometryTrigonometryBlock.js.map +1 -1
  56. package/Meshes/abstractMesh.d.ts +5 -2
  57. package/Meshes/abstractMesh.js +5 -2
  58. package/Meshes/abstractMesh.js.map +1 -1
  59. package/Meshes/thinInstanceMesh.d.ts +9 -0
  60. package/Meshes/thinInstanceMesh.js +31 -4
  61. package/Meshes/thinInstanceMesh.js.map +1 -1
  62. package/Particles/pointsCloudSystem.js +26 -29
  63. package/Particles/pointsCloudSystem.js.map +1 -1
  64. package/Rendering/GlobalIllumination/giRSMManager.d.ts +1 -1
  65. package/Rendering/GlobalIllumination/giRSMManager.js +1 -1
  66. package/Rendering/GlobalIllumination/giRSMManager.js.map +1 -1
  67. package/Rendering/reflectiveShadowMap.d.ts +5 -4
  68. package/Rendering/reflectiveShadowMap.js +1 -1
  69. package/Rendering/reflectiveShadowMap.js.map +1 -1
  70. package/Shaders/ShadersInclude/pbrDebug.js +1 -1
  71. package/Shaders/ShadersInclude/pbrDebug.js.map +1 -1
  72. package/Shaders/pbr.vertex.js +1 -1
  73. package/Shaders/pbr.vertex.js.map +1 -1
  74. package/XR/features/WebXRControllerPointerSelection.js +11 -0
  75. package/XR/features/WebXRControllerPointerSelection.js.map +1 -1
  76. package/package.json +1 -1
  77. package/types.d.ts +1 -1
  78. package/types.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"computeEffect.js","sourceRoot":"","sources":["../../../../dev/core/src/Compute/computeEffect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAExE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AA8B7D;;GAEG;AACH,MAAM,OAAO,aAAa;IAgEtB;;;;;;OAMG;IACH,YAAY,QAAa,EAAE,OAAsC,EAAE,MAAc,EAAE,GAAG,GAAG,EAAE;QAhE3F;;WAEG;QACI,SAAI,GAAQ,IAAI,CAAC;QACxB;;WAEG;QACI,YAAO,GAAW,EAAE,CAAC;QAC5B;;WAEG;QACI,eAAU,GAA8C,IAAI,CAAC;QACpE;;WAEG;QACI,YAAO,GAA8D,IAAI,CAAC;QACjF;;WAEG;QACI,aAAQ,GAAG,CAAC,CAAC;QACpB;;;WAGG;QACI,wBAAmB,GAAG,IAAI,UAAU,EAAiB,CAAC;QAC7D;;WAEG;QACI,sBAAiB,GAAG,IAAI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,CAAC,gBAAgB,EAAE;YACvB,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC;SACnC;QACD,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,cAAc,CAAC,IAAY,EAAE,aAAqB;QAC5D,WAAW,CAAC,eAAe,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,eAAe,CAAC,GAAG,aAAa,CAAC;IAC7F,CAAC;;AAzZc,2BAAa,GAAG,CAAC,AAAJ,CAAK;AAEjC;;GAEG;AACW,6CAA+B,GAAG,IAAI,AAAP,CAAQ","sourcesContent":["import { Logger } from \"../Misc/logger\";\r\nimport type { Nullable } from \"../types\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { IComputePipelineContext } from \"./IComputePipelineContext\";\r\nimport { GetDOMTextContent, IsWindowObjectExist } from \"../Misc/domManagement\";\r\nimport { ShaderProcessor } from \"../Engines/Processors/shaderProcessor\";\r\nimport type { ProcessingOptions } from \"../Engines/Processors/shaderProcessingOptions\";\r\nimport { ShaderStore } from \"../Engines/shaderStore\";\r\nimport { ShaderLanguage } from \"../Materials/shaderLanguage\";\r\n\r\nimport type { Engine } from \"../Engines/engine\";\r\n\r\n/**\r\n * Options to be used when creating a compute effect.\r\n */\r\nexport interface IComputeEffectCreationOptions {\r\n /**\r\n * Define statements that will be set in the shader.\r\n */\r\n defines: any;\r\n /**\r\n * The name of the entry point in the shader source (default: \"main\")\r\n */\r\n entryPoint?: string;\r\n /**\r\n * Callback that will be called when the shader is compiled.\r\n */\r\n onCompiled: Nullable<(effect: ComputeEffect) => void>;\r\n /**\r\n * Callback that will be called if an error occurs during shader compilation.\r\n */\r\n onError: Nullable<(effect: ComputeEffect, errors: string) => void>;\r\n /**\r\n * If provided, will be called with the shader code so that this code can be updated before it is compiled by the GPU\r\n */\r\n processFinalCode?: Nullable<(code: string) => string>;\r\n}\r\n\r\n/**\r\n * Effect wrapping a compute shader and let execute (dispatch) the shader\r\n */\r\nexport class ComputeEffect {\r\n private static _UniqueIdSeed = 0;\r\n\r\n /**\r\n * Enable logging of the shader code when a compilation error occurs\r\n */\r\n public static LogShaderCodeOnCompilationError = true;\r\n /**\r\n * Name of the effect.\r\n */\r\n public name: any = null;\r\n /**\r\n * String container all the define statements that should be set on the shader.\r\n */\r\n public defines: string = \"\";\r\n /**\r\n * Callback that will be called when the shader is compiled.\r\n */\r\n public onCompiled: Nullable<(effect: ComputeEffect) => void> = null;\r\n /**\r\n * Callback that will be called if an error occurs during shader compilation.\r\n */\r\n public onError: Nullable<(effect: ComputeEffect, errors: string) => void> = null;\r\n /**\r\n * Unique ID of the effect.\r\n */\r\n public uniqueId = 0;\r\n /**\r\n * Observable that will be called when the shader is compiled.\r\n * It is recommended to use executeWhenCompile() or to make sure that scene.isReady() is called to get this observable raised.\r\n */\r\n public onCompileObservable = new Observable<ComputeEffect>();\r\n /**\r\n * Observable that will be called if an error occurs during shader compilation.\r\n */\r\n public onErrorObservable = new Observable<ComputeEffect>();\r\n /**\r\n * Observable that will be called when effect is bound.\r\n */\r\n public onBindObservable = new Observable<ComputeEffect>();\r\n\r\n /**\r\n * @internal\r\n * Specifies if the effect was previously ready\r\n */\r\n public _wasPreviouslyReady = false;\r\n\r\n private _engine: Engine;\r\n private _isReady = false;\r\n private _compilationError = \"\";\r\n /** @internal */\r\n public _key: string = \"\";\r\n private _computeSourceCodeOverride: string = \"\";\r\n /** @internal */\r\n public _pipelineContext: Nullable<IComputePipelineContext> = null;\r\n /** @internal */\r\n public _computeSourceCode: string = \"\";\r\n private _rawComputeSourceCode: string = \"\";\r\n private _entryPoint: string;\r\n private _shaderLanguage = ShaderLanguage.WGSL;\r\n private _shaderStore: { [key: string]: string };\r\n private _shaderRepository: string;\r\n private _includeShaderStore: { [key: string]: string };\r\n\r\n /**\r\n * Creates a compute effect that can be used to execute a compute shader\r\n * @param baseName Name of the effect\r\n * @param options Set of all options to create the effect\r\n * @param engine The engine the effect is created for\r\n * @param key Effect Key identifying uniquely compiled shader variants\r\n */\r\n constructor(baseName: any, options: IComputeEffectCreationOptions, engine: Engine, key = \"\") {\r\n this.name = baseName;\r\n this._key = key;\r\n\r\n this._engine = engine;\r\n this.uniqueId = ComputeEffect._UniqueIdSeed++;\r\n\r\n this.defines = options.defines ?? \"\";\r\n this.onError = options.onError;\r\n this.onCompiled = options.onCompiled;\r\n this._entryPoint = options.entryPoint ?? \"main\";\r\n\r\n this._shaderStore = ShaderStore.GetShadersStore(this._shaderLanguage);\r\n this._shaderRepository = ShaderStore.GetShadersRepository(this._shaderLanguage);\r\n this._includeShaderStore = ShaderStore.GetIncludesShadersStore(this._shaderLanguage);\r\n\r\n let computeSource: any;\r\n\r\n const hostDocument = IsWindowObjectExist() ? this._engine.getHostDocument() : null;\r\n\r\n if (baseName.computeSource) {\r\n computeSource = \"source:\" + baseName.computeSource;\r\n } else if (baseName.computeElement) {\r\n computeSource = hostDocument ? hostDocument.getElementById(baseName.computeElement) : null;\r\n\r\n if (!computeSource) {\r\n computeSource = baseName.computeElement;\r\n }\r\n } else {\r\n computeSource = baseName.compute || baseName;\r\n }\r\n\r\n const processorOptions: ProcessingOptions = {\r\n defines: this.defines.split(\"\\n\"),\r\n indexParameters: undefined,\r\n isFragment: false,\r\n shouldUseHighPrecisionShader: false,\r\n processor: null,\r\n supportsUniformBuffers: this._engine.supportsUniformBuffers,\r\n shadersRepository: this._shaderRepository,\r\n includesShadersStore: this._includeShaderStore,\r\n version: (this._engine.version * 100).toString(),\r\n platformName: this._engine.shaderPlatformName,\r\n processingContext: null,\r\n isNDCHalfZRange: this._engine.isNDCHalfZRange,\r\n useReverseDepthBuffer: this._engine.useReverseDepthBuffer,\r\n };\r\n\r\n this._loadShader(computeSource, \"Compute\", \"\", (computeCode) => {\r\n ShaderProcessor.Initialize(processorOptions);\r\n ShaderProcessor.PreProcess(\r\n computeCode,\r\n processorOptions,\r\n (migratedCommputeCode) => {\r\n this._rawComputeSourceCode = computeCode;\r\n if (options.processFinalCode) {\r\n migratedCommputeCode = options.processFinalCode(migratedCommputeCode);\r\n }\r\n const finalShaders = ShaderProcessor.Finalize(migratedCommputeCode, \"\", processorOptions);\r\n this._useFinalCode(finalShaders.vertexCode, baseName);\r\n },\r\n this._engine\r\n );\r\n });\r\n }\r\n\r\n private _useFinalCode(migratedCommputeCode: string, baseName: any) {\r\n if (baseName) {\r\n const compute = baseName.computeElement || baseName.compute || baseName.spectorName || baseName;\r\n\r\n this._computeSourceCode = \"//#define SHADER_NAME compute:\" + compute + \"\\n\" + migratedCommputeCode;\r\n } else {\r\n this._computeSourceCode = migratedCommputeCode;\r\n }\r\n this._prepareEffect();\r\n }\r\n\r\n /**\r\n * Unique key for this effect\r\n */\r\n public get key(): string {\r\n return this._key;\r\n }\r\n\r\n /**\r\n * If the effect has been compiled and prepared.\r\n * @returns if the effect is compiled and prepared.\r\n */\r\n public isReady(): boolean {\r\n try {\r\n return this._isReadyInternal();\r\n } catch {\r\n return false;\r\n }\r\n }\r\n\r\n private _isReadyInternal(): boolean {\r\n if (this._isReady) {\r\n return true;\r\n }\r\n if (this._pipelineContext) {\r\n return this._pipelineContext.isReady;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * The engine the effect was initialized with.\r\n * @returns the engine.\r\n */\r\n public getEngine(): Engine {\r\n return this._engine;\r\n }\r\n\r\n /**\r\n * The pipeline context for this effect\r\n * @returns the associated pipeline context\r\n */\r\n public getPipelineContext(): Nullable<IComputePipelineContext> {\r\n return this._pipelineContext;\r\n }\r\n\r\n /**\r\n * The error from the last compilation.\r\n * @returns the error string.\r\n */\r\n public getCompilationError(): string {\r\n return this._compilationError;\r\n }\r\n\r\n /**\r\n * Adds a callback to the onCompiled observable and call the callback immediately if already ready.\r\n * @param func The callback to be used.\r\n */\r\n public executeWhenCompiled(func: (effect: ComputeEffect) => void): void {\r\n if (this.isReady()) {\r\n func(this);\r\n return;\r\n }\r\n\r\n this.onCompileObservable.add((effect) => {\r\n func(effect);\r\n });\r\n\r\n if (!this._pipelineContext || this._pipelineContext.isAsync) {\r\n setTimeout(() => {\r\n this._checkIsReady(null);\r\n }, 16);\r\n }\r\n }\r\n\r\n private _checkIsReady(previousPipelineContext: Nullable<IComputePipelineContext>) {\r\n try {\r\n if (this._isReadyInternal()) {\r\n return;\r\n }\r\n } catch (e) {\r\n this._processCompilationErrors(e, previousPipelineContext);\r\n return;\r\n }\r\n\r\n setTimeout(() => {\r\n this._checkIsReady(previousPipelineContext);\r\n }, 16);\r\n }\r\n\r\n private _loadShader(shader: any, key: string, optionalKey: string, callback: (data: any) => void): void {\r\n if (typeof HTMLElement !== \"undefined\") {\r\n // DOM element ?\r\n if (shader instanceof HTMLElement) {\r\n const shaderCode = GetDOMTextContent(shader);\r\n callback(shaderCode);\r\n return;\r\n }\r\n }\r\n\r\n // Direct source ?\r\n if (shader.substr(0, 7) === \"source:\") {\r\n callback(shader.substr(7));\r\n return;\r\n }\r\n\r\n // Base64 encoded ?\r\n if (shader.substr(0, 7) === \"base64:\") {\r\n const shaderBinary = window.atob(shader.substr(7));\r\n callback(shaderBinary);\r\n return;\r\n }\r\n\r\n // Is in local store ?\r\n if (this._shaderStore[shader + key + \"Shader\"]) {\r\n callback(this._shaderStore[shader + key + \"Shader\"]);\r\n return;\r\n }\r\n\r\n if (optionalKey && this._shaderStore[shader + optionalKey + \"Shader\"]) {\r\n callback(this._shaderStore[shader + optionalKey + \"Shader\"]);\r\n return;\r\n }\r\n\r\n let shaderUrl;\r\n\r\n if (shader[0] === \".\" || shader[0] === \"/\" || shader.indexOf(\"http\") > -1) {\r\n shaderUrl = shader;\r\n } else {\r\n shaderUrl = this._shaderRepository + shader;\r\n }\r\n\r\n this._engine._loadFile(shaderUrl + \".\" + key.toLowerCase() + \".fx\", callback);\r\n }\r\n\r\n /**\r\n * Gets the compute shader source code of this effect\r\n */\r\n public get computeSourceCode(): string {\r\n return this._computeSourceCodeOverride ? this._computeSourceCodeOverride : this._pipelineContext?._getComputeShaderCode() ?? this._computeSourceCode;\r\n }\r\n\r\n /**\r\n * Gets the compute shader source code before it has been processed by the preprocessor\r\n */\r\n public get rawComputeSourceCode(): string {\r\n return this._rawComputeSourceCode;\r\n }\r\n\r\n /**\r\n * Prepares the effect\r\n * @internal\r\n */\r\n public _prepareEffect() {\r\n const defines = this.defines;\r\n\r\n const previousPipelineContext = this._pipelineContext;\r\n\r\n this._isReady = false;\r\n\r\n try {\r\n const engine = this._engine;\r\n\r\n this._pipelineContext = engine.createComputePipelineContext();\r\n this._pipelineContext._name = this._key;\r\n\r\n engine._prepareComputePipelineContext(\r\n this._pipelineContext,\r\n this._computeSourceCodeOverride ? this._computeSourceCodeOverride : this._computeSourceCode,\r\n this._rawComputeSourceCode,\r\n this._computeSourceCodeOverride ? null : defines,\r\n this._entryPoint\r\n );\r\n\r\n engine._executeWhenComputeStateIsCompiled(this._pipelineContext, () => {\r\n this._compilationError = \"\";\r\n this._isReady = true;\r\n if (this.onCompiled) {\r\n this.onCompiled(this);\r\n }\r\n this.onCompileObservable.notifyObservers(this);\r\n this.onCompileObservable.clear();\r\n\r\n if (previousPipelineContext) {\r\n this.getEngine()._deleteComputePipelineContext(previousPipelineContext);\r\n }\r\n });\r\n\r\n if (this._pipelineContext.isAsync) {\r\n this._checkIsReady(previousPipelineContext);\r\n }\r\n } catch (e) {\r\n this._processCompilationErrors(e, previousPipelineContext);\r\n }\r\n }\r\n\r\n private _getShaderCodeAndErrorLine(code: Nullable<string>, error: Nullable<string>): [Nullable<string>, Nullable<string>] {\r\n const regexp = /COMPUTE SHADER ERROR: 0:(\\d+?):/;\r\n\r\n let errorLine = null;\r\n\r\n if (error && code) {\r\n const res = error.match(regexp);\r\n if (res && res.length === 2) {\r\n const lineNumber = parseInt(res[1]);\r\n const lines = code.split(\"\\n\", -1);\r\n if (lines.length >= lineNumber) {\r\n errorLine = `Offending line [${lineNumber}] in compute code: ${lines[lineNumber - 1]}`;\r\n }\r\n }\r\n }\r\n\r\n return [code, errorLine];\r\n }\r\n\r\n private _processCompilationErrors(e: any, previousPipelineContext: Nullable<IComputePipelineContext> = null) {\r\n this._compilationError = e.message;\r\n\r\n // Let's go through fallbacks then\r\n Logger.Error(\"Unable to compile compute effect:\");\r\n Logger.Error(\"Defines:\\n\" + this.defines);\r\n if (ComputeEffect.LogShaderCodeOnCompilationError) {\r\n let lineErrorVertex = null,\r\n code = null;\r\n if (this._pipelineContext?._getComputeShaderCode()) {\r\n [code, lineErrorVertex] = this._getShaderCodeAndErrorLine(this._pipelineContext._getComputeShaderCode(), this._compilationError);\r\n if (code) {\r\n Logger.Error(\"Compute code:\");\r\n Logger.Error(code);\r\n }\r\n }\r\n if (lineErrorVertex) {\r\n Logger.Error(lineErrorVertex);\r\n }\r\n }\r\n Logger.Error(\"Error: \" + this._compilationError);\r\n if (previousPipelineContext) {\r\n this._pipelineContext = previousPipelineContext;\r\n this._isReady = true;\r\n if (this.onError) {\r\n this.onError(this, this._compilationError);\r\n }\r\n this.onErrorObservable.notifyObservers(this);\r\n }\r\n }\r\n\r\n /**\r\n * Release all associated resources.\r\n **/\r\n public dispose() {\r\n if (this._pipelineContext) {\r\n this._pipelineContext.dispose();\r\n }\r\n this._engine._releaseComputeEffect(this);\r\n }\r\n\r\n /**\r\n * This function will add a new compute shader to the shader store\r\n * @param name the name of the shader\r\n * @param computeShader compute shader content\r\n */\r\n public static RegisterShader(name: string, computeShader: string) {\r\n ShaderStore.GetShadersStore(ShaderLanguage.WGSL)[`${name}ComputeShader`] = computeShader;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"computeEffect.js","sourceRoot":"","sources":["../../../../dev/core/src/Compute/computeEffect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,u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AAC,IAAI,CAAC,CAAC;iBACtB;aACJ;YACD,IAAI,eAAe,EAAE;gBACjB,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;aACjC;SACJ;QACD,MAAM,CAAC,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,iBAAiB,CAAC,CAAC;QACjD,IAAI,uBAAuB,EAAE;YACzB,IAAI,CAAC,gBAAgB,GAAG,uBAAuB,CAAC;YAChD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;YACrB,IAAI,IAAI,CAAC,OAAO,EAAE;gBACd,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;aAC9C;YACD,IAAI,CAAC,iBAAiB,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;SAChD;IACL,CAAC;IAED;;QAEI;IACG,OAAO;QACV,IAAI,IAAI,CAAC,gBAAgB,EAAE;YACvB,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC;SACnC;QACD,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,cAAc,CAAC,IAAY,EAAE,aAAqB;QAC5D,WAAW,CAAC,eAAe,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,eAAe,CAAC,GAAG,aAAa,CAAC;IAC7F,CAAC;;AAvZc,2BAAa,GAAG,CAAC,AAAJ,CAAK;AAEjC;;GAEG;AACW,6CAA+B,GAAG,IAAI,AAAP,CAAQ","sourcesContent":["import { Logger } from \"../Misc/logger\";\r\nimport type { Nullable } from \"../types\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { IComputePipelineContext } from \"./IComputePipelineContext\";\r\nimport { GetDOMTextContent, IsWindowObjectExist } from \"../Misc/domManagement\";\r\nimport { ShaderProcessor } from \"../Engines/Processors/shaderProcessor\";\r\nimport type { ProcessingOptions } from \"../Engines/Processors/shaderProcessingOptions\";\r\nimport { ShaderStore } from \"../Engines/shaderStore\";\r\nimport { ShaderLanguage } from \"../Materials/shaderLanguage\";\r\n\r\nimport type { Engine } from \"../Engines/engine\";\r\n\r\n/**\r\n * Defines the route to the shader code. The priority is as follows:\r\n * * object: `{ computeSource: \"compute shader code string\"}` for directly passing the shader code\r\n * * object: `{ computeElement: \"vertexShaderCode\" }`, used with shader code in script tags\r\n * * object: `{ compute: \"custom\" }`, used with `Effect.ShadersStore[\"customVertexShader\"]` and `Effect.ShadersStore[\"customFragmentShader\"]`\r\n * * string: `\"./COMMON_NAME\"`, used with external files COMMON_NAME.vertex.fx and COMMON_NAME.fragment.fx in index.html folder.\r\n */\r\nexport type IComputeShaderPath =\r\n | {\r\n /**\r\n * Directly pass the shader code\r\n */\r\n computeSource?: string;\r\n /**\r\n * Used with Effect.ShadersStore. If the `vertex` is set to `\"custom`, then\r\n * Babylon.js will read from Effect.ShadersStore[\"customVertexShader\"]\r\n */\r\n compute?: string;\r\n /**\r\n * Used with shader code in script tags\r\n */\r\n computeElement?: string;\r\n }\r\n | string;\r\n\r\n/**\r\n * Options to be used when creating a compute effect.\r\n */\r\nexport interface IComputeEffectCreationOptions {\r\n /**\r\n * Define statements that will be set in the shader.\r\n */\r\n defines: any;\r\n /**\r\n * The name of the entry point in the shader source (default: \"main\")\r\n */\r\n entryPoint?: string;\r\n /**\r\n * Callback that will be called when the shader is compiled.\r\n */\r\n onCompiled: Nullable<(effect: ComputeEffect) => void>;\r\n /**\r\n * Callback that will be called if an error occurs during shader compilation.\r\n */\r\n onError: Nullable<(effect: ComputeEffect, errors: string) => void>;\r\n /**\r\n * If provided, will be called with the shader code so that this code can be updated before it is compiled by the GPU\r\n */\r\n processFinalCode?: Nullable<(code: string) => string>;\r\n}\r\n\r\n/**\r\n * Effect wrapping a compute shader and let execute (dispatch) the shader\r\n */\r\nexport class ComputeEffect {\r\n private static _UniqueIdSeed = 0;\r\n\r\n /**\r\n * Enable logging of the shader code when a compilation error occurs\r\n */\r\n public static LogShaderCodeOnCompilationError = true;\r\n /**\r\n * Name of the effect.\r\n */\r\n public name: IComputeShaderPath;\r\n /**\r\n * String container all the define statements that should be set on the shader.\r\n */\r\n public defines: string = \"\";\r\n /**\r\n * Callback that will be called when the shader is compiled.\r\n */\r\n public onCompiled: Nullable<(effect: ComputeEffect) => void> = null;\r\n /**\r\n * Callback that will be called if an error occurs during shader compilation.\r\n */\r\n public onError: Nullable<(effect: ComputeEffect, errors: string) => void> = null;\r\n /**\r\n * Unique ID of the effect.\r\n */\r\n public uniqueId = 0;\r\n /**\r\n * Observable that will be called when the shader is compiled.\r\n * It is recommended to use executeWhenCompile() or to make sure that scene.isReady() is called to get this observable raised.\r\n */\r\n public onCompileObservable = new Observable<ComputeEffect>();\r\n /**\r\n * Observable that will be called if an error occurs during shader compilation.\r\n */\r\n public onErrorObservable = new Observable<ComputeEffect>();\r\n /**\r\n * Observable that will be called when effect is bound.\r\n */\r\n public onBindObservable = new Observable<ComputeEffect>();\r\n\r\n /**\r\n * @internal\r\n * Specifies if the effect was previously ready\r\n */\r\n public _wasPreviouslyReady = false;\r\n\r\n private _engine: Engine;\r\n private _isReady = false;\r\n private _compilationError = \"\";\r\n /** @internal */\r\n public _key: string = \"\";\r\n private _computeSourceCodeOverride: string = \"\";\r\n /** @internal */\r\n public _pipelineContext: Nullable<IComputePipelineContext> = null;\r\n /** @internal */\r\n public _computeSourceCode: string = \"\";\r\n private _rawComputeSourceCode: string = \"\";\r\n private _entryPoint: string;\r\n private _shaderLanguage = ShaderLanguage.WGSL;\r\n private _shaderStore: { [key: string]: string };\r\n private _shaderRepository: string;\r\n private _includeShaderStore: { [key: string]: string };\r\n\r\n /**\r\n * Creates a compute effect that can be used to execute a compute shader\r\n * @param baseName Name of the effect\r\n * @param options Set of all options to create the effect\r\n * @param engine The engine the effect is created for\r\n * @param key Effect Key identifying uniquely compiled shader variants\r\n */\r\n constructor(baseName: IComputeShaderPath, options: IComputeEffectCreationOptions, engine: Engine, key = \"\") {\r\n this.name = baseName;\r\n this._key = key;\r\n\r\n this._engine = engine;\r\n this.uniqueId = ComputeEffect._UniqueIdSeed++;\r\n\r\n this.defines = options.defines ?? \"\";\r\n this.onError = options.onError;\r\n this.onCompiled = options.onCompiled;\r\n this._entryPoint = options.entryPoint ?? \"main\";\r\n\r\n this._shaderStore = ShaderStore.GetShadersStore(this._shaderLanguage);\r\n this._shaderRepository = ShaderStore.GetShadersRepository(this._shaderLanguage);\r\n this._includeShaderStore = ShaderStore.GetIncludesShadersStore(this._shaderLanguage);\r\n\r\n let computeSource: IComputeShaderPath | HTMLElement;\r\n\r\n const hostDocument = IsWindowObjectExist() ? this._engine.getHostDocument() : null;\r\n\r\n if (typeof baseName === \"string\") {\r\n computeSource = baseName;\r\n } else if (baseName.computeSource) {\r\n computeSource = \"source:\" + baseName.computeSource;\r\n } else if (baseName.computeElement) {\r\n computeSource = hostDocument?.getElementById(baseName.computeElement) || baseName.computeElement;\r\n } else {\r\n computeSource = baseName.compute || baseName;\r\n }\r\n\r\n const processorOptions: ProcessingOptions = {\r\n defines: this.defines.split(\"\\n\"),\r\n indexParameters: undefined,\r\n isFragment: false,\r\n shouldUseHighPrecisionShader: false,\r\n processor: null,\r\n supportsUniformBuffers: this._engine.supportsUniformBuffers,\r\n shadersRepository: this._shaderRepository,\r\n includesShadersStore: this._includeShaderStore,\r\n version: (this._engine.version * 100).toString(),\r\n platformName: this._engine.shaderPlatformName,\r\n processingContext: null,\r\n isNDCHalfZRange: this._engine.isNDCHalfZRange,\r\n useReverseDepthBuffer: this._engine.useReverseDepthBuffer,\r\n };\r\n\r\n this._loadShader(computeSource, \"Compute\", \"\", (computeCode) => {\r\n ShaderProcessor.Initialize(processorOptions);\r\n ShaderProcessor.PreProcess(\r\n computeCode,\r\n processorOptions,\r\n (migratedCommputeCode) => {\r\n this._rawComputeSourceCode = computeCode;\r\n if (options.processFinalCode) {\r\n migratedCommputeCode = options.processFinalCode(migratedCommputeCode);\r\n }\r\n const finalShaders = ShaderProcessor.Finalize(migratedCommputeCode, \"\", processorOptions);\r\n this._useFinalCode(finalShaders.vertexCode, baseName);\r\n },\r\n this._engine\r\n );\r\n });\r\n }\r\n\r\n private _useFinalCode(migratedCommputeCode: string, baseName: any) {\r\n if (baseName) {\r\n const compute = baseName.computeElement || baseName.compute || baseName.spectorName || baseName;\r\n\r\n this._computeSourceCode = \"//#define SHADER_NAME compute:\" + compute + \"\\n\" + migratedCommputeCode;\r\n } else {\r\n this._computeSourceCode = migratedCommputeCode;\r\n }\r\n this._prepareEffect();\r\n }\r\n\r\n /**\r\n * Unique key for this effect\r\n */\r\n public get key(): string {\r\n return this._key;\r\n }\r\n\r\n /**\r\n * If the effect has been compiled and prepared.\r\n * @returns if the effect is compiled and prepared.\r\n */\r\n public isReady(): boolean {\r\n try {\r\n return this._isReadyInternal();\r\n } catch {\r\n return false;\r\n }\r\n }\r\n\r\n private _isReadyInternal(): boolean {\r\n if (this._isReady) {\r\n return true;\r\n }\r\n if (this._pipelineContext) {\r\n return this._pipelineContext.isReady;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * The engine the effect was initialized with.\r\n * @returns the engine.\r\n */\r\n public getEngine(): Engine {\r\n return this._engine;\r\n }\r\n\r\n /**\r\n * The pipeline context for this effect\r\n * @returns the associated pipeline context\r\n */\r\n public getPipelineContext(): Nullable<IComputePipelineContext> {\r\n return this._pipelineContext;\r\n }\r\n\r\n /**\r\n * The error from the last compilation.\r\n * @returns the error string.\r\n */\r\n public getCompilationError(): string {\r\n return this._compilationError;\r\n }\r\n\r\n /**\r\n * Adds a callback to the onCompiled observable and call the callback immediately if already ready.\r\n * @param func The callback to be used.\r\n */\r\n public executeWhenCompiled(func: (effect: ComputeEffect) => void): void {\r\n if (this.isReady()) {\r\n func(this);\r\n return;\r\n }\r\n\r\n this.onCompileObservable.add((effect) => {\r\n func(effect);\r\n });\r\n\r\n if (!this._pipelineContext || this._pipelineContext.isAsync) {\r\n setTimeout(() => {\r\n this._checkIsReady(null);\r\n }, 16);\r\n }\r\n }\r\n\r\n private _checkIsReady(previousPipelineContext: Nullable<IComputePipelineContext>) {\r\n try {\r\n if (this._isReadyInternal()) {\r\n return;\r\n }\r\n } catch (e) {\r\n this._processCompilationErrors(e, previousPipelineContext);\r\n return;\r\n }\r\n\r\n setTimeout(() => {\r\n this._checkIsReady(previousPipelineContext);\r\n }, 16);\r\n }\r\n\r\n private _loadShader(shader: any, key: string, optionalKey: string, callback: (data: any) => void): void {\r\n if (typeof HTMLElement !== \"undefined\") {\r\n // DOM element ?\r\n if (shader instanceof HTMLElement) {\r\n const shaderCode = GetDOMTextContent(shader);\r\n callback(shaderCode);\r\n return;\r\n }\r\n }\r\n\r\n // Direct source ?\r\n if (shader.substr(0, 7) === \"source:\") {\r\n callback(shader.substr(7));\r\n return;\r\n }\r\n\r\n // Base64 encoded ?\r\n if (shader.substr(0, 7) === \"base64:\") {\r\n const shaderBinary = window.atob(shader.substr(7));\r\n callback(shaderBinary);\r\n return;\r\n }\r\n\r\n // Is in local store ?\r\n if (this._shaderStore[shader + key + \"Shader\"]) {\r\n callback(this._shaderStore[shader + key + \"Shader\"]);\r\n return;\r\n }\r\n\r\n if (optionalKey && this._shaderStore[shader + optionalKey + \"Shader\"]) {\r\n callback(this._shaderStore[shader + optionalKey + \"Shader\"]);\r\n return;\r\n }\r\n\r\n let shaderUrl;\r\n\r\n if (shader[0] === \".\" || shader[0] === \"/\" || shader.indexOf(\"http\") > -1) {\r\n shaderUrl = shader;\r\n } else {\r\n shaderUrl = this._shaderRepository + shader;\r\n }\r\n\r\n this._engine._loadFile(shaderUrl + \".\" + key.toLowerCase() + \".fx\", callback);\r\n }\r\n\r\n /**\r\n * Gets the compute shader source code of this effect\r\n */\r\n public get computeSourceCode(): string {\r\n return this._computeSourceCodeOverride ? this._computeSourceCodeOverride : this._pipelineContext?._getComputeShaderCode() ?? this._computeSourceCode;\r\n }\r\n\r\n /**\r\n * Gets the compute shader source code before it has been processed by the preprocessor\r\n */\r\n public get rawComputeSourceCode(): string {\r\n return this._rawComputeSourceCode;\r\n }\r\n\r\n /**\r\n * Prepares the effect\r\n * @internal\r\n */\r\n public _prepareEffect() {\r\n const defines = this.defines;\r\n\r\n const previousPipelineContext = this._pipelineContext;\r\n\r\n this._isReady = false;\r\n\r\n try {\r\n const engine = this._engine;\r\n\r\n this._pipelineContext = engine.createComputePipelineContext();\r\n this._pipelineContext._name = this._key;\r\n\r\n engine._prepareComputePipelineContext(\r\n this._pipelineContext,\r\n this._computeSourceCodeOverride ? this._computeSourceCodeOverride : this._computeSourceCode,\r\n this._rawComputeSourceCode,\r\n this._computeSourceCodeOverride ? null : defines,\r\n this._entryPoint\r\n );\r\n\r\n engine._executeWhenComputeStateIsCompiled(this._pipelineContext, () => {\r\n this._compilationError = \"\";\r\n this._isReady = true;\r\n if (this.onCompiled) {\r\n this.onCompiled(this);\r\n }\r\n this.onCompileObservable.notifyObservers(this);\r\n this.onCompileObservable.clear();\r\n\r\n if (previousPipelineContext) {\r\n this.getEngine()._deleteComputePipelineContext(previousPipelineContext);\r\n }\r\n });\r\n\r\n if (this._pipelineContext.isAsync) {\r\n this._checkIsReady(previousPipelineContext);\r\n }\r\n } catch (e) {\r\n this._processCompilationErrors(e, previousPipelineContext);\r\n }\r\n }\r\n\r\n private _getShaderCodeAndErrorLine(code: Nullable<string>, error: Nullable<string>): [Nullable<string>, Nullable<string>] {\r\n const regexp = /COMPUTE SHADER ERROR: 0:(\\d+?):/;\r\n\r\n let errorLine = null;\r\n\r\n if (error && code) {\r\n const res = error.match(regexp);\r\n if (res && res.length === 2) {\r\n const lineNumber = parseInt(res[1]);\r\n const lines = code.split(\"\\n\", -1);\r\n if (lines.length >= lineNumber) {\r\n errorLine = `Offending line [${lineNumber}] in compute code: ${lines[lineNumber - 1]}`;\r\n }\r\n }\r\n }\r\n\r\n return [code, errorLine];\r\n }\r\n\r\n private _processCompilationErrors(e: any, previousPipelineContext: Nullable<IComputePipelineContext> = null) {\r\n this._compilationError = e.message;\r\n\r\n // Let's go through fallbacks then\r\n Logger.Error(\"Unable to compile compute effect:\");\r\n Logger.Error(\"Defines:\\n\" + this.defines);\r\n if (ComputeEffect.LogShaderCodeOnCompilationError) {\r\n let lineErrorVertex = null,\r\n code = null;\r\n if (this._pipelineContext?._getComputeShaderCode()) {\r\n [code, lineErrorVertex] = this._getShaderCodeAndErrorLine(this._pipelineContext._getComputeShaderCode(), this._compilationError);\r\n if (code) {\r\n Logger.Error(\"Compute code:\");\r\n Logger.Error(code);\r\n }\r\n }\r\n if (lineErrorVertex) {\r\n Logger.Error(lineErrorVertex);\r\n }\r\n }\r\n Logger.Error(\"Error: \" + this._compilationError);\r\n if (previousPipelineContext) {\r\n this._pipelineContext = previousPipelineContext;\r\n this._isReady = true;\r\n if (this.onError) {\r\n this.onError(this, this._compilationError);\r\n }\r\n this.onErrorObservable.notifyObservers(this);\r\n }\r\n }\r\n\r\n /**\r\n * Release all associated resources.\r\n **/\r\n public dispose() {\r\n if (this._pipelineContext) {\r\n this._pipelineContext.dispose();\r\n }\r\n this._engine._releaseComputeEffect(this);\r\n }\r\n\r\n /**\r\n * This function will add a new compute shader to the shader store\r\n * @param name the name of the shader\r\n * @param computeShader compute shader content\r\n */\r\n public static RegisterShader(name: string, computeShader: string) {\r\n ShaderStore.GetShadersStore(ShaderLanguage.WGSL)[`${name}ComputeShader`] = computeShader;\r\n }\r\n}\r\n"]}
@@ -1,7 +1,7 @@
1
1
  import type { UniformBuffer } from "../Materials/uniformBuffer";
2
2
  import type { Scene } from "../scene";
3
3
  import type { Nullable } from "../types";
4
- import type { ComputeEffect } from "./computeEffect";
4
+ import type { ComputeEffect, IComputeShaderPath } from "./computeEffect";
5
5
  import type { ComputeBindingMapping } from "../Engines/Extensions/engine.computeShader";
6
6
  import type { BaseTexture } from "../Materials/Textures/baseTexture";
7
7
  import type { StorageBuffer } from "../Buffers/storageBuffer";
@@ -62,7 +62,7 @@ export declare class ComputeShader {
62
62
  /**
63
63
  * The shaderPath used to create the shader
64
64
  */
65
- get shaderPath(): any;
65
+ get shaderPath(): IComputeShaderPath;
66
66
  /**
67
67
  * When set to true, dispatch won't call isReady anymore and won't check if the underlying GPU resources should be (re)created because of a change in the inputs (texture, uniform buffer, etc.)
68
68
  * If you know that your inputs did not change since last time dispatch was called and that isReady() returns true, set this flag to true to improve performance
@@ -85,14 +85,14 @@ export declare class ComputeShader {
85
85
  * Instantiates a new compute shader.
86
86
  * @param name Defines the name of the compute shader in the scene
87
87
  * @param engine Defines the engine the compute shader belongs to
88
- * @param shaderPath Defines the route to the shader code in one of three ways:
88
+ * @param shaderPath Defines the route to the shader code in one of three ways:
89
89
  * * object: \{ compute: "custom" \}, used with ShaderStore.ShadersStoreWGSL["customComputeShader"]
90
90
  * * object: \{ computeElement: "HTMLElementId" \}, used with shader code in script tags
91
91
  * * object: \{ computeSource: "compute shader code string" \}, where the string contains the shader code
92
92
  * * string: try first to find the code in ShaderStore.ShadersStoreWGSL[shaderPath + "ComputeShader"]. If not, assumes it is a file with name shaderPath.compute.fx in index.html folder.
93
93
  * @param options Define the options used to create the shader
94
94
  */
95
- constructor(name: string, engine: ThinEngine, shaderPath: any, options?: Partial<IComputeShaderOptions>);
95
+ constructor(name: string, engine: ThinEngine, shaderPath: IComputeShaderPath, options?: Partial<IComputeShaderOptions>);
96
96
  /**
97
97
  * Gets the current class name of the material e.g. "ComputeShader"
98
98
  * Mainly use in serialization.
@@ -28,7 +28,7 @@ export class ComputeShader {
28
28
  * Instantiates a new compute shader.
29
29
  * @param name Defines the name of the compute shader in the scene
30
30
  * @param engine Defines the engine the compute shader belongs to
31
- * @param shaderPath Defines the route to the shader code in one of three ways:
31
+ * @param shaderPath Defines the route to the shader code in one of three ways:
32
32
  * * object: \{ compute: "custom" \}, used with ShaderStore.ShadersStoreWGSL["customComputeShader"]
33
33
  * * object: \{ computeElement: "HTMLElementId" \}, used with shader code in script tags
34
34
  * * object: \{ computeSource: "compute shader code string" \}, where the string contains the sh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AK,SAAS,CAAC;IACnE,CAAC;CACJ;AA7aU;IADN,SAAS,EAAE;2CACQ;AAqBb;IADN,SAAS,EAAE;+CACY;AA0Z5B,aAAa,CAAC,uBAAuB,EAAE,aAAa,CAAC,CAAC","sourcesContent":["import type { UniformBuffer } from \"../Materials/uniformBuffer\";\r\nimport type { WebGPUEngine } from \"../Engines/webgpuEngine\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { Nullable } from \"../types\";\r\nimport { serialize } from \"../Misc/decorators\";\r\nimport { SerializationHelper } from \"../Misc/decorators.serialization\";\r\nimport { RegisterClass } from \"../Misc/typeStore\";\r\nimport type { ComputeEffect, IComputeEffectCreationOptions } from \"./computeEffect\";\r\nimport type { ComputeBindingMapping } from \"../Engines/Extensions/engine.computeShader\";\r\nimport { ComputeBindingType } from \"../Engines/Extensions/engine.computeShader\";\r\nimport type { BaseTexture } from \"../Materials/Textures/baseTexture\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { UniqueIdGenerator } from \"../Misc/uniqueIdGenerator\";\r\nimport type { IComputeContext } from \"./IComputeContext\";\r\nimport type { StorageBuffer } from \"../Buffers/storageBuffer\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport { TextureSampler } from \"../Materials/Textures/textureSampler\";\r\nimport type { DataBuffer } from \"core/Buffers/dataBuffer\";\r\nimport type { ExternalTexture } from \"core/Materials/Textures/externalTexture\";\r\nimport type { VideoTexture } from \"core/Materials/Textures/videoTexture\";\r\nimport { WebGPUPerfCounter } from \"core/Engines/WebGPU/webgpuPerfCounter\";\r\nimport type { ThinEngine } from \"core/Engines/thinEngine\";\r\n\r\n/**\r\n * Defines the options associated with the creation of a compute shader.\r\n */\r\nexport interface IComputeShaderOptions {\r\n /**\r\n * list of bindings mapping (key is property name, value is binding location)\r\n * Must be provided because browsers don't support reflection for wgsl shaders yet (so there's no way to query the binding/group from a variable name)\r\n * TODO: remove this when browsers support reflection for wgsl shaders\r\n */\r\n bindingsMapping: ComputeBindingMapping;\r\n\r\n /**\r\n * The list of defines used in the shader\r\n */\r\n defines?: string[];\r\n\r\n /**\r\n * The name of the entry point in the shader source (default: \"main\")\r\n */\r\n entryPoint?: string;\r\n\r\n /**\r\n * If provided, will be called with the shader code so that this code can be updated before it is compiled by the GPU\r\n */\r\n processFinalCode?: Nullable<(code: string) => string>;\r\n}\r\n\r\ntype ComputeBindingListInternal = { [key: string]: { type: ComputeBindingType; object: any; indexInGroupEntries?: number; buffer?: Nullable<DataBuffer> } };\r\n\r\n/**\r\n * The ComputeShader object lets you execute a compute shader on your GPU (if supported by the engine)\r\n */\r\nexport class ComputeShader {\r\n private _engine: ThinEngine;\r\n private _shaderPath: any;\r\n private _options: IComputeShaderOptions;\r\n private _effect: ComputeEffect;\r\n private _cachedDefines: string;\r\n private _bindings: ComputeBindingListInternal = {};\r\n private _samplers: { [key: string]: TextureSampler } = {};\r\n private _context: IComputeContext;\r\n private _contextIsDirty = false;\r\n\r\n /**\r\n * Gets the unique id of the compute shader\r\n */\r\n public readonly uniqueId: number;\r\n\r\n /**\r\n * The name of the shader\r\n */\r\n @serialize()\r\n public name: string;\r\n\r\n /**\r\n * The options used to create the shader\r\n */\r\n public get options() {\r\n return this._options;\r\n }\r\n\r\n /**\r\n * The shaderPath used to create the shader\r\n */\r\n public get shaderPath() {\r\n return this._shaderPath;\r\n }\r\n\r\n /**\r\n * When set to true, dispatch won't call isReady anymore and won't check if the underlying GPU resources should be (re)created because of a change in the inputs (texture, uniform buffer, etc.)\r\n * If you know that your inputs did not change since last time dispatch was called and that isReady() returns true, set this flag to true to improve performance\r\n */\r\n @serialize()\r\n public fastMode = false;\r\n\r\n /**\r\n * Callback triggered when the shader is compiled\r\n */\r\n public onCompiled: Nullable<(effect: ComputeEffect) => void> = null;\r\n\r\n /**\r\n * Callback triggered when an error occurs\r\n */\r\n public onError: Nullable<(effect: ComputeEffect, errors: string) => void> = null;\r\n\r\n /**\r\n * Gets the GPU time spent running the compute shader for the last frame rendered (in nanoseconds).\r\n * You have to enable the \"timestamp-query\" extension in the engine constructor options and set engine.enableGPUTimingMeasurements = true.\r\n */\r\n public readonly gpuTimeInFrame?: WebGPUPerfCounter;\r\n\r\n /**\r\n * Instantiates a new compute shader.\r\n * @param name Defines the name of the compute shader in the scene\r\n * @param engine Defines the engine the compute shader belongs to\r\n * @param shaderPath Defines the route to the shader code in one of three ways:\r\n * * object: \\{ compute: \"custom\" \\}, used with ShaderStore.ShadersStoreWGSL[\"customComputeShader\"]\r\n * * object: \\{ computeElement: \"HTMLElementId\" \\}, used with shader code in script tags\r\n * * object: \\{ computeSource: \"compute shader code string\" \\}, where the string contains the shader code\r\n * * string: try first to find the code in ShaderStore.ShadersStoreWGSL[shaderPath + \"ComputeShader\"]. If not, assumes it is a file with name shaderPath.compute.fx in index.html folder.\r\n * @param options Define the options used to create the shader\r\n */\r\n constructor(name: string, engine: ThinEngine, shaderPath: any, options: Partial<IComputeShaderOptions> = {}) {\r\n this.name = name;\r\n this._engine = engine;\r\n this.uniqueId = UniqueIdGenerator.UniqueId;\r\n if ((engine as WebGPUEngine).enableGPUTimingMeasurements) {\r\n this.gpuTimeInFrame = new WebGPUPerfCounter();\r\n }\r\n\r\n if (!this._engine.getCaps().supportComputeShaders) {\r\n Logger.Error(\"This engine does not support compute shaders!\");\r\n return;\r\n }\r\n if (!options.bindingsMapping) {\r\n Logger.Error(\"You must provide the binding mappings as browsers don't support reflection for wgsl shaders yet!\");\r\n return;\r\n }\r\n\r\n this._context = engine.createComputeContext()!;\r\n this._shaderPath = shaderPath;\r\n this._options = {\r\n bindingsMapping: {},\r\n defines: [],\r\n ...options,\r\n };\r\n }\r\n\r\n /**\r\n * Gets the current class name of the material e.g. \"ComputeShader\"\r\n * Mainly use in serialization.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"ComputeShader\";\r\n }\r\n\r\n /**\r\n * Binds a texture to the shader\r\n * @param name Binding name of the texture\r\n * @param texture Texture to bind\r\n * @param bindSampler Bind the sampler corresponding to the texture (default: true). The sampler will be bound just before the binding index of the texture\r\n */\r\n public setTexture(name: string, texture: BaseTexture, bindSampler = true): void {\r\n const current = this._bindings[name];\r\n\r\n this._bindings[name] = {\r\n type: bindSampler ? ComputeBindingType.Texture : ComputeBindingType.TextureWithoutSampler,\r\n object: texture,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n\r\n this._contextIsDirty ||= !current || current.object !== texture || current.type !== this._bindings[name].type;\r\n }\r\n\r\n /**\r\n * Binds a storage texture to the shader\r\n * @param name Binding name of the texture\r\n * @param texture Texture to bind\r\n */\r\n public setStorageTexture(name: string, texture: BaseTexture): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || current.object !== texture;\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.StorageTexture,\r\n object: texture,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Binds an external texture to the shader\r\n * @param name Binding name of the texture\r\n * @param texture Texture to bind\r\n */\r\n public setExternalTexture(name: string, texture: ExternalTexture): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || current.object !== texture;\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.ExternalTexture,\r\n object: texture,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Binds a video texture to the shader (by binding the external texture attached to this video)\r\n * @param name Binding name of the texture\r\n * @param texture Texture to bind\r\n * @returns true if the video texture was successfully bound, else false. false will be returned if the current engine does not support external textures\r\n */\r\n public setVideoTexture(name: string, texture: VideoTexture) {\r\n if (texture.externalTexture) {\r\n this.setExternalTexture(name, texture.externalTexture);\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Binds a uniform buffer to the shader\r\n * @param name Binding name of the buffer\r\n * @param buffer Buffer to bind\r\n */\r\n public setUniformBuffer(name: string, buffer: UniformBuffer | DataBuffer): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || current.object !== buffer;\r\n\r\n this._bindings[name] = {\r\n type: ComputeShader._BufferIsDataBuffer(buffer) ? ComputeBindingType.DataBuffer : ComputeBindingType.UniformBuffer,\r\n object: buffer,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Binds a storage buffer to the shader\r\n * @param name Binding name of the buffer\r\n * @param buffer Buffer to bind\r\n */\r\n public setStorageBuffer(name: string, buffer: StorageBuffer | DataBuffer): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || current.object !== buffer;\r\n\r\n this._bindings[name] = {\r\n type: ComputeShader._BufferIsDataBuffer(buffer) ? ComputeBindingType.DataBuffer : ComputeBindingType.StorageBuffer,\r\n object: buffer,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Binds a texture sampler to the shader\r\n * @param name Binding name of the sampler\r\n * @param sampler Sampler to bind\r\n */\r\n public setTextureSampler(name: string, sampler: TextureSampler): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || !sampler.compareSampler(current.object);\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.Sampler,\r\n object: sampler,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Specifies that the compute shader is ready to be executed (the compute effect and all the resources are ready)\r\n * @returns true if the compute shader is ready to be executed\r\n */\r\n public isReady(): boolean {\r\n let effect = this._effect;\r\n\r\n for (const key in this._bindings) {\r\n const binding = this._bindings[key],\r\n type = binding.type,\r\n object = binding.object;\r\n\r\n switch (type) {\r\n case ComputeBindingType.Texture:\r\n case ComputeBindingType.TextureWithoutSampler:\r\n case ComputeBindingType.StorageTexture: {\r\n const texture = object as BaseTexture;\r\n if (!texture.isReady()) {\r\n return false;\r\n }\r\n break;\r\n }\r\n case ComputeBindingType.ExternalTexture: {\r\n const texture = object as ExternalTexture;\r\n if (!texture.isReady()) {\r\n return false;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n\r\n const defines = [];\r\n\r\n const shaderName = this._shaderPath;\r\n\r\n if (this._options.defines) {\r\n for (let index = 0; index < this._options.defines.length; index++) {\r\n defines.push(this._options.defines[index]);\r\n }\r\n }\r\n\r\n const join = defines.join(\"\\n\");\r\n\r\n if (this._cachedDefines !== join) {\r\n this._cachedDefines = join;\r\n\r\n effect = this._engine.createComputeEffect(shaderName, <IComputeEffectCreationOptions>{\r\n defines: join,\r\n entryPoint: this._options.entryPoint,\r\n onCompiled: this.onCompiled,\r\n onError: this.onError,\r\n });\r\n\r\n this._effect = effect;\r\n }\r\n\r\n if (!effect.isReady()) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Dispatches (executes) the compute shader\r\n * @param x Number of workgroups to execute on the X dimension\r\n * @param y Number of workgroups to execute on the Y dimension (default: 1)\r\n * @param z Number of workgroups to execute on the Z dimension (default: 1)\r\n * @returns True if the dispatch could be done, else false (meaning either the compute effect or at least one of the bound resources was not ready)\r\n */\r\n public dispatch(x: number, y?: number, z?: number): boolean {\r\n if (!this.fastMode) {\r\n if (!this.isReady()) {\r\n return false;\r\n }\r\n\r\n // If the sampling parameters of a texture bound to the shader have changed, we must clear the compute context so that it is recreated with the updated values\r\n // Also, if the actual (gpu) buffer used by a uniform buffer has changed, we must clear the compute context so that it is recreated with the updated value\r\n for (const key in this._bindings) {\r\n const binding = this._bindings[key];\r\n\r\n if (!this._options.bindingsMapping[key]) {\r\n throw new Error(\"ComputeShader ('\" + this.name + \"'): No binding mapping has been provided for the property '\" + key + \"'\");\r\n }\r\n\r\n switch (binding.type) {\r\n case ComputeBindingType.Texture: {\r\n const sampler = this._samplers[key];\r\n const texture = binding.object as BaseTexture;\r\n\r\n if (!sampler || !texture._texture || !sampler.compareSampler(texture._texture)) {\r\n this._samplers[key] = new TextureSampler().setParameters(\r\n texture.wrapU,\r\n texture.wrapV,\r\n texture.wrapR,\r\n texture.anisotropicFilteringLevel,\r\n texture._texture!.samplingMode,\r\n texture._texture?._comparisonFunction\r\n );\r\n this._contextIsDirty = true;\r\n }\r\n break;\r\n }\r\n case ComputeBindingType.ExternalTexture: {\r\n // we must recreate the bind groups each time if there's an external texture, because device.importExternalTexture must be called each frame\r\n this._contextIsDirty = true;\r\n break;\r\n }\r\n case ComputeBindingType.UniformBuffer: {\r\n const ubo = binding.object as UniformBuffer;\r\n if (ubo.getBuffer() !== binding.buffer) {\r\n binding.buffer = ubo.getBuffer();\r\n this._contextIsDirty = true;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n\r\n if (this._contextIsDirty) {\r\n this._contextIsDirty = false;\r\n this._context.clear();\r\n }\r\n }\r\n\r\n this._engine.computeDispatch(this._effect, this._context, this._bindings, x, y, z, this._options.bindingsMapping, this.gpuTimeInFrame);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Waits for the compute shader to be ready and executes it\r\n * @param x Number of workgroups to execute on the X dimension\r\n * @param y Number of workgroups to execute on the Y dimension (default: 1)\r\n * @param z Number of workgroups to execute on the Z dimension (default: 1)\r\n * @param delay Delay between the retries while the shader is not ready (in milliseconds - 10 by default)\r\n * @returns A promise that is resolved once the shader has been sent to the GPU. Note that it does not mean that the shader execution itself is finished!\r\n */\r\n public dispatchWhenReady(x: number, y?: number, z?: number, delay = 10): Promise<void> {\r\n return new Promise((resolve) => {\r\n const check = () => {\r\n if (!this.dispatch(x, y, z)) {\r\n setTimeout(check, delay);\r\n } else {\r\n resolve();\r\n }\r\n };\r\n\r\n check();\r\n });\r\n }\r\n\r\n /**\r\n * Serializes this compute shader in a JSON representation\r\n * @returns the serialized compute shader object\r\n */\r\n public serialize(): any {\r\n const serializationObject = SerializationHelper.Serialize(this);\r\n\r\n serializationObject.options = this._options;\r\n serializationObject.shaderPath = this._shaderPath;\r\n serializationObject.bindings = {};\r\n serializationObject.textures = {};\r\n\r\n for (const key in this._bindings) {\r\n const binding = this._bindings[key];\r\n const object = binding.object;\r\n\r\n switch (binding.type) {\r\n case ComputeBindingType.Texture:\r\n case ComputeBindingType.TextureWithoutSampler:\r\n case ComputeBindingType.StorageTexture: {\r\n const serializedData = (object as BaseTexture).serialize();\r\n if (serializedData) {\r\n serializationObject.textures[key] = serializedData;\r\n serializationObject.bindings[key] = {\r\n type: binding.type,\r\n };\r\n }\r\n break;\r\n }\r\n\r\n case ComputeBindingType.UniformBuffer: {\r\n break;\r\n }\r\n }\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Creates a compute shader from parsed compute shader data\r\n * @param source defines the JSON representation of the compute shader\r\n * @param scene defines the hosting scene\r\n * @param rootUrl defines the root URL to use to load textures and relative dependencies\r\n * @returns a new compute shader\r\n */\r\n public static Parse(source: any, scene: Scene, rootUrl: string): ComputeShader {\r\n const compute = SerializationHelper.Parse(\r\n () => new ComputeShader(source.name, scene.getEngine() as WebGPUEngine, source.shaderPath, source.options),\r\n source,\r\n scene,\r\n rootUrl\r\n );\r\n\r\n for (const key in source.textures) {\r\n const binding = source.bindings[key];\r\n const texture = <Texture>Texture.Parse(source.textures[key], scene, rootUrl);\r\n\r\n if (binding.type === ComputeBindingType.Texture) {\r\n compute.setTexture(key, texture);\r\n } else if (binding.type === ComputeBindingType.TextureWithoutSampler) {\r\n compute.setTexture(key, texture, false);\r\n } else {\r\n compute.setStorageTexture(key, texture);\r\n }\r\n }\r\n\r\n return compute;\r\n }\r\n\r\n protected static _BufferIsDataBuffer(buffer: UniformBuffer | StorageBuffer | DataBuffer): buffer is DataBuffer {\r\n return (buffer as DataBuffer).underlyingResource !== undefined;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.ComputeShader\", ComputeShader);\r\n"]}
1
+ {"version":3,"file":"computeShader.js","sourceRoot":"","sources":["../../../../dev/core/src/Compute/computeShader.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE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niformBuffer\";\r\nimport type { WebGPUEngine } from \"../Engines/webgpuEngine\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { Nullable } from \"../types\";\r\nimport { serialize } from \"../Misc/decorators\";\r\nimport { SerializationHelper } from \"../Misc/decorators.serialization\";\r\nimport { RegisterClass } from \"../Misc/typeStore\";\r\nimport type { ComputeEffect, IComputeEffectCreationOptions, IComputeShaderPath } from \"./computeEffect\";\r\nimport type { ComputeBindingMapping } from \"../Engines/Extensions/engine.computeShader\";\r\nimport { ComputeBindingType } from \"../Engines/Extensions/engine.computeShader\";\r\nimport type { BaseTexture } from \"../Materials/Textures/baseTexture\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { UniqueIdGenerator } from \"../Misc/uniqueIdGenerator\";\r\nimport type { IComputeContext } from \"./IComputeContext\";\r\nimport type { StorageBuffer } from \"../Buffers/storageBuffer\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport { TextureSampler } from \"../Materials/Textures/textureSampler\";\r\nimport type { DataBuffer } from \"core/Buffers/dataBuffer\";\r\nimport type { ExternalTexture } from \"core/Materials/Textures/externalTexture\";\r\nimport type { VideoTexture } from \"core/Materials/Textures/videoTexture\";\r\nimport { WebGPUPerfCounter } from \"core/Engines/WebGPU/webgpuPerfCounter\";\r\nimport type { ThinEngine } from \"core/Engines/thinEngine\";\r\n\r\n/**\r\n * Defines the options associated with the creation of a compute shader.\r\n */\r\nexport interface IComputeShaderOptions {\r\n /**\r\n * list of bindings mapping (key is property name, value is binding location)\r\n * Must be provided because browsers don't support reflection for wgsl shaders yet (so there's no way to query the binding/group from a variable name)\r\n * TODO: remove this when browsers support reflection for wgsl shaders\r\n */\r\n bindingsMapping: ComputeBindingMapping;\r\n\r\n /**\r\n * The list of defines used in the shader\r\n */\r\n defines?: string[];\r\n\r\n /**\r\n * The name of the entry point in the shader source (default: \"main\")\r\n */\r\n entryPoint?: string;\r\n\r\n /**\r\n * If provided, will be called with the shader code so that this code can be updated before it is compiled by the GPU\r\n */\r\n processFinalCode?: Nullable<(code: string) => string>;\r\n}\r\n\r\ntype ComputeBindingListInternal = { [key: string]: { type: ComputeBindingType; object: any; indexInGroupEntries?: number; buffer?: Nullable<DataBuffer> } };\r\n\r\n/**\r\n * The ComputeShader object lets you execute a compute shader on your GPU (if supported by the engine)\r\n */\r\nexport class ComputeShader {\r\n private _engine: ThinEngine;\r\n private _shaderPath: IComputeShaderPath;\r\n private _options: IComputeShaderOptions;\r\n private _effect: ComputeEffect;\r\n private _cachedDefines: string;\r\n private _bindings: ComputeBindingListInternal = {};\r\n private _samplers: { [key: string]: TextureSampler } = {};\r\n private _context: IComputeContext;\r\n private _contextIsDirty = false;\r\n\r\n /**\r\n * Gets the unique id of the compute shader\r\n */\r\n public readonly uniqueId: number;\r\n\r\n /**\r\n * The name of the shader\r\n */\r\n @serialize()\r\n public name: string;\r\n\r\n /**\r\n * The options used to create the shader\r\n */\r\n public get options() {\r\n return this._options;\r\n }\r\n\r\n /**\r\n * The shaderPath used to create the shader\r\n */\r\n public get shaderPath() {\r\n return this._shaderPath;\r\n }\r\n\r\n /**\r\n * When set to true, dispatch won't call isReady anymore and won't check if the underlying GPU resources should be (re)created because of a change in the inputs (texture, uniform buffer, etc.)\r\n * If you know that your inputs did not change since last time dispatch was called and that isReady() returns true, set this flag to true to improve performance\r\n */\r\n @serialize()\r\n public fastMode = false;\r\n\r\n /**\r\n * Callback triggered when the shader is compiled\r\n */\r\n public onCompiled: Nullable<(effect: ComputeEffect) => void> = null;\r\n\r\n /**\r\n * Callback triggered when an error occurs\r\n */\r\n public onError: Nullable<(effect: ComputeEffect, errors: string) => void> = null;\r\n\r\n /**\r\n * Gets the GPU time spent running the compute shader for the last frame rendered (in nanoseconds).\r\n * You have to enable the \"timestamp-query\" extension in the engine constructor options and set engine.enableGPUTimingMeasurements = true.\r\n */\r\n public readonly gpuTimeInFrame?: WebGPUPerfCounter;\r\n\r\n /**\r\n * Instantiates a new compute shader.\r\n * @param name Defines the name of the compute shader in the scene\r\n * @param engine Defines the engine the compute shader belongs to\r\n * @param shaderPath Defines the route to the shader code in one of three ways:\r\n * * object: \\{ compute: \"custom\" \\}, used with ShaderStore.ShadersStoreWGSL[\"customComputeShader\"]\r\n * * object: \\{ computeElement: \"HTMLElementId\" \\}, used with shader code in script tags\r\n * * object: \\{ computeSource: \"compute shader code string\" \\}, where the string contains the shader code\r\n * * string: try first to find the code in ShaderStore.ShadersStoreWGSL[shaderPath + \"ComputeShader\"]. If not, assumes it is a file with name shaderPath.compute.fx in index.html folder.\r\n * @param options Define the options used to create the shader\r\n */\r\n constructor(name: string, engine: ThinEngine, shaderPath: IComputeShaderPath, options: Partial<IComputeShaderOptions> = {}) {\r\n this.name = name;\r\n this._engine = engine;\r\n this.uniqueId = UniqueIdGenerator.UniqueId;\r\n if ((engine as WebGPUEngine).enableGPUTimingMeasurements) {\r\n this.gpuTimeInFrame = new WebGPUPerfCounter();\r\n }\r\n\r\n if (!this._engine.getCaps().supportComputeShaders) {\r\n Logger.Error(\"This engine does not support compute shaders!\");\r\n return;\r\n }\r\n if (!options.bindingsMapping) {\r\n Logger.Error(\"You must provide the binding mappings as browsers don't support reflection for wgsl shaders yet!\");\r\n return;\r\n }\r\n\r\n this._context = engine.createComputeContext()!;\r\n this._shaderPath = shaderPath;\r\n this._options = {\r\n bindingsMapping: {},\r\n defines: [],\r\n ...options,\r\n };\r\n }\r\n\r\n /**\r\n * Gets the current class name of the material e.g. \"ComputeShader\"\r\n * Mainly use in serialization.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"ComputeShader\";\r\n }\r\n\r\n /**\r\n * Binds a texture to the shader\r\n * @param name Binding name of the texture\r\n * @param texture Texture to bind\r\n * @param bindSampler Bind the sampler corresponding to the texture (default: true). The sampler will be bound just before the binding index of the texture\r\n */\r\n public setTexture(name: string, texture: BaseTexture, bindSampler = true): void {\r\n const current = this._bindings[name];\r\n\r\n this._bindings[name] = {\r\n type: bindSampler ? ComputeBindingType.Texture : ComputeBindingType.TextureWithoutSampler,\r\n object: texture,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n\r\n this._contextIsDirty ||= !current || current.object !== texture || current.type !== this._bindings[name].type;\r\n }\r\n\r\n /**\r\n * Binds a storage texture to the shader\r\n * @param name Binding name of the texture\r\n * @param texture Texture to bind\r\n */\r\n public setStorageTexture(name: string, texture: BaseTexture): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || current.object !== texture;\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.StorageTexture,\r\n object: texture,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Binds an external texture to the shader\r\n * @param name Binding name of the texture\r\n * @param texture Texture to bind\r\n */\r\n public setExternalTexture(name: string, texture: ExternalTexture): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || current.object !== texture;\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.ExternalTexture,\r\n object: texture,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Binds a video texture to the shader (by binding the external texture attached to this video)\r\n * @param name Binding name of the texture\r\n * @param texture Texture to bind\r\n * @returns true if the video texture was successfully bound, else false. false will be returned if the current engine does not support external textures\r\n */\r\n public setVideoTexture(name: string, texture: VideoTexture) {\r\n if (texture.externalTexture) {\r\n this.setExternalTexture(name, texture.externalTexture);\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Binds a uniform buffer to the shader\r\n * @param name Binding name of the buffer\r\n * @param buffer Buffer to bind\r\n */\r\n public setUniformBuffer(name: string, buffer: UniformBuffer | DataBuffer): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || current.object !== buffer;\r\n\r\n this._bindings[name] = {\r\n type: ComputeShader._BufferIsDataBuffer(buffer) ? ComputeBindingType.DataBuffer : ComputeBindingType.UniformBuffer,\r\n object: buffer,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Binds a storage buffer to the shader\r\n * @param name Binding name of the buffer\r\n * @param buffer Buffer to bind\r\n */\r\n public setStorageBuffer(name: string, buffer: StorageBuffer | DataBuffer): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || current.object !== buffer;\r\n\r\n this._bindings[name] = {\r\n type: ComputeShader._BufferIsDataBuffer(buffer) ? ComputeBindingType.DataBuffer : ComputeBindingType.StorageBuffer,\r\n object: buffer,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Binds a texture sampler to the shader\r\n * @param name Binding name of the sampler\r\n * @param sampler Sampler to bind\r\n */\r\n public setTextureSampler(name: string, sampler: TextureSampler): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || !sampler.compareSampler(current.object);\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.Sampler,\r\n object: sampler,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Specifies that the compute shader is ready to be executed (the compute effect and all the resources are ready)\r\n * @returns true if the compute shader is ready to be executed\r\n */\r\n public isReady(): boolean {\r\n let effect = this._effect;\r\n\r\n for (const key in this._bindings) {\r\n const binding = this._bindings[key],\r\n type = binding.type,\r\n object = binding.object;\r\n\r\n switch (type) {\r\n case ComputeBindingType.Texture:\r\n case ComputeBindingType.TextureWithoutSampler:\r\n case ComputeBindingType.StorageTexture: {\r\n const texture = object as BaseTexture;\r\n if (!texture.isReady()) {\r\n return false;\r\n }\r\n break;\r\n }\r\n case ComputeBindingType.ExternalTexture: {\r\n const texture = object as ExternalTexture;\r\n if (!texture.isReady()) {\r\n return false;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n\r\n const defines = [];\r\n\r\n const shaderName = this._shaderPath;\r\n\r\n if (this._options.defines) {\r\n for (let index = 0; index < this._options.defines.length; index++) {\r\n defines.push(this._options.defines[index]);\r\n }\r\n }\r\n\r\n const join = defines.join(\"\\n\");\r\n\r\n if (this._cachedDefines !== join) {\r\n this._cachedDefines = join;\r\n\r\n effect = this._engine.createComputeEffect(shaderName, <IComputeEffectCreationOptions>{\r\n defines: join,\r\n entryPoint: this._options.entryPoint,\r\n onCompiled: this.onCompiled,\r\n onError: this.onError,\r\n });\r\n\r\n this._effect = effect;\r\n }\r\n\r\n if (!effect.isReady()) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Dispatches (executes) the compute shader\r\n * @param x Number of workgroups to execute on the X dimension\r\n * @param y Number of workgroups to execute on the Y dimension (default: 1)\r\n * @param z Number of workgroups to execute on the Z dimension (default: 1)\r\n * @returns True if the dispatch could be done, else false (meaning either the compute effect or at least one of the bound resources was not ready)\r\n */\r\n public dispatch(x: number, y?: number, z?: number): boolean {\r\n if (!this.fastMode) {\r\n if (!this.isReady()) {\r\n return false;\r\n }\r\n\r\n // If the sampling parameters of a texture bound to the shader have changed, we must clear the compute context so that it is recreated with the updated values\r\n // Also, if the actual (gpu) buffer used by a uniform buffer has changed, we must clear the compute context so that it is recreated with the updated value\r\n for (const key in this._bindings) {\r\n const binding = this._bindings[key];\r\n\r\n if (!this._options.bindingsMapping[key]) {\r\n throw new Error(\"ComputeShader ('\" + this.name + \"'): No binding mapping has been provided for the property '\" + key + \"'\");\r\n }\r\n\r\n switch (binding.type) {\r\n case ComputeBindingType.Texture: {\r\n const sampler = this._samplers[key];\r\n const texture = binding.object as BaseTexture;\r\n\r\n if (!sampler || !texture._texture || !sampler.compareSampler(texture._texture)) {\r\n this._samplers[key] = new TextureSampler().setParameters(\r\n texture.wrapU,\r\n texture.wrapV,\r\n texture.wrapR,\r\n texture.anisotropicFilteringLevel,\r\n texture._texture!.samplingMode,\r\n texture._texture?._comparisonFunction\r\n );\r\n this._contextIsDirty = true;\r\n }\r\n break;\r\n }\r\n case ComputeBindingType.ExternalTexture: {\r\n // we must recreate the bind groups each time if there's an external texture, because device.importExternalTexture must be called each frame\r\n this._contextIsDirty = true;\r\n break;\r\n }\r\n case ComputeBindingType.UniformBuffer: {\r\n const ubo = binding.object as UniformBuffer;\r\n if (ubo.getBuffer() !== binding.buffer) {\r\n binding.buffer = ubo.getBuffer();\r\n this._contextIsDirty = true;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n\r\n if (this._contextIsDirty) {\r\n this._contextIsDirty = false;\r\n this._context.clear();\r\n }\r\n }\r\n\r\n this._engine.computeDispatch(this._effect, this._context, this._bindings, x, y, z, this._options.bindingsMapping, this.gpuTimeInFrame);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Waits for the compute shader to be ready and executes it\r\n * @param x Number of workgroups to execute on the X dimension\r\n * @param y Number of workgroups to execute on the Y dimension (default: 1)\r\n * @param z Number of workgroups to execute on the Z dimension (default: 1)\r\n * @param delay Delay between the retries while the shader is not ready (in milliseconds - 10 by default)\r\n * @returns A promise that is resolved once the shader has been sent to the GPU. Note that it does not mean that the shader execution itself is finished!\r\n */\r\n public dispatchWhenReady(x: number, y?: number, z?: number, delay = 10): Promise<void> {\r\n return new Promise((resolve) => {\r\n const check = () => {\r\n if (!this.dispatch(x, y, z)) {\r\n setTimeout(check, delay);\r\n } else {\r\n resolve();\r\n }\r\n };\r\n\r\n check();\r\n });\r\n }\r\n\r\n /**\r\n * Serializes this compute shader in a JSON representation\r\n * @returns the serialized compute shader object\r\n */\r\n public serialize(): any {\r\n const serializationObject = SerializationHelper.Serialize(this);\r\n\r\n serializationObject.options = this._options;\r\n serializationObject.shaderPath = this._shaderPath;\r\n serializationObject.bindings = {};\r\n serializationObject.textures = {};\r\n\r\n for (const key in this._bindings) {\r\n const binding = this._bindings[key];\r\n const object = binding.object;\r\n\r\n switch (binding.type) {\r\n case ComputeBindingType.Texture:\r\n case ComputeBindingType.TextureWithoutSampler:\r\n case ComputeBindingType.StorageTexture: {\r\n const serializedData = (object as BaseTexture).serialize();\r\n if (serializedData) {\r\n serializationObject.textures[key] = serializedData;\r\n serializationObject.bindings[key] = {\r\n type: binding.type,\r\n };\r\n }\r\n break;\r\n }\r\n\r\n case ComputeBindingType.UniformBuffer: {\r\n break;\r\n }\r\n }\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Creates a compute shader from parsed compute shader data\r\n * @param source defines the JSON representation of the compute shader\r\n * @param scene defines the hosting scene\r\n * @param rootUrl defines the root URL to use to load textures and relative dependencies\r\n * @returns a new compute shader\r\n */\r\n public static Parse(source: any, scene: Scene, rootUrl: string): ComputeShader {\r\n const compute = SerializationHelper.Parse(\r\n () => new ComputeShader(source.name, scene.getEngine() as WebGPUEngine, source.shaderPath, source.options),\r\n source,\r\n scene,\r\n rootUrl\r\n );\r\n\r\n for (const key in source.textures) {\r\n const binding = source.bindings[key];\r\n const texture = <Texture>Texture.Parse(source.textures[key], scene, rootUrl);\r\n\r\n if (binding.type === ComputeBindingType.Texture) {\r\n compute.setTexture(key, texture);\r\n } else if (binding.type === ComputeBindingType.TextureWithoutSampler) {\r\n compute.setTexture(key, texture, false);\r\n } else {\r\n compute.setStorageTexture(key, texture);\r\n }\r\n }\r\n\r\n return compute;\r\n }\r\n\r\n protected static _BufferIsDataBuffer(buffer: UniformBuffer | StorageBuffer | DataBuffer): buffer is DataBuffer {\r\n return (buffer as DataBuffer).underlyingResource !== undefined;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.ComputeShader\", ComputeShader);\r\n"]}
@@ -1,4 +1,4 @@
1
- import type { ComputeEffect, IComputeEffectCreationOptions } from "../../Compute/computeEffect";
1
+ import type { ComputeEffect, IComputeEffectCreationOptions, IComputeShaderPath } from "../../Compute/computeEffect";
2
2
  import type { IComputeContext } from "../../Compute/IComputeContext";
3
3
  import type { IComputePipelineContext } from "../../Compute/IComputePipelineContext";
4
4
  import type { Nullable } from "../../types";
@@ -45,7 +45,12 @@ declare module "../../Engines/thinEngine" {
45
45
  * @param options Options used to create the effect
46
46
  * @returns The new compute effect
47
47
  */
48
- createComputeEffect(baseName: any, options: IComputeEffectCreationOptions): ComputeEffect;
48
+ createComputeEffect(baseName: IComputeShaderPath & {
49
+ /**
50
+ * @internal
51
+ */
52
+ computeToken?: string;
53
+ }, options: IComputeEffectCreationOptions): ComputeEffect;
49
54
  /**
50
55
  * Creates a new compute pipeline context
51
56
  * @returns the new pipeline
@@ -1 +1 @@
1
- {"version":3,"file":"engine.computeShader.js","sourceRoot":"","sources":["../../../../../dev/core/src/Engines/Extensions/engine.computeShader.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAgBtD,gBAAgB;AAChB,MAAM,CAAN,IAAY,kBASX;AATD,WAAY,kBAAkB;IAC1B,iEAAW,CAAA;IACX,+EAAkB,CAAA;IAClB,6EAAiB,CAAA;IACjB,6EAAiB,CAAA;IACjB,6FAAyB,CAAA;IACzB,iEAAW,CAAA;IACX,iFAAmB,CAAA;IACnB,uEAAc,CAAA;AAClB,CAAC,EATW,kBAAkB,KAAlB,kBAAkB,QAS7B;AAmFD,UAAU,CAAC,SAAS,CAAC,mBAAmB,GAAG,UAAU,QAAa,EAAE,OAAsC;IACtG,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAC;AAC1F,CAAC,CAAC;AAEF,UAAU,CAAC,SAAS,CAAC,4BAA4B,GAAG;IAChD,MAAM,IAAI,KAAK,CAAC,6EAA6E,CAAC,CAAC;AACnG,CAAC,CAAC;AAEF,UAAU,CAAC,SAAS,CAAC,oBAAoB,GAAG;IACxC,OAAO,SAAS,CAAC;AACrB,CAAC,CAAC;AAEF,UAAU,CAAC,SAAS,CAAC,eAAe,GAAG,UACnC,MAAqB,EACrB,OAAwB,EACxB,QAA4B,EAC5B,CAAS,EACT,CAAU,EACV,CAAU,EACV,eAAuC;IAEvC,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;AACtF,CAAC,CAAC;AAEF,UAAU,CAAC,SAAS,CAAC,yBAAyB,GAAG;IAC7C,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC;AAEF,UAAU,CAAC,SAAS,CAAC,qBAAqB,GAAG,cAAmB,CAAC,CAAC;AAElE,UAAU,CAAC,SAAS,CAAC,8BAA8B,GAAG,UAClD,eAAwC,EACxC,iBAAyB,EACzB,oBAA4B,EAC5B,OAAyB,EACzB,UAAkB,IACb,CAAC,CAAC;AAEX,UAAU,CAAC,SAAS,CAAC,sBAAsB,GAAG,cAAmB,CAAC,CAAC;AAEnE,UAAU,CAAC,SAAS,CAAC,kCAAkC,GAAG,UAAU,eAAwC,EAAE,MAAkB;IAC5H,MAAM,EAAE,CAAC;AACb,CAAC,CAAC;AAEF,UAAU,CAAC,SAAS,CAAC,qBAAqB,GAAG,UAAU,MAAqB,IAAS,CAAC,CAAC;AAEvF,UAAU,CAAC,SAAS,CAAC,6BAA6B,GAAG,UAAU,eAAwC,IAAS,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\r\nimport type { ComputeEffect, IComputeEffectCreationOptions } from \"../../Compute/computeEffect\";\r\nimport type { IComputeContext } from \"../../Compute/IComputeContext\";\r\nimport type { IComputePipelineContext } from \"../../Compute/IComputePipelineContext\";\r\nimport { ThinEngine } from \"../../Engines/thinEngine\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { WebGPUPerfCounter } from \"../WebGPU/webgpuPerfCounter\";\r\n\r\n/**\r\n * Type used to locate a resource in a compute shader.\r\n * TODO: remove this when browsers support reflection for wgsl shaders\r\n */\r\nexport type ComputeBindingLocation = { group: number; binding: number };\r\n\r\n/**\r\n * Type used to lookup a resource and retrieve its binding location\r\n * TODO: remove this when browsers support reflection for wgsl shaders\r\n */\r\nexport type ComputeBindingMapping = { [key: string]: ComputeBindingLocation };\r\n\r\n/** @internal */\r\nexport enum ComputeBindingType {\r\n Texture = 0,\r\n StorageTexture = 1,\r\n UniformBuffer = 2,\r\n StorageBuffer = 3,\r\n TextureWithoutSampler = 4,\r\n Sampler = 5,\r\n ExternalTexture = 6,\r\n DataBuffer = 7,\r\n}\r\n\r\n/** @internal */\r\nexport type ComputeBindingList = { [key: string]: { type: ComputeBindingType; object: any; indexInGroupEntries?: number } };\r\n\r\ndeclare module \"../../Engines/thinEngine\" {\r\n export interface ThinEngine {\r\n /**\r\n * Creates a new compute effect\r\n * @param baseName Name of the effect\r\n * @param options Options used to create the effect\r\n * @returns The new compute effect\r\n */\r\n createComputeEffect(baseName: any, options: IComputeEffectCreationOptions): ComputeEffect;\r\n\r\n /**\r\n * Creates a new compute pipeline context\r\n * @returns the new pipeline\r\n */\r\n createComputePipelineContext(): IComputePipelineContext;\r\n\r\n /**\r\n * Creates a new compute context\r\n * @returns the new context\r\n */\r\n createComputeContext(): IComputeContext | undefined;\r\n\r\n /**\r\n * Dispatches a compute shader\r\n * @param effect The compute effect\r\n * @param context The compute context\r\n * @param bindings The list of resources to bind to the shader\r\n * @param x The number of workgroups to execute on the X dimension\r\n * @param y The number of workgroups to execute on the Y dimension\r\n * @param z The number of workgroups to execute on the Z dimension\r\n * @param bindingsMapping list of bindings mapping (key is property name, value is binding location)\r\n * @param gpuPerfCounter GPU time computed for the compute shader will be assigned to this object\r\n */\r\n computeDispatch(\r\n effect: ComputeEffect,\r\n context: IComputeContext,\r\n bindings: ComputeBindingList,\r\n x: number,\r\n y?: number,\r\n z?: number,\r\n bindingsMapping?: ComputeBindingMapping,\r\n gpuPerfCounter?: WebGPUPerfCounter\r\n ): void;\r\n\r\n /**\r\n * Gets a boolean indicating if all created compute effects are ready\r\n * @returns true if all effects are ready\r\n */\r\n areAllComputeEffectsReady(): boolean;\r\n\r\n /**\r\n * Forces the engine to release all cached compute effects. This means that next effect compilation will have to be done completely even if a similar effect was already compiled\r\n */\r\n releaseComputeEffects(): void;\r\n\r\n /** @internal */\r\n _prepareComputePipelineContext(\r\n pipelineContext: IComputePipelineContext,\r\n computeSourceCode: string,\r\n rawComputeSourceCode: string,\r\n defines: Nullable<string>,\r\n entryPoint: string\r\n ): void;\r\n\r\n /** @internal */\r\n _rebuildComputeEffects(): void;\r\n\r\n /** @internal */\r\n _executeWhenComputeStateIsCompiled(pipelineContext: IComputePipelineContext, action: () => void): void;\r\n\r\n /** @internal */\r\n _releaseComputeEffect(effect: ComputeEffect): void;\r\n\r\n /** @internal */\r\n _deleteComputePipelineContext(pipelineContext: IComputePipelineContext): void;\r\n }\r\n}\r\n\r\nThinEngine.prototype.createComputeEffect = function (baseName: any, options: IComputeEffectCreationOptions): ComputeEffect {\r\n throw new Error(\"createComputeEffect: This engine does not support compute shaders!\");\r\n};\r\n\r\nThinEngine.prototype.createComputePipelineContext = function (): IComputePipelineContext {\r\n throw new Error(\"createComputePipelineContext: This engine does not support compute shaders!\");\r\n};\r\n\r\nThinEngine.prototype.createComputeContext = function (): IComputeContext | undefined {\r\n return undefined;\r\n};\r\n\r\nThinEngine.prototype.computeDispatch = function (\r\n effect: ComputeEffect,\r\n context: IComputeContext,\r\n bindings: ComputeBindingList,\r\n x: number,\r\n y?: number,\r\n z?: number,\r\n bindingsMapping?: ComputeBindingMapping\r\n): void {\r\n throw new Error(\"computeDispatch: This engine does not support compute shaders!\");\r\n};\r\n\r\nThinEngine.prototype.areAllComputeEffectsReady = function (): boolean {\r\n return true;\r\n};\r\n\r\nThinEngine.prototype.releaseComputeEffects = function (): void {};\r\n\r\nThinEngine.prototype._prepareComputePipelineContext = function (\r\n pipelineContext: IComputePipelineContext,\r\n computeSourceCode: string,\r\n rawComputeSourceCode: string,\r\n defines: Nullable<string>,\r\n entryPoint: string\r\n): void {};\r\n\r\nThinEngine.prototype._rebuildComputeEffects = function (): void {};\r\n\r\nThinEngine.prototype._executeWhenComputeStateIsCompiled = function (pipelineContext: IComputePipelineContext, action: () => void): void {\r\n action();\r\n};\r\n\r\nThinEngine.prototype._releaseComputeEffect = function (effect: ComputeEffect): void {};\r\n\r\nThinEngine.prototype._deleteComputePipelineContext = function (pipelineContext: IComputePipelineContext): void {};\r\n"]}
1
+ {"version":3,"file":"engine.computeShader.js","sourceRoot":"","sources":["../../../../../dev/core/src/Engines/Extensions/engine.computeShader.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAgBtD,gBAAgB;AAChB,MAAM,CAAN,IAAY,kBASX;AATD,WAAY,kBAAkB;IAC1B,iEAAW,CAAA;IACX,+EAAkB,CAAA;IAClB,6EAAiB,CAAA;IACjB,6EAAiB,CAAA;IACjB,6FAAyB,CAAA;IACzB,iEAAW,CAAA;IACX,iFAAmB,CAAA;IACnB,uEAAc,CAAA;AAClB,CAAC,EATW,kBAAkB,KAAlB,kBAAkB,QAS7B;AA2FD,UAAU,CAAC,SAAS,CAAC,mBAAmB,GAAG,UAAU,QAAwD,EAAE,OAAsC;IACjJ,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAC;AAC1F,CAAC,CAAC;AAEF,UAAU,CAAC,SAAS,CAAC,4BAA4B,GAAG;IAChD,MAAM,IAAI,KAAK,CAAC,6EAA6E,CAAC,CAAC;AACnG,CAAC,CAAC;AAEF,UAAU,CAAC,SAAS,CAAC,oBAAoB,GAAG;IACxC,OAAO,SAAS,CAAC;AACrB,CAAC,CAAC;AAEF,UAAU,CAAC,SAAS,CAAC,eAAe,GAAG,UACnC,MAAqB,EACrB,OAAwB,EACxB,QAA4B,EAC5B,CAAS,EACT,CAAU,EACV,CAAU,EACV,eAAuC;IAEvC,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;AACtF,CAAC,CAAC;AAEF,UAAU,CAAC,SAAS,CAAC,yBAAyB,GAAG;IAC7C,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC;AAEF,UAAU,CAAC,SAAS,CAAC,qBAAqB,GAAG,cAAmB,CAAC,CAAC;AAElE,UAAU,CAAC,SAAS,CAAC,8BAA8B,GAAG,UAClD,eAAwC,EACxC,iBAAyB,EACzB,oBAA4B,EAC5B,OAAyB,EACzB,UAAkB,IACb,CAAC,CAAC;AAEX,UAAU,CAAC,SAAS,CAAC,sBAAsB,GAAG,cAAmB,CAAC,CAAC;AAEnE,UAAU,CAAC,SAAS,CAAC,kCAAkC,GAAG,UAAU,eAAwC,EAAE,MAAkB;IAC5H,MAAM,EAAE,CAAC;AACb,CAAC,CAAC;AAEF,UAAU,CAAC,SAAS,CAAC,qBAAqB,GAAG,UAAU,MAAqB,IAAS,CAAC,CAAC;AAEvF,UAAU,CAAC,SAAS,CAAC,6BAA6B,GAAG,UAAU,eAAwC,IAAS,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\r\nimport type { ComputeEffect, IComputeEffectCreationOptions, IComputeShaderPath } from \"../../Compute/computeEffect\";\r\nimport type { IComputeContext } from \"../../Compute/IComputeContext\";\r\nimport type { IComputePipelineContext } from \"../../Compute/IComputePipelineContext\";\r\nimport { ThinEngine } from \"../../Engines/thinEngine\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { WebGPUPerfCounter } from \"../WebGPU/webgpuPerfCounter\";\r\n\r\n/**\r\n * Type used to locate a resource in a compute shader.\r\n * TODO: remove this when browsers support reflection for wgsl shaders\r\n */\r\nexport type ComputeBindingLocation = { group: number; binding: number };\r\n\r\n/**\r\n * Type used to lookup a resource and retrieve its binding location\r\n * TODO: remove this when browsers support reflection for wgsl shaders\r\n */\r\nexport type ComputeBindingMapping = { [key: string]: ComputeBindingLocation };\r\n\r\n/** @internal */\r\nexport enum ComputeBindingType {\r\n Texture = 0,\r\n StorageTexture = 1,\r\n UniformBuffer = 2,\r\n StorageBuffer = 3,\r\n TextureWithoutSampler = 4,\r\n Sampler = 5,\r\n ExternalTexture = 6,\r\n DataBuffer = 7,\r\n}\r\n\r\n/** @internal */\r\nexport type ComputeBindingList = { [key: string]: { type: ComputeBindingType; object: any; indexInGroupEntries?: number } };\r\n\r\ndeclare module \"../../Engines/thinEngine\" {\r\n export interface ThinEngine {\r\n /**\r\n * Creates a new compute effect\r\n * @param baseName Name of the effect\r\n * @param options Options used to create the effect\r\n * @returns The new compute effect\r\n */\r\n createComputeEffect(\r\n baseName: IComputeShaderPath & {\r\n /**\r\n * @internal\r\n */\r\n computeToken?: string;\r\n },\r\n options: IComputeEffectCreationOptions\r\n ): ComputeEffect;\r\n\r\n /**\r\n * Creates a new compute pipeline context\r\n * @returns the new pipeline\r\n */\r\n createComputePipelineContext(): IComputePipelineContext;\r\n\r\n /**\r\n * Creates a new compute context\r\n * @returns the new context\r\n */\r\n createComputeContext(): IComputeContext | undefined;\r\n\r\n /**\r\n * Dispatches a compute shader\r\n * @param effect The compute effect\r\n * @param context The compute context\r\n * @param bindings The list of resources to bind to the shader\r\n * @param x The number of workgroups to execute on the X dimension\r\n * @param y The number of workgroups to execute on the Y dimension\r\n * @param z The number of workgroups to execute on the Z dimension\r\n * @param bindingsMapping list of bindings mapping (key is property name, value is binding location)\r\n * @param gpuPerfCounter GPU time computed for the compute shader will be assigned to this object\r\n */\r\n computeDispatch(\r\n effect: ComputeEffect,\r\n context: IComputeContext,\r\n bindings: ComputeBindingList,\r\n x: number,\r\n y?: number,\r\n z?: number,\r\n bindingsMapping?: ComputeBindingMapping,\r\n gpuPerfCounter?: WebGPUPerfCounter\r\n ): void;\r\n\r\n /**\r\n * Gets a boolean indicating if all created compute effects are ready\r\n * @returns true if all effects are ready\r\n */\r\n areAllComputeEffectsReady(): boolean;\r\n\r\n /**\r\n * Forces the engine to release all cached compute effects. This means that next effect compilation will have to be done completely even if a similar effect was already compiled\r\n */\r\n releaseComputeEffects(): void;\r\n\r\n /** @internal */\r\n _prepareComputePipelineContext(\r\n pipelineContext: IComputePipelineContext,\r\n computeSourceCode: string,\r\n rawComputeSourceCode: string,\r\n defines: Nullable<string>,\r\n entryPoint: string\r\n ): void;\r\n\r\n /** @internal */\r\n _rebuildComputeEffects(): void;\r\n\r\n /** @internal */\r\n _executeWhenComputeStateIsCompiled(pipelineContext: IComputePipelineContext, action: () => void): void;\r\n\r\n /** @internal */\r\n _releaseComputeEffect(effect: ComputeEffect): void;\r\n\r\n /** @internal */\r\n _deleteComputePipelineContext(pipelineContext: IComputePipelineContext): void;\r\n }\r\n}\r\n\r\nThinEngine.prototype.createComputeEffect = function (baseName: IComputeShaderPath & { computeToken?: string }, options: IComputeEffectCreationOptions): ComputeEffect {\r\n throw new Error(\"createComputeEffect: This engine does not support compute shaders!\");\r\n};\r\n\r\nThinEngine.prototype.createComputePipelineContext = function (): IComputePipelineContext {\r\n throw new Error(\"createComputePipelineContext: This engine does not support compute shaders!\");\r\n};\r\n\r\nThinEngine.prototype.createComputeContext = function (): IComputeContext | undefined {\r\n return undefined;\r\n};\r\n\r\nThinEngine.prototype.computeDispatch = function (\r\n effect: ComputeEffect,\r\n context: IComputeContext,\r\n bindings: ComputeBindingList,\r\n x: number,\r\n y?: number,\r\n z?: number,\r\n bindingsMapping?: ComputeBindingMapping\r\n): void {\r\n throw new Error(\"computeDispatch: This engine does not support compute shaders!\");\r\n};\r\n\r\nThinEngine.prototype.areAllComputeEffectsReady = function (): boolean {\r\n return true;\r\n};\r\n\r\nThinEngine.prototype.releaseComputeEffects = function (): void {};\r\n\r\nThinEngine.prototype._prepareComputePipelineContext = function (\r\n pipelineContext: IComputePipelineContext,\r\n computeSourceCode: string,\r\n rawComputeSourceCode: string,\r\n defines: Nullable<string>,\r\n entryPoint: string\r\n): void {};\r\n\r\nThinEngine.prototype._rebuildComputeEffects = function (): void {};\r\n\r\nThinEngine.prototype._executeWhenComputeStateIsCompiled = function (pipelineContext: IComputePipelineContext, action: () => void): void {\r\n action();\r\n};\r\n\r\nThinEngine.prototype._releaseComputeEffect = function (effect: ComputeEffect): void {};\r\n\r\nThinEngine.prototype._deleteComputePipelineContext = function (pipelineContext: IComputePipelineContext): void {};\r\n"]}
@@ -101,6 +101,16 @@ export interface ITextMetrics {
101
101
  * property to the right side of the bounding rectangle of the given text
102
102
  */
103
103
  readonly actualBoundingBoxRight: number;
104
+ /**
105
+ * distance (in pixels) from the horizontal line indicated by the CanvasRenderingContext2D.textBaseline
106
+ * property to the top side of the bounding rectangle of the given text
107
+ */
108
+ readonly actualBoundingBoxAscent: number;
109
+ /**
110
+ * distance (in pixels) from the horizontal line indicated by the CanvasRenderingContext2D.textBaseline
111
+ * property to the bottom side of the bounding rectangle of the given text
112
+ */
113
+ readonly actualBoundingBoxDescent: number;
104
114
  }
105
115
  /**
106
116
  * Class used to abstract a matrix
@@ -1 +1 @@
1
- {"version":3,"file":"ICanvas.js","sourceRoot":"","sources":["../../../../dev/core/src/Engines/ICanvas.ts"],"names":[],"mappings":"","sourcesContent":["/**\r\n * Class used to abstract a canvas\r\n */\r\nexport interface ICanvas {\r\n /**\r\n * Canvas width.\r\n */\r\n width: number;\r\n\r\n /**\r\n * Canvas height.\r\n */\r\n height: number;\r\n\r\n /**\r\n * returns a drawing context on the canvas.\r\n * @param contextType context identifier.\r\n * @param contextAttributes context attributes.\r\n * @returns ICanvasRenderingContext object.\r\n */\r\n getContext(contextType: string, contextAttributes?: any): ICanvasRenderingContext;\r\n\r\n /**\r\n * returns a data URI containing a representation of the image in the format specified by the type parameter.\r\n * @param mime the image format.\r\n * @returns string containing the requested data URI.\r\n */\r\n toDataURL(mime: string): string;\r\n\r\n /**\r\n * Removes the canvas from the document.\r\n * Offscreen canvases don't have the remove function, so we need to make it optional.\r\n */\r\n remove?(): void;\r\n}\r\n\r\n/**\r\n * Class used to abstract am image to use with the canvas and its context\r\n */\r\nexport interface IImage {\r\n /**\r\n * onload callback.\r\n */\r\n onload: ((this: GlobalEventHandlers, ev: Event) => any) | null;\r\n\r\n /**\r\n * Error callback.\r\n */\r\n onerror: ((this: GlobalEventHandlers, ev: Event) => any) | null;\r\n\r\n /**\r\n * Image source.\r\n */\r\n src: string;\r\n\r\n /**\r\n * Image width.\r\n */\r\n readonly width: number;\r\n\r\n /**\r\n * Image height.\r\n */\r\n readonly height: number;\r\n\r\n /**\r\n * The original height of the image resource before sizing.\r\n */\r\n readonly naturalHeight: number;\r\n\r\n /**\r\n * The original width of the image resource before sizing.\r\n */\r\n readonly naturalWidth: number;\r\n\r\n /**\r\n * provides support for CORS, defining how the element handles crossorigin requests,\r\n * thereby enabling the configuration of the CORS requests for the element's fetched data.\r\n */\r\n crossOrigin: string | null;\r\n\r\n /**\r\n * provides support for referrer policy on xhr load request,\r\n * it is used to control the request header.\r\n */\r\n referrerPolicy: string;\r\n}\r\n\r\n/**\r\n * Class used to abstract a canvas gradient\r\n */\r\nexport interface ICanvasGradient {\r\n /**\r\n * adds a new color stop, defined by an offset and a color, to a given canvas gradient.\r\n * @param offset A number between 0 and 1, inclusive, representing the position of the color stop. 0 represents the start of the gradient and 1 represents the end.\r\n * @param color value representing the color of the stop.\r\n */\r\n addColorStop(offset: number, color: string): void;\r\n}\r\n\r\n/**\r\n * Class used to abstract a text measurement\r\n */\r\nexport interface ITextMetrics {\r\n /**\r\n * Text width.\r\n */\r\n readonly width: number;\r\n /**\r\n * distance (in pixels) parallel to the baseline from the alignment point given by the CanvasRenderingContext2D.textAlign\r\n * property to the left side of the bounding rectangle of the given text\r\n */\r\n readonly actualBoundingBoxLeft: number;\r\n /**\r\n * distance (in pixels) parallel to the baseline from the alignment point given by the CanvasRenderingContext2D.textAlign\r\n * property to the right side of the bounding rectangle of the given text\r\n */\r\n readonly actualBoundingBoxRight: number;\r\n}\r\n\r\n/**\r\n * Class used to abstract a matrix\r\n */\r\nexport interface DOMMatrix {\r\n /**\r\n * A Boolean flag whose value is true if the matrix was initialized as a 2D matrix. If false, the matrix is 3D.\r\n */\r\n is2D: boolean;\r\n /**\r\n * A Boolean whose value is true if the matrix is the identity matrix. The identity matrix is one in which every value is 0 except those on the main diagonal from top-left to bottom-right corner (in other words, where the offsets in each direction are equal).\r\n */\r\n isIdentity: boolean;\r\n /**\r\n * The following double-precision floating-point values represent the components of a matrix which are required in order to perform 2D rotations and translations.\r\n */\r\n a: number;\r\n /**\r\n * The following double-precision floating-point values represent the components of a matrix which are required in order to perform 2D rotations and translations.\r\n */\r\n b: number;\r\n /**\r\n * The following double-precision floating-point values represent the components of a matrix which are required in order to perform 2D rotations and translations.\r\n */\r\n c: number;\r\n /**\r\n * The following double-precision floating-point values represent the components of a matrix which are required in order to perform 2D rotations and translations.\r\n */\r\n d: number;\r\n /**\r\n * The following double-precision floating-point values represent the components of a matrix which are required in order to perform 2D rotations and translations.\r\n */\r\n e: number;\r\n /**\r\n * The following double-precision floating-point values represent the components of a matrix which are required in order to perform 2D rotations and translations.\r\n */\r\n f: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m11: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m12: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m13: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m14: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m21: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m22: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m23: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m24: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m31: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m32: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m33: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m34: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m41: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m42: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m43: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m44: number;\r\n}\r\n\r\n/**\r\n * Class used to abstract canvas rendering\r\n */\r\nexport interface ICanvasRenderingContext {\r\n /**\r\n * Defines the type of corners where two lines meet. Possible values: round, bevel, miter (default).\r\n */\r\n lineJoin: string;\r\n\r\n /**\r\n * Miter limit ratio. Default 10.\r\n */\r\n miterLimit: number;\r\n\r\n /**\r\n * Font setting. Default value 10px sans-serif.\r\n */\r\n font: string;\r\n\r\n /**\r\n * Color or style to use for the lines around shapes. Default #000 (black).\r\n */\r\n strokeStyle: string | ICanvasGradient;\r\n\r\n /**\r\n * Color or style to use inside shapes. Default #000 (black).\r\n */\r\n fillStyle: string | ICanvasGradient;\r\n\r\n /**\r\n * Alpha value that is applied to shapes and images before they are composited onto the canvas. Default 1.0 (opaque).\r\n */\r\n globalAlpha: number;\r\n\r\n /**\r\n * Color of the shadow. Default: fully-transparent black.\r\n */\r\n shadowColor: string;\r\n\r\n /**\r\n * Specifies the blurring effect. Default: 0.\r\n */\r\n shadowBlur: number;\r\n\r\n /**\r\n * Horizontal distance the shadow will be offset. Default: 0.\r\n */\r\n shadowOffsetX: number;\r\n\r\n /**\r\n * Vertical distance the shadow will be offset. Default: 0.\r\n */\r\n shadowOffsetY: number;\r\n\r\n /**\r\n * Width of lines. Default 1.0.\r\n */\r\n lineWidth: number;\r\n\r\n /**\r\n * canvas is a read-only reference to ICanvas.\r\n */\r\n readonly canvas: ICanvas;\r\n\r\n /**\r\n * Sets all pixels in the rectangle defined by starting point (x, y) and size (width, height) to transparent black, erasing any previously drawn content.\r\n * @param x The x-axis coordinate of the rectangle's starting point.\r\n * @param y The y-axis coordinate of the rectangle's starting point.\r\n * @param width The rectangle's width. Positive values are to the right, and negative to the left.\r\n * @param height The rectangle's height. Positive values are down, and negative are up.\r\n */\r\n clearRect(x: number, y: number, width: number, height: number): void;\r\n\r\n /**\r\n * Saves the current drawing style state using a stack so you can revert any change you make to it using restore().\r\n */\r\n save(): void;\r\n\r\n /**\r\n * Restores the drawing style state to the last element on the 'state stack' saved by save().\r\n */\r\n restore(): void;\r\n\r\n /**\r\n * Draws a filled rectangle at (x, y) position whose size is determined by width and height.\r\n * @param x The x-axis coordinate of the rectangle's starting point.\r\n * @param y The y-axis coordinate of the rectangle's starting point.\r\n * @param width The rectangle's width. Positive values are to the right, and negative to the left.\r\n * @param height The rectangle's height. Positive values are down, and negative are up.\r\n */\r\n fillRect(x: number, y: number, width: number, height: number): void;\r\n\r\n /**\r\n * Adds a scaling transformation to the canvas units by x horizontally and by y vertically.\r\n * @param x Scaling factor in the horizontal direction. A negative value flips pixels across the vertical axis. A value of 1 results in no horizontal scaling.\r\n * @param y Scaling factor in the vertical direction. A negative value flips pixels across the horizontal axis. A value of 1 results in no vertical scaling.\r\n */\r\n scale(x: number, y: number): void;\r\n\r\n /**\r\n * Adds a rotation to the transformation matrix. The angle argument represents a clockwise rotation angle and is expressed in radians.\r\n * @param angle The rotation angle, clockwise in radians. You can use degree * Math.PI / 180 to calculate a radian from a degree.\r\n */\r\n rotate(angle: number): void;\r\n\r\n /**\r\n * Adds a translation transformation by moving the canvas and its origin x horizontally and y vertically on the grid.\r\n * @param x Distance to move in the horizontal direction. Positive values are to the right, and negative to the left.\r\n * @param y Distance to move in the vertical direction. Positive values are down, and negative are up.\r\n */\r\n translate(x: number, y: number): void;\r\n\r\n /**\r\n * Paints a rectangle which has a starting point at (x, y) and has a w width and an h height onto the canvas, using the current stroke style.\r\n * @param x The x-axis coordinate of the rectangle's starting point.\r\n * @param y The y-axis coordinate of the rectangle's starting point.\r\n * @param width The rectangle's width. Positive values are to the right, and negative to the left.\r\n * @param height The rectangle's height. Positive values are down, and negative are up.\r\n */\r\n strokeRect(x: number, y: number, width: number, height: number): void;\r\n\r\n /**\r\n * Creates a path for a rectangle at position (x, y) with a size that is determined by width and height.\r\n * @param x The x-axis coordinate of the rectangle's starting point.\r\n * @param y The y-axis coordinate of the rectangle's starting point.\r\n * @param width The rectangle's width. Positive values are to the right, and negative to the left.\r\n * @param height The rectangle's height. Positive values are down, and negative are up.\r\n */\r\n rect(x: number, y: number, width: number, height: number): void;\r\n\r\n /**\r\n * Creates a clipping path from the current sub-paths. Everything drawn after clip() is called appears inside the clipping path only.\r\n */\r\n clip(): void;\r\n\r\n /**\r\n * Paints data from the given ImageData object onto the bitmap. If a dirty rectangle is provided, only the pixels from that rectangle are painted.\r\n * @param imageData An ImageData object containing the array of pixel values.\r\n * @param dx Horizontal position (x coordinate) at which to place the image data in the destination canvas.\r\n * @param dy Vertical position (y coordinate) at which to place the image data in the destination canvas.\r\n */\r\n putImageData(imageData: ImageData, dx: number, dy: number): void;\r\n\r\n /**\r\n * Adds a circular arc to the current path.\r\n * @param x The horizontal coordinate of the arc's center.\r\n * @param y The vertical coordinate of the arc's center.\r\n * @param radius The arc's radius. Must be positive.\r\n * @param startAngle The angle at which the arc starts in radians, measured from the positive x-axis.\r\n * @param endAngle The angle at which the arc ends in radians, measured from the positive x-axis.\r\n * @param anticlockwise An optional Boolean. If true, draws the arc counter-clockwise between the start and end angles. The default is false (clockwise).\r\n */\r\n arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean): void;\r\n\r\n /**\r\n * Starts a new path by emptying the list of sub-paths. Call this method when you want to create a new path.\r\n */\r\n beginPath(): void;\r\n\r\n /**\r\n * Causes the point of the pen to move back to the start of the current sub-path. It tries to draw a straight line from the current point to the start.\r\n * If the shape has already been closed or has only one point, this function does nothing.\r\n */\r\n closePath(): void;\r\n\r\n /**\r\n * Moves the starting point of a new sub-path to the (x, y) coordinates.\r\n * @param x The x-axis (horizontal) coordinate of the point.\r\n * @param y The y-axis (vertical) coordinate of the point.\r\n */\r\n moveTo(x: number, y: number): void;\r\n\r\n /**\r\n * Connects the last point in the current sub-path to the specified (x, y) coordinates with a straight line.\r\n * @param x The x-axis coordinate of the line's end point.\r\n * @param y The y-axis coordinate of the line's end point.\r\n */\r\n lineTo(x: number, y: number): void;\r\n\r\n /**\r\n * Adds a quadratic Bézier curve to the current path.\r\n * @param cpx The x-axis coordinate of the control point.\r\n * @param cpy The y-axis coordinate of the control point.\r\n * @param x The x-axis coordinate of the end point.\r\n * @param y The y-axis coordinate of the end point.\r\n */\r\n quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void;\r\n\r\n /**\r\n * Returns a TextMetrics object.\r\n * @param text The text String to measure.\r\n * @returns ITextMetrics A ITextMetrics object.\r\n */\r\n measureText(text: string): ITextMetrics;\r\n\r\n /**\r\n * Strokes the current sub-paths with the current stroke style.\r\n */\r\n stroke(): void;\r\n\r\n /**\r\n * Fills the current sub-paths with the current fill style.\r\n */\r\n fill(): void;\r\n\r\n /**\r\n * Draws the specified image. This method is available in multiple formats, providing a great deal of flexibility in its use.\r\n * @param image An element to draw into the context.\r\n * @param sx The x-axis coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination context.\r\n * @param sy The y-axis coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination context.\r\n * @param sWidth The width of the sub-rectangle of the source image to draw into the destination context. If not specified, the entire rectangle from the coordinates specified by sx and sy to the bottom-right corner of the image is used.\r\n * @param sHeight The height of the sub-rectangle of the source image to draw into the destination context.\r\n * @param dx The x-axis coordinate in the destination canvas at which to place the top-left corner of the source image.\r\n * @param dy The y-axis coordinate in the destination canvas at which to place the top-left corner of the source image.\r\n * @param dWidth The width to draw the image in the destination canvas. This allows scaling of the drawn image. If not specified, the image is not scaled in width when drawn.\r\n * @param dHeight The height to draw the image in the destination canvas. This allows scaling of the drawn image. If not specified, the image is not scaled in height when drawn.\r\n */\r\n\r\n drawImage(image: any, sx: number, sy: number, sWidth: number, sHeight: number, dx: number, dy: number, dWidth: number, dHeight: number): void;\r\n /**\r\n * Draws the specified image. This method is available in multiple formats, providing a great deal of flexibility in its use.\r\n * @param image An element to draw into the context.\r\n * @param dx The x-axis coordinate in the destination canvas at which to place the top-left corner of the source image.\r\n * @param dy The y-axis coordinate in the destination canvas at which to place the top-left corner of the source image.\r\n * @param dWidth The width to draw the image in the destination canvas. This allows scaling of the drawn image. If not specified, the image is not scaled in width when drawn.\r\n * @param dHeight The height to draw the image in the destination canvas. This allows scaling of the drawn image. If not specified, the image is not scaled in height when drawn.\r\n */\r\n drawImage(image: any, dx: number, dy: number, dWidth: number, dHeight: number): void;\r\n\r\n /**\r\n * Draws the specified image. This method is available in multiple formats, providing a great deal of flexibility in its use.\r\n * @param image An element to draw into the context.\r\n * @param dx The x-axis coordinate in the destination canvas at which to place the top-left corner of the source image.\r\n * @param dy The y-axis coordinate in the destination canvas at which to place the top-left corner of the source image.\r\n */\r\n drawImage(image: any, dx: number, dy: number): void;\r\n\r\n /**\r\n * Returns an ImageData object representing the underlying pixel data for the area of the canvas denoted by the rectangle which starts at (sx, sy) and has an sw width and sh height.\r\n * @param sx The x-axis coordinate of the top-left corner of the rectangle from which the ImageData will be extracted.\r\n * @param sy The y-axis coordinate of the top-left corner of the rectangle from which the ImageData will be extracted.\r\n * @param sw The width of the rectangle from which the ImageData will be extracted. Positive values are to the right, and negative to the left.\r\n * @param sh The height of the rectangle from which the ImageData will be extracted. Positive values are down, and negative are up.\r\n * @returns ImageData An ImageData object containing the image data for the rectangle of the canvas specified.\r\n */\r\n getImageData(sx: number, sy: number, sw: number, sh: number): ImageData;\r\n\r\n /**\r\n * Sets the current line dash pattern.\r\n * @param segments An Array of numbers that specify distances to alternately draw a line and a gap (in coordinate space units).\r\n */\r\n setLineDash(segments: Array<number>): void;\r\n\r\n /**\r\n * Draws (fills) a given text at the given (x, y) position.\r\n * @param text A String specifying the text string to render into the context. The text is rendered using the settings specified by font, textAlign, textBaseline, and direction.\r\n * @param x The x-axis coordinate of the point at which to begin drawing the text, in pixels.\r\n * @param y The y-axis coordinate of the baseline on which to begin drawing the text, in pixels.\r\n * @param maxWidth The maximum number of pixels wide the text may be once rendered. If not specified, there is no limit to the width of the text.\r\n */\r\n fillText(text: string, x: number, y: number, maxWidth?: number): void;\r\n\r\n /**\r\n * Draws (strokes) a given text at the given (x, y) position.\r\n * @param text A String specifying the text string to render into the context. The text is rendered using the settings specified by font, textAlign, textBaseline, and direction.\r\n * @param x The x-axis coordinate of the point at which to begin drawing the text, in pixels.\r\n * @param y The y-axis coordinate of the baseline on which to begin drawing the text, in pixels.\r\n * @param maxWidth The maximum number of pixels wide the text may be once rendered. If not specified, there is no limit to the width of the text.\r\n */\r\n strokeText(text: string, x: number, y: number, maxWidth?: number): void;\r\n\r\n /**\r\n * Creates a linear gradient along the line given by the coordinates represented by the parameters.\r\n * @param x0 The x-axis coordinate of the start point.\r\n * @param y0 The y-axis coordinate of the start point.\r\n * @param x1 The x-axis coordinate of the end point.\r\n * @param y1 The y-axis coordinate of the end point.\r\n * @returns ICanvasGradient A linear ICanvasGradient initialized with the specified line.\r\n */\r\n createLinearGradient(x0: number, y0: number, x1: number, y1: number): ICanvasGradient;\r\n\r\n /**\r\n * Creates a linear gradient along the line given by the coordinates represented by the parameters.\r\n * @param x0 The x-axis coordinate of the start circle.\r\n * @param y0 The y-axis coordinate of the start circle.\r\n * @param r0 The radius of the start circle. Must be non-negative and finite.\r\n * @param x1 The x-axis coordinate of the end point.\r\n * @param y1 The y-axis coordinate of the end point.\r\n * @param r1 The radius of the end circle. Must be non-negative and finite.\r\n * @returns ICanvasGradient A linear ICanvasGradient initialized with the two specified circles.\r\n */\r\n createRadialGradient(x0: number, y0: number, r0: number, x1: number, y1: number, r1: number): ICanvasGradient;\r\n\r\n /**\r\n * Resets the current transform to matrix composed with a, b, c, d, e, f.\r\n * @param a Horizontal scaling. A value of 1 results in no scaling.\r\n * @param b Vertical skewing.\r\n * @param c Horizontal skewing.\r\n * @param d Vertical scaling. A value of 1 results in no scaling.\r\n * @param e Horizontal translation (moving).\r\n * @param f Vertical translation (moving).\r\n */\r\n setTransform(a: number, b: number, c: number, d: number, e: number, f: number): void;\r\n\r\n /**\r\n * Retrieves the current transformation matrix being applied to the context.\r\n */\r\n getTransform(): DOMMatrix;\r\n}\r\n"]}
1
+ {"version":3,"file":"ICanvas.js","sourceRoot":"","sources":["../../../../dev/core/src/Engines/ICanvas.ts"],"names":[],"mappings":"","sourcesContent":["/**\r\n * Class used to abstract a canvas\r\n */\r\nexport interface ICanvas {\r\n /**\r\n * Canvas width.\r\n */\r\n width: number;\r\n\r\n /**\r\n * Canvas height.\r\n */\r\n height: number;\r\n\r\n /**\r\n * returns a drawing context on the canvas.\r\n * @param contextType context identifier.\r\n * @param contextAttributes context attributes.\r\n * @returns ICanvasRenderingContext object.\r\n */\r\n getContext(contextType: string, contextAttributes?: any): ICanvasRenderingContext;\r\n\r\n /**\r\n * returns a data URI containing a representation of the image in the format specified by the type parameter.\r\n * @param mime the image format.\r\n * @returns string containing the requested data URI.\r\n */\r\n toDataURL(mime: string): string;\r\n\r\n /**\r\n * Removes the canvas from the document.\r\n * Offscreen canvases don't have the remove function, so we need to make it optional.\r\n */\r\n remove?(): void;\r\n}\r\n\r\n/**\r\n * Class used to abstract am image to use with the canvas and its context\r\n */\r\nexport interface IImage {\r\n /**\r\n * onload callback.\r\n */\r\n onload: ((this: GlobalEventHandlers, ev: Event) => any) | null;\r\n\r\n /**\r\n * Error callback.\r\n */\r\n onerror: ((this: GlobalEventHandlers, ev: Event) => any) | null;\r\n\r\n /**\r\n * Image source.\r\n */\r\n src: string;\r\n\r\n /**\r\n * Image width.\r\n */\r\n readonly width: number;\r\n\r\n /**\r\n * Image height.\r\n */\r\n readonly height: number;\r\n\r\n /**\r\n * The original height of the image resource before sizing.\r\n */\r\n readonly naturalHeight: number;\r\n\r\n /**\r\n * The original width of the image resource before sizing.\r\n */\r\n readonly naturalWidth: number;\r\n\r\n /**\r\n * provides support for CORS, defining how the element handles crossorigin requests,\r\n * thereby enabling the configuration of the CORS requests for the element's fetched data.\r\n */\r\n crossOrigin: string | null;\r\n\r\n /**\r\n * provides support for referrer policy on xhr load request,\r\n * it is used to control the request header.\r\n */\r\n referrerPolicy: string;\r\n}\r\n\r\n/**\r\n * Class used to abstract a canvas gradient\r\n */\r\nexport interface ICanvasGradient {\r\n /**\r\n * adds a new color stop, defined by an offset and a color, to a given canvas gradient.\r\n * @param offset A number between 0 and 1, inclusive, representing the position of the color stop. 0 represents the start of the gradient and 1 represents the end.\r\n * @param color value representing the color of the stop.\r\n */\r\n addColorStop(offset: number, color: string): void;\r\n}\r\n\r\n/**\r\n * Class used to abstract a text measurement\r\n */\r\nexport interface ITextMetrics {\r\n /**\r\n * Text width.\r\n */\r\n readonly width: number;\r\n /**\r\n * distance (in pixels) parallel to the baseline from the alignment point given by the CanvasRenderingContext2D.textAlign\r\n * property to the left side of the bounding rectangle of the given text\r\n */\r\n readonly actualBoundingBoxLeft: number;\r\n /**\r\n * distance (in pixels) parallel to the baseline from the alignment point given by the CanvasRenderingContext2D.textAlign\r\n * property to the right side of the bounding rectangle of the given text\r\n */\r\n readonly actualBoundingBoxRight: number;\r\n /**\r\n * distance (in pixels) from the horizontal line indicated by the CanvasRenderingContext2D.textBaseline\r\n * property to the top side of the bounding rectangle of the given text\r\n */\r\n readonly actualBoundingBoxAscent: number;\r\n /**\r\n * distance (in pixels) from the horizontal line indicated by the CanvasRenderingContext2D.textBaseline\r\n * property to the bottom side of the bounding rectangle of the given text\r\n */\r\n readonly actualBoundingBoxDescent: number;\r\n}\r\n\r\n/**\r\n * Class used to abstract a matrix\r\n */\r\nexport interface DOMMatrix {\r\n /**\r\n * A Boolean flag whose value is true if the matrix was initialized as a 2D matrix. If false, the matrix is 3D.\r\n */\r\n is2D: boolean;\r\n /**\r\n * A Boolean whose value is true if the matrix is the identity matrix. The identity matrix is one in which every value is 0 except those on the main diagonal from top-left to bottom-right corner (in other words, where the offsets in each direction are equal).\r\n */\r\n isIdentity: boolean;\r\n /**\r\n * The following double-precision floating-point values represent the components of a matrix which are required in order to perform 2D rotations and translations.\r\n */\r\n a: number;\r\n /**\r\n * The following double-precision floating-point values represent the components of a matrix which are required in order to perform 2D rotations and translations.\r\n */\r\n b: number;\r\n /**\r\n * The following double-precision floating-point values represent the components of a matrix which are required in order to perform 2D rotations and translations.\r\n */\r\n c: number;\r\n /**\r\n * The following double-precision floating-point values represent the components of a matrix which are required in order to perform 2D rotations and translations.\r\n */\r\n d: number;\r\n /**\r\n * The following double-precision floating-point values represent the components of a matrix which are required in order to perform 2D rotations and translations.\r\n */\r\n e: number;\r\n /**\r\n * The following double-precision floating-point values represent the components of a matrix which are required in order to perform 2D rotations and translations.\r\n */\r\n f: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m11: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m12: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m13: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m14: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m21: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m22: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m23: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m24: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m31: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m32: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m33: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m34: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m41: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m42: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m43: number;\r\n /**\r\n * The following are double-precision floating-point values representing each component of a 4×4 matrix, where m11 through m14 are the first column, m21 through m24 are the second column, and so forth.\r\n */\r\n m44: number;\r\n}\r\n\r\n/**\r\n * Class used to abstract canvas rendering\r\n */\r\nexport interface ICanvasRenderingContext {\r\n /**\r\n * Defines the type of corners where two lines meet. Possible values: round, bevel, miter (default).\r\n */\r\n lineJoin: string;\r\n\r\n /**\r\n * Miter limit ratio. Default 10.\r\n */\r\n miterLimit: number;\r\n\r\n /**\r\n * Font setting. Default value 10px sans-serif.\r\n */\r\n font: string;\r\n\r\n /**\r\n * Color or style to use for the lines around shapes. Default #000 (black).\r\n */\r\n strokeStyle: string | ICanvasGradient;\r\n\r\n /**\r\n * Color or style to use inside shapes. Default #000 (black).\r\n */\r\n fillStyle: string | ICanvasGradient;\r\n\r\n /**\r\n * Alpha value that is applied to shapes and images before they are composited onto the canvas. Default 1.0 (opaque).\r\n */\r\n globalAlpha: number;\r\n\r\n /**\r\n * Color of the shadow. Default: fully-transparent black.\r\n */\r\n shadowColor: string;\r\n\r\n /**\r\n * Specifies the blurring effect. Default: 0.\r\n */\r\n shadowBlur: number;\r\n\r\n /**\r\n * Horizontal distance the shadow will be offset. Default: 0.\r\n */\r\n shadowOffsetX: number;\r\n\r\n /**\r\n * Vertical distance the shadow will be offset. Default: 0.\r\n */\r\n shadowOffsetY: number;\r\n\r\n /**\r\n * Width of lines. Default 1.0.\r\n */\r\n lineWidth: number;\r\n\r\n /**\r\n * canvas is a read-only reference to ICanvas.\r\n */\r\n readonly canvas: ICanvas;\r\n\r\n /**\r\n * Sets all pixels in the rectangle defined by starting point (x, y) and size (width, height) to transparent black, erasing any previously drawn content.\r\n * @param x The x-axis coordinate of the rectangle's starting point.\r\n * @param y The y-axis coordinate of the rectangle's starting point.\r\n * @param width The rectangle's width. Positive values are to the right, and negative to the left.\r\n * @param height The rectangle's height. Positive values are down, and negative are up.\r\n */\r\n clearRect(x: number, y: number, width: number, height: number): void;\r\n\r\n /**\r\n * Saves the current drawing style state using a stack so you can revert any change you make to it using restore().\r\n */\r\n save(): void;\r\n\r\n /**\r\n * Restores the drawing style state to the last element on the 'state stack' saved by save().\r\n */\r\n restore(): void;\r\n\r\n /**\r\n * Draws a filled rectangle at (x, y) position whose size is determined by width and height.\r\n * @param x The x-axis coordinate of the rectangle's starting point.\r\n * @param y The y-axis coordinate of the rectangle's starting point.\r\n * @param width The rectangle's width. Positive values are to the right, and negative to the left.\r\n * @param height The rectangle's height. Positive values are down, and negative are up.\r\n */\r\n fillRect(x: number, y: number, width: number, height: number): void;\r\n\r\n /**\r\n * Adds a scaling transformation to the canvas units by x horizontally and by y vertically.\r\n * @param x Scaling factor in the horizontal direction. A negative value flips pixels across the vertical axis. A value of 1 results in no horizontal scaling.\r\n * @param y Scaling factor in the vertical direction. A negative value flips pixels across the horizontal axis. A value of 1 results in no vertical scaling.\r\n */\r\n scale(x: number, y: number): void;\r\n\r\n /**\r\n * Adds a rotation to the transformation matrix. The angle argument represents a clockwise rotation angle and is expressed in radians.\r\n * @param angle The rotation angle, clockwise in radians. You can use degree * Math.PI / 180 to calculate a radian from a degree.\r\n */\r\n rotate(angle: number): void;\r\n\r\n /**\r\n * Adds a translation transformation by moving the canvas and its origin x horizontally and y vertically on the grid.\r\n * @param x Distance to move in the horizontal direction. Positive values are to the right, and negative to the left.\r\n * @param y Distance to move in the vertical direction. Positive values are down, and negative are up.\r\n */\r\n translate(x: number, y: number): void;\r\n\r\n /**\r\n * Paints a rectangle which has a starting point at (x, y) and has a w width and an h height onto the canvas, using the current stroke style.\r\n * @param x The x-axis coordinate of the rectangle's starting point.\r\n * @param y The y-axis coordinate of the rectangle's starting point.\r\n * @param width The rectangle's width. Positive values are to the right, and negative to the left.\r\n * @param height The rectangle's height. Positive values are down, and negative are up.\r\n */\r\n strokeRect(x: number, y: number, width: number, height: number): void;\r\n\r\n /**\r\n * Creates a path for a rectangle at position (x, y) with a size that is determined by width and height.\r\n * @param x The x-axis coordinate of the rectangle's starting point.\r\n * @param y The y-axis coordinate of the rectangle's starting point.\r\n * @param width The rectangle's width. Positive values are to the right, and negative to the left.\r\n * @param height The rectangle's height. Positive values are down, and negative are up.\r\n */\r\n rect(x: number, y: number, width: number, height: number): void;\r\n\r\n /**\r\n * Creates a clipping path from the current sub-paths. Everything drawn after clip() is called appears inside the clipping path only.\r\n */\r\n clip(): void;\r\n\r\n /**\r\n * Paints data from the given ImageData object onto the bitmap. If a dirty rectangle is provided, only the pixels from that rectangle are painted.\r\n * @param imageData An ImageData object containing the array of pixel values.\r\n * @param dx Horizontal position (x coordinate) at which to place the image data in the destination canvas.\r\n * @param dy Vertical position (y coordinate) at which to place the image data in the destination canvas.\r\n */\r\n putImageData(imageData: ImageData, dx: number, dy: number): void;\r\n\r\n /**\r\n * Adds a circular arc to the current path.\r\n * @param x The horizontal coordinate of the arc's center.\r\n * @param y The vertical coordinate of the arc's center.\r\n * @param radius The arc's radius. Must be positive.\r\n * @param startAngle The angle at which the arc starts in radians, measured from the positive x-axis.\r\n * @param endAngle The angle at which the arc ends in radians, measured from the positive x-axis.\r\n * @param anticlockwise An optional Boolean. If true, draws the arc counter-clockwise between the start and end angles. The default is false (clockwise).\r\n */\r\n arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean): void;\r\n\r\n /**\r\n * Starts a new path by emptying the list of sub-paths. Call this method when you want to create a new path.\r\n */\r\n beginPath(): void;\r\n\r\n /**\r\n * Causes the point of the pen to move back to the start of the current sub-path. It tries to draw a straight line from the current point to the start.\r\n * If the shape has already been closed or has only one point, this function does nothing.\r\n */\r\n closePath(): void;\r\n\r\n /**\r\n * Moves the starting point of a new sub-path to the (x, y) coordinates.\r\n * @param x The x-axis (horizontal) coordinate of the point.\r\n * @param y The y-axis (vertical) coordinate of the point.\r\n */\r\n moveTo(x: number, y: number): void;\r\n\r\n /**\r\n * Connects the last point in the current sub-path to the specified (x, y) coordinates with a straight line.\r\n * @param x The x-axis coordinate of the line's end point.\r\n * @param y The y-axis coordinate of the line's end point.\r\n */\r\n lineTo(x: number, y: number): void;\r\n\r\n /**\r\n * Adds a quadratic Bézier curve to the current path.\r\n * @param cpx The x-axis coordinate of the control point.\r\n * @param cpy The y-axis coordinate of the control point.\r\n * @param x The x-axis coordinate of the end point.\r\n * @param y The y-axis coordinate of the end point.\r\n */\r\n quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void;\r\n\r\n /**\r\n * Returns a TextMetrics object.\r\n * @param text The text String to measure.\r\n * @returns ITextMetrics A ITextMetrics object.\r\n */\r\n measureText(text: string): ITextMetrics;\r\n\r\n /**\r\n * Strokes the current sub-paths with the current stroke style.\r\n */\r\n stroke(): void;\r\n\r\n /**\r\n * Fills the current sub-paths with the current fill style.\r\n */\r\n fill(): void;\r\n\r\n /**\r\n * Draws the specified image. This method is available in multiple formats, providing a great deal of flexibility in its use.\r\n * @param image An element to draw into the context.\r\n * @param sx The x-axis coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination context.\r\n * @param sy The y-axis coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination context.\r\n * @param sWidth The width of the sub-rectangle of the source image to draw into the destination context. If not specified, the entire rectangle from the coordinates specified by sx and sy to the bottom-right corner of the image is used.\r\n * @param sHeight The height of the sub-rectangle of the source image to draw into the destination context.\r\n * @param dx The x-axis coordinate in the destination canvas at which to place the top-left corner of the source image.\r\n * @param dy The y-axis coordinate in the destination canvas at which to place the top-left corner of the source image.\r\n * @param dWidth The width to draw the image in the destination canvas. This allows scaling of the drawn image. If not specified, the image is not scaled in width when drawn.\r\n * @param dHeight The height to draw the image in the destination canvas. This allows scaling of the drawn image. If not specified, the image is not scaled in height when drawn.\r\n */\r\n\r\n drawImage(image: any, sx: number, sy: number, sWidth: number, sHeight: number, dx: number, dy: number, dWidth: number, dHeight: number): void;\r\n /**\r\n * Draws the specified image. This method is available in multiple formats, providing a great deal of flexibility in its use.\r\n * @param image An element to draw into the context.\r\n * @param dx The x-axis coordinate in the destination canvas at which to place the top-left corner of the source image.\r\n * @param dy The y-axis coordinate in the destination canvas at which to place the top-left corner of the source image.\r\n * @param dWidth The width to draw the image in the destination canvas. This allows scaling of the drawn image. If not specified, the image is not scaled in width when drawn.\r\n * @param dHeight The height to draw the image in the destination canvas. This allows scaling of the drawn image. If not specified, the image is not scaled in height when drawn.\r\n */\r\n drawImage(image: any, dx: number, dy: number, dWidth: number, dHeight: number): void;\r\n\r\n /**\r\n * Draws the specified image. This method is available in multiple formats, providing a great deal of flexibility in its use.\r\n * @param image An element to draw into the context.\r\n * @param dx The x-axis coordinate in the destination canvas at which to place the top-left corner of the source image.\r\n * @param dy The y-axis coordinate in the destination canvas at which to place the top-left corner of the source image.\r\n */\r\n drawImage(image: any, dx: number, dy: number): void;\r\n\r\n /**\r\n * Returns an ImageData object representing the underlying pixel data for the area of the canvas denoted by the rectangle which starts at (sx, sy) and has an sw width and sh height.\r\n * @param sx The x-axis coordinate of the top-left corner of the rectangle from which the ImageData will be extracted.\r\n * @param sy The y-axis coordinate of the top-left corner of the rectangle from which the ImageData will be extracted.\r\n * @param sw The width of the rectangle from which the ImageData will be extracted. Positive values are to the right, and negative to the left.\r\n * @param sh The height of the rectangle from which the ImageData will be extracted. Positive values are down, and negative are up.\r\n * @returns ImageData An ImageData object containing the image data for the rectangle of the canvas specified.\r\n */\r\n getImageData(sx: number, sy: number, sw: number, sh: number): ImageData;\r\n\r\n /**\r\n * Sets the current line dash pattern.\r\n * @param segments An Array of numbers that specify distances to alternately draw a line and a gap (in coordinate space units).\r\n */\r\n setLineDash(segments: Array<number>): void;\r\n\r\n /**\r\n * Draws (fills) a given text at the given (x, y) position.\r\n * @param text A String specifying the text string to render into the context. The text is rendered using the settings specified by font, textAlign, textBaseline, and direction.\r\n * @param x The x-axis coordinate of the point at which to begin drawing the text, in pixels.\r\n * @param y The y-axis coordinate of the baseline on which to begin drawing the text, in pixels.\r\n * @param maxWidth The maximum number of pixels wide the text may be once rendered. If not specified, there is no limit to the width of the text.\r\n */\r\n fillText(text: string, x: number, y: number, maxWidth?: number): void;\r\n\r\n /**\r\n * Draws (strokes) a given text at the given (x, y) position.\r\n * @param text A String specifying the text string to render into the context. The text is rendered using the settings specified by font, textAlign, textBaseline, and direction.\r\n * @param x The x-axis coordinate of the point at which to begin drawing the text, in pixels.\r\n * @param y The y-axis coordinate of the baseline on which to begin drawing the text, in pixels.\r\n * @param maxWidth The maximum number of pixels wide the text may be once rendered. If not specified, there is no limit to the width of the text.\r\n */\r\n strokeText(text: string, x: number, y: number, maxWidth?: number): void;\r\n\r\n /**\r\n * Creates a linear gradient along the line given by the coordinates represented by the parameters.\r\n * @param x0 The x-axis coordinate of the start point.\r\n * @param y0 The y-axis coordinate of the start point.\r\n * @param x1 The x-axis coordinate of the end point.\r\n * @param y1 The y-axis coordinate of the end point.\r\n * @returns ICanvasGradient A linear ICanvasGradient initialized with the specified line.\r\n */\r\n createLinearGradient(x0: number, y0: number, x1: number, y1: number): ICanvasGradient;\r\n\r\n /**\r\n * Creates a linear gradient along the line given by the coordinates represented by the parameters.\r\n * @param x0 The x-axis coordinate of the start circle.\r\n * @param y0 The y-axis coordinate of the start circle.\r\n * @param r0 The radius of the start circle. Must be non-negative and finite.\r\n * @param x1 The x-axis coordinate of the end point.\r\n * @param y1 The y-axis coordinate of the end point.\r\n * @param r1 The radius of the end circle. Must be non-negative and finite.\r\n * @returns ICanvasGradient A linear ICanvasGradient initialized with the two specified circles.\r\n */\r\n createRadialGradient(x0: number, y0: number, r0: number, x1: number, y1: number, r1: number): ICanvasGradient;\r\n\r\n /**\r\n * Resets the current transform to matrix composed with a, b, c, d, e, f.\r\n * @param a Horizontal scaling. A value of 1 results in no scaling.\r\n * @param b Vertical skewing.\r\n * @param c Horizontal skewing.\r\n * @param d Vertical scaling. A value of 1 results in no scaling.\r\n * @param e Horizontal translation (moving).\r\n * @param f Vertical translation (moving).\r\n */\r\n setTransform(a: number, b: number, c: number, d: number, e: number, f: number): void;\r\n\r\n /**\r\n * Retrieves the current transformation matrix being applied to the context.\r\n */\r\n getTransform(): DOMMatrix;\r\n}\r\n"]}
@@ -1,3 +1,4 @@
1
+ import type { DeepImmutable, FloatArray } from "../../types";
1
2
  /** @internal */
2
3
  export type NativeData = Uint32Array;
3
4
  /** @internal */
@@ -39,7 +40,7 @@ export declare class NativeDataStream {
39
40
  * Writes a float32 array to the stream
40
41
  * @param values the values to write
41
42
  */
42
- writeFloat32Array(values: Float32Array): void;
43
+ writeFloat32Array(values: DeepImmutable<FloatArray>): void;
43
44
  /**
44
45
  * Writes native data to the stream
45
46
  * @param handle the handle to the native data
@@ -1 +1 @@
1
- {"version":3,"file":"nativeDataStream.js","sourceRoot":"","sources":["../../../../../dev/core/src/Engines/Native/nativeDataStream.ts"],"names":[],"mappings":"AAOA,gBAAgB;AAChB,MAAM,OAAO,gBAAgB;IAYzB;QACI,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,CAAC;QACrE,IAAI,CAAC,QAAQ,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;QACxC,IAAI,CAAC,OAAO,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;QACtC,IAAI,CAAC,SAAS,GAAG,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC;QAE1C,IAAI,CAAC,OAAO,GAAG,gBAAgB,CAAC,mBAAmB,GAAG,CAAC,CAAC;QACxD,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;QAEnB,IAAI,CAAC,iBAAiB,GAAG,IAAI,OAAO,CAAC,gBAAgB,CAAC,GAAG,EAAE;YACvD,IAAI,CAAC,MAAM,EAAE,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;;OAGG;IACI,WAAW,CAAC,KAAa;QAC5B,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;QAC1B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,GAAG,KAAK,CAAC;IAC5C,CAAC;IAED;;;OAGG;IACI,UAAU,CAAC,KAAa;QAC3B,IAAI,CAAC,iBAAiB,CAAC,C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AS,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QAC3C,IAAI,CAAC,SAAS,IAAI,MAAM,CAAC,MAAM,CAAC;IACpC,CAAC;IAED;;;OAGG;IACI,eAAe,CAAC,MAAkB;QACrC,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACtC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QAC1C,IAAI,CAAC,SAAS,IAAI,MAAM,CAAC,MAAM,CAAC;IACpC,CAAC;IAED;;;OAGG;IACI,YAAY,CAAC,KAAc;QAC9B,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACpC,CAAC;IAEO,iBAAiB,CAAC,QAAgB;QACtC,IAAI,IAAI,CAAC,SAAS,GAAG,QAAQ,GAAG,IAAI,CAAC,OAAO,EAAE;YAC1C,IAAI,CAAC,MAAM,EAAE,CAAC;SACjB;IACL,CAAC;IAEO,MAAM;QACV,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QACzE,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;IACvB,CAAC;;AAzGD,yBAAyB;AACzB,gEAAgE;AACxC,oCAAmB,GAAG,KAAK,CAAC","sourcesContent":["import type { INative, INativeDataStream } from \"./nativeInterfaces\";\r\n\r\ndeclare const _native: INative;\r\n\r\n/** @internal */\r\nexport type NativeData = Uint32Array;\r\n\r\n/** @internal */\r\nexport class NativeDataStream {\r\n private readonly _uint32s: Uint32Array;\r\n private readonly _int32s: Int32Array;\r\n private readonly _float32s: Float32Array;\r\n private readonly _length: number;\r\n private _position: number;\r\n private readonly _nativeDataStream: INativeDataStream;\r\n\r\n // Must be multiple of 4!\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n private static readonly DEFAULT_BUFFER_SIZE = 65536;\r\n\r\n constructor() {\r\n const buffer = new ArrayBuffer(NativeDataStream.DEFAULT_BUFFER_SIZE);\r\n this._uint32s = new Uint32Array(buffer);\r\n this._int32s = new Int32Array(buffer);\r\n this._float32s = new Float32Array(buffer);\r\n\r\n this._length = NativeDataStream.DEFAULT_BUFFER_SIZE / 4;\r\n this._position = 0;\r\n\r\n this._nativeDataStream = new _native.NativeDataStream(() => {\r\n this._flush();\r\n });\r\n }\r\n\r\n /**\r\n * Writes a uint32 to the stream\r\n * @param value the value to write\r\n */\r\n public writeUint32(value: number): void {\r\n this._flushIfNecessary(1);\r\n this._uint32s[this._position++] = value;\r\n }\r\n\r\n /**\r\n * Writes an int32 to the stream\r\n * @param value the value to write\r\n */\r\n public writeInt32(value: number): void {\r\n this._flushIfNecessary(1);\r\n this._int32s[this._position++] = value;\r\n }\r\n\r\n /**\r\n * Writes a float32 to the stream\r\n * @param value the value to write\r\n */\r\n public writeFloat32(value: number): void {\r\n this._flushIfNecessary(1);\r\n this._float32s[this._position++] = value;\r\n }\r\n\r\n /**\r\n * Writes a uint32 array to the stream\r\n * @param values the values to write\r\n */\r\n public writeUint32Array(values: Uint32Array): void {\r\n this._flushIfNecessary(1 + values.length);\r\n this._uint32s[this._position++] = values.length;\r\n this._uint32s.set(values, this._position);\r\n this._position += values.length;\r\n }\r\n\r\n /**\r\n * Writes an int32 array to the stream\r\n * @param values the values to write\r\n */\r\n public writeInt32Array(values: Int32Array): void {\r\n this._flushIfNecessary(1 + values.length);\r\n this._uint32s[this._position++] = values.length;\r\n this._int32s.set(values, this._position);\r\n this._position += values.length;\r\n }\r\n\r\n /**\r\n * Writes a float32 array to the stream\r\n * @param values the values to write\r\n */\r\n public writeFloat32Array(values: Float32Array): void {\r\n this._flushIfNecessary(1 + values.length);\r\n this._uint32s[this._position++] = values.length;\r\n this._float32s.set(values, this._position);\r\n this._position += values.length;\r\n }\r\n\r\n /**\r\n * Writes native data to the stream\r\n * @param handle the handle to the native data\r\n */\r\n public writeNativeData(handle: NativeData) {\r\n this._flushIfNecessary(handle.length);\r\n this._uint32s.set(handle, this._position);\r\n this._position += handle.length;\r\n }\r\n\r\n /**\r\n * Writes a boolean to the stream\r\n * @param value the value to write\r\n */\r\n public writeBoolean(value: boolean) {\r\n this.writeUint32(value ? 1 : 0);\r\n }\r\n\r\n private _flushIfNecessary(required: number): void {\r\n if (this._position + required > this._length) {\r\n this._flush();\r\n }\r\n }\r\n\r\n private _flush(): void {\r\n this._nativeDataStream.writeBuffer(this._uint32s.buffer, this._position);\r\n this._position = 0;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"nativeDataStream.js","sourceRoot":"","sources":["../../../../../dev/core/src/Engines/Native/nativeDataStream.ts"],"names":[],"mappings":"AAQA,gBAAgB;AAChB,MAAM,OAAO,gBAAgB;IAYzB;QACI,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,CAAC;QACrE,IAAI,CAAC,QAAQ,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;QACxC,IAAI,CAAC,OAAO,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;QACtC,IAAI,CAAC,SAAS,GAAG,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC;QAE1C,IAAI,CAAC,OAAO,GAAG,gBAAgB,CAAC,mBAAmB,GAAG,CAAC,CAAC;QACxD,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;QAEnB,IAAI,CAAC,iBAAiB,GAAG,IAAI,OAAO,CAAC,gBAAgB,CAAC,GAAG,EAAE;YACvD,IAAI,CAAC,MAAM,EAAE,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;;OAGG;IACI,WAAW,CAAC,KAAa;QAC5B,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;QAC1B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC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C,CAAC;QAC1C,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;QAChD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QAC3C,IAAI,CAAC,SAAS,IAAI,MAAM,CAAC,MAAM,CAAC;IACpC,CAAC;IAED;;;OAGG;IACI,eAAe,CAAC,MAAkB;QACrC,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACtC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QAC1C,IAAI,CAAC,SAAS,IAAI,MAAM,CAAC,MAAM,CAAC;IACpC,CAAC;IAED;;;OAGG;IACI,YAAY,CAAC,KAAc;QAC9B,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACpC,CAAC;IAEO,iBAAiB,CAAC,QAAgB;QACtC,IAAI,IAAI,CAAC,SAAS,GAAG,QAAQ,GAAG,IAAI,CAAC,OAAO,EAAE;YAC1C,IAAI,CAAC,MAAM,EAAE,CAAC;SACjB;IACL,CAAC;IAEO,MAAM;QACV,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QACzE,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;IACvB,CAAC;;AAzGD,yBAAyB;AACzB,gEAAgE;AACxC,oCAAmB,GAAG,KAAK,CAAC","sourcesContent":["import type { DeepImmutable, FloatArray } from \"../../types\";\r\nimport type { INative, INativeDataStream } from \"./nativeInterfaces\";\r\n\r\ndeclare const _native: INative;\r\n\r\n/** @internal */\r\nexport type NativeData = Uint32Array;\r\n\r\n/** @internal */\r\nexport class NativeDataStream {\r\n private readonly _uint32s: Uint32Array;\r\n private readonly _int32s: Int32Array;\r\n private readonly _float32s: Float32Array;\r\n private readonly _length: number;\r\n private _position: number;\r\n private readonly _nativeDataStream: INativeDataStream;\r\n\r\n // Must be multiple of 4!\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n private static readonly DEFAULT_BUFFER_SIZE = 65536;\r\n\r\n constructor() {\r\n const buffer = new ArrayBuffer(NativeDataStream.DEFAULT_BUFFER_SIZE);\r\n this._uint32s = new Uint32Array(buffer);\r\n this._int32s = new Int32Array(buffer);\r\n this._float32s = new Float32Array(buffer);\r\n\r\n this._length = NativeDataStream.DEFAULT_BUFFER_SIZE / 4;\r\n this._position = 0;\r\n\r\n this._nativeDataStream = new _native.NativeDataStream(() => {\r\n this._flush();\r\n });\r\n }\r\n\r\n /**\r\n * Writes a uint32 to the stream\r\n * @param value the value to write\r\n */\r\n public writeUint32(value: number): void {\r\n this._flushIfNecessary(1);\r\n this._uint32s[this._position++] = value;\r\n }\r\n\r\n /**\r\n * Writes an int32 to the stream\r\n * @param value the value to write\r\n */\r\n public writeInt32(value: number): void {\r\n this._flushIfNecessary(1);\r\n this._int32s[this._position++] = value;\r\n }\r\n\r\n /**\r\n * Writes a float32 to the stream\r\n * @param value the value to write\r\n */\r\n public writeFloat32(value: number): void {\r\n this._flushIfNecessary(1);\r\n this._float32s[this._position++] = value;\r\n }\r\n\r\n /**\r\n * Writes a uint32 array to the stream\r\n * @param values the values to write\r\n */\r\n public writeUint32Array(values: Uint32Array): void {\r\n this._flushIfNecessary(1 + values.length);\r\n this._uint32s[this._position++] = values.length;\r\n this._uint32s.set(values, this._position);\r\n this._position += values.length;\r\n }\r\n\r\n /**\r\n * Writes an int32 array to the stream\r\n * @param values the values to write\r\n */\r\n public writeInt32Array(values: Int32Array): void {\r\n this._flushIfNecessary(1 + values.length);\r\n this._uint32s[this._position++] = values.length;\r\n this._int32s.set(values, this._position);\r\n this._position += values.length;\r\n }\r\n\r\n /**\r\n * Writes a float32 array to the stream\r\n * @param values the values to write\r\n */\r\n public writeFloat32Array(values: DeepImmutable<FloatArray>): void {\r\n this._flushIfNecessary(1 + values.length);\r\n this._uint32s[this._position++] = values.length;\r\n this._float32s.set(values, this._position);\r\n this._position += values.length;\r\n }\r\n\r\n /**\r\n * Writes native data to the stream\r\n * @param handle the handle to the native data\r\n */\r\n public writeNativeData(handle: NativeData) {\r\n this._flushIfNecessary(handle.length);\r\n this._uint32s.set(handle, this._position);\r\n this._position += handle.length;\r\n }\r\n\r\n /**\r\n * Writes a boolean to the stream\r\n * @param value the value to write\r\n */\r\n public writeBoolean(value: boolean) {\r\n this.writeUint32(value ? 1 : 0);\r\n }\r\n\r\n private _flushIfNecessary(required: number): void {\r\n if (this._position + required > this._length) {\r\n this._flush();\r\n }\r\n }\r\n\r\n private _flush(): void {\r\n this._nativeDataStream.writeBuffer(this._uint32s.buffer, this._position);\r\n this._position = 0;\r\n }\r\n}\r\n"]}