[Interest] QOpenGLWindow or QOpenGLWidget if need to render to framebuffer?

Fan Kevin kevinfandroid at gmail.com
Thu Aug 3 09:45:51 CEST 2017


Hi,

Thank you very much for your answer.
Following your answer on Context and FBO, I tried to convert the Qt
QOpenGLWindow sample to render to Oculus.

As I just need to render to Oculus, not the QOpenGLWindow, I use only the
context created by QOpenGLWindow and create FBO with that.
In my rendering, some parts are correctly rendered to FBO, but some
remained on the on screen QOpenGLWindow.
Here is the code.

void OpenGLWindow::paintGL()
{
        // code to get headset render desc

// Render Scene to Eye Buffers
for (int eye = 0; eye < 2; ++eye)
{
// Switch to eye render target, bind FBO etc.
eyeRenderTexture[eye]->SetAndClearRenderSurface(eyeDepthBuffer[eye]);

m_fragment_toy.draw(size());  // this is rendered to Oculus

                 /* just a quick test drawing, this also rendered to Oculus
*/
glBegin(GL_TRIANGLES);
glColor3f(1.0, 0.0, 0.0); glVertex3f(-1.0, -1.0, 0.0);
glColor3f(0.0, 1.0, 0.0); glVertex3f(0.0, 1.0, 0.0);
glColor3f(0.0, 0.0, 1.0); glVertex3f(1.0, -1.0, 0.0);
glEnd();

                /* original QOpenGL sample, this is rendered to on screen */
QPainter p(this);
p.setWorldTransform(m_window_normalised_matrix.toTransform());
QMatrix4x4 mvp = m_projection * m_view * m_model_triangle;
p.setTransform(mvp.toTransform(), true);
p.fillPath(painterPathForTriangle(), m_brush);

                // unbind FBO etc
eyeRenderTexture[eye]->UnsetRenderSurface();

// Commit changes to the textures so they get picked up frame
eyeRenderTexture[eye]->Commit();
}

// code to write FBO texture to headset
}

The background and the fixed function pipeline triangle is rendered to FBO
and then to headset.
But the QPainter triangle does not seem to be rendered to the FBO and
remains on screen.
Since I use one context, is there something I may have missed that may have
conflicted with QPainter?
Thank you.

Best,

Kevin


2017-08-02 15:27 GMT+09:00 Laszlo Agocs <laszlo.agocs at qt.io>:

> Hi,
>
>
>
> It is always possible to render into an offscreen render target. You do
> not even need any window for that.
>
>
>
> The typical pattern is:
>
>
>
> QOpenGLContext ctx;
>
> QSurfaceFormat fmt;
>
> fmt.setDepthBufferSize(24);
>
>>
> ctx.setFormat(fmt);
>
> if (!ctx.create()) panic();
>
>
>
> QOffscreenSurface s;
>
> s.setFormat(ctx.format());
>
> s.create();
>
>
>
> if (!ctx.makeCurrent(&s)) panic();
>
>
>
> ctx.functions()->glBindFrameBuffer(…)
>
> … // render
>
>
>
> In the OVR case you presumably need to render into the texture retrieved
> from ovr_GetTextureSwapChainBufferGL. So you still need to create your
> own FBO with the depth attachment and whatnot, but the color attachment
> will be the provided texture.
>
>
>
> If you already have a QOpenGLWindow, then the QOffscreenSurface is not
> necessary since you already have something that can be used with
> makeCurrent().
>
>
>
> Best regards,
>
> Laszlo
>
>
>
> *From:* Interest [mailto:interest-bounces+laszlo.agocs=qt.io at qt-project.
> org] *On Behalf Of *Fan Kevin
> *Sent:* onsdag 2. august 2017 02.41
> *To:* interest at qt-project.org
> *Subject:* [Interest] QOpenGLWindow or QOpenGLWidget if need to render to
> framebuffer?
>
>
>
> Hi,
> I was wondering between the difference between QOpenGLWindow and
> QOpenGLWidget.
> I read that
> "OpenGLWindow renders directly to the given window, while QOpenGLWidget
> renders to offscreen buffer that is then rendered to the widget"
>
> I have to do some rendering to the framebuffer, as that is necessary for
> displaying in Oculus Rift.
> However, it seems unable to do so in our software which is built upon
> QOpenGLWindow.
> Is it possible to render to a framebuffer using QOpenGLWindow? or should I
> use QOpenGLWidget?
> Thank you.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170803/c848735f/attachment.html>


More information about the Interest mailing list