postProcessRenderPipelineManager.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import { Camera } from "../../Cameras/camera";
  2. import { PostProcessRenderPipeline } from "./postProcessRenderPipeline";
  3. /**
  4. * PostProcessRenderPipelineManager class
  5. * @see https://doc.babylonjs.com/how_to/how_to_use_postprocessrenderpipeline
  6. */
  7. export class PostProcessRenderPipelineManager {
  8. private _renderPipelines: { [Key: string]: PostProcessRenderPipeline };
  9. /**
  10. * Initializes a PostProcessRenderPipelineManager
  11. * @see https://doc.babylonjs.com/how_to/how_to_use_postprocessrenderpipeline
  12. */
  13. constructor() {
  14. this._renderPipelines = {};
  15. }
  16. /**
  17. * Gets the list of supported render pipelines
  18. */
  19. public get supportedPipelines(): PostProcessRenderPipeline[] {
  20. let result = [];
  21. for (var renderPipelineName in this._renderPipelines) {
  22. if (this._renderPipelines.hasOwnProperty(renderPipelineName)) {
  23. var pipeline = this._renderPipelines[renderPipelineName];
  24. if (pipeline.isSupported) {
  25. result.push(pipeline);
  26. }
  27. }
  28. }
  29. return result;
  30. }
  31. /**
  32. * Adds a pipeline to the manager
  33. * @param renderPipeline The pipeline to add
  34. */
  35. public addPipeline(renderPipeline: PostProcessRenderPipeline): void {
  36. this._renderPipelines[renderPipeline._name] = renderPipeline;
  37. }
  38. /**
  39. * Attaches a camera to the pipeline
  40. * @param renderPipelineName The name of the pipeline to attach to
  41. * @param cameras the camera to attach
  42. * @param unique if the camera can be attached multiple times to the pipeline
  43. */
  44. public attachCamerasToRenderPipeline(renderPipelineName: string, cameras: any | Camera[] | Camera, unique: boolean = false): void {
  45. var renderPipeline: PostProcessRenderPipeline = this._renderPipelines[renderPipelineName];
  46. if (!renderPipeline) {
  47. return;
  48. }
  49. renderPipeline._attachCameras(cameras, unique);
  50. }
  51. /**
  52. * Detaches a camera from the pipeline
  53. * @param renderPipelineName The name of the pipeline to detach from
  54. * @param cameras the camera to detach
  55. */
  56. public detachCamerasFromRenderPipeline(renderPipelineName: string, cameras: any | Camera[] | Camera): void {
  57. var renderPipeline: PostProcessRenderPipeline = this._renderPipelines[renderPipelineName];
  58. if (!renderPipeline) {
  59. return;
  60. }
  61. renderPipeline._detachCameras(cameras);
  62. }
  63. /**
  64. * Enables an effect by name on a pipeline
  65. * @param renderPipelineName the name of the pipeline to enable the effect in
  66. * @param renderEffectName the name of the effect to enable
  67. * @param cameras the cameras that the effect should be enabled on
  68. */
  69. public enableEffectInPipeline(renderPipelineName: string, renderEffectName: string, cameras: any | Camera[] | Camera): void {
  70. var renderPipeline: PostProcessRenderPipeline = this._renderPipelines[renderPipelineName];
  71. if (!renderPipeline) {
  72. return;
  73. }
  74. renderPipeline._enableEffect(renderEffectName, cameras);
  75. }
  76. /**
  77. * Disables an effect by name on a pipeline
  78. * @param renderPipelineName the name of the pipeline to disable the effect in
  79. * @param renderEffectName the name of the effect to disable
  80. * @param cameras the cameras that the effect should be disabled on
  81. */
  82. public disableEffectInPipeline(renderPipelineName: string, renderEffectName: string, cameras: any | Camera[] | Camera): void {
  83. var renderPipeline: PostProcessRenderPipeline = this._renderPipelines[renderPipelineName];
  84. if (!renderPipeline) {
  85. return;
  86. }
  87. renderPipeline._disableEffect(renderEffectName, cameras);
  88. }
  89. /**
  90. * Updates the state of all contained render pipelines and disposes of any non supported pipelines
  91. */
  92. public update(): void {
  93. for (var renderPipelineName in this._renderPipelines) {
  94. if (this._renderPipelines.hasOwnProperty(renderPipelineName)) {
  95. var pipeline = this._renderPipelines[renderPipelineName];
  96. if (!pipeline.isSupported) {
  97. pipeline.dispose();
  98. delete this._renderPipelines[renderPipelineName];
  99. } else {
  100. pipeline._update();
  101. }
  102. }
  103. }
  104. }
  105. /** @hidden */
  106. public _rebuild(): void {
  107. for (var renderPipelineName in this._renderPipelines) {
  108. if (this._renderPipelines.hasOwnProperty(renderPipelineName)) {
  109. var pipeline = this._renderPipelines[renderPipelineName];
  110. pipeline._rebuild();
  111. }
  112. }
  113. }
  114. /**
  115. * Disposes of the manager and pipelines
  116. */
  117. public dispose(): void {
  118. for (var renderPipelineName in this._renderPipelines) {
  119. if (this._renderPipelines.hasOwnProperty(renderPipelineName)) {
  120. var pipeline = this._renderPipelines[renderPipelineName];
  121. pipeline.dispose();
  122. }
  123. }
  124. }
  125. }