1

In my Qt app with C++, I am using a QQuickItem derived class to display textures which are produced on every frame render by running some filters on each frame render. this works fine.

Next, I used the takeTexture method provided by QOpenGLFramebufferObject to save some textures & display them back whenever required. These saved textures are of type GLuints. I am able to display it back using the normal OpenGL rendering pipeline. It works well.

But, Is there a way I can avoid the rendering pipeline calls & map this saved texture on GPU memory directly to my QQuickItem?

TheWaterProgrammer
  • 7,055
  • 12
  • 70
  • 159
  • Are you asking how to create a QQuickItem that renders the contents of a texture? – peppe Mar 01 '17 at 23:22
  • yes in a way. I see some methods like [setTexture](http://doc.qt.io/qt-5/qsgsimpletexturenode.html#setTexture) available in QSGSimpleTextureNode. But not able to figure out how to pass the `GLuint` that I got from [takeTexture](http://doc.qt.io/qt-5/qopenglframebufferobject.html#takeTexture) into some method which can take the texture & display it on a QQuickItem. – TheWaterProgrammer Mar 02 '17 at 06:01
  • discussion [here](http://stackoverflow.com/questions/32162215/adding-a-background-image-to-a-qquickitem) suggests how to create a `QSGTexture` from an image & `setTexture` using it. is there a way I can create a `QSGTexture` from a Gluint & then call `setTexture` on the window ? – TheWaterProgrammer Mar 02 '17 at 06:12
  • 1
    `item->window()->createTextureFromId(texture_id)` will give you a `QSGTexture`. Then combine it with a geometry node, geometry and a material node. – peppe Mar 02 '17 at 07:48
  • @peppe is it possible for you to give a sample of what to do after creating a `QSGTexture` out of the `GLuint texture_id` ? Is some way I can tell my method `updatePaintNode` to use this `QSGTexture` & render it ? or if there is a better way, please suggest – TheWaterProgrammer Mar 02 '17 at 13:26
  • Check out some of the examples that create a custom QQuickItem. Yes, you need to override `updatePaintNode` and return a minimal tree of nodes to render your texture. At a minimum, you need geometry (a quad) and a material that draws your texture. – peppe Mar 02 '17 at 15:08
  • @peppe thanks `updatePaintNode` with a correct `TextureNode` worked. You can pls post the same as an answer. it will great if can explain some more about how the Qt scene graph works along with your answer (iff u wish) – TheWaterProgrammer Mar 04 '17 at 17:11

0 Answers0