Fix offscreen rendering in QOpenGLWidget

Amends 68a4c5da9a

In a case sharing QOpenGLContext,
offscreen renderings cannot get QOpenGLContext from Rhi.

Fixes: QTBUG-123005
Pick-to: 6.7 6.6 6.5
Change-Id: I9baae5e5c77878885f73ee39df5cd39117e8f1c2
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
bb10
Inho Lee 2024-03-07 15:00:52 +01:00
parent f9136fd0db
commit 50c81f5490
1 changed files with 5 additions and 3 deletions

View File

@ -855,9 +855,11 @@ void QOpenGLWidgetPrivate::initialize()
context = new QOpenGLContext;
context->setFormat(requestedFormat);
if (contextFromRhi) {
context->setShareContext(contextFromRhi);
context->setScreen(contextFromRhi->screen());
QOpenGLContext *shareContext = contextFromRhi ? contextFromRhi : qt_gl_global_share_context();
if (shareContext) {
context->setShareContext(shareContext);
context->setScreen(shareContext->screen());
}
if (Q_UNLIKELY(!context->create())) {
qWarning("QOpenGLWidget: Failed to create context");