[Interest] Porting Qt5 OpenGL app to Qt6 - QQuickRenderTarget and OpenGL frame buffer object

Nuno Santos nuno.santos at imaginando.pt
Wed May 15 16:48:44 CEST 2024


Lazslo,

Thank you very much for your prompt reply.

If I will be doing this very very regularly, should I keep an instance of the FBO instance of creating and deleting all the time?

Best regards,

Nuno

> On 15 May 2024, at 15:46, Laszlo Agocs <laszlo.agocs at qt.io> wrote:
> 
> 
> Hi Nuno,
> 
> You can always create an FBO on the fly for the purposes of the readback.
> 
> For example, something along the lines of:
> 
> glGenFramebuffers(1, &fbo);
> glBindFramebuffer(GL_FRAMEBUFFER, fbo);
> glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
> glReadPixels(...);
> glBindFramebuffer(GL_FRAMEBUFFER, context->defaultFramebufferObject());
> glDeleteFramebuffers(1, &fbo);
> 
> Best regards,
> Laszlo
> 
> From: Nuno Santos <nuno.santos at imaginando.pt <mailto:nuno.santos at imaginando.pt>>
> Sent: Wednesday, May 15, 2024 4:29 PM
> To: Laszlo Agocs <laszlo.agocs at qt.io <mailto:laszlo.agocs at qt.io>>
> Cc: interestqt-project. org <interest at qt-project.org <mailto:interest at qt-project.org>>
> Subject: Re: [Interest] Porting Qt5 OpenGL app to Qt6 - QQuickRenderTarget and OpenGL frame buffer object
>  
> Laszlo,
> 
> I have a new problem regarding this question.
> 
> I have a QQuickRenderControl in order to do a side render and be able to extract the render output. I was reading from the FBO using the glReadPixels function.
> 
> But now the render target is a OpenGL Texture but apparently the function that reads from a GLTexture is glGetTexImage but that function is not on the qopenglfunctions.
> 
> How can I read the texture now? 
> 
> Thanks!
> 
> Best regards,
> 
> Nuno
> 
>> On 8 May 2024, at 16:41, Laszlo Agocs <laszlo.agocs at qt.io <mailto:laszlo.agocs at qt.io>> wrote:
>> 
>> Hi,
>> 
>> Passing 0 as a renderbuffer object name is not going to work. Try using https://doc.qt.io/qt-6/qquickrendertarget.html#fromOpenGLTexture with the texture that is used as the color attachment of your OpenGL framebuffer object. (actually that FBO is not useful in Qt 6 as one will be created internally as needed)
>> 
>> Best regards,
>> Laszlo
>> 
>> From: Interest <interest-bounces at qt-project.org <mailto:interest-bounces at qt-project.org>> on behalf of Nuno Santos via Interest <interest at qt-project.org <mailto:interest at qt-project.org>>
>> Sent: Tuesday, April 16, 2024 4:21 PM
>> To: interestqt-project. org <interest at qt-project.org <mailto:interest at qt-project.org>>
>> Subject: [Interest] Porting Qt5 OpenGL app to Qt6 - QQuickRenderTarget and OpenGL frame buffer object
>>  
>> Hi,
>> 
>> I have an application that was heavily written on top of OpenGL. Right now I want to port it to Qt 6 with the minimum effort trying to stick to the OpenGL backend until I get the grip on the new things of Qt 6 Graphics API abstraction.
>> 
>> I used to do this in order to assign a target FBO to a QuickWindow:
>> 
>> _quickWindow->setRenderTarget(_fboRender);
>> 
>> This is no longer possible and it requires a QQuickRenderTarget to be created and I seem to have three options:
>> 
>> (since 6.2) QQuickRenderTarget  fromOpenGLRenderBuffer(uint renderbufferId, const QSize &pixelSize, int sampleCount = 1)
>> (since 6.4) QQuickRenderTarget  fromOpenGLTexture(uint textureId, uint format, const QSize &pixelSize, int sampleCount = 1)
>> QQuickRenderTarget      fromOpenGLTexture(uint textureId, const QSize &pixelSize, int sampleCount = 1)
>> 
>> I’m trying this:
>> 
>> _renderTarget = QQuickRenderTarget::fromOpenGLRenderBuffer(0, QSize(_renderResolution.width(), _renderResolution.height()));
>> _quickWindow->setRenderTarget(_renderTarget);
>> 
>> But nothing appears on the screen and I get a warning:
>> 
>> QQuickWindow: No render target (neither swapchain nor custom target was provided)
>> 
>> Can anyone tell me what am I failing here?
>> 
>> Any ideas suggestions are very welcome.
>> 
>> With my best regards,
>> 
>> Nuno
>> _______________________________________________
>> 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/20240515/1f6eceaa/attachment.htm>


More information about the Interest mailing list