Qt World Summit: Submit your Presentation

Embedding OpenGL in QuickItem in Qt5 Scenegraph

  • Hi everyone,

    I'm not sure if this is the right place to post, but I couldn't find a Qt5 specific place, and there seems to be the most opengl chatter here. I have been messing with qt5 from git lately, and I want to make a custom QuickItem and corresponding node to embed an externally rendered texture into the scenegraph. I found the qmlogre example at qtlabs and it seems to fit the bill perfectly except he uses a private header file to reference QSGPlainTexture. Is there a public interface equivalent of QSGPlainTexture, or do I have to subclass QSGTexture and create it in my project? From what I can tell, the only public way to get my hands on a QSGTexture is from the QQuickWindow::createTextureFrom*** functions. Is there something I'm missing?


  • I sat down tonight to take a second look at this and the answer is obvious. All I had to do was change from a custom node to a SimpleTextureNode and generate the GL texture in the quick item, which has a window reference. Now its all working, hooray!

  • can we use this approach to have a custom rendering in QtQuick 2.0 ?

  • You can do custom rendering in this manner with openGL.

    "Check out this example":http://qt-project.org/doc/qt-5.1/qtquick/scenegraph-textureinthread.html

  • yes but I think it won't be performance efficient, is it?

  • I have been looking far and wide to find out how, if it's possible, you can fill a particular area in a QML screen with an OpenGL context and do custom OpenGL only in that context. I've seen plenty of demos where the QML components like buttons, etc lay on top or below a screen-wide OpenGL context (as is typically required by games), but I'd like to be able to situate several distinct OpenGL contexts within QML and have the QML file define how large they are, where they are positioned, etc.

    Now, since Qt 5 is all OpenGL under the hood, it makes me wonder if using a Canvas element with custom drawing via javascript would technically result in the same performance as custom OpenGL? This would be a meaningful alternative but it's not clear to me how the javascript drawing is handled via runtime compared to custom OpenGL drawing.

Log in to reply