FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
GpuTimer.h
1#pragma once
2#ifdef FH_VISUALIZATION
3
4# include <OgreRenderTargetListener.h>
5# include <array>
6# include <cstdint>
7# include <string>
8
9namespace Ogre
10{
11class RenderTarget;
12}
13
14namespace visual
15{
16
26class GpuTimer : public Ogre::RenderTargetListener
27{
28public:
33 explicit GpuTimer(Ogre::RenderTarget* target);
34 ~GpuTimer() override;
35
36 GpuTimer(const GpuTimer&) = delete;
37 GpuTimer& operator=(const GpuTimer&) = delete;
38
40 bool IsActive() const { return m_active; }
41
43 double MeanMilliseconds() const { return m_frames > 0 ? m_sumMs / double(m_frames) : -1.0; }
44
46 double MaxMilliseconds() const { return m_maxMs; }
47
49 int Frames() const { return m_frames; }
50
52 void Reset();
53
55 std::string Summary() const;
56
57 void preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt) override;
58 void postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt) override;
59
60private:
61 void Collect();
62
63 static constexpr int kRing = 4;
64 Ogre::RenderTarget* m_target = nullptr;
65 bool m_active = false;
66 std::array<unsigned, kRing> m_queries {};
67 std::array<bool, kRing> m_pending {};
68 int m_next = 0;
69 bool m_inQuery = false;
70 double m_sumMs = 0.0;
71 double m_maxMs = 0.0;
72 int m_frames = 0;
73};
74
75} // namespace visual
76#endif
Visualization utilities.
Definition VisualDomain.h:12