RenderDebugComponentController.cpp 7.2 KB

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