How can I control frame rate in Qt 3D?
Asked Answered
A

2

10

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.

Am‚lie answered 13/7, 2016 at 0:53 Comment(4)
Are you sure that it doesn't have something to do with your graphics?Venegas
At what fps is it running and what would be the highest fps for your preference?Venegas
This might be worth a look. It probably won't solve it, but it might shed some light on the problem. #36182032Venegas
Did this answer work? If not, what happened?Venegas
P
2

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.

Postimpressionism answered 16/11, 2020 at 23:26 Comment(0)
V
0

The best way to do this is probably to use the class FrameRateRange in the header file <FrameRateRange>. There are two public functions in this class: FrameRateRange() and FrameRateRange(qreal minimumFrameRate, qreal maximumFrameRate). qreal is the parameter that appears in both parameters in the latter function. This is a global typedef declared in the header file <QtGlobal>. minimum and maximum are frame rates in frames per second. More information from here and here.

Venegas answered 18/7, 2016 at 16:15 Comment(1)
FrameRateRange seems completely unrelated to Qt 3D, so I can't accept this answer, but since you're the only one to answer at all and your questioning helped me understand more about the problem, I'll likely award you the bounty shortly.Am‚lie

© 2022 - 2024 — McMap. All rights reserved.