Toggle VSync during runtime with QtQuick/QSG
athairus last edited by
From what I can tell, the use of VSync is implicitly defined by the value of the environment variable
QSG_RENDER_LOOP. If (for example on Windows) it is set to
windows, the default, it will use VSync. If set to
basic, it'll run its own internal timer (
qtdeclarative/src/scenegraph/qsgrenderloop.cpp:455). You can verify that it's not VSync'd by the tearing you'll observe while in fullscreen. Why it doesn't tear while windowed I'm not sure (I imagine the way the compositor works has something to do with it).
Anyway, this environment variable is read during startup. It seems that once set, this is immutable for the lifetime of the
QQuickWindow. I'd like something better than that. I'd like to be able to turn it on or off on demand, like virtually all modern PC games do. The way I see it, I have two approaches:
- Use QQuickRenderControl
- Extend the built-in render loops, somehow
The first approach seems to be the most straightforward. An example exists that creates a custom threaded render loop. However, what gave me pause was this comment at the top of
This is similar to the built-in threaded
render loop, but does not support all the features.
Then there's the second approach. All I really want to do is (what I hope) a minor tweak to the default threaded renderer. I don't want to sign up for patching/maintaining my custom threaded renderer to reach feature parity with the default one.
The only change I think I need to do is not block on vblank and use a custom timer to control rendering, just like the
basicloop does. Of course, I'll need some way to tell the render loop whether or not to use VSync.
Only problem with this approach is it's looking like a rabbit hole. In order to override
QSGRenderLoop::instance()with my own type of loop, I'll have to override
QQuickWindowPrivate::init, and so on and so forth. Sounds like even more of a maintainability nightmare than the first approach.
Which approach do you guys recommend?
Hi and welcome to devnet,
I'd recommend posting this question to the interest mailing list. You'll find there Qt's developers/maintainers (this forum is more user oriented)