diff options
author | Stefan Hacker <dd0t@users.sourceforge.net> | 2010-04-28 22:22:28 +0400 |
---|---|---|
committer | Stefan Hacker <dd0t@users.sourceforge.net> | 2010-04-28 22:22:28 +0400 |
commit | d8f1ac1115ad341b9bc20cb79e3406dd5e099028 (patch) | |
tree | b556c8a3afd1dd876053e7e0f7e78a3803d7c1e7 /overlay/d3d10.cpp | |
parent | fbb54cb9632041b9e1e64472c719f8d29fc336ec (diff) |
Add an optional FPS counter to the overlay
Diffstat (limited to 'overlay/d3d10.cpp')
-rw-r--r-- | overlay/d3d10.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/overlay/d3d10.cpp b/overlay/d3d10.cpp index f665d59b2..0d0ee7ea3 100644 --- a/overlay/d3d10.cpp +++ b/overlay/d3d10.cpp @@ -32,6 +32,7 @@ #include "overlay.hex" #include <d3d10.h> #include <d3dx10.h> +#include <time.h> DXGIData *dxgi = NULL; @@ -90,6 +91,9 @@ class D10State: protected Pipe { ID3D10Texture2D *pTexture; ID3D10ShaderResourceView *pSRView; + clock_t timeT; + unsigned int frameCount; + D10State(IDXGISwapChain *, ID3D10Device *); ~D10State(); void init(); @@ -125,6 +129,9 @@ D10State::D10State(IDXGISwapChain *pSwapChain, ID3D10Device *pDevice) { pTexture = NULL; pSRView = NULL; + timeT = clock(); + frameCount = 0; + pDevice->AddRef(); initRefCount = pDevice->Release(); } @@ -377,6 +384,22 @@ D10State::~D10State() { } void D10State::draw() { + clock_t t = clock(); + float elapsed = static_cast<float>(t - timeT) / CLOCKS_PER_SEC; + ++frameCount; + if (elapsed > 1.0) { // Send FPS update every second + OverlayMsg om; + om.omh.uiMagic = OVERLAY_MAGIC_NUMBER; + om.omh.uiType = OVERLAY_MSGTYPE_FPS; + om.omh.iLength = sizeof(OverlayMsgFps); + om.omf.fps = static_cast<unsigned int>(frameCount * elapsed); + + sendMessage(om); + + frameCount = 0; + timeT = t; + } + HRESULT hr; dwMyThread = GetCurrentThreadId(); |