From 3d46094b6835103293dae0e573c561a07048d7d1 Mon Sep 17 00:00:00 2001 From: Even Oscar Andersen Date: Mon, 11 Mar 2024 12:42:47 +0100 Subject: wasm: Lift restriction on offscreen for fake context sharing We only activated our fake context sharing logic for offscreen surfaces. This commit removed that restriction this allows the rendercontrol example to run Fixes: QTBUG-117410 Change-Id: Id86617f57c6a98a920f5dd82332dcd8277f103e4 Reviewed-by: Lorn Potter --- src/plugins/platforms/wasm/qwasmopenglcontext.cpp | 37 ++++++++++------------- 1 file changed, 16 insertions(+), 21 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/wasm/qwasmopenglcontext.cpp b/src/plugins/platforms/wasm/qwasmopenglcontext.cpp index aaea74f29b..07ae1d1cf5 100644 --- a/src/plugins/platforms/wasm/qwasmopenglcontext.cpp +++ b/src/plugins/platforms/wasm/qwasmopenglcontext.cpp @@ -58,27 +58,19 @@ QWasmOpenGLContext::obtainEmscriptenContext(QPlatformSurface *surface) return m_ownedWebGLContext.handle; if (surface->surface()->surfaceClass() == QSurface::Offscreen) { - if (const auto *shareContext = m_qGlContext->shareContext()) { - // Since there are no resource sharing capabilities with WebGL whatsoever, we use the - // same actual underlaying WebGL context. This is not perfect, but it works in most - // cases. - return static_cast(shareContext->handle()) - ->m_ownedWebGLContext.handle; - } else { - // Reuse the existing context for offscreen drawing, even if it happens to be a canvas - // context. This is because it is impossible to re-home an existing context to the - // new surface and works as an emulation measure. - if (m_ownedWebGLContext.handle) - return m_ownedWebGLContext.handle; - - // The non-shared offscreen context is heavily limited on WASM, but we provide it - // anyway for potential pixel readbacks. - m_ownedWebGLContext = - QOpenGLContextData{ .surface = surface, - .handle = createEmscriptenContext( - static_cast(surface)->id(), - m_actualFormat) }; - } + // Reuse the existing context for offscreen drawing, even if it happens to be a canvas + // context. This is because it is impossible to re-home an existing context to the + // new surface and works as an emulation measure. + if (m_ownedWebGLContext.handle) + return m_ownedWebGLContext.handle; + + // The non-shared offscreen context is heavily limited on WASM, but we provide it + // anyway for potential pixel readbacks. + m_ownedWebGLContext = + QOpenGLContextData{ .surface = surface, + .handle = createEmscriptenContext( + static_cast(surface)->id(), + m_actualFormat) }; } else { destroyWebGLContext(m_ownedWebGLContext.handle); @@ -160,6 +152,9 @@ GLuint QWasmOpenGLContext::defaultFramebufferObject(QPlatformSurface *surface) c bool QWasmOpenGLContext::makeCurrent(QPlatformSurface *surface) { + if (auto *shareContext = m_qGlContext->shareContext()) + return shareContext->makeCurrent(surface->surface()); + const auto context = obtainEmscriptenContext(surface); if (!context) return false; -- cgit v1.2.3