[Interest] QOpenGLWindow or QOpenGLWidget if need to render to framebuffer?
laszlo.agocs at qt.io
Thu Aug 3 14:53:22 CEST 2017
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.
From: Fan Kevin <kevinfandroid at gmail.com>
Sent: Thursday, August 3, 2017 9:45:51 AM
To: Laszlo Agocs
Cc: interest at qt-project.org
Subject: Re: [Interest] QOpenGLWindow or QOpenGLWidget if need to render to framebuffer?
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.
// 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.
m_fragment_toy.draw(size()); // this is rendered to Oculus
/* just a quick test drawing, this also rendered to Oculus */
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);
/* original QOpenGL sample, this is rendered to on screen */
QMatrix4x4 mvp = m_projection * m_view * m_model_triangle;
// unbind FBO etc
// Commit changes to the textures so they get picked up frame
// 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?
2017-08-02 15:27 GMT+09:00 Laszlo Agocs <laszlo.agocs at qt.io<mailto:laszlo.agocs at qt.io>>:
It is always possible to render into an offscreen render target. You do not even need any window for that.
The typical pattern is:
if (!ctx.create()) panic();
if (!ctx.makeCurrent(&s)) panic();
… // 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().
From: Interest [mailto:interest-bounces+laszlo.agocs<mailto:interest-bounces%2Blaszlo.agocs>=qt.io at qt-project.org<mailto:qt.io at qt-project.org>] On Behalf Of Fan Kevin
Sent: onsdag 2. august 2017 02.41
To: interest at qt-project.org<mailto:interest at qt-project.org>
Subject: [Interest] QOpenGLWindow or QOpenGLWidget if need to render to framebuffer?
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?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Interest