SkyAtmosphereParentPass.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <SkyAtmosphere/SkyAtmosphereParentPass.h>
  9. namespace AZ::Render
  10. {
  11. SkyAtmosphereParentPass::SkyAtmosphereParentPass(const RPI::PassDescriptor& descriptor)
  12. : Base(descriptor)
  13. {
  14. }
  15. RPI::Ptr<SkyAtmosphereParentPass> SkyAtmosphereParentPass::Create(const RPI::PassDescriptor& descriptor)
  16. {
  17. return aznew SkyAtmosphereParentPass(descriptor);
  18. }
  19. void SkyAtmosphereParentPass::CreateAtmospherePass(SkyAtmosphereFeatureProcessorInterface::AtmosphereId id)
  20. {
  21. // make sure a pass doesn't already exist for this id
  22. if (m_atmosphereIds.contains(id))
  23. {
  24. return;
  25. }
  26. m_atmosphereIds.insert(id);
  27. m_flags.m_createChildren = true;
  28. QueueForBuildAndInitialization();
  29. }
  30. void SkyAtmosphereParentPass::ReleaseAtmospherePass(SkyAtmosphereFeatureProcessorInterface::AtmosphereId id)
  31. {
  32. if (m_atmosphereIds.contains(id))
  33. {
  34. m_atmosphereIds.erase(id);
  35. if (auto pass = GetPass(id))
  36. {
  37. pass->QueueForRemoval();
  38. }
  39. }
  40. }
  41. void SkyAtmosphereParentPass::UpdateAtmospherePassSRG(SkyAtmosphereFeatureProcessorInterface::AtmosphereId id, const SkyAtmosphereParams& params)
  42. {
  43. // child passes should already be built because UpdateAtmospherePassSRG is called from Render()
  44. // which is run after CreateChildPassesInternal()
  45. if (auto pass = GetPass(id))
  46. {
  47. pass->UpdateRenderPassSRG(params);
  48. }
  49. }
  50. RPI::Ptr<SkyAtmospherePass> SkyAtmosphereParentPass::GetPass(SkyAtmosphereFeatureProcessorInterface::AtmosphereId id) const
  51. {
  52. for (const RPI::Ptr<Pass>& child : m_children)
  53. {
  54. SkyAtmospherePass* pass = azrtti_cast<SkyAtmospherePass*>(child.get());
  55. if (pass && pass->GetAtmosphereId() == id)
  56. {
  57. return pass;
  58. }
  59. }
  60. return nullptr;
  61. }
  62. void SkyAtmosphereParentPass::CreateChildPassesInternal()
  63. {
  64. for(const auto& id : m_atmosphereIds)
  65. {
  66. auto pass = GetPass(id);
  67. if (pass)
  68. {
  69. AZ_Error("SkyAtmosphereParentPass", false, "Trying to create a SkyAtmospherePass that already exists");
  70. continue;
  71. }
  72. pass = SkyAtmospherePass::CreateWithPassRequest(id);
  73. if (pass)
  74. {
  75. AddChild(pass);
  76. }
  77. }
  78. }
  79. } // namespace AZ::Render