-
Notifications
You must be signed in to change notification settings - Fork 773
/
dxvk_hud_fps.cpp
47 lines (31 loc) · 980 Bytes
/
dxvk_hud_fps.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "dxvk_hud_fps.h"
#include <iomanip>
namespace dxvk::hud {
HudFps::HudFps()
: m_fpsString("FPS: "),
m_prevUpdate(Clock::now()) {
}
HudFps::~HudFps() {
}
void HudFps::update() {
m_frameCount += 1;
const TimePoint now = Clock::now();
const TimeDiff elapsed = std::chrono::duration_cast<TimeDiff>(now - m_prevUpdate);
if (elapsed.count() >= UpdateInterval) {
const int64_t fps = (10'000'000ll * m_frameCount) / elapsed.count();
m_fpsString = str::format("FPS: ", fps / 10, ".", fps % 10);
m_prevUpdate = now;
m_frameCount = 0;
}
}
HudPos HudFps::renderText(
const Rc<DxvkContext>& context,
HudTextRenderer& renderer,
HudPos position) {
renderer.drawText(context, 16.0f,
{ position.x, position.y },
{ 1.0f, 1.0f, 1.0f, 1.0f },
m_fpsString);
return HudPos { position.x, position.y + 20 };
}
}