Hi,

Because the QPaintDevice is the QOpenGLWindow. Instead of passing 'this' to 
QPainter, create a http://doc.qt.io/qt-5/qopenglpaintdevice.html on the stack 
(while the appropriate context is current), and pass that. You will probably 
need to pass in the FBO dimensions to the QOpenGLPaintDevice constructor.


Best regards,

Laszlo


________________________________
From: Fan Kevin <kevinfandr...@gmail.com>
Sent: Thursday, August 3, 2017 9:45:51 AM
To: Laszlo Agocs
Cc: interest@qt-project.org
Subject: Re: [Interest] QOpenGLWindow or QOpenGLWidget if need to render to 
framebuffer?

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.ag...@qt.io<mailto:laszlo.ag...@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<mailto:interest-bounces%2Blaszlo.agocs>=qt...@qt-project.org<mailto:qt...@qt-project.org>]
 On Behalf Of Fan Kevin
Sent: onsdag 2. august 2017 02.41
To: interest@qt-project.org<mailto:interest@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.

_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to