Merge pull request #549 from djdeath/master
Make FPS counter more accurate
This commit is contained in:
commit
783199b1c8
2 changed files with 12 additions and 12 deletions
|
|
@ -250,7 +250,7 @@ void VulkanExampleBase::renderFrame()
|
||||||
timer -= 1.0f;
|
timer -= 1.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fpsTimer += (float)tDiff;
|
float fpsTimer = std::chrono::duration<double, std::milli>(tEnd - lastTimestamp).count();
|
||||||
if (fpsTimer > 1000.0f)
|
if (fpsTimer > 1000.0f)
|
||||||
{
|
{
|
||||||
lastFPS = static_cast<uint32_t>((float)frameCounter * (1000.0f / fpsTimer));
|
lastFPS = static_cast<uint32_t>((float)frameCounter * (1000.0f / fpsTimer));
|
||||||
|
|
@ -260,8 +260,8 @@ void VulkanExampleBase::renderFrame()
|
||||||
SetWindowText(window, windowTitle.c_str());
|
SetWindowText(window, windowTitle.c_str());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
fpsTimer = 0.0f;
|
|
||||||
frameCounter = 0;
|
frameCounter = 0;
|
||||||
|
lastTimestamp = tEnd;
|
||||||
}
|
}
|
||||||
// TODO: Cap UI overlay update rates
|
// TODO: Cap UI overlay update rates
|
||||||
updateOverlay();
|
updateOverlay();
|
||||||
|
|
@ -280,6 +280,7 @@ void VulkanExampleBase::renderLoop()
|
||||||
|
|
||||||
destWidth = width;
|
destWidth = width;
|
||||||
destHeight = height;
|
destHeight = height;
|
||||||
|
lastTimestamp = std::chrono::high_resolution_clock::now();
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
MSG msg;
|
MSG msg;
|
||||||
bool quitMessageReceived = false;
|
bool quitMessageReceived = false;
|
||||||
|
|
@ -347,12 +348,12 @@ void VulkanExampleBase::renderLoop()
|
||||||
timer -= 1.0f;
|
timer -= 1.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fpsTimer += (float)tDiff;
|
float fpsTimer = std::chrono::duration<double, std::milli>(tEnd - lastTimestamp).count();
|
||||||
if (fpsTimer > 1000.0f)
|
if (fpsTimer > 1000.0f)
|
||||||
{
|
{
|
||||||
lastFPS = (float)frameCounter * (1000.0f / fpsTimer);
|
lastFPS = (float)frameCounter * (1000.0f / fpsTimer);
|
||||||
fpsTimer = 0.0f;
|
|
||||||
frameCounter = 0;
|
frameCounter = 0;
|
||||||
|
lastTimestamp = tEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Cap UI overlay update rates/only issue when update requested
|
// TODO: Cap UI overlay update rates/only issue when update requested
|
||||||
|
|
@ -437,12 +438,12 @@ void VulkanExampleBase::renderLoop()
|
||||||
timer -= 1.0f;
|
timer -= 1.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fpsTimer += (float)tDiff;
|
float fpsTimer = std::chrono::duration<double, std::milli>(tEnd - lastTimestamp).count();
|
||||||
if (fpsTimer > 1000.0f)
|
if (fpsTimer > 1000.0f)
|
||||||
{
|
{
|
||||||
lastFPS = (float)frameCounter * (1000.0f / fpsTimer);
|
lastFPS = (float)frameCounter * (1000.0f / fpsTimer);
|
||||||
fpsTimer = 0.0f;
|
|
||||||
frameCounter = 0;
|
frameCounter = 0;
|
||||||
|
lastTimestamp = tEnd;
|
||||||
}
|
}
|
||||||
updateOverlay();
|
updateOverlay();
|
||||||
}
|
}
|
||||||
|
|
@ -483,7 +484,7 @@ void VulkanExampleBase::renderLoop()
|
||||||
timer -= 1.0f;
|
timer -= 1.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fpsTimer += (float)tDiff;
|
float fpsTimer = std::chrono::duration<double, std::milli>(tEnd - lastTimestamp).count();
|
||||||
if (fpsTimer > 1000.0f)
|
if (fpsTimer > 1000.0f)
|
||||||
{
|
{
|
||||||
if (!settings.overlay)
|
if (!settings.overlay)
|
||||||
|
|
@ -492,8 +493,8 @@ void VulkanExampleBase::renderLoop()
|
||||||
xdg_toplevel_set_title(xdg_toplevel, windowTitle.c_str());
|
xdg_toplevel_set_title(xdg_toplevel, windowTitle.c_str());
|
||||||
}
|
}
|
||||||
lastFPS = (float)frameCounter * (1000.0f / fpsTimer);
|
lastFPS = (float)frameCounter * (1000.0f / fpsTimer);
|
||||||
fpsTimer = 0.0f;
|
|
||||||
frameCounter = 0;
|
frameCounter = 0;
|
||||||
|
lastTimestamp = tEnd;
|
||||||
}
|
}
|
||||||
updateOverlay();
|
updateOverlay();
|
||||||
}
|
}
|
||||||
|
|
@ -532,7 +533,7 @@ void VulkanExampleBase::renderLoop()
|
||||||
timer -= 1.0f;
|
timer -= 1.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fpsTimer += (float)tDiff;
|
float fpsTimer = std::chrono::duration<double, std::milli>(tEnd - lastTimestamp).count();
|
||||||
if (fpsTimer > 1000.0f)
|
if (fpsTimer > 1000.0f)
|
||||||
{
|
{
|
||||||
if (!settings.overlay)
|
if (!settings.overlay)
|
||||||
|
|
@ -543,8 +544,8 @@ void VulkanExampleBase::renderLoop()
|
||||||
windowTitle.size(), windowTitle.c_str());
|
windowTitle.size(), windowTitle.c_str());
|
||||||
}
|
}
|
||||||
lastFPS = (float)frameCounter * (1000.0f / fpsTimer);
|
lastFPS = (float)frameCounter * (1000.0f / fpsTimer);
|
||||||
fpsTimer = 0.0f;
|
|
||||||
frameCounter = 0;
|
frameCounter = 0;
|
||||||
|
lastTimestamp = tEnd;
|
||||||
}
|
}
|
||||||
updateOverlay();
|
updateOverlay();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,8 +57,6 @@
|
||||||
class VulkanExampleBase
|
class VulkanExampleBase
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// fps timer (one second interval)
|
|
||||||
float fpsTimer = 0.0f;
|
|
||||||
// Get window title with example name, device, et.
|
// Get window title with example name, device, et.
|
||||||
std::string getWindowTitle();
|
std::string getWindowTitle();
|
||||||
/** brief Indicates that the view (position, rotation) has changed and buffers containing camera matrices need to be updated */
|
/** brief Indicates that the view (position, rotation) has changed and buffers containing camera matrices need to be updated */
|
||||||
|
|
@ -74,6 +72,7 @@ protected:
|
||||||
// Frame counter to display fps
|
// Frame counter to display fps
|
||||||
uint32_t frameCounter = 0;
|
uint32_t frameCounter = 0;
|
||||||
uint32_t lastFPS = 0;
|
uint32_t lastFPS = 0;
|
||||||
|
std::chrono::time_point<std::chrono::high_resolution_clock> lastTimestamp;
|
||||||
// Vulkan instance, stores all per-application states
|
// Vulkan instance, stores all per-application states
|
||||||
VkInstance instance;
|
VkInstance instance;
|
||||||
// Physical device (GPU) that Vulkan will ise
|
// Physical device (GPU) that Vulkan will ise
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue