@onerjs/core 8.27.3 → 8.27.5

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 (91) hide show
  1. package/Behaviors/Meshes/pointerDragBehavior.d.ts +1 -0
  2. package/Behaviors/Meshes/pointerDragBehavior.js +4 -0
  3. package/Behaviors/Meshes/pointerDragBehavior.js.map +1 -1
  4. package/Cameras/arcRotateCamera.js +7 -5
  5. package/Cameras/arcRotateCamera.js.map +1 -1
  6. package/Cameras/targetCamera.d.ts +12 -0
  7. package/Cameras/targetCamera.js +19 -5
  8. package/Cameras/targetCamera.js.map +1 -1
  9. package/Engines/abstractEngine.js +2 -2
  10. package/Engines/abstractEngine.js.map +1 -1
  11. package/FrameGraph/Node/Blocks/inputBlock.js +1 -1
  12. package/FrameGraph/Node/Blocks/inputBlock.js.map +1 -1
  13. package/FrameGraph/Node/nodeRenderGraph.d.ts +2 -1
  14. package/FrameGraph/Node/nodeRenderGraph.js +8 -8
  15. package/FrameGraph/Node/nodeRenderGraph.js.map +1 -1
  16. package/FrameGraph/Passes/renderPass.js +3 -3
  17. package/FrameGraph/Passes/renderPass.js.map +1 -1
  18. package/FrameGraph/Tasks/Rendering/taaObjectRendererTask.js +7 -7
  19. package/FrameGraph/Tasks/Rendering/taaObjectRendererTask.js.map +1 -1
  20. package/FrameGraph/Tasks/Texture/clearTextureTask.js +1 -1
  21. package/FrameGraph/Tasks/Texture/clearTextureTask.js.map +1 -1
  22. package/FrameGraph/frameGraph.d.ts +4 -0
  23. package/FrameGraph/frameGraph.js +8 -0
  24. package/FrameGraph/frameGraph.js.map +1 -1
  25. package/FrameGraph/frameGraphRenderContext.d.ts +2 -1
  26. package/FrameGraph/frameGraphRenderContext.js +10 -3
  27. package/FrameGraph/frameGraphRenderContext.js.map +1 -1
  28. package/FrameGraph/frameGraphTextureManager.d.ts +32 -6
  29. package/FrameGraph/frameGraphTextureManager.js +138 -14
  30. package/FrameGraph/frameGraphTextureManager.js.map +1 -1
  31. package/Materials/Background/backgroundMaterial.js +1 -1
  32. package/Materials/Background/backgroundMaterial.js.map +1 -1
  33. package/Materials/PBR/openPbrMaterial.js +1 -1
  34. package/Materials/PBR/openPbrMaterial.js.map +1 -1
  35. package/Materials/PBR/pbrBaseMaterial.js +1 -1
  36. package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
  37. package/Materials/Textures/texture.js +13 -3
  38. package/Materials/Textures/texture.js.map +1 -1
  39. package/Materials/floatingOriginMatrixOverrides.js +11 -6
  40. package/Materials/floatingOriginMatrixOverrides.js.map +1 -1
  41. package/Materials/materialHelper.functions.d.ts +3 -3
  42. package/Materials/materialHelper.functions.js +2 -3
  43. package/Materials/materialHelper.functions.js.map +1 -1
  44. package/Materials/standardMaterial.js +1 -1
  45. package/Materials/standardMaterial.js.map +1 -1
  46. package/Maths/math.vector.functions.d.ts +17 -0
  47. package/Maths/math.vector.functions.js +27 -0
  48. package/Maths/math.vector.functions.js.map +1 -1
  49. package/Meshes/mesh.js +1 -1
  50. package/Meshes/mesh.js.map +1 -1
  51. package/Misc/screenshotTools.d.ts +63 -1
  52. package/Misc/screenshotTools.js +207 -4
  53. package/Misc/screenshotTools.js.map +1 -1
  54. package/Misc/textureTools.d.ts +6 -0
  55. package/Misc/textureTools.js +6 -1
  56. package/Misc/textureTools.js.map +1 -1
  57. package/Particles/Node/Blocks/Emitters/boxShapeBlock.js +1 -0
  58. package/Particles/Node/Blocks/Emitters/boxShapeBlock.js.map +1 -1
  59. package/Particles/Node/Blocks/Emitters/customShapeBlock.js +1 -0
  60. package/Particles/Node/Blocks/Emitters/customShapeBlock.js.map +1 -1
  61. package/Particles/Node/Blocks/Emitters/cylinderShapeBlock.js +1 -0
  62. package/Particles/Node/Blocks/Emitters/cylinderShapeBlock.js.map +1 -1
  63. package/Particles/Node/Blocks/Emitters/meshShapeBlock.js +1 -0
  64. package/Particles/Node/Blocks/Emitters/meshShapeBlock.js.map +1 -1
  65. package/Particles/Node/Blocks/Emitters/pointShapeBlock.js +1 -0
  66. package/Particles/Node/Blocks/Emitters/pointShapeBlock.js.map +1 -1
  67. package/Particles/Node/Blocks/Emitters/sphereShapeBlock.js +1 -0
  68. package/Particles/Node/Blocks/Emitters/sphereShapeBlock.js.map +1 -1
  69. package/Particles/Node/Blocks/index.d.ts +1 -0
  70. package/Particles/Node/Blocks/index.js +1 -0
  71. package/Particles/Node/Blocks/index.js.map +1 -1
  72. package/Particles/Node/Blocks/particleFresnelBlock.d.ts +34 -0
  73. package/Particles/Node/Blocks/particleFresnelBlock.js +74 -0
  74. package/Particles/Node/Blocks/particleFresnelBlock.js.map +1 -0
  75. package/Particles/Node/Blocks/particleInputBlock.js +2 -0
  76. package/Particles/Node/Blocks/particleInputBlock.js.map +1 -1
  77. package/Particles/Node/Blocks/particleLerpBlock.d.ts +1 -1
  78. package/Particles/Node/Blocks/particleLerpBlock.js +1 -1
  79. package/Particles/Node/Blocks/particleLerpBlock.js.map +1 -1
  80. package/Particles/Node/Enums/nodeParticleContextualSources.d.ts +3 -1
  81. package/Particles/Node/Enums/nodeParticleContextualSources.js +2 -0
  82. package/Particles/Node/Enums/nodeParticleContextualSources.js.map +1 -1
  83. package/Particles/Node/Enums/nodeParticleSystemSources.d.ts +3 -1
  84. package/Particles/Node/Enums/nodeParticleSystemSources.js +2 -0
  85. package/Particles/Node/Enums/nodeParticleSystemSources.js.map +1 -1
  86. package/Particles/Node/nodeParticleBuildState.d.ts +1 -1
  87. package/Particles/Node/nodeParticleBuildState.js +4 -0
  88. package/Particles/Node/nodeParticleBuildState.js.map +1 -1
  89. package/node.js +4 -1
  90. package/node.js.map +1 -1
  91. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"clearTextureTask.js","sourceRoot":"","sources":["../../../../../../dev/core/src/FrameGraph/Tasks/Texture/clearTextureTask.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO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,IAAI,CAAC,CAAC;QAEvD,IAAI,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC;QACrC,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC7C,IAAI,CAAC,cAAc,CAAC,CAAC,OAAO,EAAE,EAAE;YAC5B,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC3B,IAAI,IAAI,CAAC,yBAAyB,EAAE,CAAC;gBACjC,KAAK,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;YACpC,CAAC;YAED,OAAO,CAAC,gBAAgB,CAAC,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAC/H,CAAC,CAAC,CAAC;QAEH,MAAM,YAAY,GAAG,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,GAAG,WAAW,EAAE,IAAI,CAAC,CAAC;QAEnF,YAAY,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC;QAC7C,YAAY,CAAC,oBAAoB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACrD,YAAY,CAAC,cAAc,CAAC,CAAC,QAAQ,EAAE,EAAE,GAAE,CAAC,CAAC,CAAC;QAE9C,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ","sourcesContent":["import type { FrameGraph, FrameGraphTextureHandle, FrameGraphRenderPass } from \"core/index\";\r\nimport { Color4, TmpColors } from \"../../../Maths/math.color\";\r\nimport { FrameGraphTask } from \"../../frameGraphTask\";\r\nimport { backbufferColorTextureHandle } from \"../../frameGraphTypes\";\r\n\r\n/**\r\n * Task used to clear a texture.\r\n */\r\nexport class FrameGraphClearTextureTask extends FrameGraphTask {\r\n /**\r\n * The color to clear the texture with.\r\n */\r\n public color = new Color4(0.2, 0.2, 0.3, 1);\r\n\r\n /**\r\n * If the color should be cleared.\r\n */\r\n public clearColor = true;\r\n\r\n /**\r\n * If the color should be converted to linear space (default: false).\r\n */\r\n public convertColorToLinearSpace = false;\r\n\r\n /**\r\n * If the depth should be cleared.\r\n */\r\n public clearDepth = false;\r\n\r\n /**\r\n * If the stencil should be cleared.\r\n */\r\n public clearStencil = false;\r\n\r\n /**\r\n * The value to use to clear the stencil buffer (default: 0).\r\n */\r\n public stencilValue = 0;\r\n\r\n /**\r\n * The color texture to clear.\r\n */\r\n public targetTexture?: FrameGraphTextureHandle | FrameGraphTextureHandle[];\r\n\r\n /**\r\n * The depth attachment texture to clear.\r\n */\r\n public depthTexture?: FrameGraphTextureHandle;\r\n\r\n /**\r\n * The output texture (same as targetTexture, but the handle will be different).\r\n */\r\n public readonly outputTexture: FrameGraphTextureHandle;\r\n\r\n /**\r\n * The output depth texture (same as depthTexture, but the handle will be different).\r\n */\r\n public readonly outputDepthTexture: FrameGraphTextureHandle;\r\n\r\n /**\r\n * Constructs a new clear task.\r\n * @param name The name of the task.\r\n * @param frameGraph The frame graph the task belongs to.\r\n */\r\n constructor(name: string, frameGraph: FrameGraph) {\r\n super(name, frameGraph);\r\n\r\n this.outputTexture = this._frameGraph.textureManager.createDanglingHandle();\r\n this.outputDepthTexture = this._frameGraph.textureManager.createDanglingHandle();\r\n }\r\n\r\n public record(): FrameGraphRenderPass {\r\n if (this.targetTexture === undefined && this.depthTexture === undefined) {\r\n throw new Error(`FrameGraphClearTextureTask ${this.name}: targetTexture and depthTexture can't both be undefined.`);\r\n }\r\n\r\n const targetTextures = this.targetTexture !== undefined ? (Array.isArray(this.targetTexture) ? this.targetTexture : [this.targetTexture]) : undefined;\r\n\r\n let textureSamples = 0;\r\n let depthSamples = 0;\r\n\r\n if (this.targetTexture !== undefined) {\r\n textureSamples = this._frameGraph.textureManager.getTextureDescription(targetTextures![0]).options.samples || 1;\r\n this._frameGraph.textureManager.resolveDanglingHandle(this.outputTexture, targetTextures![0]);\r\n }\r\n if (this.depthTexture !== undefined) {\r\n depthSamples = this._frameGraph.textureManager.getTextureDescription(this.depthTexture).options.samples || 1;\r\n this._frameGraph.textureManager.resolveDanglingHandle(this.outputDepthTexture, this.depthTexture);\r\n }\r\n\r\n if (textureSamples !== depthSamples && textureSamples !== 0 && depthSamples !== 0) {\r\n throw new Error(`FrameGraphClearTextureTask ${this.name}: the depth texture and the target texture must have the same number of samples.`);\r\n }\r\n\r\n const attachments = this._frameGraph.engine.buildTextureLayout(\r\n targetTextures ? Array(targetTextures.length).fill(true) : [],\r\n this.targetTexture === backbufferColorTextureHandle\r\n );\r\n\r\n const color = TmpColors.Color4[0];\r\n\r\n const pass = this._frameGraph.addRenderPass(this.name);\r\n\r\n pass.setRenderTarget(targetTextures);\r\n pass.setRenderTargetDepth(this.depthTexture);\r\n pass.setExecuteFunc((context) => {\r\n color.copyFrom(this.color);\r\n if (this.convertColorToLinearSpace) {\r\n color.toLinearSpaceToRef(color);\r\n }\r\n\r\n context.clearAttachments(color, attachments, !!this.clearColor, !!this.clearDepth, !!this.clearStencil, this.stencilValue);\r\n });\r\n\r\n const passDisabled = this._frameGraph.addRenderPass(this.name + \"_disabled\", true);\r\n\r\n passDisabled.setRenderTarget(targetTextures);\r\n passDisabled.setRenderTargetDepth(this.depthTexture);\r\n passDisabled.setExecuteFunc((_context) => {});\r\n\r\n return pass;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"clearTextureTask.js","sourceRoot":"","sources":["../../../../../../dev/core/src/FrameGraph/Tasks/Texture/clearTextureTask.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AAErE;;GAEG;AACH,MAAM,OAAO,0BAA2B,SAAQ,cAAc;IAmD1D;;;;OAIG;IACH,Y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,YAAY,CAAC,CAAC;QAC7C,IAAI,CAAC,cAAc,CAAC,CAAC,OAAO,EAAE,EAAE;YAC5B,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC3B,IAAI,IAAI,CAAC,yBAAyB,EAAE,CAAC;gBACjC,KAAK,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;YACpC,CAAC;YAED,OAAO,CAAC,gBAAgB,CAAC,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAC/H,CAAC,CAAC,CAAC;QAEH,MAAM,YAAY,GAAG,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,GAAG,WAAW,EAAE,IAAI,CAAC,CAAC;QAEnF,YAAY,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC;QAC7C,YAAY,CAAC,oBAAoB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACrD,YAAY,CAAC,cAAc,CAAC,CAAC,QAAQ,EAAE,EAAE,GAAE,CAAC,CAAC,CAAC;QAE9C,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ","sourcesContent":["import type { FrameGraph, FrameGraphTextureHandle, FrameGraphRenderPass } from \"core/index\";\r\nimport { Color4, TmpColors } from \"../../../Maths/math.color\";\r\nimport { FrameGraphTask } from \"../../frameGraphTask\";\r\nimport { backbufferColorTextureHandle } from \"../../frameGraphTypes\";\r\n\r\n/**\r\n * Task used to clear a texture.\r\n */\r\nexport class FrameGraphClearTextureTask extends FrameGraphTask {\r\n /**\r\n * The color to clear the texture with.\r\n */\r\n public color = new Color4(0.2, 0.2, 0.3, 1);\r\n\r\n /**\r\n * If the color should be cleared.\r\n */\r\n public clearColor = true;\r\n\r\n /**\r\n * If the color should be converted to linear space (default: false).\r\n */\r\n public convertColorToLinearSpace = false;\r\n\r\n /**\r\n * If the depth should be cleared.\r\n */\r\n public clearDepth = false;\r\n\r\n /**\r\n * If the stencil should be cleared.\r\n */\r\n public clearStencil = false;\r\n\r\n /**\r\n * The value to use to clear the stencil buffer (default: 0).\r\n */\r\n public stencilValue = 0;\r\n\r\n /**\r\n * The color texture to clear.\r\n */\r\n public targetTexture?: FrameGraphTextureHandle | FrameGraphTextureHandle[];\r\n\r\n /**\r\n * The depth attachment texture to clear.\r\n */\r\n public depthTexture?: FrameGraphTextureHandle;\r\n\r\n /**\r\n * The output texture (same as targetTexture, but the handle will be different).\r\n */\r\n public readonly outputTexture: FrameGraphTextureHandle;\r\n\r\n /**\r\n * The output depth texture (same as depthTexture, but the handle will be different).\r\n */\r\n public readonly outputDepthTexture: FrameGraphTextureHandle;\r\n\r\n /**\r\n * Constructs a new clear task.\r\n * @param name The name of the task.\r\n * @param frameGraph The frame graph the task belongs to.\r\n */\r\n constructor(name: string, frameGraph: FrameGraph) {\r\n super(name, frameGraph);\r\n\r\n this.outputTexture = this._frameGraph.textureManager.createDanglingHandle();\r\n this.outputDepthTexture = this._frameGraph.textureManager.createDanglingHandle();\r\n }\r\n\r\n public record(): FrameGraphRenderPass {\r\n if (this.targetTexture === undefined && this.depthTexture === undefined) {\r\n throw new Error(`FrameGraphClearTextureTask ${this.name}: targetTexture and depthTexture can't both be undefined.`);\r\n }\r\n\r\n const targetTextures = this.targetTexture !== undefined ? (Array.isArray(this.targetTexture) ? this.targetTexture : [this.targetTexture]) : undefined;\r\n\r\n let textureSamples = 0;\r\n let depthSamples = 0;\r\n\r\n if (this.targetTexture !== undefined) {\r\n textureSamples = this._frameGraph.textureManager.getTextureDescription(targetTextures![0]).options.samples || 1;\r\n this._frameGraph.textureManager.resolveDanglingHandle(this.outputTexture, targetTextures![0]);\r\n }\r\n if (this.depthTexture !== undefined) {\r\n depthSamples = this._frameGraph.textureManager.getTextureDescription(this.depthTexture).options.samples || 1;\r\n this._frameGraph.textureManager.resolveDanglingHandle(this.outputDepthTexture, this.depthTexture);\r\n }\r\n\r\n if (textureSamples !== depthSamples && textureSamples !== 0 && depthSamples !== 0) {\r\n throw new Error(`FrameGraphClearTextureTask ${this.name}: the depth texture and the target texture must have the same number of samples.`);\r\n }\r\n\r\n const attachments = this._frameGraph.engine.buildTextureLayout(\r\n targetTextures ? Array(targetTextures.length).fill(true) : [],\r\n this.targetTexture === backbufferColorTextureHandle && !this._frameGraph.textureManager.backBufferTextureOverriden\r\n );\r\n\r\n const color = TmpColors.Color4[0];\r\n\r\n const pass = this._frameGraph.addRenderPass(this.name);\r\n\r\n pass.setRenderTarget(targetTextures);\r\n pass.setRenderTargetDepth(this.depthTexture);\r\n pass.setExecuteFunc((context) => {\r\n color.copyFrom(this.color);\r\n if (this.convertColorToLinearSpace) {\r\n color.toLinearSpaceToRef(color);\r\n }\r\n\r\n context.clearAttachments(color, attachments, !!this.clearColor, !!this.clearDepth, !!this.clearStencil, this.stencilValue);\r\n });\r\n\r\n const passDisabled = this._frameGraph.addRenderPass(this.name + \"_disabled\", true);\r\n\r\n passDisabled.setRenderTarget(targetTextures);\r\n passDisabled.setRenderTargetDepth(this.depthTexture);\r\n passDisabled.setExecuteFunc((_context) => {});\r\n\r\n return pass;\r\n }\r\n}\r\n"]}
