postProcessRenderPipelineManagerSceneComponent.ts 3.4 KB

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