BloomComponentController.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 <AzCore/RTTI/BehaviorContext.h>
  9. #include <Atom/RPI.Public/Scene.h>
  10. #include <PostProcess/Bloom/BloomComponentController.h>
  11. namespace AZ
  12. {
  13. namespace Render
  14. {
  15. void BloomComponentController::Reflect(ReflectContext* context)
  16. {
  17. BloomComponentConfig::Reflect(context);
  18. if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
  19. {
  20. serializeContext->Class<BloomComponentController>()
  21. ->Version(0)
  22. ->Field("Configuration", &BloomComponentController::m_configuration);
  23. }
  24. if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  25. {
  26. behaviorContext->EBus<BloomRequestBus>("BloomRequestBus")
  27. ->Attribute(AZ::Script::Attributes::Module, "render")
  28. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
  29. // Auto-gen behavior context...
  30. #define PARAM_EVENT_BUS BloomRequestBus::Events
  31. #include <Atom/Feature/ParamMacros/StartParamBehaviorContext.inl>
  32. #include <Atom/Feature/PostProcess/Bloom/BloomParams.inl>
  33. #include <Atom/Feature/ParamMacros/EndParams.inl>
  34. #undef PARAM_EVENT_BUS
  35. ;
  36. }
  37. }
  38. void BloomComponentController::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  39. {
  40. provided.push_back(AZ_CRC_CE("BloomService"));
  41. }
  42. void BloomComponentController::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  43. {
  44. incompatible.push_back(AZ_CRC_CE("BloomService"));
  45. }
  46. void BloomComponentController::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  47. {
  48. required.push_back(AZ_CRC_CE("PostFXLayerService"));
  49. }
  50. BloomComponentController::BloomComponentController(const BloomComponentConfig& config)
  51. : m_configuration(config)
  52. {
  53. }
  54. void BloomComponentController::Activate(EntityId entityId)
  55. {
  56. m_entityId = entityId;
  57. PostProcessFeatureProcessorInterface* fp = RPI::Scene::GetFeatureProcessorForEntity<PostProcessFeatureProcessorInterface>(m_entityId);
  58. if (fp)
  59. {
  60. m_postProcessInterface = fp->GetOrCreateSettingsInterface(m_entityId);
  61. if (m_postProcessInterface)
  62. {
  63. m_settingsInterface = m_postProcessInterface->GetOrCreateBloomSettingsInterface();
  64. OnConfigChanged();
  65. }
  66. }
  67. BloomRequestBus::Handler::BusConnect(m_entityId);
  68. }
  69. void BloomComponentController::Deactivate()
  70. {
  71. BloomRequestBus::Handler::BusDisconnect(m_entityId);
  72. if (m_postProcessInterface)
  73. {
  74. m_postProcessInterface->RemoveBloomSettingsInterface();
  75. }
  76. m_postProcessInterface = nullptr;
  77. m_settingsInterface = nullptr;
  78. m_entityId.SetInvalid();
  79. }
  80. // Getters & Setters...
  81. void BloomComponentController::SetConfiguration(const BloomComponentConfig& config)
  82. {
  83. m_configuration = config;
  84. OnConfigChanged();
  85. }
  86. const BloomComponentConfig& BloomComponentController::GetConfiguration() const
  87. {
  88. return m_configuration;
  89. }
  90. void BloomComponentController::OnConfigChanged()
  91. {
  92. if (m_settingsInterface)
  93. {
  94. m_configuration.CopySettingsTo(m_settingsInterface);
  95. m_settingsInterface->OnConfigChanged();
  96. }
  97. }
  98. // Auto-gen getter/setter function definitions...
  99. // The setter functions will set the values on the Atom settings class, then get the value back
  100. // from the settings class to set the local configuration. This is in case the settings class
  101. // applies some custom logic that results in the set value being different from the input
  102. #define AZ_GFX_COMMON_PARAM(ValueType, Name, MemberName, DefaultValue) \
  103. ValueType BloomComponentController::Get##Name() const \
  104. { \
  105. return m_configuration.MemberName; \
  106. } \
  107. void BloomComponentController::Set##Name(ValueType val) \
  108. { \
  109. if(m_settingsInterface) \
  110. { \
  111. m_settingsInterface->Set##Name(val); \
  112. m_settingsInterface->OnConfigChanged(); \
  113. m_configuration.MemberName = m_settingsInterface->Get##Name(); \
  114. } \
  115. else \
  116. { \
  117. m_configuration.MemberName = val; \
  118. } \
  119. } \
  120. #define AZ_GFX_COMMON_OVERRIDE(ValueType, Name, MemberName, OverrideValueType) \
  121. OverrideValueType BloomComponentController::Get##Name##Override() const \
  122. { \
  123. return m_configuration.MemberName##Override; \
  124. } \
  125. void BloomComponentController::Set##Name##Override(OverrideValueType val) \
  126. { \
  127. m_configuration.MemberName##Override = val; \
  128. if(m_settingsInterface) \
  129. { \
  130. m_settingsInterface->Set##Name##Override(val); \
  131. m_settingsInterface->OnConfigChanged(); \
  132. } \
  133. } \
  134. #include <Atom/Feature/ParamMacros/MapAllCommon.inl>
  135. #include <Atom/Feature/PostProcess/Bloom/BloomParams.inl>
  136. #include <Atom/Feature/ParamMacros/EndParams.inl>
  137. } // namespace Render
  138. } // namespace AZ