diff --git a/src/Magnum/Platform/GlfwApplication.cpp b/src/Magnum/Platform/GlfwApplication.cpp index 55da5ad12..e1d635775 100644 --- a/src/Magnum/Platform/GlfwApplication.cpp +++ b/src/Magnum/Platform/GlfwApplication.cpp @@ -724,6 +724,15 @@ int GlfwApplication::exec() { return _exitCode; } +bool GlfwApplication::mainLoopDrawEventIteration() { + if(_flags & Flag::Redraw) { + _flags &= ~Flag::Redraw; + drawEvent(); + return true; + } + return false; +} + bool GlfwApplication::mainLoopIteration() { /* If exit was requested directly in the constructor, exit immediately without calling anything else */ @@ -756,11 +765,10 @@ bool GlfwApplication::mainLoopIteration() { /* If redrawing, poll for events immediately after drawEvent() (which could be setting the Redraw flag again, thus doing constant redraw). If not, avoid spinning the CPU by waiting for the next input event. */ - if(_flags & Flag::Redraw) { - _flags &= ~Flag::Redraw; - drawEvent(); + if (mainLoopDrawEventIteration()) glfwPollEvents(); - } else glfwWaitEvents(); + else + glfwWaitEvents(); return !glfwWindowShouldClose(_window); } diff --git a/src/Magnum/Platform/GlfwApplication.h b/src/Magnum/Platform/GlfwApplication.h index 63c0d5beb..5fcae13ce 100644 --- a/src/Magnum/Platform/GlfwApplication.h +++ b/src/Magnum/Platform/GlfwApplication.h @@ -263,13 +263,24 @@ class GlfwApplication { * should exit, @cpp true @ce otherwise * @m_since{2020,06} * + * Calls @ref mainLoopDrawEventIteration(), @ref glfwPollEvents() and/or + * @ref glfwWaitEvents() managing the delays between them. * Called internally from @ref exec(). If you want to have better * control over how the main loop behaves, you can call this function + * (or the sub mainLoopDrawEventIteration with the glfw events functions such as glfwPollEvents / glfwWaitEvents) * yourself from your own `main()` function instead of it being called * automatically from @ref exec() / @ref MAGNUM_GLFWAPPLICATION_MAIN(). */ bool mainLoopIteration(); + /** + * @brief Calls @ref drawEvent() if @ref Flag::Redraw is set and unset it. + * @return @cpp true @ce if @ref drawEvent() was called, @cpp false @ce otherwise + * + * Called internally from @ref mainLoopIteration(). + */ + bool mainLoopDrawEventIteration(); + /** * @brief Exit application * @param exitCode The exit code the application should return