Fix offscreen rendering in QOpenGLWidget

Amends 68a4c5da9a080101cccd8a3b2edb1c908da0ca8e

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

Fixes: QTBUG-123005
Pick-to: 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>
(cherry picked from commit 50c81f549030aba3c29f8cd161662b019028e91b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Inho Lee 2024-03-07 15:00:52 +01:00 committed by Qt Cherry-pick Bot
parent 617aa644c0
commit 2bbfa7f18d

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");