Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I control frame rate in Qt 3D?

I'm using the new Qt 3D API to display a 3D scene during a computationally intense calculation. This scene only changes as a response to user input. However, the default behavior of Qt 3D seems to lock the scene's frame rate to some high constant value, which consumes an unacceptable amount of resources in this case.

Is there a way to control the frame rate in Qt 3D? Ideally, I'd like to only render a new frame when changes are made to the scene, but lowering it to a smaller fixed value would also suffice. The Qt 3D documentation is sparse, and I've been unable to find a way to do either of these things.

Edit: I managed to find and apply QRenderSettings::OnDemand to my root node and frame graph, but it seemingly has no effect, although this implies that it should, as I'm using Qt 5.7. Any additional input on this would be very welcome (even if it only warrants a comment).

Edit 2: After installing Fraps and measuring the frame rate directly, it appears that the scene is, in fact, rendering frames only as needed with QRenderSettings::OnDemand applied. Without this, the frame rate remains at a steady 60fps, which happens to be my screen's refresh rate. However, the program continues to consume a large amount of CPU time while idling with Qt 3D enabled, regardless of if the 3D window is even being shown. I'm beginning to think this is a separate Qt 3D issue unrelated to frame rate, and will likely open a new question accordingly.

like image 957
Ryan Hilbert Avatar asked Jul 13 '16 00:07

Ryan Hilbert


1 Answers

The most recent discussion about this might be a message from 2018 in a mailing list from qt-project.org:

Qt3D relies on your GPU vsync settings. To reach the maximum number of FPS, just disable vsync in your driver settings. If on the other hand you want to reduce FPS, call setSwapInterval on the QSurfaceFormat::defaultFormat and set it before starting your Qt3D application with QSurfaceFormat::setDefaultFormat.

The same user appears to have replied a similar question on KDAB's website years earlier.

like image 56
karlphillip Avatar answered Sep 20 '22 21:09

karlphillip