RayTracingDebugComponentController.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 <Atom/Feature/Debug/RayTracingDebugFeatureProcessorInterface.h>
  9. #include <Atom/RPI.Public/Scene.h>
  10. #include <Debug/RayTracingDebugComponentController.h>
  11. namespace AZ::Render
  12. {
  13. void RayTracingDebugComponentController::Reflect(ReflectContext* context)
  14. {
  15. RayTracingDebugComponentConfig::Reflect(context);
  16. if (auto* serializeContext{ azrtti_cast<SerializeContext*>(context) })
  17. {
  18. // clang-format off
  19. serializeContext->Class<RayTracingDebugComponentController>()
  20. ->Version(0)
  21. ->Field("Configuration", &RayTracingDebugComponentController::m_configuration)
  22. ;
  23. // clang-format on
  24. }
  25. if (auto* behaviorContext{ azrtti_cast<BehaviorContext*>(context) })
  26. {
  27. // clang-format off
  28. behaviorContext->EBus<RayTracingDebugRequestBus>("RayTracingDebugRequestBus")
  29. // Generate behavior context
  30. #define PARAM_EVENT_BUS RayTracingDebugRequestBus::Events
  31. #include <Atom/Feature/ParamMacros/StartParamBehaviorContext.inl>
  32. #include <Atom/Feature/Debug/RayTracingDebugParams.inl>
  33. #include <Atom/Feature/ParamMacros/EndParams.inl>
  34. #undef PARAM_EVENT_BUS
  35. ;
  36. // clang-format on
  37. }
  38. }
  39. RayTracingDebugComponentController::RayTracingDebugComponentController(const RayTracingDebugComponentConfig& config)
  40. : m_configuration{ config }
  41. {
  42. }
  43. void RayTracingDebugComponentController::Activate(EntityId entityId)
  44. {
  45. m_entityId = entityId;
  46. auto fp{ RPI::Scene::GetFeatureProcessorForEntity<RayTracingDebugFeatureProcessorInterface>(m_entityId) };
  47. if (fp)
  48. {
  49. m_rayTracingDebugSettingsInterface = fp->GetSettingsInterface();
  50. if (m_rayTracingDebugSettingsInterface)
  51. {
  52. OnConfigurationChanged();
  53. }
  54. fp->OnRayTracingDebugComponentAdded();
  55. }
  56. RayTracingDebugRequestBus::Handler::BusConnect(m_entityId);
  57. }
  58. void RayTracingDebugComponentController::Deactivate()
  59. {
  60. auto fp{ RPI::Scene::GetFeatureProcessorForEntity<RayTracingDebugFeatureProcessorInterface>(m_entityId) };
  61. if (fp)
  62. {
  63. fp->OnRayTracingDebugComponentRemoved();
  64. }
  65. RayTracingDebugRequestBus::Handler::BusDisconnect(m_entityId);
  66. m_rayTracingDebugSettingsInterface = nullptr;
  67. m_entityId.SetInvalid();
  68. }
  69. void RayTracingDebugComponentController::SetConfiguration(const RayTracingDebugComponentConfig& config)
  70. {
  71. m_configuration = config;
  72. OnConfigurationChanged();
  73. }
  74. const RayTracingDebugComponentConfig& RayTracingDebugComponentController::GetConfiguration() const
  75. {
  76. return m_configuration;
  77. }
  78. void RayTracingDebugComponentController::OnConfigurationChanged()
  79. {
  80. m_configuration.CopySettingsTo(m_rayTracingDebugSettingsInterface);
  81. }
  82. // clang-format off
  83. // Generate getter/setter function definitions.
  84. // The setter functions will set the values on the Atom settings class, then get the value back
  85. // from the settings class to set the local configuration. This is in case the settings class
  86. // applies some custom logic that results in the set value being different from the input
  87. #define AZ_GFX_COMMON_PARAM(ValueType, Name, MemberName, DefaultValue) \
  88. ValueType RayTracingDebugComponentController::Get##Name() const \
  89. { \
  90. return m_configuration.MemberName; \
  91. } \
  92. void RayTracingDebugComponentController::Set##Name(ValueType val) \
  93. { \
  94. if (m_rayTracingDebugSettingsInterface) \
  95. { \
  96. m_rayTracingDebugSettingsInterface->Set##Name(val); \
  97. m_configuration.CopySettingsFrom(m_rayTracingDebugSettingsInterface); \
  98. } \
  99. else \
  100. { \
  101. m_configuration.MemberName = val; \
  102. } \
  103. } \
  104. #define AZ_GFX_COMMON_OVERRIDE(ValueType, Name, MemberName, OverrideValueType) \
  105. OverrideValueType RayTracingDebugComponentController::Get##Name##Override() const \
  106. { \
  107. return m_configuration.MemberName##Override; \
  108. } \
  109. void RayTracingDebugComponentController::Set##Name##Override(OverrideValueType val) \
  110. { \
  111. m_configuration.MemberName##Override = val; \
  112. if (m_RayTracingDebugSettingsInterface) \
  113. { \
  114. m_rayTracingDebugSettingsInterface->Set##Name##Override(val); \
  115. m_configuration.CopySettingsFrom(m_rayTracingDebugSettingsInterface); \
  116. } \
  117. } \
  118. #include <Atom/Feature/ParamMacros/MapAllCommon.inl>
  119. #include <Atom/Feature/Debug/RayTracingDebugParams.inl>
  120. #include <Atom/Feature/ParamMacros/EndParams.inl>
  121. // clang-format on
  122. } // namespace AZ::Render