babylon.postProcessRenderPipelineManagerSceneComponent.ts 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. module BABYLON {
  2. export interface Scene {
  3. /** @hidden (Backing field) */
  4. _postProcessRenderPipelineManager: PostProcessRenderPipelineManager
  5. /**
  6. * Gets the postprocess render pipeline manager
  7. * @see http://doc.babylonjs.com/how_to/how_to_use_postprocessrenderpipeline
  8. * @see http://doc.babylonjs.com/how_to/using_default_rendering_pipeline
  9. */
  10. readonly postProcessRenderPipelineManager: PostProcessRenderPipelineManager;
  11. }
  12. Object.defineProperty(Scene.prototype, "postProcessRenderPipelineManager", {
  13. get: function (this:Scene) {
  14. if (!this._postProcessRenderPipelineManager) {
  15. // Register the G Buffer component to the scene.
  16. let component = this._getComponent(SceneComponentConstants.NAME_POSTPROCESSRENDERPIPELINEMANAGER) as PostProcessRenderPipelineManagerSceneComponent;
  17. if (!component) {
  18. component = new PostProcessRenderPipelineManagerSceneComponent(this);
  19. this._addComponent(component);
  20. }
  21. this._postProcessRenderPipelineManager = new PostProcessRenderPipelineManager();
  22. }
  23. return this._postProcessRenderPipelineManager;
  24. },
  25. enumerable: true,
  26. configurable: true
  27. });
  28. /**
  29. * Defines the Render Pipeline scene component responsible to rendering pipelines
  30. */
  31. export class PostProcessRenderPipelineManagerSceneComponent implements ISceneComponent {
  32. /**
  33. * The component name helpfull to identify the component in the list of scene components.
  34. */
  35. public readonly name = SceneComponentConstants.NAME_POSTPROCESSRENDERPIPELINEMANAGER;
  36. /**
  37. * The scene the component belongs to.
  38. */
  39. public scene: Scene;
  40. /**
  41. * Creates a new instance of the component for the given scene
  42. * @param scene Defines the scene to register the component in
  43. */
  44. constructor(scene: Scene) {
  45. this.scene = scene;
  46. }
  47. /**
  48. * Registers the component in a given scene
  49. */
  50. public register(): void {
  51. this.scene._gatherRenderTargetsStage.registerStep(SceneComponentConstants.STEP_GATHERRENDERTARGETS_POSTPROCESSRENDERPIPELINEMANAGER, this, this._gatherRenderTargets);
  52. }
  53. /**
  54. * Rebuilds the elements related to this component in case of
  55. * context lost for instance.
  56. */
  57. public rebuild(): void {
  58. if (this.scene._postProcessRenderPipelineManager) {
  59. this.scene._postProcessRenderPipelineManager._rebuild();
  60. }
  61. }
  62. /**
  63. * Disposes the component and the associated ressources
  64. */
  65. public dispose(): void {
  66. if (this.scene._postProcessRenderPipelineManager) {
  67. this.scene._postProcessRenderPipelineManager.dispose();
  68. }
  69. }
  70. private _gatherRenderTargets(renderTargets: SmartArrayNoDuplicate<RenderTargetTexture>): void {
  71. if (this.scene._postProcessRenderPipelineManager) {
  72. this.scene._postProcessRenderPipelineManager.update();
  73. }
  74. }
  75. }
  76. }