DebugHud.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. //
  2. // Copyright (c) 2008-2015 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 Atomic
  26. {
  27. class Engine;
  28. class XMLFile;
  29. namespace SystemUI
  30. {
  31. class Font;
  32. class Text;
  33. static const unsigned DEBUGHUD_SHOW_NONE = 0x0;
  34. static const unsigned DEBUGHUD_SHOW_STATS = 0x1;
  35. static const unsigned DEBUGHUD_SHOW_MODE = 0x2;
  36. static const unsigned DEBUGHUD_SHOW_PROFILER = 0x4;
  37. static const unsigned DEBUGHUD_SHOW_ALL = 0x7;
  38. /// Displays rendering stats and profiling information.
  39. class ATOMIC_API DebugHud : public Object
  40. {
  41. OBJECT(DebugHud);
  42. public:
  43. /// Construct.
  44. DebugHud(Context* context);
  45. /// Destruct.
  46. ~DebugHud();
  47. /// Update. Called by HandlePostUpdate().
  48. void Update();
  49. /// Set UI elements' style from an XML file.
  50. void SetDefaultStyle(XMLFile* style);
  51. /// Set elements to show.
  52. void SetMode(unsigned mode);
  53. /// Set maximum profiler block depth, default unlimited.
  54. void SetProfilerMaxDepth(unsigned depth);
  55. /// Set profiler accumulation interval in seconds.
  56. void SetProfilerInterval(float interval);
  57. /// Set whether to show 3D geometry primitive/batch count only. Default false.
  58. void SetUseRendererStats(bool enable);
  59. /// Toggle elements.
  60. void Toggle(unsigned mode);
  61. /// Toggle all elements.
  62. void ToggleAll();
  63. /// Return the UI style file.
  64. XMLFile* GetDefaultStyle() const;
  65. /// Return rendering stats text.
  66. Text* GetStatsText() const { return statsText_; }
  67. /// Return rendering mode text.
  68. Text* GetModeText() const { return modeText_; }
  69. /// Return profiler text.
  70. Text* GetProfilerText() const { return profilerText_; }
  71. /// Return currently shown elements.
  72. unsigned GetMode() const { return mode_; }
  73. /// Return maximum profiler block depth.
  74. unsigned GetProfilerMaxDepth() const { return profilerMaxDepth_; }
  75. /// Return profiler accumulation interval in seconds
  76. float GetProfilerInterval() const;
  77. /// Return whether showing 3D geometry primitive/batch count only.
  78. bool GetUseRendererStats() const { return useRendererStats_; }
  79. /// Set application-specific stats.
  80. void SetAppStats(const String& label, const Variant& stats);
  81. /// Set application-specific stats.
  82. void SetAppStats(const String& label, const String& stats);
  83. /// Reset application-specific stats. Return true if it was erased successfully.
  84. bool ResetAppStats(const String& label);
  85. /// Clear all application-specific stats.
  86. void ClearAppStats();
  87. private:
  88. /// Handle logic post-update event. The HUD texts are updated here.
  89. void HandlePostUpdate(StringHash eventType, VariantMap& eventData);
  90. /// Rendering stats text.
  91. SharedPtr<Text> statsText_;
  92. /// Rendering mode text.
  93. SharedPtr<Text> modeText_;
  94. /// Profiling information text.
  95. SharedPtr<Text> profilerText_;
  96. /// Hashmap containing application specific stats.
  97. HashMap<String, String> appStats_;
  98. /// Profiler timer.
  99. Timer profilerTimer_;
  100. /// Profiler max block depth.
  101. unsigned profilerMaxDepth_;
  102. /// Profiler accumulation interval.
  103. unsigned profilerInterval_;
  104. /// Show 3D geometry primitive/batch count flag.
  105. bool useRendererStats_;
  106. /// Current shown-element mode.
  107. unsigned mode_;
  108. };
  109. }
  110. }