LyShinePass.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0 OR MIT
  5. *
  6. */
  7. #pragma once
  8. #include <Atom/RPI.Public/Pass/ParentPass.h>
  9. #include <Atom/RPI.Public/Pass/RasterPass.h>
  10. #include <AzCore/std/containers/span.h>
  11. #include <AzCore/Memory/SystemAllocator.h>
  12. #include <AzCore/std/containers/vector.h>
  13. #include "LyShinePassDataBus.h"
  14. namespace LyShine
  15. {
  16. class LyShineChildPass;
  17. //! Manages child passes at runtime that render to render targets
  18. class LyShinePass final
  19. : public AZ::RPI::ParentPass
  20. , protected LyShinePassRequestBus::Handler
  21. {
  22. AZ_RPI_PASS(LyShinePass);
  23. using Base = AZ::RPI::ParentPass;
  24. public:
  25. AZ_CLASS_ALLOCATOR(LyShinePass, AZ::SystemAllocator);
  26. AZ_RTTI(LyShinePass, "C3B812ED-3771-42F4-A96F-EBD94B4D54CA", Base);
  27. virtual ~LyShinePass();
  28. static AZ::RPI::Ptr<LyShinePass> Create(const AZ::RPI::PassDescriptor& descriptor);
  29. protected:
  30. // Pass behavior overrides
  31. void ResetInternal() override;
  32. void BuildInternal() override;
  33. void CreateChildPassesInternal() override;
  34. void SetRenderPipeline(AZ::RPI::RenderPipeline* pipeline) override;
  35. // LyShinePassRequestBus overrides
  36. void RebuildRttChildren() override;
  37. AZ::RPI::RasterPass* GetRttPass(const AZStd::string& name) override;
  38. AZ::RPI::RasterPass* GetUiCanvasPass() override;
  39. private:
  40. LyShinePass() = delete;
  41. explicit LyShinePass(const AZ::RPI::PassDescriptor& descriptor);
  42. // Build the render to texture child passes
  43. void AddRttChildPasses(LyShine::AttachmentImagesAndDependencies AttachmentImagesAndDependencies);
  44. // Add a render to texture child pass
  45. void AddRttChildPass(AZ::Data::Instance<AZ::RPI::AttachmentImage> attachmentImage, AttachmentImages dependentAttachmentImages);
  46. // Append the final pass to render UI Canvas elements to the screen
  47. void AddUiCanvasChildPass(LyShine::AttachmentImagesAndDependencies AttachmentImagesAndDependencies);
  48. // Pass that renders the UI Canvas elements to the screen
  49. AZ::RPI::Ptr<LyShineChildPass> m_uiCanvasChildPass;
  50. };
  51. // Child pass with potential attachment dependencies
  52. class LyShineChildPass
  53. : public AZ::RPI::RasterPass
  54. {
  55. AZ_RPI_PASS(LyShineChildPass);
  56. friend class LyShinePass;
  57. public:
  58. AZ_RTTI(LyShineChildPass, "{41D525F9-09EB-4004-97DC-082078FF8DD2}", RasterPass);
  59. AZ_CLASS_ALLOCATOR(LyShineChildPass, AZ::SystemAllocator);
  60. virtual ~LyShineChildPass();
  61. //! Creates a LyShineChildPass
  62. static AZ::RPI::Ptr<LyShineChildPass> Create(const AZ::RPI::PassDescriptor& descriptor);
  63. protected:
  64. LyShineChildPass(const AZ::RPI::PassDescriptor& descriptor);
  65. // Scope producer Overrides...
  66. void SetupFrameGraphDependencies(AZ::RHI::FrameGraphInterface frameGraph) override;
  67. AttachmentImages m_attachmentImageDependencies;
  68. };
  69. // Child pass that renders UI elements to a render target
  70. class RttChildPass
  71. : public LyShineChildPass
  72. {
  73. AZ_RPI_PASS(RttChildPass);
  74. friend class LyShinePass;
  75. public:
  76. AZ_RTTI(RttChildPass, "{54B0574D-2EB3-4054-9E1D-0E0D9C8CB09A}", LyShineChildPass);
  77. AZ_CLASS_ALLOCATOR(RttChildPass, AZ::SystemAllocator);
  78. virtual ~RttChildPass();
  79. //! Creates a RttChildPass
  80. static AZ::RPI::Ptr<RttChildPass> Create(const AZ::RPI::PassDescriptor& descriptor);
  81. protected:
  82. RttChildPass(const AZ::RPI::PassDescriptor& descriptor);
  83. // Pass behavior overrides
  84. void BuildInternal() override;
  85. AZ::Data::Instance<AZ::RPI::AttachmentImage> m_attachmentImage;
  86. };
  87. } // namespace LyShine