[Interest] Running code in the scene graph renderer thread

Sletta Gunnar Gunnar.Sletta at digia.com
Thu Apr 11 16:12:43 CEST 2013


> Hi! I'm implementing a plugin for Qt Multimedia for playing video and audio
> using hardware acceleration. When opening a content which includes video, I
> need to instantiate an OpenGL texture and an EGLImageKHR. To do this I need
> to be in the thread with the current OpenGL context, which should be the
> renderer thread.
> 
> I did this in a custom QML component (in the updatePaintNode method), and
> everything is working correctly: but how do I execute my code in the
> renderer thread of the scene graph from a Qt Multimedia plugin? What
> options do I have?
> 
> I quickly read the Qt Multimedia plugin for Android, but that is a little
> different because the texture is instantiated by the SurfaceTexture java
> class.

There are two ways you can do this. If you follow samuels way with hooking into QQuickWindow::beforeRendering() that works fine. QQuickWindow is accessible from QQuickItem::window(), and you always have a valid window in the QQuickItem::updatePaintNode() function.

An alternative which is more in line with how the API is meant to be used is to create a QSGTexture implementation which wraps your EGLImageKHR and which does what it needs to do in the bind() function. Beware of that the texture from the start though, otherwise, the scene graph sorting will get very confused :)

In the updatePaintNode() function, create and set up the QSGTexture instance, assign it to a QSGSimpleTextureNode and return that back to the scene graph, and you should be good to go.

cheers,
Gunnar


More information about the Interest mailing list