DebugHud.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //
  2. // Copyright (c) 2008-2020 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "../Core/Object.h"
  24. #include "../Core/Timer.h"
  25. namespace Urho3D
  26. {
  27. class Engine;
  28. class Font;
  29. class Text;
  30. class XMLFile;
  31. static const unsigned DEBUGHUD_SHOW_NONE = 0x0;
  32. static const unsigned DEBUGHUD_SHOW_STATS = 0x1;
  33. static const unsigned DEBUGHUD_SHOW_MODE = 0x2;
  34. static const unsigned DEBUGHUD_SHOW_PROFILER = 0x4;
  35. static const unsigned DEBUGHUD_SHOW_MEMORY = 0x8;
  36. static const unsigned DEBUGHUD_SHOW_EVENTPROFILER = 0x10;
  37. static const unsigned DEBUGHUD_SHOW_ALL = DEBUGHUD_SHOW_STATS | DEBUGHUD_SHOW_MODE | DEBUGHUD_SHOW_PROFILER | DEBUGHUD_SHOW_MEMORY;
  38. /// Displays rendering stats and profiling information.
  39. class URHO3D_API DebugHud : public Object
  40. {
  41. URHO3D_OBJECT(DebugHud, Object);
  42. public:
  43. /// Construct.
  44. explicit DebugHud(Context* context);
  45. /// Destruct.
  46. ~DebugHud() override;
  47. /// Update. Called by HandlePostUpdate().
  48. void Update();
  49. /// Set UI elements' style from an XML file.
  50. /// @property
  51. void SetDefaultStyle(XMLFile* style);
  52. /// Set elements to show.
  53. /// @property
  54. void SetMode(unsigned mode);
  55. /// Set maximum profiler block depth, default unlimited.
  56. /// @property
  57. void SetProfilerMaxDepth(unsigned depth);
  58. /// Set profiler accumulation interval in seconds.
  59. /// @property
  60. void SetProfilerInterval(float interval);
  61. /// Set whether to show 3D geometry primitive/batch count only. Default false.
  62. /// @property
  63. void SetUseRendererStats(bool enable);
  64. /// Toggle elements.
  65. void Toggle(unsigned mode);
  66. /// Toggle all elements.
  67. void ToggleAll();
  68. /// Return the UI style file.
  69. /// @property
  70. XMLFile* GetDefaultStyle() const;
  71. /// Return rendering stats text.
  72. /// @property
  73. Text* GetStatsText() const { return statsText_; }
  74. /// Return rendering mode text.
  75. /// @property
  76. Text* GetModeText() const { return modeText_; }
  77. /// Return profiler text.
  78. /// @property
  79. Text* GetProfilerText() const { return profilerText_; }
  80. /// Return memory text.
  81. /// @property
  82. Text* GetMemoryText() const { return memoryText_; }
  83. /// Return currently shown elements.
  84. /// @property
  85. unsigned GetMode() const { return mode_; }
  86. /// Return maximum profiler block depth.
  87. /// @property
  88. unsigned GetProfilerMaxDepth() const { return profilerMaxDepth_; }
  89. /// Return profiler accumulation interval in seconds.
  90. /// @property
  91. float GetProfilerInterval() const;
  92. /// Return whether showing 3D geometry primitive/batch count only.
  93. /// @property
  94. bool GetUseRendererStats() const { return useRendererStats_; }
  95. /// Set application-specific stats.
  96. void SetAppStats(const String& label, const Variant& stats);
  97. /// Set application-specific stats.
  98. void SetAppStats(const String& label, const String& stats);
  99. /// Reset application-specific stats. Return true if it was erased successfully.
  100. bool ResetAppStats(const String& label);
  101. /// Clear all application-specific stats.
  102. void ClearAppStats();
  103. private:
  104. /// Handle logic post-update event. The HUD texts are updated here.
  105. void HandlePostUpdate(StringHash eventType, VariantMap& eventData);
  106. /// Rendering stats text.
  107. SharedPtr<Text> statsText_;
  108. /// Rendering mode text.
  109. SharedPtr<Text> modeText_;
  110. /// Profiling information text.
  111. SharedPtr<Text> profilerText_;
  112. /// Event profiling information text.
  113. SharedPtr<Text> eventProfilerText_;
  114. /// Memory stats text.
  115. SharedPtr<Text> memoryText_;
  116. /// Hashmap containing application specific stats.
  117. HashMap<String, String> appStats_;
  118. /// Profiler timer.
  119. Timer profilerTimer_;
  120. /// Profiler max block depth.
  121. unsigned profilerMaxDepth_;
  122. /// Profiler accumulation interval.
  123. unsigned profilerInterval_;
  124. /// Show 3D geometry primitive/batch count flag.
  125. bool useRendererStats_;
  126. /// Current shown-element mode.
  127. unsigned mode_;
  128. };
  129. }