[Interest] Setting current QOpenGLContext with an EGLContext
Thomas Sevaldrud
thomas at silentwings.no
Wed Sep 30 15:55:28 CEST 2015
Ok, one step closer again :-)
Thank God for open source! I was able to step into the ANGLE code with a
debugger and found out that the blit operation would fail if the pixel
formats of the source and destination buffers were different.
QOpenGLFrameBuffer uses GL_RGBA by default while the pbuffer apparently has
0x93A1 which appears to be GL_BGRA8_EXT, but I can't actually find the
definition of it in any header files.
By setting internalFormat to 0x93A1 on my multisample FBO I am able to blit
into the PBuffer. It feels a little bit flakey to assume this hardcoded
pixel format though, is there a supported way to read out the internal
format of the PBuffer, or to set it explicitly so I can use the same format
in both buffers?
- Thomas
On Wed, Sep 30, 2015 at 1:02 PM, Thomas Sevaldrud <thomas at silentwings.no>
wrote:
> Ok, I can live with the dummy offscreen surface, it seems to work OK at
> least.
>
> I have now tried to create a multisample FBO for blitting into the
> PBuffer, but it's not entirely straight forward it seems :-) What I've done
> is this:
>
>
> QOpenGLFramebufferObjectFormat format;
>
> format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
>
> format.setSamples(4);
>
> gl_fbo_ = new QOpenGLFramebufferObject(fbo_size, format);
>
>
> ...
>
>
> gl_fbo_->bind();
>
>
> .. render stuff...
>
>
> gl_fbo_->release();
>
> QImage img(gl_fbo_->toImage()); // For debugging
>
> img.save("fbo_test.png");
>
> gl_context_->makeCurrent(gl_dummy_surface_);
>
> eglMakeCurrent(egl_display_, egl_pbuffer_, egl_pbuffer_, egl_context_);
>
> QOpenGLFramebufferObject::blitFramebuffer(NULL, gl_fbo_);
>
>
> The "fbo_test.png" image contains the OpenGL scene as it should, but the
> PBuffer remains black. Any ideas?
>
> - Thomas
>
>
> On Tue, Sep 29, 2015 at 4:30 PM, Agocs Laszlo <
> laszlo.agocs at theqtcompany.com> wrote:
>
>> Well, there’s no nice solution since QOffscreenSurface is backed by a
>> window, not a pbuffer on Windows. (arguably this should be changed in some
>> future release, for ANGLE at least, but that won’t help you now)
>>
>>
>>
>> You can make a QOpenGLContext current with a QOffscreenSurface, then call
>> eglMakeCurrent directly with the pbuffer surface and the EGLContext you
>> dig out from the QOpenGLContext. This way Qt’s tracking will be correct
>> (when it comes to the current QOpenGLContext) too.
>>
>>
>>
>> This is apparently exactly what you are doing already.
>>
>>
>>
>> As for the multisample issues, it could be that multisampling is not
>> supported for pbuffers. As a workaround you could render into an FBO with a
>> multisample renderbuffer (assuming that’s supported) and then blit that
>> into the default framebuffer (FBO 0) of the pbuffer surface.
>>
>>
>>
>> BR,
>>
>> Laszlo
>>
>> *From:* interest-bounces+laszlo.agocs=theqtcompany.com at qt-project.org
>> [mailto:interest-bounces+laszlo.agocs=theqtcompany.com at qt-project.org] *On
>> Behalf Of *Thomas Sevaldrud
>> *Sent:* 29. september 2015 15:24
>> *To:* Interest at qt-project.org
>> *Subject:* Re: [Interest] Setting current QOpenGLContext with an
>> EGLContext
>>
>>
>>
>> It works if I add a dummy OffscreenSurface and make my context current on
>> this before making the PBuffer current. Not sure if this is the best way of
>> doing it though?
>>
>>
>>
>> - Thomas
>>
>>
>>
>> On Tue, Sep 29, 2015 at 11:37 AM, Thomas Sevaldrud <thomas at silentwings.no>
>> wrote:
>>
>> Hi,
>>
>>
>>
>> I'm still working on the EGL PBuffer/DirectX integration through Qt that
>> I posted about last week :-)
>>
>>
>>
>> Thanks to good help from this list I now have the PBuffer and DirectX
>> texture set up with the share handle. I also have a QOpenGLContext which I
>> have used to set up the EGL PBuffer. I don't have a QSurface though, since
>> my surface is the EGL PBuffer.
>>
>>
>>
>> So, the question now is how do I make the QOpenGLContext current. (I need
>> a QOpenGLContext::currentContext() for QOpenGLFunctions and so on).
>>
>>
>>
>> The code looks something like this:
>>
>>
>>
>> glContext_ = new QOpenGLContext;
>>
>> glContext_->setFormat(format);
>>
>> glContext_->create();
>>
>>
>>
>> ....
>>
>>
>>
>> QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
>>
>> egl_display_ = static_cast<EGLDisplay>(nativeInterface->*nativeResourceForContext*("eglDisplay", glContext_));
>>
>> egl_context_ = static_cast<EGLContext>(nativeInterface->*nativeResourceForContext*("eglContext", glContext_));
>>
>> EGLConfig egl_config = static_cast<EGLConfig>(nativeInterface->*nativeResourceForContext*("eglConfig", glContext_));
>>
>>
>>
>> EGLint attribs[] = { ...
>>
>>
>>
>> };
>>
>>
>>
>> egl_pbuffer_ = eglCreatePbufferSurface(egl_display_, egl_config, attribs);
>>
>>
>>
>> ... D3D setup stuff...
>>
>>
>>
>> // Start rendering to PBuffer:
>>
>>
>>
>> eglMakeCurrent(egl_display_, egl_pbuffer_, egl_pbuffer_, egl_context_);
>>
>>
>>
>> ... Here I should like to set glContext current somehow...
>>
>>
>>
>> Any ideas?
>>
>>
>>
>> - Thomas
>>
>>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150930/15bc07a6/attachment.html>
More information about the Interest
mailing list