DebugHud.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "../Core/Object.h"
  5. #include "../Core/Timer.h"
  6. namespace Urho3D
  7. {
  8. class Engine;
  9. class Font;
  10. class Text;
  11. class XMLFile;
  12. enum class DebugHudElements
  13. {
  14. None = 0,
  15. Stats = 1 << 0,
  16. Mode = 1 << 1,
  17. Profiler = 1 << 2,
  18. Memory = 1 << 3,
  19. EventProfiler = 1 << 4,
  20. All = Stats | Mode | Profiler | Memory
  21. };
  22. URHO3D_FLAGS(DebugHudElements);
  23. /// Displays rendering stats and profiling information.
  24. class URHO3D_API DebugHud : public Object
  25. {
  26. URHO3D_OBJECT(DebugHud, Object);
  27. public:
  28. /// Construct.
  29. explicit DebugHud(Context* context);
  30. /// Destruct.
  31. ~DebugHud() override;
  32. /// Update. Called by HandlePostUpdate().
  33. void Update();
  34. /// Set UI elements' style from an XML file.
  35. /// @property
  36. void SetDefaultStyle(XMLFile* style);
  37. /// Set elements to show.
  38. /// @property
  39. void SetMode(DebugHudElements mode);
  40. /// Set maximum profiler block depth, default unlimited.
  41. /// @property
  42. void SetProfilerMaxDepth(unsigned depth);
  43. /// Set profiler accumulation interval in seconds.
  44. /// @property
  45. void SetProfilerInterval(float interval);
  46. /// Set whether to show 3D geometry primitive/batch count only. Default false.
  47. /// @property
  48. void SetUseRendererStats(bool enable);
  49. /// Toggle elements.
  50. void Toggle(DebugHudElements mode);
  51. /// Toggle all elements.
  52. void ToggleAll();
  53. /// Return the UI style file.
  54. /// @property
  55. XMLFile* GetDefaultStyle() const;
  56. /// Return rendering stats text.
  57. /// @property
  58. Text* GetStatsText() const { return statsText_; }
  59. /// Return rendering mode text.
  60. /// @property
  61. Text* GetModeText() const { return modeText_; }
  62. /// Return profiler text.
  63. /// @property
  64. Text* GetProfilerText() const { return profilerText_; }
  65. /// Return memory text.
  66. /// @property
  67. Text* GetMemoryText() const { return memoryText_; }
  68. /// Return currently shown elements.
  69. /// @property
  70. DebugHudElements GetMode() const { return mode_; }
  71. /// Return maximum profiler block depth.
  72. /// @property
  73. unsigned GetProfilerMaxDepth() const { return profilerMaxDepth_; }
  74. /// Return profiler accumulation interval in seconds.
  75. /// @property
  76. float GetProfilerInterval() const;
  77. /// Return whether showing 3D geometry primitive/batch count only.
  78. /// @property
  79. bool GetUseRendererStats() const { return useRendererStats_; }
  80. /// Set application-specific stats.
  81. void SetAppStats(const String& label, const Variant& stats);
  82. /// Set application-specific stats.
  83. void SetAppStats(const String& label, const String& stats);
  84. /// Reset application-specific stats. Return true if it was erased successfully.
  85. bool ResetAppStats(const String& label);
  86. /// Clear all application-specific stats.
  87. void ClearAppStats();
  88. private:
  89. /// Handle logic post-update event. The HUD texts are updated here.
  90. void HandlePostUpdate(StringHash eventType, VariantMap& eventData);
  91. /// Rendering stats text.
  92. SharedPtr<Text> statsText_;
  93. /// Rendering mode text.
  94. SharedPtr<Text> modeText_;
  95. /// Profiling information text.
  96. SharedPtr<Text> profilerText_;
  97. /// Event profiling information text.
  98. SharedPtr<Text> eventProfilerText_;
  99. /// Memory stats text.
  100. SharedPtr<Text> memoryText_;
  101. /// Hashmap containing application specific stats.
  102. HashMap<String, String> appStats_;
  103. /// Profiler timer.
  104. Timer profilerTimer_;
  105. /// Profiler max block depth.
  106. unsigned profilerMaxDepth_;
  107. /// Profiler accumulation interval.
  108. unsigned profilerInterval_;
  109. /// Show 3D geometry primitive/batch count flag.
  110. bool useRendererStats_;
  111. /// Current shown-element mode.
  112. DebugHudElements mode_;
  113. };
  114. }