[Interest] Rendering Qt/QML within native OpenGL or to texture

Giuseppe D'Angelo giuseppe.dangelo at kdab.com
Fri Mar 8 00:02:38 CET 2019


Il 07/03/19 18:33, Stefan Fabian ha scritto:
> Today I've found another way to use native OpenGL to draw on top of the scene in OGRE after the render queue ended but couldn't work out how to paint on it using Qt without getting stuck at the getting the content on screen without the QImage copy workaround in Approach 2.

See my talk at QtWS17 about how to integrate Qt Quick 2 with OpenGL. You 
basically need the third method (QQuickRenderControl) as you don't have 
control over the GL context creation.

You can wrap a foreign OpenGL context in a QOpenGLContext using its 
setNativeHandle function. Then you can use QQuickRenderControl as 
illustrated in my talks, the accompanying code and the examples in Qt.

> Unfortunately, 3D graphics and OpenGL is pretty far from my fields of expertise which is why I'm hoping someone who is more competent than me regarding OpenGL and QOpenGL can help me figure this out.
> I'll attach code parts that I deem important below, if you require a working example I can send you the code (it's not opensource yet but I'm planning on releasing it in the near future) but it requires a Linux distribution (only tested with Ubuntu) and a ROS installation.
> To summarize: I'm trying to find a way to either render directly to the texture, use a quicker method to copy the content from the FBO to the texture than getting a QImage and memcpy or, alternatively, render directly on top of the scene using the access to native OpenGL I've found today (here the problem is that I don't really know how to continue using OGRE's context when rendering Qt/QML).

An alternative of the above: create yourself a new OpenGL context that 
shares with the one used by Ogre. Then use this new context (again 
together with QQRC) to render Qt Quick content into a FBO (see 
QQuickWindow::setRenderTarget). Now, since your OpenGL context and 
OGRE's are sharing, the textures that you use inside your FBO are also 
visible from the OGRE context -- you just need to paint with them, no 
copies or CPU roundtrips are involved. Just beware of the headaches that 
go together with sharing OpenGL objects: there's no implicit command 
synchronization amongst contexts, you must be sure that all your drawing 
on the texture is fully realized by the GL before reading from it from 
the other context. Sync objects (or the very crude glFinish) can be used 
for this.

Hope this helps,
Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4007 bytes
Desc: Firma crittografica S/MIME
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190308/6bd89db9/attachment.bin>

More information about the Interest mailing list