From 65bf47e8fbfedf847df3ca449cac4673b756f940 Mon Sep 17 00:00:00 2001 From: rokuz Date: Tue, 15 Oct 2024 09:11:24 +0100 Subject: [PATCH] [Android] Output FPS only when it was recalculated --- samples/001_HelloTriangle.cpp | 7 ++++--- samples/001_HelloTriangle_Slang.cpp | 7 ++++--- samples/002_RenderToCubeMap.cpp | 5 +++-- samples/003_RenderToCubeMapSinglePass.cpp | 5 +++-- samples/004_YUV.cpp | 7 ++++--- samples/006_RayTracingHello.cpp | 5 +++-- samples/007_RayTracingAO.cpp | 5 +++-- samples/Tiny.cpp | 7 ++++--- samples/Tiny_Mesh.cpp | 5 +++-- samples/Tiny_MeshLarge.cpp | 5 +++-- 10 files changed, 34 insertions(+), 24 deletions(-) diff --git a/samples/001_HelloTriangle.cpp b/samples/001_HelloTriangle.cpp index df40da33c7..d0b13598c8 100644 --- a/samples/001_HelloTriangle.cpp +++ b/samples/001_HelloTriangle.cpp @@ -184,9 +184,10 @@ void android_main(android_app* app) { do { timespec newTime = {0, 0}; clock_gettime(CLOCK_MONOTONIC, &newTime); - fps_.tick(((double)newTime.tv_sec + 1.0e-9 * newTime.tv_nsec) - - ((double)prevTime.tv_sec + 1.0e-9 * prevTime.tv_nsec)); - LLOGL("FPS: %.1f\n", fps_.getFPS()); + if (fps_.tick(((double)newTime.tv_sec + 1.0e-9 * newTime.tv_nsec) - + ((double)prevTime.tv_sec + 1.0e-9 * prevTime.tv_nsec))) { + LLOGL("FPS: %.1f\n", fps_.getFPS()); + } prevTime = newTime; if (ctx_) { render(); diff --git a/samples/001_HelloTriangle_Slang.cpp b/samples/001_HelloTriangle_Slang.cpp index 35b669aa9b..3c008d257f 100644 --- a/samples/001_HelloTriangle_Slang.cpp +++ b/samples/001_HelloTriangle_Slang.cpp @@ -300,9 +300,10 @@ void android_main(android_app* app) { do { timespec newTime = {0, 0}; clock_gettime(CLOCK_MONOTONIC, &newTime); - fps_.tick(((double)newTime.tv_sec + 1.0e-9 * newTime.tv_nsec) - - ((double)prevTime.tv_sec + 1.0e-9 * prevTime.tv_nsec)); - LLOGL("FPS: %.1f\n", fps_.getFPS()); + if (fps_.tick(((double)newTime.tv_sec + 1.0e-9 * newTime.tv_nsec) - + ((double)prevTime.tv_sec + 1.0e-9 * prevTime.tv_nsec))) { + LLOGL("FPS: %.1f\n", fps_.getFPS()); + } prevTime = newTime; if (ctx_) { render(); diff --git a/samples/002_RenderToCubeMap.cpp b/samples/002_RenderToCubeMap.cpp index 390e868c3b..68837644ce 100644 --- a/samples/002_RenderToCubeMap.cpp +++ b/samples/002_RenderToCubeMap.cpp @@ -339,8 +339,9 @@ void android_main(android_app* app) { timespec newTime = {0, 0}; clock_gettime(CLOCK_MONOTONIC, &newTime); double newTimeSec = ((double)newTime.tv_sec + 1.0e-9 * newTime.tv_nsec); - fps_.tick(newTimeSec - ((double)prevTime.tv_sec + 1.0e-9 * prevTime.tv_nsec)); - LLOGL("FPS: %.1f\n", fps_.getFPS()); + if (fps_.tick(newTimeSec - ((double)prevTime.tv_sec + 1.0e-9 * prevTime.tv_nsec))) { + LLOGL("FPS: %.1f\n", fps_.getFPS()); + } prevTime = newTime; if (ctx_) { render((float)newTimeSec); diff --git a/samples/003_RenderToCubeMapSinglePass.cpp b/samples/003_RenderToCubeMapSinglePass.cpp index d0cd47a7a1..c68f4c48d8 100644 --- a/samples/003_RenderToCubeMapSinglePass.cpp +++ b/samples/003_RenderToCubeMapSinglePass.cpp @@ -353,8 +353,9 @@ void android_main(android_app* app) { timespec newTime = {0, 0}; clock_gettime(CLOCK_MONOTONIC, &newTime); double newTimeSec = ((double)newTime.tv_sec + 1.0e-9 * newTime.tv_nsec); - fps_.tick(newTimeSec - ((double)prevTime.tv_sec + 1.0e-9 * prevTime.tv_nsec)); - LLOGL("FPS: %.1f\n", fps_.getFPS()); + if (fps_.tick(newTimeSec - ((double)prevTime.tv_sec + 1.0e-9 * prevTime.tv_nsec))) { + LLOGL("FPS: %.1f\n", fps_.getFPS()); + } prevTime = newTime; if (ctx_) { render((float)newTimeSec); diff --git a/samples/004_YUV.cpp b/samples/004_YUV.cpp index 2b101c8d2b..566d557e6b 100644 --- a/samples/004_YUV.cpp +++ b/samples/004_YUV.cpp @@ -300,9 +300,10 @@ void android_main(android_app* app) { do { timespec newTime = {0, 0}; clock_gettime(CLOCK_MONOTONIC, &newTime); - fps_.tick(((double)newTime.tv_sec + 1.0e-9 * newTime.tv_nsec) - - ((double)prevTime.tv_sec + 1.0e-9 * prevTime.tv_nsec)); - LLOGL("FPS: %.1f\n", fps_.getFPS()); + if (fps_.tick(((double)newTime.tv_sec + 1.0e-9 * newTime.tv_nsec) - + ((double)prevTime.tv_sec + 1.0e-9 * prevTime.tv_nsec))) { + LLOGL("FPS: %.1f\n", fps_.getFPS()); + } prevTime = newTime; if (ctx_) { render(); diff --git a/samples/006_RayTracingHello.cpp b/samples/006_RayTracingHello.cpp index d293c95518..eb5301c702 100644 --- a/samples/006_RayTracingHello.cpp +++ b/samples/006_RayTracingHello.cpp @@ -402,8 +402,9 @@ void android_main(android_app* app) { do { double newTime = glfwGetTime(); double delta = newTime - prevTime; - fps_.tick(delta); - LLOGL("FPS: %.1f\n", fps_.getFPS()); + if (fps_.tick(delta)) { + LLOGL("FPS: %.1f\n", fps_.getFPS()); + } prevTime = newTime; if (ctx_) { render(); diff --git a/samples/007_RayTracingAO.cpp b/samples/007_RayTracingAO.cpp index 2af32e31ee..0d73e07135 100644 --- a/samples/007_RayTracingAO.cpp +++ b/samples/007_RayTracingAO.cpp @@ -1340,8 +1340,9 @@ void android_main(android_app* app) { do { double newTime = getCurrentTimestamp(); double delta = newTime - prevTime; - fps_.tick(delta); - LLOGL("FPS: %.1f\n", fps_.getFPS()); + if (fps_.tick(delta)) { + LLOGL("FPS: %.1f\n", fps_.getFPS()); + } prevTime = newTime; if (ctx_) { render(delta, frameIndex); diff --git a/samples/Tiny.cpp b/samples/Tiny.cpp index 17c5e1260e..1d19513819 100644 --- a/samples/Tiny.cpp +++ b/samples/Tiny.cpp @@ -228,9 +228,10 @@ void android_main(android_app* app) { do { timespec newTime = {0, 0}; clock_gettime(CLOCK_MONOTONIC, &newTime); - fps_.tick(((double)newTime.tv_sec + 1.0e-9 * newTime.tv_nsec) - - ((double)prevTime.tv_sec + 1.0e-9 * prevTime.tv_nsec)); - LLOGL("FPS: %.1f\n", fps_.getFPS()); + if (fps_.tick(((double)newTime.tv_sec + 1.0e-9 * newTime.tv_nsec) - + ((double)prevTime.tv_sec + 1.0e-9 * prevTime.tv_nsec))) { + LLOGL("FPS: %.1f\n", fps_.getFPS()); + } prevTime = newTime; if (ctx_) { vk.render(); diff --git a/samples/Tiny_Mesh.cpp b/samples/Tiny_Mesh.cpp index fccf6738f8..497d799399 100644 --- a/samples/Tiny_Mesh.cpp +++ b/samples/Tiny_Mesh.cpp @@ -554,8 +554,9 @@ void android_main(android_app* app) { timespec newTime = {0, 0}; clock_gettime(CLOCK_MONOTONIC, &newTime); double newTimeSec = ((double)newTime.tv_sec + 1.0e-9 * newTime.tv_nsec); - fps_.tick(newTimeSec - ((double)prevTime.tv_sec + 1.0e-9 * prevTime.tv_nsec)); - LLOGL("FPS: %.1f\n", fps_.getFPS()); + if (fps_.tick(newTimeSec - ((double)prevTime.tv_sec + 1.0e-9 * prevTime.tv_nsec))) { + LLOGL("FPS: %.1f\n", fps_.getFPS()); + } prevTime = newTime; if (ctx_) { render(frameIndex, (float)newTimeSec); diff --git a/samples/Tiny_MeshLarge.cpp b/samples/Tiny_MeshLarge.cpp index 006cb9ef99..c8813a6eab 100644 --- a/samples/Tiny_MeshLarge.cpp +++ b/samples/Tiny_MeshLarge.cpp @@ -2334,8 +2334,9 @@ void android_main(android_app* app) { do { double newTime = getCurrentTimestamp(); double delta = newTime - prevTime; - fps_.tick(delta); - LLOGL("FPS: %.1f\n", fps_.getFPS()); + if (fps_.tick(delta)) { + LLOGL("FPS: %.1f\n", fps_.getFPS()); + } prevTime = newTime; if (ctx_) { render(delta, frameIndex);