[Interest] Render QQuickRenderControl render target texture into a QuickItem in the visible QQuickWindow

Frank Mertens frank at cyblogic.de
Thu Jul 8 02:17:47 CEST 2021


Hi Nuno,

another link doing magic with FBO and offscreen rendering, from which I learned a lot:
github.com/machinekoder/qml-oled-renderer

God speed,
Frank

On 07.07.21 08:13, Nuno Santos wrote:
> Frank,
>
> Thanks for your reply.
>
> I’ve been on your StackOverflow question before! :) Several times actually!
>
> In the mean time I have found the answer for my question. The trick is to use QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts) before starting QGuiApplication.
>
> Then, when initialising the QOpenGLContext that will be used offscreen renderer, we need to set _context->setShareContext(QOpenGLContext::globalShareContext()); This way, the texture is know to both renderers. 
>
> While it is working pretty good on Mac, on Windows I’m having flickering. My theory is that the texture is being updated while it is being painted. I might need to find the right time to render the offscreen surface. Maybe before “beforeRendering” of the main window so that when it paints, the texture is available. If someone has a solution for this please let me know.
>
> I’ve also tried another suggestion which is use ShaderEffectSource with the item I want to capture as source, take it to the C++ level and access to the textureProvider()->texture() at the afterRendering signal of the main window. I was not successful with this technic. All I could see was black or rubbish. This technic would spare me a separate render engine though.
>
> I know this is not a feature that every single Qt app developer will require but having official hook for this kind of things would be great. 
>
> I’m using the single threaded version of the rendercontrol example. Since it's being instantiated and driven by the main thread, it stresses the process main cpu usage a bit. I will eventually give a try to the multi threaded version to see if it has more benefits than problems. 
>
> Best regards,
>
> Nuno
>
>> On 7 Jul 2021, at 02:36, Frank Mertens <frank at cyblogic.de <mailto:frank at cyblogic.de>> wrote:
>>
>> Hey Nuno,
>>
>> done a lot of QQuickRenderControl tricks lately. But I'm using it on QSGRendererInterface::Software.
>> I'm not sure if it helps, but check out: https://stackoverflow.com/questions/17146747/capture-qml-drawing-buffer-without-displaying/67187802#67187802
>>
>> God speed,
>> Frank
>>
>> On 29.06.21 17:27, Nuno Santos wrote:
>>> Hi,
>>>
>>> I’m trying to make a offscreen renderer for a quick scene and then display it’s output in the main and visible QQuickWindow scene.
>>>
>>> The reason I’m trying to achieve this is because I need to intercept the frames to be able to send them to other programs or encode as a video file.
>>>
>>> I’ve based myself on the rendercontrol example and I have a working offscreen renderer. Now, what I’m trying to do is to paint the result of the offscreen renderer into the main QQuickWindow.
>>>
>>> What I’m doing is creating a new QQuickItem that paints a texture. When I declare this item in qml, I register it on the render control. Render control has it’s own render timing. Whenever render control paints, I tell the registered quick item to paint with the fbo texture.
>>>
>>> The problem is that the only thing that is painted is black. I’m pretty sure the quick item is paint texture correctly because it works with images:
>>>
>>> // render method
>>>
>>>>>>
>>> if(_renderView)
>>> {
>>> _renderView->setImage(_fbo->toImage()); // this works
>>> _renderView->setTexture(_quickWindow->createTextureFromId(_fbo->texture(),_size)); // this doesn’t work - only black is painted
>>> }
>>>
>>> … 
>>>
>>> I wonder if I’m stumbling on synchronisation issues. Maybe when its time for the main window to paint again, that texture is not valid anymore. 
>>>
>>> Performance is a key factor in this architecture. I need the fastest solution possible and it doesn’t seem that creating a QImage from a texture and then convert it to QSGTexture is the most performant solution possible.
>>>
>>> Has anyone been here before? 
>>>
>>> Any advise on how to overcome this problem?
>>>
>>> Thanks!
>>>
>>> Best regards,
>>>
>>> Nuno
>>>
>>> _______________________________________________
>>> Interest mailing list
>>> Interest at qt-project.org
>>> https://lists.qt-project.org/listinfo/interest
>>
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org <mailto:Interest at qt-project.org>
>> https://lists.qt-project.org/listinfo/interest
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210708/9dd15f57/attachment.html>


More information about the Interest mailing list