3

My custom QQuickItem currently does the following

  1. Create a QSGNode that subclasses QSGSimpleTextureNode
  2. In the nodes preprocess function, create a QOpenGLFramebufferObject to draw to
  3. Draw on the QOpenGLFramebufferObject using a QPainter
  4. Display the contents of the QOpenGLFramebufferObject as the node contents

The process I have for converting the FBO to a QSGTexture that I can set on the QSGSimpleTextureNode is the following.

QImage img = m_fbo->toImage();

QSGTexture* tex = m_window->createTextureFromImage(img, QQuickWindow::TextureCanUseAtlas);

setTexture(tex);

This seems very inefficient, and the app starts to get real framey even with relatively reasonable sized FBOs.

My questions are the following.

  1. Is there a simpler way of getting an FBO into a QSGTexture?
  2. Is there a better QPaintDevice compatible item that I should be using rather than a QOpenGLFramebufferObject?
  3. Is there a better subclass I should be extending than QSGSimpleTextureNode to do what I am wanting to do?

Thanks!

1 Answers1

1

1) For non multisample framebuffer objects a texture with the specified texture target is created. You can get the texture id for the texture attached to framebuffer object, using QOpenGLFramebufferObject::takeTexture(). And then create a new QSGTexture object from an existing GL texture id:

QSize textureSize = m_fbo.size();
GLuint textureId = m_fbo.takeTexture();
QSGTexture* texture = window()->createTextureFromId(textureId, textureSize);

2, 3) The QQuickPaintedItem class provides a way to use the QPainter API in the QML Scene Graph.

The QQuickFramebufferObject class is a convenience class for integrating rendering using a framebuffer object (FBO) with Qt Quick.

Meefte
  • 6,469
  • 1
  • 39
  • 42
  • In regards to QQuickPaintedItem, can you still override updatePaintNode to be able to create a node subtree? – XenoByteZero May 05 '15 at 14:51
  • how can I pass this `QSGTexture` created finally in step 1 into the `updatePaintNode` ? Or in other words, how can I display this `QSGTexture` on my QQuickItem ? – TheWaterProgrammer Mar 02 '17 at 13:28