babylon.postProcessRenderPipelineManager.ts 4.9 KB

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