postProcessRenderPipelineManager.js 4.8 KB

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