3
0

AtomViewportDisplayInfoSystemComponent.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #pragma once
  9. #include <AzCore/Component/Component.h>
  10. #include <CryCommon/CrySystemBus.h>
  11. #include <AzCore/Script/ScriptTimePoint.h>
  12. #include <AzFramework/Entity/EntityDebugDisplayBus.h>
  13. #include <AzFramework/Font/FontInterface.h>
  14. #include <Atom/RPI.Public/Base.h>
  15. #include <Atom/RPI.Public/ViewportContextBus.h>
  16. #include <AtomLyIntegration/AtomViewportDisplayInfo/AtomViewportInfoDisplayBus.h>
  17. namespace AZ
  18. {
  19. class TickRequests;
  20. namespace Render
  21. {
  22. class AtomViewportDisplayInfoSystemComponent
  23. : public AZ::Component
  24. , public AZ::RPI::ViewportContextNotificationBus::Handler
  25. , public AZ::AtomBridge::AtomViewportInfoDisplayRequestBus::Handler
  26. {
  27. public:
  28. AZ_COMPONENT(AtomViewportDisplayInfoSystemComponent, "{AC32F173-E7E2-4943-8E6C-7C3091978221}");
  29. static void Reflect(AZ::ReflectContext* context);
  30. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  31. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
  32. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  33. static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
  34. protected:
  35. // AZ::Component overrides...
  36. void Activate() override;
  37. void Deactivate() override;
  38. // AZ::RPI::ViewportContextNotificationBus::Handler overrides...
  39. void OnRenderTick() override;
  40. // AZ::AtomBridge::AtomViewportInfoDisplayRequestBus::Handler overrides...
  41. AtomBridge::ViewportInfoDisplayState GetDisplayState() const override;
  42. void SetDisplayState(AtomBridge::ViewportInfoDisplayState state) override;
  43. private:
  44. AZ::RPI::ViewportContextPtr GetViewportContext() const;
  45. void DrawLine(AZStd::string_view line, AZ::Color color = AZ::Colors::White);
  46. void UpdateFramerate();
  47. void DrawRendererInfo();
  48. void DrawCameraInfo();
  49. void DrawPassInfo();
  50. void DrawMemoryInfo();
  51. void DrawFramerate();
  52. static constexpr float BaseFontSize = 0.7f;
  53. AZStd::string m_rendererDescription;
  54. AzFramework::TextDrawParameters m_drawParams;
  55. AzFramework::FontDrawInterface* m_fontDrawInterface = nullptr;
  56. float m_lineSpacing;
  57. AZStd::chrono::duration<double> m_fpsInterval = AZStd::chrono::seconds(1);
  58. AZStd::deque<AZStd::chrono::steady_clock::time_point> m_fpsHistory;
  59. AZStd::optional<AZStd::chrono::steady_clock::time_point> m_lastMemoryUpdate;
  60. bool m_updateRootPassQuery = true;
  61. };
  62. } // namespace Render
  63. } // namespace AZ