ExposureControlComponentController.cpp 8.2 KB

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