aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2025-01-21 16:08:13 -0500
committerDavid Robillard <d@drobilla.net>2025-01-21 16:24:17 -0500
commitbf01b1e98f1759982e0ee012a3379507f3e72af7 (patch)
treefab71fa4abdb5efa3c9cae6dbf78d0e3bf5aabe6
parent90e05c940a4f99548d982b6976ba9aff8e6bdd8f (diff)
downloadpugl-bf01b1e98f1759982e0ee012a3379507f3e72af7.tar.gz
pugl-bf01b1e98f1759982e0ee012a3379507f3e72af7.tar.bz2
pugl-bf01b1e98f1759982e0ee012a3379507f3e72af7.zip
Fix pugl_shader_demo refresh rate on Windows
-rw-r--r--examples/demo_utils.h9
-rw-r--r--examples/pugl_shader_demo.c4
2 files changed, 7 insertions, 6 deletions
diff --git a/examples/demo_utils.h b/examples/demo_utils.h
index b43cc2b..da3b2cd 100644
--- a/examples/demo_utils.h
+++ b/examples/demo_utils.h
@@ -95,13 +95,14 @@ puglPrintFps(const PuglWorld* world,
unsigned* const framesDrawn)
{
const double thisTime = puglGetTime(world);
- if (thisTime > printer->lastReportTime + 5) {
- const double fps = *framesDrawn / (thisTime - printer->lastReportTime);
+ if (thisTime > printer->lastReportTime + 5.0) {
+ const double elapsed = (thisTime - printer->lastReportTime);
+ const double fps = *framesDrawn / elapsed;
fprintf(stderr,
- "FPS: %.2f (%u frames in %.0f seconds)\n",
+ "FPS: %.2f (%u frames / %.2f seconds)\n",
fps,
*framesDrawn,
- thisTime - printer->lastReportTime);
+ elapsed);
printer->lastReportTime = thisTime;
*framesDrawn = 0;
diff --git a/examples/pugl_shader_demo.c b/examples/pugl_shader_demo.c
index 9ba3da0..2cdcb6e 100644
--- a/examples/pugl_shader_demo.c
+++ b/examples/pugl_shader_demo.c
@@ -470,7 +470,7 @@ updateTimeout(const PuglTestApp* const app)
const double nextExposeTime = nextFrameEndTime - neededTime;
const double timeUntilNext = nextExposeTime - now;
- return timeUntilNext;
+ return fmax(0.0, (timeUntilNext * 0.9) - 0.001);
}
int
@@ -505,7 +505,7 @@ main(int argc, char** argv)
const double startTime = puglGetTime(app.world);
PuglFpsPrinter fpsPrinter = {startTime};
while (!app.quit) {
- puglUpdate(app.world, fmax(0.0, updateTimeout(&app)));
+ puglUpdate(app.world, updateTimeout(&app));
puglPrintFps(app.world, &fpsPrinter, &app.framesDrawn);
}