From 6f4d58292f6ee8d2dfc4e6ab71d1f76b01291532 Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Fri, 13 Feb 2026 10:02:07 +0900 Subject: [PATCH 1/3] use the alias for nfd only if it exists --- SofaImGui/CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/SofaImGui/CMakeLists.txt b/SofaImGui/CMakeLists.txt index fb86e73562..d7e5c1368c 100644 --- a/SofaImGui/CMakeLists.txt +++ b/SofaImGui/CMakeLists.txt @@ -150,8 +150,12 @@ set(IMGUI_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/resources ${imgui_SOURCE_DIR} $ add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES} ${IMGUI_SOURCE_FILES}) target_include_directories(${PROJECT_NAME} PUBLIC "$") target_link_libraries(${PROJECT_NAME} PUBLIC SofaGLFW Sofa.GL.Component.Rendering3D ${CMAKE_DL_LIBS}) -target_link_libraries(${PROJECT_NAME} PRIVATE nfd) target_link_libraries(${PROJECT_NAME} PRIVATE SimpleIni::SimpleIni) +if (EXISTS nfd) + target_link_libraries(${PROJECT_NAME} PRIVATE nfd) +else() + target_link_libraries(${PROJECT_NAME} PRIVATE nfd::nfd) +endif() # setup the same API exports for imgui target_compile_definitions(${PROJECT_NAME} PUBLIC IMGUI_API=SOFAIMGUI_API) From 31ee595a24a440210d001ffeb091a315ca7bad09 Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Mon, 19 Dec 2022 12:54:30 +0900 Subject: [PATCH 2/3] add fps in title bar --- SofaGLFW/src/SofaGLFW/NullGUIEngine.cpp | 23 ++++++++++++++++++----- SofaGLFW/src/SofaGLFW/NullGUIEngine.h | 5 +++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/NullGUIEngine.cpp b/SofaGLFW/src/SofaGLFW/NullGUIEngine.cpp index 306106d15b..0dd78b51c0 100644 --- a/SofaGLFW/src/SofaGLFW/NullGUIEngine.cpp +++ b/SofaGLFW/src/SofaGLFW/NullGUIEngine.cpp @@ -29,19 +29,32 @@ namespace sofaglfw void NullGUIEngine::init() { - + m_startTime = glfwGetTime(); } -void NullGUIEngine::initBackend(GLFWwindow*) +void NullGUIEngine::initBackend(GLFWwindow* window) { - + m_window = window; } void NullGUIEngine::startFrame(SofaGLFWBaseGUI*) { - } void NullGUIEngine::endFrame() { - + constexpr double refreshTime = 1.0; + + m_currentTime = glfwGetTime(); + + const auto diffTime = m_currentTime - m_startTime; + if (diffTime > refreshTime || m_nbFrames == 0) + { + char title_string[32]; + double fps = static_cast(m_nbFrames) / diffTime; + std::snprintf(title_string, sizeof(title_string), "FPS: %.1f", fps); + glfwSetWindowTitle(m_window, title_string); + m_startTime = m_currentTime; + m_nbFrames = 0; + } + m_nbFrames++; } void NullGUIEngine::beforeDraw(GLFWwindow* window) diff --git a/SofaGLFW/src/SofaGLFW/NullGUIEngine.h b/SofaGLFW/src/SofaGLFW/NullGUIEngine.h index b33c543c3b..8c0e1b82ab 100644 --- a/SofaGLFW/src/SofaGLFW/NullGUIEngine.h +++ b/SofaGLFW/src/SofaGLFW/NullGUIEngine.h @@ -44,6 +44,11 @@ class NullGUIEngine : public BaseGUIEngine bool dispatchMouseEvents() override; void resetCounter() override; sofa::type::Vec2i getFrameBufferPixels(std::vector& pixels) override; +private: + GLFWwindow* m_window{ nullptr }; + double m_startTime{ 0.0 }; + double m_currentTime{ 0.0 }; + std::size_t m_nbFrames{ 0 }; }; } // namespace sofaglfw From f85897f8684562944c6f9d5bd5b65edd71a4cd0c Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Fri, 13 Feb 2026 11:36:02 +0900 Subject: [PATCH 3/3] improvment by claude for a smooth display Replaced the frame-counting-over-1-second approach with an exponential moving average (EMA) on individual frame times, which smooths out FPS fluctuations instead of producing jumpy per-window measurements. --- SofaGLFW/src/SofaGLFW/NullGUIEngine.cpp | 28 +++++++++++++++++-------- SofaGLFW/src/SofaGLFW/NullGUIEngine.h | 6 +++--- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/SofaGLFW/src/SofaGLFW/NullGUIEngine.cpp b/SofaGLFW/src/SofaGLFW/NullGUIEngine.cpp index 0dd78b51c0..8f8130b287 100644 --- a/SofaGLFW/src/SofaGLFW/NullGUIEngine.cpp +++ b/SofaGLFW/src/SofaGLFW/NullGUIEngine.cpp @@ -29,7 +29,9 @@ namespace sofaglfw void NullGUIEngine::init() { - m_startTime = glfwGetTime(); + m_lastTime = glfwGetTime(); + m_lastDisplayTime = m_lastTime; + m_avgFrameTime = 0.0; } void NullGUIEngine::initBackend(GLFWwindow* window) { @@ -40,21 +42,29 @@ void NullGUIEngine::startFrame(SofaGLFWBaseGUI*) } void NullGUIEngine::endFrame() { - constexpr double refreshTime = 1.0; + constexpr double displayRefreshInterval = 0.1; + constexpr double smoothingFactor = 0.05; - m_currentTime = glfwGetTime(); + const double now = glfwGetTime(); + const double dt = now - m_lastTime; + m_lastTime = now; - const auto diffTime = m_currentTime - m_startTime; - if (diffTime > refreshTime || m_nbFrames == 0) + if (dt > 0.0) { + if (m_avgFrameTime <= 0.0) + m_avgFrameTime = dt; + else + m_avgFrameTime += smoothingFactor * (dt - m_avgFrameTime); + } + + if (now - m_lastDisplayTime >= displayRefreshInterval) + { + const double fps = (m_avgFrameTime > 0.0) ? 1.0 / m_avgFrameTime : 0.0; char title_string[32]; - double fps = static_cast(m_nbFrames) / diffTime; std::snprintf(title_string, sizeof(title_string), "FPS: %.1f", fps); glfwSetWindowTitle(m_window, title_string); - m_startTime = m_currentTime; - m_nbFrames = 0; + m_lastDisplayTime = now; } - m_nbFrames++; } void NullGUIEngine::beforeDraw(GLFWwindow* window) diff --git a/SofaGLFW/src/SofaGLFW/NullGUIEngine.h b/SofaGLFW/src/SofaGLFW/NullGUIEngine.h index 8c0e1b82ab..e39140fa99 100644 --- a/SofaGLFW/src/SofaGLFW/NullGUIEngine.h +++ b/SofaGLFW/src/SofaGLFW/NullGUIEngine.h @@ -46,9 +46,9 @@ class NullGUIEngine : public BaseGUIEngine sofa::type::Vec2i getFrameBufferPixels(std::vector& pixels) override; private: GLFWwindow* m_window{ nullptr }; - double m_startTime{ 0.0 }; - double m_currentTime{ 0.0 }; - std::size_t m_nbFrames{ 0 }; + double m_lastTime{ 0.0 }; + double m_lastDisplayTime{ 0.0 }; + double m_avgFrameTime{ 0.0 }; }; } // namespace sofaglfw