summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/wasm/qwasmopenglcontext.h
diff options
context:
space:
mode:
authorMorten Sørvig <morten.sorvig@qt.io>2025-06-03 09:27:58 +0200
committerMorten Sørvig <morten.sorvig@qt.io>2025-06-12 15:37:19 +0200
commitc2ec20b226f0613db74a1e9fadffcf423ff1a180 (patch)
tree11e3556ecc0ea580ef55982a1f6ad1aaf45b7016 /src/plugins/platforms/wasm/qwasmopenglcontext.h
parent59c29436db8731fb7a8c9a932bf55d79b370668c (diff)
wasm: don't recreate WebGL context on surface change
The native WebGL context is tied to a single canvas, and can only be used with that canvas. (Qt creates one canvas per QPlatformWindow). This means that we need new native contexts in cases where a QWindow is repeatedly created and destroyed. It can be tempting to just create a new WebGL context "behind the scenes" on the makeCurrent() call in this case, but this does not work since GL resources created by user code with the original WebGL context in place are now invalid. Inform user code that this has happened by signaling a context loss. This is done by returning false from makeCurrent(), and then making sure isValid() returns false as well. The context becomes invalid whenever the owning platform window is destroyed; add a call from ~QWasmWindow() which handles that bookkeeping. Pick-to: 6.10 Task-number: QTBUG-120138 Change-Id: I929b9bb51153007c16630b1a991399f01ebffa62 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Diffstat (limited to 'src/plugins/platforms/wasm/qwasmopenglcontext.h')
-rw-r--r--src/plugins/platforms/wasm/qwasmopenglcontext.h21
1 files changed, 8 insertions, 13 deletions
diff --git a/src/plugins/platforms/wasm/qwasmopenglcontext.h b/src/plugins/platforms/wasm/qwasmopenglcontext.h
index 2a8bcc5d9bd..832736dbf67 100644
--- a/src/plugins/platforms/wasm/qwasmopenglcontext.h
+++ b/src/plugins/platforms/wasm/qwasmopenglcontext.h
@@ -4,6 +4,8 @@
#ifndef QWASMOPENGLCONTEXT_H
#define QWASMOPENGLCONTEXT_H
+#include <QtCore/qhash.h>
+
#include <qpa/qplatformopenglcontext.h>
#include <emscripten.h>
@@ -29,24 +31,17 @@ public:
bool isValid() const override;
QFunctionPointer getProcAddress(const char *procName) override;
-private:
- struct QOpenGLContextData
- {
- QPlatformSurface *surface = nullptr;
- EMSCRIPTEN_WEBGL_CONTEXT_HANDLE handle = 0;
- };
+ static void destroyWebGLContext(QPlatformSurface *surface);
+private:
static bool isOpenGLVersionSupported(QSurfaceFormat format);
- EMSCRIPTEN_WEBGL_CONTEXT_HANDLE obtainEmscriptenContext(QPlatformSurface *surface);
- static EMSCRIPTEN_WEBGL_CONTEXT_HANDLE
- createEmscriptenContext(const std::string &canvasSelector, QSurfaceFormat format);
-
+ EMSCRIPTEN_WEBGL_CONTEXT_HANDLE createEmscriptenContext(const std::string &canvasSelector, QSurfaceFormat format);
static void destroyWebGLContext(EMSCRIPTEN_WEBGL_CONTEXT_HANDLE contextHandle);
QSurfaceFormat m_actualFormat;
- QOpenGLContext *m_qGlContext;
- QOpenGLContextData m_ownedWebGLContext;
- EMSCRIPTEN_WEBGL_CONTEXT_HANDLE m_usedWebGLContextHandle = 0;
+ QPlatformSurface *m_madeCurrentSurface = nullptr;
+ QPlatformSurface *m_contextOwningSurface = nullptr;
+ static QHash<QPlatformSurface *, EMSCRIPTEN_WEBGL_CONTEXT_HANDLE> s_contexts;
};
QT_END_NAMESPACE