@@ -52,6 +52,10 @@ export declare class FrameGraph implements IDisposable {
52
52
  * Gets the list of tasks in the frame graph
53
53
  */
54
54
  get tasks(): FrameGraphTask[];
55
+ /**
56
+ * Indicates whether the execution of the frame graph is paused (default is false)
57
+ */
58
+ pausedExecution: boolean;
55
59
  /**
56
60
  * Gets the node render graph linked to the frame graph (if any)
57
61
  * @returns the linked node render graph or null if none
@@ -73,6 +73,10 @@ export class FrameGraph {
73
73
  * Observable raised when the node render graph is built
74
74
  */
75
75
  this.onBuildObservable = new Observable();
76
+ /**
77
+ * Indicates whether the execution of the frame graph is paused (default is false)
78
+ */
79
+ this.pausedExecution = false;
76
80
  this._scene = scene;
77
81
  this._engine = scene.getEngine();
78
82
  this.textureManager = new FrameGraphTextureManager(this._engine, debugTextures, scene);
@@ -237,6 +241,9 @@ export class FrameGraph {
237
241
  * Executes the frame graph.
238
242
  */
239
243
  execute() {
244
+ if (this.pausedExecution) {
245
+ return;
246
+ }
240
247
  this._renderContext.bindRenderTarget();
241
248
  this.textureManager._updateHistoryTextures();
242
249
  for (const task of this._tasks) {
@@ -245,6 +252,7 @@ export class FrameGraph {
245
252
  pass._execute();
246
253
  }
247
254
  }
255
+ this._renderContext.bindRenderTarget(undefined, undefined, true); // restore default framebuffer
248
256
  }
249
257
  /**
250
258
  * Clears the frame graph (remove the tasks and release the textures).
@@ -1 +1 @@
1
- {"version":3,"file":"frameGraph.js","sourceRoot":"","sources":["../../../../dev/core/src/FrameGraph/frameGraph.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,8BAA6B;AAClD,OAAO,EAAE,kBAAkB,EAAE,+BAA8B;AAC3D,OAAO,EAAE,MAAM,EAAE,0BAAyB;AAC1C,OAAO,EAAE,iBAAiB,EAAE,qCAAoC;AAEhE,qDAAoD;AACpD,4DAA2D;AAE3D,IAAK,kBAIJ;AAJD,WAAK,kBAAkB;IACnB,+DAAU,CAAA;IACV,+DAAU,CAAA;IACV,2DAAQ,CAAA;AACZ,CAAC,EAJI,kBAAkB,KAAlB,kBAAkB,QAItB;AAED;;;GAGG;AACH,MAAM,OAAO,UAAU;IAkCnB;;OAEG;IACH,IAAW,MAAM;QACb,O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IAAI,MAAM,EAAE,CAAC;gBACxB,IAAI,CAAC,QAAQ,EAAE,CAAC;YACpB,CAAC;QACL,CAAC;IACL,CAAC;IAED;;;OAGG;IACI,KAAK;QACR,IAAI,CAAC,qBAAqB,EAAE,EAAE,CAAC;QAC/B,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC;QAElC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAC7B,IAAI,CAAC,MAAM,EAAE,CAAC;QAClB,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QACvB,IAAI,CAAC,cAAc,CAAC,gBAAgB,EAAE,CAAC;QACvC,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC;IACtC,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,CAAC,qBAAqB,EAAE,EAAE,CAAC;QAC/B,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC;QAClC,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC;QAC/B,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC;QAE/B,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;CACJ","sourcesContent":["import type { Scene, AbstractEngine, FrameGraphTask, Nullable, NodeRenderGraph, IDisposable } from \"core/index\";\r\nimport { FrameGraphPass } from \"./Passes/pass\";\r\nimport { FrameGraphRenderPass } from \"./Passes/renderPass\";\r\nimport { FrameGraphCullPass } from \"./Passes/cullPass\";\r\nimport { FrameGraphRenderContext } from \"./frameGraphRenderContext\";\r\nimport { FrameGraphContext } from \"./frameGraphContext\";\r\nimport { FrameGraphTextureManager } from \"./frameGraphTextureManager\";\r\nimport { Observable } from \"core/Misc/observable\";\r\nimport { _RetryWithInterval } from \"core/Misc/timingTools\";\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport { UniqueIdGenerator } from \"core/Misc/uniqueIdGenerator\";\r\n\r\nimport \"core/Engines/Extensions/engine.multiRender\";\r\nimport \"core/Engines/WebGPU/Extensions/engine.multiRender\";\r\n\r\nenum FrameGraphPassType {\r\n Normal = 0,\r\n Render = 1,\r\n Cull = 2,\r\n}\r\n\r\n/**\r\n * Class used to implement a frame graph\r\n * @experimental\r\n */\r\nexport class FrameGraph implements IDisposable {\r\n /**\r\n * Gets the texture manager used by the frame graph\r\n */\r\n public readonly textureManager: FrameGraphTextureManager;\r\n\r\n private readonly _engine: AbstractEngine;\r\n private readonly _scene: Scene;\r\n private readonly _tasks: FrameGraphTask[] = [];\r\n private readonly _passContext: FrameGraphContext;\r\n private readonly _renderContext: FrameGraphRenderContext;\r\n private _currentProcessedTask: FrameGraphTask | null = null;\r\n private _whenReadyAsyncCancel: Nullable<() => void> = null;\r\n\r\n /**\r\n * Name of the frame graph\r\n */\r\n public name = \"Frame Graph\";\r\n\r\n /**\r\n * Gets the unique id of the frame graph\r\n */\r\n public readonly uniqueId = UniqueIdGenerator.UniqueId;\r\n\r\n /**\r\n * Gets or sets a boolean indicating that texture allocation should be optimized (that is, reuse existing textures when possible to limit GPU memory usage) (default: true)\r\n */\r\n public optimizeTextureAllocation = true;\r\n\r\n /**\r\n * Observable raised when the node render graph is built\r\n */\r\n public onBuildObservable = new Observable<FrameGraph>();\r\n\r\n /**\r\n * Gets the engine used by the frame graph\r\n */\r\n public get engine() {\r\n return this._engine;\r\n }\r\n\r\n /**\r\n * Gets the scene used by the frame graph\r\n */\r\n public get scene() {\r\n return this._scene;\r\n }\r\n\r\n /**\r\n * Gets the list of tasks in the frame graph\r\n */\r\n public get tasks() {\r\n return this._tasks;\r\n }\r\n\r\n /**\r\n * Gets the node render graph linked to the frame graph (if any)\r\n * @returns the linked node render graph or null if none\r\n */\r\n public getLinkedNodeRenderGraph(): Nullable<NodeRenderGraph> {\r\n return this._linkedNodeRenderGraph;\r\n }\r\n\r\n /**\r\n * Constructs the frame graph\r\n * @param scene defines the scene the frame graph is associated with\r\n * @param debugTextures defines a boolean indicating that textures created by the frame graph should be visible in the inspector (default is false)\r\n * @param _linkedNodeRenderGraph defines the linked node render graph (if any)\r\n */\r\n constructor(\r\n scene: Scene,\r\n debugTextures = false,\r\n private readonly _linkedNodeRenderGraph: Nullable<NodeRenderGraph> = null\r\n ) {\r\n this._scene = scene;\r\n this._engine = scene.getEngine();\r\n this.textureManager = new FrameGraphTextureManager(this._engine, debugTextures, scene);\r\n this._passContext = new FrameGraphContext(this._engine, this.textureManager, scene);\r\n this._renderContext = new FrameGraphRenderContext(this._engine, this.textureManager, scene);\r\n\r\n this._scene.addFrameGraph(this);\r\n }\r\n\r\n /**\r\n * Gets the class name of the frame graph\r\n * @returns the class name\r\n */\r\n public getClassName() {\r\n return \"FrameGraph\";\r\n }\r\n\r\n /**\r\n * Gets a task by name\r\n * @param name Name of the task to get\r\n * @returns The task or undefined if not found\r\n */\r\n public getTaskByName<T extends FrameGraphTask>(name: string): T | undefined {\r\n return this._tasks.find((t) => t.name === name) as T;\r\n }\r\n\r\n /**\r\n * Gets all tasks of a specific type\r\n * @param taskType Type of the task(s) to get\r\n * @returns The list of tasks of the specified type\r\n */\r\n public getTasksByType<T extends FrameGraphTask>(taskType: new (...args: any[]) => T): T[] {\r\n return this._tasks.filter((t) => t instanceof taskType) as T[];\r\n }\r\n\r\n /**\r\n * Adds a task to the frame graph\r\n * @param task Task to add\r\n */\r\n public addTask(task: FrameGraphTask): void {\r\n if (this._currentProcessedTask !== null) {\r\n throw new Error(`FrameGraph.addTask: Can't add the task \"${task.name}\" while another task is currently building (task: ${this._currentProcessedTask.name}).`);\r\n }\r\n\r\n this._tasks.push(task);\r\n }\r\n\r\n /**\r\n * Adds a pass to a task. This method can only be called during a Task.record execution.\r\n * @param name The name of the pass\r\n * @param whenTaskDisabled If true, the pass will be added to the list of passes to execute when the task is disabled (default is false)\r\n * @returns The render pass created\r\n */\r\n public addPass(name: string, whenTaskDisabled = false): FrameGraphPass<FrameGraphContext> {\r\n return this._addPass(name, FrameGraphPassType.Normal, whenTaskDisabled) as FrameGraphPass<FrameGraphContext>;\r\n }\r\n\r\n /**\r\n * Adds a render pass to a task. This method can only be called during a Task.record execution.\r\n * @param name The name of the pass\r\n * @param whenTaskDisabled If true, the pass will be added to the list of passes to execute when the task is disabled (default is false)\r\n * @returns The render pass created\r\n */\r\n public addRenderPass(name: string, whenTaskDisabled = false): FrameGraphRenderPass {\r\n return this._addPass(name, FrameGraphPassType.Render, whenTaskDisabled) as FrameGraphRenderPass;\r\n }\r\n\r\n /**\r\n * Adds a cull pass to a task. This method can only be called during a Task.record execution.\r\n * @param name The name of the pass\r\n * @param whenTaskDisabled If true, the pass will be added to the list of passes to execute when the task is disabled (default is false)\r\n * @returns The cull pass created\r\n */\r\n public addCullPass(name: string, whenTaskDisabled = false): FrameGraphCullPass {\r\n return this._addPass(name, FrameGraphPassType.Cull, whenTaskDisabled) as FrameGraphCullPass;\r\n }\r\n\r\n private _addPass(name: string, passType: FrameGraphPassType, whenTaskDisabled = false): FrameGraphPass<FrameGraphContext> | FrameGraphRenderPass {\r\n if (!this._currentProcessedTask) {\r\n throw new Error(\"FrameGraph: A pass must be created during a Task.record execution only.\");\r\n }\r\n\r\n let pass: FrameGraphPass<FrameGraphContext> | FrameGraphRenderPass;\r\n\r\n switch (passType) {\r\n case FrameGraphPassType.Render:\r\n pass = new FrameGraphRenderPass(name, this._currentProcessedTask, this._renderContext, this._engine);\r\n break;\r\n case FrameGraphPassType.Cull:\r\n pass = new FrameGraphCullPass(name, this._currentProcessedTask, this._passContext, this._engine);\r\n break;\r\n default:\r\n pass = new FrameGraphPass(name, this._currentProcessedTask, this._passContext);\r\n break;\r\n }\r\n\r\n this._currentProcessedTask._addPass(pass, whenTaskDisabled);\r\n\r\n return pass;\r\n }\r\n\r\n /**\r\n * Builds the frame graph.\r\n * This method should be called after all tasks have been added to the frame graph (FrameGraph.addTask) and before the graph is executed (FrameGraph.execute).\r\n */\r\n public build(): void {\r\n this.textureManager._releaseTextures(false);\r\n\r\n try {\r\n for (const task of this._tasks) {\r\n task._reset();\r\n\r\n this._currentProcessedTask = task;\r\n this.textureManager._isRecordingTask = true;\r\n\r\n task.record();\r\n\r\n this.textureManager._isRecordingTask = false;\r\n this._currentProcessedTask = null;\r\n }\r\n\r\n this.textureManager._allocateTextures(this.optimizeTextureAllocation ? this._tasks : undefined);\r\n\r\n for (const task of this._tasks) {\r\n task._checkTask();\r\n }\r\n\r\n for (const task of this._tasks) {\r\n task.onTexturesAllocatedObservable.notifyObservers(this._renderContext);\r\n }\r\n\r\n this.onBuildObservable.notifyObservers(this);\r\n } catch (e) {\r\n this._tasks.length = 0;\r\n this._currentProcessedTask = null;\r\n this.textureManager._isRecordingTask = false;\r\n throw e;\r\n }\r\n }\r\n\r\n /**\r\n * Returns a promise that resolves when the frame graph is ready to be executed\r\n * This method must be called after the graph has been built (FrameGraph.build called)!\r\n * @param timeStep Time step in ms between retries (default is 16)\r\n * @param maxTimeout Maximum time in ms to wait for the graph to be ready (default is 30000)\r\n * @returns The promise that resolves when the graph is ready\r\n */\r\n public async whenReadyAsync(timeStep = 16, maxTimeout = 30000): Promise<void> {\r\n let firstNotReadyTask: FrameGraphTask | null = null;\r\n return await new Promise((resolve) => {\r\n this._whenReadyAsyncCancel = _RetryWithInterval(\r\n () => {\r\n let ready = this._renderContext._isReady();\r\n for (const task of this._tasks) {\r\n const taskIsReady = task.isReady();\r\n if (!taskIsReady && !firstNotReadyTask) {\r\n firstNotReadyTask = task;\r\n }\r\n ready &&= taskIsReady;\r\n }\r\n return ready;\r\n },\r\n () => {\r\n this._whenReadyAsyncCancel = null;\r\n resolve();\r\n },\r\n (err, isTimeout) => {\r\n this._whenReadyAsyncCancel = null;\r\n if (!isTimeout) {\r\n Logger.Error(\"FrameGraph: An unexpected error occurred while waiting for the frame graph to be ready.\");\r\n if (err) {\r\n Logger.Error(err);\r\n if (err.stack) {\r\n Logger.Error(err.stack);\r\n }\r\n }\r\n } else {\r\n Logger.Error(\r\n `FrameGraph: Timeout while waiting for the frame graph to be ready.${firstNotReadyTask ? ` First task not ready: ${firstNotReadyTask.name}` : \"\"}`\r\n );\r\n if (err) {\r\n Logger.Error(err);\r\n }\r\n }\r\n },\r\n timeStep,\r\n maxTimeout\r\n );\r\n });\r\n }\r\n\r\n /**\r\n * Executes the frame graph.\r\n */\r\n public execute(): void {\r\n this._renderContext.bindRenderTarget();\r\n\r\n this.textureManager._updateHistoryTextures();\r\n\r\n for (const task of this._tasks) {\r\n const passes = task._getPasses();\r\n\r\n for (const pass of passes) {\r\n pass._execute();\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Clears the frame graph (remove the tasks and release the textures).\r\n * The frame graph can be built again after this method is called.\r\n */\r\n public clear(): void {\r\n this._whenReadyAsyncCancel?.();\r\n this._whenReadyAsyncCancel = null;\r\n\r\n for (const task of this._tasks) {\r\n task._reset();\r\n }\r\n\r\n this._tasks.length = 0;\r\n this.textureManager._releaseTextures();\r\n this._currentProcessedTask = null;\r\n }\r\n\r\n /**\r\n * Disposes the frame graph\r\n */\r\n public dispose(): void {\r\n this._whenReadyAsyncCancel?.();\r\n this._whenReadyAsyncCancel = null;\r\n this.clear();\r\n this.textureManager._dispose();\r\n this._renderContext._dispose();\r\n\r\n this._scene.removeFrameGraph(this);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"frameGraph.js","sourceRoot":"","sources":["../../../../dev/core/src/FrameGraph/frameGraph.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,4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,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC;QAC/B,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC;QAE/B,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;CACJ","sourcesContent":["import type { Scene, AbstractEngine, FrameGraphTask, Nullable, NodeRenderGraph, IDisposable } from \"core/index\";\r\nimport { FrameGraphPass } from \"./Passes/pass\";\r\nimport { FrameGraphRenderPass } from \"./Passes/renderPass\";\r\nimport { FrameGraphCullPass } from \"./Passes/cullPass\";\r\nimport { FrameGraphRenderContext } from \"./frameGraphRenderContext\";\r\nimport { FrameGraphContext } from \"./frameGraphContext\";\r\nimport { FrameGraphTextureManager } from \"./frameGraphTextureManager\";\r\nimport { Observable } from \"core/Misc/observable\";\r\nimport { _RetryWithInterval } from \"core/Misc/timingTools\";\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport { UniqueIdGenerator } from \"core/Misc/uniqueIdGenerator\";\r\n\r\nimport \"core/Engines/Extensions/engine.multiRender\";\r\nimport \"core/Engines/WebGPU/Extensions/engine.multiRender\";\r\n\r\nenum FrameGraphPassType {\r\n Normal = 0,\r\n Render = 1,\r\n Cull = 2,\r\n}\r\n\r\n/**\r\n * Class used to implement a frame graph\r\n * @experimental\r\n */\r\nexport class FrameGraph implements IDisposable {\r\n /**\r\n * Gets the texture manager used by the frame graph\r\n */\r\n public readonly textureManager: FrameGraphTextureManager;\r\n\r\n private readonly _engine: AbstractEngine;\r\n private readonly _scene: Scene;\r\n private readonly _tasks: FrameGraphTask[] = [];\r\n private readonly _passContext: FrameGraphContext;\r\n private readonly _renderContext: FrameGraphRenderContext;\r\n private _currentProcessedTask: FrameGraphTask | null = null;\r\n private _whenReadyAsyncCancel: Nullable<() => void> = null;\r\n\r\n /**\r\n * Name of the frame graph\r\n */\r\n public name = \"Frame Graph\";\r\n\r\n /**\r\n * Gets the unique id of the frame graph\r\n */\r\n public readonly uniqueId = UniqueIdGenerator.UniqueId;\r\n\r\n /**\r\n * Gets or sets a boolean indicating that texture allocation should be optimized (that is, reuse existing textures when possible to limit GPU memory usage) (default: true)\r\n */\r\n public optimizeTextureAllocation = true;\r\n\r\n /**\r\n * Observable raised when the node render graph is built\r\n */\r\n public onBuildObservable = new Observable<FrameGraph>();\r\n\r\n /**\r\n * Gets the engine used by the frame graph\r\n */\r\n public get engine() {\r\n return this._engine;\r\n }\r\n\r\n /**\r\n * Gets the scene used by the frame graph\r\n */\r\n public get scene() {\r\n return this._scene;\r\n }\r\n\r\n /**\r\n * Gets the list of tasks in the frame graph\r\n */\r\n public get tasks() {\r\n return this._tasks;\r\n }\r\n\r\n /**\r\n * Indicates whether the execution of the frame graph is paused (default is false)\r\n */\r\n public pausedExecution = false;\r\n\r\n /**\r\n * Gets the node render graph linked to the frame graph (if any)\r\n * @returns the linked node render graph or null if none\r\n */\r\n public getLinkedNodeRenderGraph(): Nullable<NodeRenderGraph> {\r\n return this._linkedNodeRenderGraph;\r\n }\r\n\r\n /**\r\n * Constructs the frame graph\r\n * @param scene defines the scene the frame graph is associated with\r\n * @param debugTextures defines a boolean indicating that textures created by the frame graph should be visible in the inspector (default is false)\r\n * @param _linkedNodeRenderGraph defines the linked node render graph (if any)\r\n */\r\n constructor(\r\n scene: Scene,\r\n debugTextures = false,\r\n private readonly _linkedNodeRenderGraph: Nullable<NodeRenderGraph> = null\r\n ) {\r\n this._scene = scene;\r\n this._engine = scene.getEngine();\r\n this.textureManager = new FrameGraphTextureManager(this._engine, debugTextures, scene);\r\n this._passContext = new FrameGraphContext(this._engine, this.textureManager, scene);\r\n this._renderContext = new FrameGraphRenderContext(this._engine, this.textureManager, scene);\r\n\r\n this._scene.addFrameGraph(this);\r\n }\r\n\r\n /**\r\n * Gets the class name of the frame graph\r\n * @returns the class name\r\n */\r\n public getClassName() {\r\n return \"FrameGraph\";\r\n }\r\n\r\n /**\r\n * Gets a task by name\r\n * @param name Name of the task to get\r\n * @returns The task or undefined if not found\r\n */\r\n public getTaskByName<T extends FrameGraphTask>(name: string): T | undefined {\r\n return this._tasks.find((t) => t.name === name) as T;\r\n }\r\n\r\n /**\r\n * Gets all tasks of a specific type\r\n * @param taskType Type of the task(s) to get\r\n * @returns The list of tasks of the specified type\r\n */\r\n public getTasksByType<T extends FrameGraphTask>(taskType: new (...args: any[]) => T): T[] {\r\n return this._tasks.filter((t) => t instanceof taskType) as T[];\r\n }\r\n\r\n /**\r\n * Adds a task to the frame graph\r\n * @param task Task to add\r\n */\r\n public addTask(task: FrameGraphTask): void {\r\n if (this._currentProcessedTask !== null) {\r\n throw new Error(`FrameGraph.addTask: Can't add the task \"${task.name}\" while another task is currently building (task: ${this._currentProcessedTask.name}).`);\r\n }\r\n\r\n this._tasks.push(task);\r\n }\r\n\r\n /**\r\n * Adds a pass to a task. This method can only be called during a Task.record execution.\r\n * @param name The name of the pass\r\n * @param whenTaskDisabled If true, the pass will be added to the list of passes to execute when the task is disabled (default is false)\r\n * @returns The render pass created\r\n */\r\n public addPass(name: string, whenTaskDisabled = false): FrameGraphPass<FrameGraphContext> {\r\n return this._addPass(name, FrameGraphPassType.Normal, whenTaskDisabled) as FrameGraphPass<FrameGraphContext>;\r\n }\r\n\r\n /**\r\n * Adds a render pass to a task. This method can only be called during a Task.record execution.\r\n * @param name The name of the pass\r\n * @param whenTaskDisabled If true, the pass will be added to the list of passes to execute when the task is disabled (default is false)\r\n * @returns The render pass created\r\n */\r\n public addRenderPass(name: string, whenTaskDisabled = false): FrameGraphRenderPass {\r\n return this._addPass(name, FrameGraphPassType.Render, whenTaskDisabled) as FrameGraphRenderPass;\r\n }\r\n\r\n /**\r\n * Adds a cull pass to a task. This method can only be called during a Task.record execution.\r\n * @param name The name of the pass\r\n * @param whenTaskDisabled If true, the pass will be added to the list of passes to execute when the task is disabled (default is false)\r\n * @returns The cull pass created\r\n */\r\n public addCullPass(name: string, whenTaskDisabled = false): FrameGraphCullPass {\r\n return this._addPass(name, FrameGraphPassType.Cull, whenTaskDisabled) as FrameGraphCullPass;\r\n }\r\n\r\n private _addPass(name: string, passType: FrameGraphPassType, whenTaskDisabled = false): FrameGraphPass<FrameGraphContext> | FrameGraphRenderPass {\r\n if (!this._currentProcessedTask) {\r\n throw new Error(\"FrameGraph: A pass must be created during a Task.record execution only.\");\r\n }\r\n\r\n let pass: FrameGraphPass<FrameGraphContext> | FrameGraphRenderPass;\r\n\r\n switch (passType) {\r\n case FrameGraphPassType.Render:\r\n pass = new FrameGraphRenderPass(name, this._currentProcessedTask, this._renderContext, this._engine);\r\n break;\r\n case FrameGraphPassType.Cull:\r\n pass = new FrameGraphCullPass(name, this._currentProcessedTask, this._passContext, this._engine);\r\n break;\r\n default:\r\n pass = new FrameGraphPass(name, this._currentProcessedTask, this._passContext);\r\n break;\r\n }\r\n\r\n this._currentProcessedTask._addPass(pass, whenTaskDisabled);\r\n\r\n return pass;\r\n }\r\n\r\n /**\r\n * Builds the frame graph.\r\n * This method should be called after all tasks have been added to the frame graph (FrameGraph.addTask) and before the graph is executed (FrameGraph.execute).\r\n */\r\n public build(): void {\r\n this.textureManager._releaseTextures(false);\r\n\r\n try {\r\n for (const task of this._tasks) {\r\n task._reset();\r\n\r\n this._currentProcessedTask = task;\r\n this.textureManager._isRecordingTask = true;\r\n\r\n task.record();\r\n\r\n this.textureManager._isRecordingTask = false;\r\n this._currentProcessedTask = null;\r\n }\r\n\r\n this.textureManager._allocateTextures(this.optimizeTextureAllocation ? this._tasks : undefined);\r\n\r\n for (const task of this._tasks) {\r\n task._checkTask();\r\n }\r\n\r\n for (const task of this._tasks) {\r\n task.onTexturesAllocatedObservable.notifyObservers(this._renderContext);\r\n }\r\n\r\n this.onBuildObservable.notifyObservers(this);\r\n } catch (e) {\r\n this._tasks.length = 0;\r\n this._currentProcessedTask = null;\r\n this.textureManager._isRecordingTask = false;\r\n throw e;\r\n }\r\n }\r\n\r\n /**\r\n * Returns a promise that resolves when the frame graph is ready to be executed\r\n * This method must be called after the graph has been built (FrameGraph.build called)!\r\n * @param timeStep Time step in ms between retries (default is 16)\r\n * @param maxTimeout Maximum time in ms to wait for the graph to be ready (default is 30000)\r\n * @returns The promise that resolves when the graph is ready\r\n */\r\n public async whenReadyAsync(timeStep = 16, maxTimeout = 30000): Promise<void> {\r\n let firstNotReadyTask: FrameGraphTask | null = null;\r\n return await new Promise((resolve) => {\r\n this._whenReadyAsyncCancel = _RetryWithInterval(\r\n () => {\r\n let ready = this._renderContext._isReady();\r\n for (const task of this._tasks) {\r\n const taskIsReady = task.isReady();\r\n if (!taskIsReady && !firstNotReadyTask) {\r\n firstNotReadyTask = task;\r\n }\r\n ready &&= taskIsReady;\r\n }\r\n return ready;\r\n },\r\n () => {\r\n this._whenReadyAsyncCancel = null;\r\n resolve();\r\n },\r\n (err, isTimeout) => {\r\n this._whenReadyAsyncCancel = null;\r\n if (!isTimeout) {\r\n Logger.Error(\"FrameGraph: An unexpected error occurred while waiting for the frame graph to be ready.\");\r\n if (err) {\r\n Logger.Error(err);\r\n if (err.stack) {\r\n Logger.Error(err.stack);\r\n }\r\n }\r\n } else {\r\n Logger.Error(\r\n `FrameGraph: Timeout while waiting for the frame graph to be ready.${firstNotReadyTask ? ` First task not ready: ${firstNotReadyTask.name}` : \"\"}`\r\n );\r\n if (err) {\r\n Logger.Error(err);\r\n }\r\n }\r\n },\r\n timeStep,\r\n maxTimeout\r\n );\r\n });\r\n }\r\n\r\n /**\r\n * Executes the frame graph.\r\n */\r\n public execute(): void {\r\n if (this.pausedExecution) {\r\n return;\r\n }\r\n\r\n this._renderContext.bindRenderTarget();\r\n\r\n this.textureManager._updateHistoryTextures();\r\n\r\n for (const task of this._tasks) {\r\n const passes = task._getPasses();\r\n\r\n for (const pass of passes) {\r\n pass._execute();\r\n }\r\n }\r\n\r\n this._renderContext.bindRenderTarget(undefined, undefined, true); // restore default framebuffer\r\n }\r\n\r\n /**\r\n * Clears the frame graph (remove the tasks and release the textures).\r\n * The frame graph can be built again after this method is called.\r\n */\r\n public clear(): void {\r\n this._whenReadyAsyncCancel?.();\r\n this._whenReadyAsyncCancel = null;\r\n\r\n for (const task of this._tasks) {\r\n task._reset();\r\n }\r\n\r\n this._tasks.length = 0;\r\n this.textureManager._releaseTextures();\r\n this._currentProcessedTask = null;\r\n }\r\n\r\n /**\r\n * Disposes the frame graph\r\n */\r\n public dispose(): void {\r\n this._whenReadyAsyncCancel?.();\r\n this._whenReadyAsyncCancel = null;\r\n this.clear();\r\n this.textureManager._dispose();\r\n this._renderContext._dispose();\r\n\r\n this._scene.removeFrameGraph(this);\r\n }\r\n}\r\n"]}
@@ -121,8 +121,9 @@ export declare class FrameGraphRenderContext extends FrameGraphContext {
121
121
  * this method several times with different render targets without incurring the cost of binding if no draw calls are made
122
122
  * @param renderTarget The handle of the render target texture to bind (default: undefined, meaning "back buffer"). Pass an array for MRT rendering.
123
123
  * @param debugMessage Optional debug message to display when the render target is bound (visible in PIX, for example)
124
+ * @param applyImmediately If true, the render target will be applied immediately (otherwise it will be applied at first use). Default is false (delayed application).
124
125
  */
125
- bindRenderTarget(renderTarget?: FrameGraphRenderTarget, debugMessage?: string): void;
126
+ bindRenderTarget(renderTarget?: FrameGraphRenderTarget, debugMessage?: string, applyImmediately?: boolean): void;
126
127
  /** @internal */
127
128
  _flushDebugMessages(): void;
128
129
  /** @internal */
@@ -28,7 +28,7 @@ export class FrameGraphRenderContext extends FrameGraphContext {
28
28
  * @returns True if the handle points to the backbuffer's color or depth texture, otherwise false
29
29
  */
30
30
  isBackbuffer(handle) {
31
- return this._textureManager.isBackbuffer(handle);
31
+ return this._textureManager._isBackbuffer(handle);
32
32
  }
33
33
  /**
34
34
  * Checks whether a texture handle points to the backbuffer's color texture
@@ -204,7 +204,7 @@ export class FrameGraphRenderContext extends FrameGraphContext {
204
204
  this.bindRenderTarget();
205
205
  }
206
206
  this._applyRenderTarget();
207
- this._copyTexture.copy(this._textureManager.getTextureFromHandle(sourceTexture));
207
+ this._copyTexture.copy(this._textureManager.getTextureFromHandle(sourceTexture, true));
208
208
  }
209
209
  /**
210
210
  * Renders a RenderTargetTexture or a layer
@@ -237,8 +237,9 @@ export class FrameGraphRenderContext extends FrameGraphContext {
237
237
  * this method several times with different render targets without incurring the cost of binding if no draw calls are made
238
238
  * @param renderTarget The handle of the render target texture to bind (default: undefined, meaning "back buffer"). Pass an array for MRT rendering.
239
239
  * @param debugMessage Optional debug message to display when the render target is bound (visible in PIX, for example)
240
+ * @param applyImmediately If true, the render target will be applied immediately (otherwise it will be applied at first use). Default is false (delayed application).
240
241
  */
241
- bindRenderTarget(renderTarget, debugMessage) {
242
+ bindRenderTarget(renderTarget, debugMessage, applyImmediately = false) {
242
243
  if ((renderTarget?.renderTargetWrapper === undefined && this._currentRenderTarget === undefined) ||
243
244
  (renderTarget && this._currentRenderTarget && renderTarget.equals(this._currentRenderTarget))) {
244
245
  this._flushDebugMessages();
@@ -247,11 +248,17 @@ export class FrameGraphRenderContext extends FrameGraphContext {
247
248
  this._debugMessageWhenTargetBound = undefined;
248
249
  this._debugMessageHasBeenPushed = true;
249
250
  }
251
+ if (applyImmediately) {
252
+ this._applyRenderTarget();
253
+ }
250
254
  return;
251
255
  }
252
256
  this._currentRenderTarget = renderTarget?.renderTargetWrapper === undefined ? undefined : renderTarget;
253
257
  this._debugMessageWhenTargetBound = debugMessage;
254
258
  this._renderTargetIsBound = false;
259
+ if (applyImmediately) {
260
+ this._applyRenderTarget();
261
+ }
255
262
  }
256
263
  /** @internal */
257
264
  _flushDebugMessages() {
@@ -1 +1 @@
1
- {"version":3,"file":"frameGraphRenderContext.js","sourceRoot":"","sources":["../../../../dev/core/src/FrameGraph/frameGraphRenderContext.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,C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;QACX,OAAO,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;IACvC,CAAC;IAED,gBAAgB;IACT,QAAQ;QACX,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC;QAC/B,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,CAAC;QACnC,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;IAChC,CAAC;CACJ","sourcesContent":["import type {\r\n Nullable,\r\n AbstractEngine,\r\n DrawWrapper,\r\n IColor4Like,\r\n Layer,\r\n FrameGraphTextureHandle,\r\n Effect,\r\n FrameGraphTextureManager,\r\n ObjectRenderer,\r\n Scene,\r\n FrameGraphRenderTarget,\r\n InternalTexture,\r\n UtilityLayerRenderer,\r\n IStencilState,\r\n} from \"core/index\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { EffectRenderer } from \"../Materials/effectRenderer\";\r\nimport { CopyTextureToTexture } from \"../Misc/copyTextureToTexture\";\r\nimport { FrameGraphContext } from \"./frameGraphContext\";\r\n\r\n/**\r\n * Frame graph context used render passes.\r\n * @experimental\r\n */\r\nexport class FrameGraphRenderContext extends FrameGraphContext {\r\n private readonly _effectRenderer: EffectRenderer;\r\n private readonly _effectRendererBack: EffectRenderer;\r\n private _currentRenderTarget: FrameGraphRenderTarget | undefined;\r\n private _debugMessageWhenTargetBound: string | undefined;\r\n private _debugMessageHasBeenPushed = false;\r\n private _renderTargetIsBound = true;\r\n private readonly _copyTexture: CopyTextureToTexture;\r\n\r\n private static _IsObjectRenderer(value: Layer | ObjectRenderer | UtilityLayerRenderer): value is ObjectRenderer {\r\n return (value as ObjectRenderer).initRender !== undefined;\r\n }\r\n\r\n /** @internal */\r\n constructor(engine: AbstractEngine, textureManager: FrameGraphTextureManager, scene: Scene) {\r\n super(engine, textureManager, scene);\r\n this._effectRenderer = new EffectRenderer(this._engine);\r\n this._effectRendererBack = new EffectRenderer(this._engine, {\r\n positions: [1, 1, -1, 1, -1, -1, 1, -1],\r\n indices: [0, 2, 1, 0, 3, 2],\r\n });\r\n this._copyTexture = new CopyTextureToTexture(this._engine);\r\n }\r\n\r\n /**\r\n * Checks whether a texture handle points to the backbuffer's color or depth texture\r\n * @param handle The handle to check\r\n * @returns True if the handle points to the backbuffer's color or depth texture, otherwise false\r\n */\r\n public isBackbuffer(handle: FrameGraphTextureHandle): boolean {\r\n return this._textureManager.isBackbuffer(handle);\r\n }\r\n\r\n /**\r\n * Checks whether a texture handle points to the backbuffer's color texture\r\n * @param handle The handle to check\r\n * @returns True if the handle points to the backbuffer's color texture, otherwise false\r\n */\r\n public isBackbufferColor(handle: FrameGraphTextureHandle): boolean {\r\n return this._textureManager.isBackbufferColor(handle);\r\n }\r\n\r\n /**\r\n * Checks whether a texture handle points to the backbuffer's depth texture\r\n * @param handle The handle to check\r\n * @returns True if the handle points to the backbuffer's depth texture, otherwise false\r\n */\r\n public isBackbufferDepthStencil(handle: FrameGraphTextureHandle): boolean {\r\n return this._textureManager.isBackbufferDepthStencil(handle);\r\n }\r\n\r\n /**\r\n * Creates a (frame graph) render target wrapper\r\n * Note that renderTargets or renderTargetDepth can be undefined, but not both at the same time!\r\n * @param name Name of the render target wrapper\r\n * @param renderTargets Render target handles (textures) to use\r\n * @param renderTargetDepth Render target depth handle (texture) to use\r\n * @param depthReadOnly If true, the depth buffer will be read-only\r\n * @param stencilReadOnly If true, the stencil buffer will be read-only\r\n * @returns The created render target wrapper\r\n */\r\n public createRenderTarget(\r\n name: string,\r\n renderTargets?: FrameGraphTextureHandle | FrameGraphTextureHandle[],\r\n renderTargetDepth?: FrameGraphTextureHandle,\r\n depthReadOnly?: boolean,\r\n stencilReadOnly?: boolean\r\n ): FrameGraphRenderTarget {\r\n return this._textureManager.createRenderTarget(name, renderTargets, renderTargetDepth, depthReadOnly, stencilReadOnly);\r\n }\r\n\r\n /**\r\n * Clears the current render buffer or the current render target (if any is set up)\r\n * @param color Defines the color to use\r\n * @param backBuffer Defines if the back buffer must be cleared\r\n * @param depth Defines if the depth buffer must be cleared\r\n * @param stencil Defines if the stencil buffer must be cleared\r\n * @param stencilClearValue Defines the value to use to clear the stencil buffer (default is 0)\r\n */\r\n public clear(color: Nullable<IColor4Like>, backBuffer: boolean, depth: boolean, stencil?: boolean, stencilClearValue = 0): void {\r\n this._applyRenderTarget();\r\n this._engine.clear(color, backBuffer, depth, stencil, stencilClearValue);\r\n }\r\n\r\n /**\r\n * Clears the color attachments of the current render target\r\n * @param color Defines the color to use\r\n * @param attachments The attachments to clear\r\n */\r\n public clearColorAttachments(color: Nullable<IColor4Like>, attachments: number[]): void {\r\n this._applyRenderTarget();\r\n this._engine.bindAttachments(attachments);\r\n this._engine.clear(color, true, false, false);\r\n }\r\n\r\n /**\r\n * Clears all attachments (color(s) + depth/stencil) of the current render target\r\n * @param color Defines the color to use\r\n * @param attachments The attachments to clear\r\n * @param backBuffer Defines if the back buffer must be cleared\r\n * @param depth Defines if the depth buffer must be cleared\r\n * @param stencil Defines if the stencil buffer must be cleared\r\n * @param stencilClearValue Defines the value to use to clear the stencil buffer (default is 0)\r\n */\r\n public clearAttachments(color: Nullable<IColor4Like>, attachments: number[], backBuffer: boolean, depth: boolean, stencil?: boolean, stencilClearValue = 0): void {\r\n this._applyRenderTarget();\r\n this._engine.bindAttachments(attachments);\r\n this._engine.clear(color, backBuffer, depth, stencil, stencilClearValue);\r\n }\r\n\r\n /**\r\n * Binds the attachments to the current render target\r\n * @param attachments The attachments to bind\r\n */\r\n public bindAttachments(attachments: number[]): void {\r\n this._applyRenderTarget();\r\n this._engine.bindAttachments(attachments);\r\n }\r\n\r\n /**\r\n * Generates mipmaps for the current render target\r\n */\r\n public generateMipMaps(): void {\r\n if (this._currentRenderTarget?.renderTargetWrapper === undefined) {\r\n return;\r\n }\r\n\r\n if (this._renderTargetIsBound && this._engine._currentRenderTarget) {\r\n // we can't generate the mipmaps if the render target is bound\r\n this._flushDebugMessages();\r\n this._engine.unBindFramebuffer(this._engine._currentRenderTarget);\r\n this._renderTargetIsBound = false;\r\n }\r\n\r\n const textures = this._currentRenderTarget.renderTargetWrapper.textures;\r\n if (textures) {\r\n for (const texture of textures) {\r\n this._engine.generateMipmaps(texture);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Sets the texture sampling mode for a given texture handle\r\n * @param handle Handle of the texture to set the sampling mode for\r\n * @param samplingMode Sampling mode to set\r\n */\r\n public setTextureSamplingMode(handle: FrameGraphTextureHandle, samplingMode: number): void {\r\n const internalTexture = this._textureManager.getTextureFromHandle(handle);\r\n if (internalTexture && internalTexture.samplingMode !== samplingMode) {\r\n this._engine.updateTextureSamplingMode(samplingMode, internalTexture);\r\n }\r\n }\r\n\r\n /**\r\n * Binds a texture handle to a given effect (resolves the handle to a texture and binds it to the effect)\r\n * @param effect The effect to bind the texture to\r\n * @param name The name of the texture in the effect\r\n * @param handle The handle of the texture to bind\r\n */\r\n public bindTextureHandle(effect: Effect, name: string, handle: FrameGraphTextureHandle): void {\r\n let texture: Nullable<InternalTexture>;\r\n\r\n const historyEntry = this._textureManager._historyTextures.get(handle);\r\n if (historyEntry) {\r\n texture = historyEntry.textures[historyEntry.index]; // texture we write to in this frame\r\n if (\r\n this._currentRenderTarget !== undefined &&\r\n this._currentRenderTarget.renderTargetWrapper !== undefined &&\r\n this._currentRenderTarget.renderTargetWrapper.textures!.includes(texture!)\r\n ) {\r\n // If the current render target renders to the history write texture, we bind the read texture instead\r\n texture = historyEntry.textures[historyEntry.index ^ 1];\r\n }\r\n } else {\r\n texture = this._textureManager._textures.get(handle)!.texture;\r\n }\r\n\r\n effect._bindTexture(name, texture);\r\n }\r\n\r\n /**\r\n * Applies a full-screen effect to the current render target\r\n * @param drawWrapper The draw wrapper containing the effect to apply\r\n * @param customBindings The custom bindings to use when applying the effect (optional)\r\n * @param stencilState The stencil state to use when applying the effect (optional)\r\n * @param disableColorWrite If true, color write will be disabled when applying the effect (optional)\r\n * @param drawBackFace If true, the fullscreen quad will be drawn as a back face (in CW - optional)\r\n * @param depthTest If true, depth testing will be enabled when applying the effect (default is false)\r\n * @returns True if the effect was applied, otherwise false (effect not ready)\r\n */\r\n public applyFullScreenEffect(\r\n drawWrapper: DrawWrapper,\r\n customBindings?: () => void,\r\n stencilState?: IStencilState,\r\n disableColorWrite?: boolean,\r\n drawBackFace?: boolean,\r\n depthTest?: boolean\r\n ): boolean {\r\n if (!drawWrapper.effect?.isReady()) {\r\n return false;\r\n }\r\n\r\n this._applyRenderTarget();\r\n\r\n const engineDepthMask = this._engine.getDepthWrite(); // for some reasons, depthWrite is not restored by EffectRenderer.restoreStates\r\n\r\n const effectRenderer = drawBackFace ? this._effectRendererBack : this._effectRenderer;\r\n\r\n effectRenderer.saveStates();\r\n effectRenderer.setViewport();\r\n\r\n this._engine.enableEffect(drawWrapper);\r\n this._engine.setState(false, undefined, undefined, undefined, undefined, stencilState);\r\n this._engine.setDepthBuffer(!!depthTest);\r\n if (disableColorWrite) {\r\n this._engine.setColorWrite(false);\r\n }\r\n this._engine.setDepthWrite(false);\r\n\r\n effectRenderer.bindBuffers(drawWrapper.effect);\r\n customBindings?.();\r\n effectRenderer.draw();\r\n effectRenderer.restoreStates();\r\n if (disableColorWrite) {\r\n this._engine.setColorWrite(true);\r\n }\r\n this._engine.setDepthWrite(engineDepthMask);\r\n this._engine.setAlphaMode(Constants.ALPHA_DISABLE);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Copies a texture to the current render target\r\n * @param sourceTexture The source texture to copy from\r\n * @param forceCopyToBackbuffer If true, the copy will be done to the back buffer regardless of the current render target\r\n */\r\n public copyTexture(sourceTexture: FrameGraphTextureHandle, forceCopyToBackbuffer = false): void {\r\n if (forceCopyToBackbuffer) {\r\n this.bindRenderTarget();\r\n }\r\n this._applyRenderTarget();\r\n this._copyTexture.copy(this._textureManager.getTextureFromHandle(sourceTexture)!);\r\n }\r\n\r\n /**\r\n * Renders a RenderTargetTexture or a layer\r\n * @param object The RenderTargetTexture/Layer to render\r\n * @param viewportWidth The width of the viewport (optional for Layer, but mandatory for ObjectRenderer)\r\n * @param viewportHeight The height of the viewport (optional for Layer, but mandatory for ObjectRenderer)\r\n */\r\n public render(object: Layer | ObjectRenderer | UtilityLayerRenderer, viewportWidth?: number, viewportHeight?: number): void {\r\n if (FrameGraphRenderContext._IsObjectRenderer(object)) {\r\n this._scene._intermediateRendering = true;\r\n if (object.shouldRender()) {\r\n this._scene.incrementRenderId();\r\n this._scene.resetCachedMaterial();\r\n\r\n this._applyRenderTarget();\r\n\r\n object.prepareRenderList();\r\n\r\n object.initRender(viewportWidth!, viewportHeight!);\r\n\r\n object.render();\r\n\r\n object.finishRender();\r\n }\r\n this._scene._intermediateRendering = false;\r\n } else {\r\n this._applyRenderTarget();\r\n object.render();\r\n }\r\n }\r\n\r\n /**\r\n * Binds a render target texture so that upcoming draw calls will render to it\r\n * Note: it is a lazy operation, so the render target will only be bound when needed. This way, it is possible to call\r\n * this method several times with different render targets without incurring the cost of binding if no draw calls are made\r\n * @param renderTarget The handle of the render target texture to bind (default: undefined, meaning \"back buffer\"). Pass an array for MRT rendering.\r\n * @param debugMessage Optional debug message to display when the render target is bound (visible in PIX, for example)\r\n */\r\n public bindRenderTarget(renderTarget?: FrameGraphRenderTarget, debugMessage?: string) {\r\n if (\r\n (renderTarget?.renderTargetWrapper === undefined && this._currentRenderTarget === undefined) ||\r\n (renderTarget && this._currentRenderTarget && renderTarget.equals(this._currentRenderTarget))\r\n ) {\r\n this._flushDebugMessages();\r\n if (debugMessage !== undefined) {\r\n this._engine._debugPushGroup?.(debugMessage, 2);\r\n this._debugMessageWhenTargetBound = undefined;\r\n this._debugMessageHasBeenPushed = true;\r\n }\r\n return;\r\n }\r\n this._currentRenderTarget = renderTarget?.renderTargetWrapper === undefined ? undefined : renderTarget;\r\n this._debugMessageWhenTargetBound = debugMessage;\r\n this._renderTargetIsBound = false;\r\n }\r\n\r\n /** @internal */\r\n public _flushDebugMessages() {\r\n if (this._debugMessageHasBeenPushed) {\r\n this._engine._debugPopGroup?.(2);\r\n this._debugMessageHasBeenPushed = false;\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _applyRenderTarget() {\r\n if (this._renderTargetIsBound) {\r\n return;\r\n }\r\n\r\n this._flushDebugMessages();\r\n\r\n const renderTargetWrapper = this._currentRenderTarget?.renderTargetWrapper;\r\n\r\n if (renderTargetWrapper === undefined) {\r\n this._engine.restoreDefaultFramebuffer();\r\n } else {\r\n if (this._engine._currentRenderTarget) {\r\n this._engine.unBindFramebuffer(this._engine._currentRenderTarget);\r\n }\r\n this._engine.bindFramebuffer(renderTargetWrapper);\r\n }\r\n\r\n if (this._debugMessageWhenTargetBound !== undefined) {\r\n this._engine._debugPushGroup?.(this._debugMessageWhenTargetBound, 2);\r\n this._debugMessageWhenTargetBound = undefined;\r\n this._debugMessageHasBeenPushed = true;\r\n }\r\n\r\n this._renderTargetIsBound = true;\r\n }\r\n\r\n /** @internal */\r\n public _isReady(): boolean {\r\n return this._copyTexture.isReady();\r\n }\r\n\r\n /** @internal */\r\n public _dispose() {\r\n this._effectRenderer.dispose();\r\n this._effectRendererBack.dispose();\r\n this._copyTexture.dispose();\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"frameGraphRenderContext.js","sourceRoot":"","sources":["../../../../dev/core/src/FrameGraph/frameGraphRenderContext.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD;;;GAGG;AACH,MAAM,OAAO,uBAAwB,SAAQ,iBAAiB;IASlD,MAAM,CAAC,iBAAiB,CAAC,KAAoD;QACjF,OAAQ,KAAwB,CAAC,UAAU,KAAK,SAAS,CAAC;IAC9D,CAAC;IAED,gBAAgB;IAChB,YAAY,MAAsB,EAAE,cAAwC,EAA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ACvC,CAAC;IAED,gBAAgB;IACT,QAAQ;QACX,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC;QAC/B,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,CAAC;QACnC,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;IAChC,CAAC;CACJ","sourcesContent":["import type {\r\n Nullable,\r\n AbstractEngine,\r\n DrawWrapper,\r\n IColor4Like,\r\n Layer,\r\n FrameGraphTextureHandle,\r\n Effect,\r\n FrameGraphTextureManager,\r\n ObjectRenderer,\r\n Scene,\r\n FrameGraphRenderTarget,\r\n InternalTexture,\r\n UtilityLayerRenderer,\r\n IStencilState,\r\n} from \"core/index\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { EffectRenderer } from \"../Materials/effectRenderer\";\r\nimport { CopyTextureToTexture } from \"../Misc/copyTextureToTexture\";\r\nimport { FrameGraphContext } from \"./frameGraphContext\";\r\n\r\n/**\r\n * Frame graph context used render passes.\r\n * @experimental\r\n */\r\nexport class FrameGraphRenderContext extends FrameGraphContext {\r\n private readonly _effectRenderer: EffectRenderer;\r\n private readonly _effectRendererBack: EffectRenderer;\r\n private _currentRenderTarget: FrameGraphRenderTarget | undefined;\r\n private _debugMessageWhenTargetBound: string | undefined;\r\n private _debugMessageHasBeenPushed = false;\r\n private _renderTargetIsBound = true;\r\n private readonly _copyTexture: CopyTextureToTexture;\r\n\r\n private static _IsObjectRenderer(value: Layer | ObjectRenderer | UtilityLayerRenderer): value is ObjectRenderer {\r\n return (value as ObjectRenderer).initRender !== undefined;\r\n }\r\n\r\n /** @internal */\r\n constructor(engine: AbstractEngine, textureManager: FrameGraphTextureManager, scene: Scene) {\r\n super(engine, textureManager, scene);\r\n this._effectRenderer = new EffectRenderer(this._engine);\r\n this._effectRendererBack = new EffectRenderer(this._engine, {\r\n positions: [1, 1, -1, 1, -1, -1, 1, -1],\r\n indices: [0, 2, 1, 0, 3, 2],\r\n });\r\n this._copyTexture = new CopyTextureToTexture(this._engine);\r\n }\r\n\r\n /**\r\n * Checks whether a texture handle points to the backbuffer's color or depth texture\r\n * @param handle The handle to check\r\n * @returns True if the handle points to the backbuffer's color or depth texture, otherwise false\r\n */\r\n public isBackbuffer(handle: FrameGraphTextureHandle): boolean {\r\n return this._textureManager._isBackbuffer(handle);\r\n }\r\n\r\n /**\r\n * Checks whether a texture handle points to the backbuffer's color texture\r\n * @param handle The handle to check\r\n * @returns True if the handle points to the backbuffer's color texture, otherwise false\r\n */\r\n public isBackbufferColor(handle: FrameGraphTextureHandle): boolean {\r\n return this._textureManager.isBackbufferColor(handle);\r\n }\r\n\r\n /**\r\n * Checks whether a texture handle points to the backbuffer's depth texture\r\n * @param handle The handle to check\r\n * @returns True if the handle points to the backbuffer's depth texture, otherwise false\r\n */\r\n public isBackbufferDepthStencil(handle: FrameGraphTextureHandle): boolean {\r\n return this._textureManager.isBackbufferDepthStencil(handle);\r\n }\r\n\r\n /**\r\n * Creates a (frame graph) render target wrapper\r\n * Note that renderTargets or renderTargetDepth can be undefined, but not both at the same time!\r\n * @param name Name of the render target wrapper\r\n * @param renderTargets Render target handles (textures) to use\r\n * @param renderTargetDepth Render target depth handle (texture) to use\r\n * @param depthReadOnly If true, the depth buffer will be read-only\r\n * @param stencilReadOnly If true, the stencil buffer will be read-only\r\n * @returns The created render target wrapper\r\n */\r\n public createRenderTarget(\r\n name: string,\r\n renderTargets?: FrameGraphTextureHandle | FrameGraphTextureHandle[],\r\n renderTargetDepth?: FrameGraphTextureHandle,\r\n depthReadOnly?: boolean,\r\n stencilReadOnly?: boolean\r\n ): FrameGraphRenderTarget {\r\n return this._textureManager.createRenderTarget(name, renderTargets, renderTargetDepth, depthReadOnly, stencilReadOnly);\r\n }\r\n\r\n /**\r\n * Clears the current render buffer or the current render target (if any is set up)\r\n * @param color Defines the color to use\r\n * @param backBuffer Defines if the back buffer must be cleared\r\n * @param depth Defines if the depth buffer must be cleared\r\n * @param stencil Defines if the stencil buffer must be cleared\r\n * @param stencilClearValue Defines the value to use to clear the stencil buffer (default is 0)\r\n */\r\n public clear(color: Nullable<IColor4Like>, backBuffer: boolean, depth: boolean, stencil?: boolean, stencilClearValue = 0): void {\r\n this._applyRenderTarget();\r\n this._engine.clear(color, backBuffer, depth, stencil, stencilClearValue);\r\n }\r\n\r\n /**\r\n * Clears the color attachments of the current render target\r\n * @param color Defines the color to use\r\n * @param attachments The attachments to clear\r\n */\r\n public clearColorAttachments(color: Nullable<IColor4Like>, attachments: number[]): void {\r\n this._applyRenderTarget();\r\n this._engine.bindAttachments(attachments);\r\n this._engine.clear(color, true, false, false);\r\n }\r\n\r\n /**\r\n * Clears all attachments (color(s) + depth/stencil) of the current render target\r\n * @param color Defines the color to use\r\n * @param attachments The attachments to clear\r\n * @param backBuffer Defines if the back buffer must be cleared\r\n * @param depth Defines if the depth buffer must be cleared\r\n * @param stencil Defines if the stencil buffer must be cleared\r\n * @param stencilClearValue Defines the value to use to clear the stencil buffer (default is 0)\r\n */\r\n public clearAttachments(color: Nullable<IColor4Like>, attachments: number[], backBuffer: boolean, depth: boolean, stencil?: boolean, stencilClearValue = 0): void {\r\n this._applyRenderTarget();\r\n this._engine.bindAttachments(attachments);\r\n this._engine.clear(color, backBuffer, depth, stencil, stencilClearValue);\r\n }\r\n\r\n /**\r\n * Binds the attachments to the current render target\r\n * @param attachments The attachments to bind\r\n */\r\n public bindAttachments(attachments: number[]): void {\r\n this._applyRenderTarget();\r\n this._engine.bindAttachments(attachments);\r\n }\r\n\r\n /**\r\n * Generates mipmaps for the current render target\r\n */\r\n public generateMipMaps(): void {\r\n if (this._currentRenderTarget?.renderTargetWrapper === undefined) {\r\n return;\r\n }\r\n\r\n if (this._renderTargetIsBound && this._engine._currentRenderTarget) {\r\n // we can't generate the mipmaps if the render target is bound\r\n this._flushDebugMessages();\r\n this._engine.unBindFramebuffer(this._engine._currentRenderTarget);\r\n this._renderTargetIsBound = false;\r\n }\r\n\r\n const textures = this._currentRenderTarget.renderTargetWrapper.textures;\r\n if (textures) {\r\n for (const texture of textures) {\r\n this._engine.generateMipmaps(texture);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Sets the texture sampling mode for a given texture handle\r\n * @param handle Handle of the texture to set the sampling mode for\r\n * @param samplingMode Sampling mode to set\r\n */\r\n public setTextureSamplingMode(handle: FrameGraphTextureHandle, samplingMode: number): void {\r\n const internalTexture = this._textureManager.getTextureFromHandle(handle);\r\n if (internalTexture && internalTexture.samplingMode !== samplingMode) {\r\n this._engine.updateTextureSamplingMode(samplingMode, internalTexture);\r\n }\r\n }\r\n\r\n /**\r\n * Binds a texture handle to a given effect (resolves the handle to a texture and binds it to the effect)\r\n * @param effect The effect to bind the texture to\r\n * @param name The name of the texture in the effect\r\n * @param handle The handle of the texture to bind\r\n */\r\n public bindTextureHandle(effect: Effect, name: string, handle: FrameGraphTextureHandle): void {\r\n let texture: Nullable<InternalTexture>;\r\n\r\n const historyEntry = this._textureManager._historyTextures.get(handle);\r\n if (historyEntry) {\r\n texture = historyEntry.textures[historyEntry.index]; // texture we write to in this frame\r\n if (\r\n this._currentRenderTarget !== undefined &&\r\n this._currentRenderTarget.renderTargetWrapper !== undefined &&\r\n this._currentRenderTarget.renderTargetWrapper.textures!.includes(texture!)\r\n ) {\r\n // If the current render target renders to the history write texture, we bind the read texture instead\r\n texture = historyEntry.textures[historyEntry.index ^ 1];\r\n }\r\n } else {\r\n texture = this._textureManager._textures.get(handle)!.texture;\r\n }\r\n\r\n effect._bindTexture(name, texture);\r\n }\r\n\r\n /**\r\n * Applies a full-screen effect to the current render target\r\n * @param drawWrapper The draw wrapper containing the effect to apply\r\n * @param customBindings The custom bindings to use when applying the effect (optional)\r\n * @param stencilState The stencil state to use when applying the effect (optional)\r\n * @param disableColorWrite If true, color write will be disabled when applying the effect (optional)\r\n * @param drawBackFace If true, the fullscreen quad will be drawn as a back face (in CW - optional)\r\n * @param depthTest If true, depth testing will be enabled when applying the effect (default is false)\r\n * @returns True if the effect was applied, otherwise false (effect not ready)\r\n */\r\n public applyFullScreenEffect(\r\n drawWrapper: DrawWrapper,\r\n customBindings?: () => void,\r\n stencilState?: IStencilState,\r\n disableColorWrite?: boolean,\r\n drawBackFace?: boolean,\r\n depthTest?: boolean\r\n ): boolean {\r\n if (!drawWrapper.effect?.isReady()) {\r\n return false;\r\n }\r\n\r\n this._applyRenderTarget();\r\n\r\n const engineDepthMask = this._engine.getDepthWrite(); // for some reasons, depthWrite is not restored by EffectRenderer.restoreStates\r\n\r\n const effectRenderer = drawBackFace ? this._effectRendererBack : this._effectRenderer;\r\n\r\n effectRenderer.saveStates();\r\n effectRenderer.setViewport();\r\n\r\n this._engine.enableEffect(drawWrapper);\r\n this._engine.setState(false, undefined, undefined, undefined, undefined, stencilState);\r\n this._engine.setDepthBuffer(!!depthTest);\r\n if (disableColorWrite) {\r\n this._engine.setColorWrite(false);\r\n }\r\n this._engine.setDepthWrite(false);\r\n\r\n effectRenderer.bindBuffers(drawWrapper.effect);\r\n customBindings?.();\r\n effectRenderer.draw();\r\n effectRenderer.restoreStates();\r\n if (disableColorWrite) {\r\n this._engine.setColorWrite(true);\r\n }\r\n this._engine.setDepthWrite(engineDepthMask);\r\n this._engine.setAlphaMode(Constants.ALPHA_DISABLE);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Copies a texture to the current render target\r\n * @param sourceTexture The source texture to copy from\r\n * @param forceCopyToBackbuffer If true, the copy will be done to the back buffer regardless of the current render target\r\n */\r\n public copyTexture(sourceTexture: FrameGraphTextureHandle, forceCopyToBackbuffer = false): void {\r\n if (forceCopyToBackbuffer) {\r\n this.bindRenderTarget();\r\n }\r\n this._applyRenderTarget();\r\n this._copyTexture.copy(this._textureManager.getTextureFromHandle(sourceTexture, true)!);\r\n }\r\n\r\n /**\r\n * Renders a RenderTargetTexture or a layer\r\n * @param object The RenderTargetTexture/Layer to render\r\n * @param viewportWidth The width of the viewport (optional for Layer, but mandatory for ObjectRenderer)\r\n * @param viewportHeight The height of the viewport (optional for Layer, but mandatory for ObjectRenderer)\r\n */\r\n public render(object: Layer | ObjectRenderer | UtilityLayerRenderer, viewportWidth?: number, viewportHeight?: number): void {\r\n if (FrameGraphRenderContext._IsObjectRenderer(object)) {\r\n this._scene._intermediateRendering = true;\r\n if (object.shouldRender()) {\r\n this._scene.incrementRenderId();\r\n this._scene.resetCachedMaterial();\r\n\r\n this._applyRenderTarget();\r\n\r\n object.prepareRenderList();\r\n\r\n object.initRender(viewportWidth!, viewportHeight!);\r\n\r\n object.render();\r\n\r\n object.finishRender();\r\n }\r\n this._scene._intermediateRendering = false;\r\n } else {\r\n this._applyRenderTarget();\r\n object.render();\r\n }\r\n }\r\n\r\n /**\r\n * Binds a render target texture so that upcoming draw calls will render to it\r\n * Note: it is a lazy operation, so the render target will only be bound when needed. This way, it is possible to call\r\n * this method several times with different render targets without incurring the cost of binding if no draw calls are made\r\n * @param renderTarget The handle of the render target texture to bind (default: undefined, meaning \"back buffer\"). Pass an array for MRT rendering.\r\n * @param debugMessage Optional debug message to display when the render target is bound (visible in PIX, for example)\r\n * @param applyImmediately If true, the render target will be applied immediately (otherwise it will be applied at first use). Default is false (delayed application).\r\n */\r\n public bindRenderTarget(renderTarget?: FrameGraphRenderTarget, debugMessage?: string, applyImmediately = false): void {\r\n if (\r\n (renderTarget?.renderTargetWrapper === undefined && this._currentRenderTarget === undefined) ||\r\n (renderTarget && this._currentRenderTarget && renderTarget.equals(this._currentRenderTarget))\r\n ) {\r\n this._flushDebugMessages();\r\n if (debugMessage !== undefined) {\r\n this._engine._debugPushGroup?.(debugMessage, 2);\r\n this._debugMessageWhenTargetBound = undefined;\r\n this._debugMessageHasBeenPushed = true;\r\n }\r\n if (applyImmediately) {\r\n this._applyRenderTarget();\r\n }\r\n return;\r\n }\r\n this._currentRenderTarget = renderTarget?.renderTargetWrapper === undefined ? undefined : renderTarget;\r\n this._debugMessageWhenTargetBound = debugMessage;\r\n this._renderTargetIsBound = false;\r\n if (applyImmediately) {\r\n this._applyRenderTarget();\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _flushDebugMessages() {\r\n if (this._debugMessageHasBeenPushed) {\r\n this._engine._debugPopGroup?.(2);\r\n this._debugMessageHasBeenPushed = false;\r\n }\r\n }\r\n\r\n /** @internal */\r\n public _applyRenderTarget() {\r\n if (this._renderTargetIsBound) {\r\n return;\r\n }\r\n\r\n this._flushDebugMessages();\r\n\r\n const renderTargetWrapper = this._currentRenderTarget?.renderTargetWrapper;\r\n\r\n if (renderTargetWrapper === undefined) {\r\n this._engine.restoreDefaultFramebuffer();\r\n } else {\r\n if (this._engine._currentRenderTarget) {\r\n this._engine.unBindFramebuffer(this._engine._currentRenderTarget);\r\n }\r\n this._engine.bindFramebuffer(renderTargetWrapper);\r\n }\r\n\r\n if (this._debugMessageWhenTargetBound !== undefined) {\r\n this._engine._debugPushGroup?.(this._debugMessageWhenTargetBound, 2);\r\n this._debugMessageWhenTargetBound = undefined;\r\n this._debugMessageHasBeenPushed = true;\r\n }\r\n\r\n this._renderTargetIsBound = true;\r\n }\r\n\r\n /** @internal */\r\n public _isReady(): boolean {\r\n return this._copyTexture.isReady();\r\n }\r\n\r\n /** @internal */\r\n public _dispose() {\r\n this._effectRenderer.dispose();\r\n this._effectRendererBack.dispose();\r\n this._copyTexture.dispose();\r\n }\r\n}\r\n"]}
@@ -50,10 +50,9 @@ export declare class FrameGraphTextureManager {
50
50
  * Gets or sets a boolean indicating if debug logs should be shown when applying texture allocation optimization (default: false)
51
51
  */
52
52
  showDebugLogsForTextureAllcationOptimization: boolean;
53
- /** If provided (greater than 0), forces the output screen width for percentage-based textures. If not provided (0), engine.getRenderWidth() will be used */
54
- forcedOutputScreenWidth: number;
55
- /** If provided (greater than 0), forces the output screen height for percentage-based textures. If not provided (0), engine.getRenderHeight() will be used */
56
- forcedOutputScreenHeight: number;
53
+ private _backBufferTextureEntry;
54
+ private _backBufferDepthStencilTextureEntry;
55
+ private _backBufferTextureOverriden;
57
56
  /**
58
57
  * Constructs a new instance of the texture manager
59
58
  * @param engine The engine to use
@@ -67,6 +66,8 @@ export declare class FrameGraphTextureManager {
67
66
  * @returns True if the handle is a backbuffer handle
68
67
  */
69
68
  isBackbuffer(handle: FrameGraphTextureHandle): boolean;
69
+ /** @internal */
70
+ _isBackbuffer(handle: FrameGraphTextureHandle): boolean;
70
71
  /**
71
72
  * Checks if a handle is a backbuffer color handle
72
73
  * @param handle The handle to check
@@ -108,11 +109,12 @@ export declare class FrameGraphTextureManager {
108
109
  getTextureHandleOrCreateTexture(handle?: FrameGraphTextureHandle, newTextureName?: string, creationOptions?: FrameGraphTextureCreationOptions): FrameGraphTextureHandle;
109
110
  /**
110
111
  * Gets a texture from a handle.
111
- * Note that if the texture is a history texture, the read texture for the current frame will be returned.
112
+ * Note that if the texture is a history texture, the read texture for the current frame will be returned, except if historyGetWriteTexture is true.
112
113
  * @param handle The handle of the texture
114
+ * @param historyGetWriteTexture If true and the texture is a history texture, the write texture for the current frame will be returned (default: false)
113
115
  * @returns The texture or null if not found
114
116
  */
115
- getTextureFromHandle(handle: FrameGraphTextureHandle): Nullable<InternalTexture>;
117
+ getTextureFromHandle(handle: FrameGraphTextureHandle, historyGetWriteTexture?: boolean): Nullable<InternalTexture>;
116
118
  /**
117
119
  * Imports a texture into the texture manager
118
120
  * @param name Name of the texture
@@ -174,6 +176,30 @@ export declare class FrameGraphTextureManager {
174
176
  * @returns The total size of all textures
175
177
  */
176
178
  computeTotalTextureSize(optimizedSize: boolean, outputWidth: number, outputHeight: number): number;
179
+ /**
180
+ * True if the back buffer texture has been overriden by a call to setBackBufferTexture
181
+ */
182
+ get backBufferTextureOverriden(): boolean;
183
+ /**
184
+ * Overrides the default back buffer color/depth-stencil textures used by the frame graph.
185
+ * Note that if both textureCreationOptions and depthStencilTextureCreationOptions are provided,
186
+ * the engine will use them to create the back buffer color and depth/stencil textures respectively.
187
+ * In that case, width and height are ignored.
188
+ * @param width The width of the back buffer color/depth-stencil texture (if 0, the engine's current back buffer color/depth-stencil texture width will be used)
189
+ * @param height The height of the back buffer color/depth-stencil texture (if 0, the engine's current back buffer color/depth-stencil texture height will be used)
190
+ * @param textureCreationOptions The color texture creation options (optional)
191
+ * @param depthStencilTextureCreationOptions The depth/stencil texture creation options (optional)
192
+ */
193
+ setBackBufferTextures(width: number, height: number, textureCreationOptions?: FrameGraphTextureCreationOptions, depthStencilTextureCreationOptions?: FrameGraphTextureCreationOptions): void;
194
+ /**
195
+ * Resets the back buffer color/depth-stencil textures to the default (the engine's current back buffer textures)
196
+ * It has no effect if setBackBufferTextures has not been called before.
197
+ */
198
+ resetBackBufferTextures(): void;
199
+ /**
200
+ * Returns true if the texture manager has at least one history texture
201
+ */
202
+ get hasHistoryTextures(): boolean;
177
203
  /** @internal */
178
204
  _dispose(): void;
179
205
  /** @internal */