-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow customizing canvas on Emscripten #5260
Comments
I had patches a while ago to allow specifying the canvas selector using I think I suggested somewhere that there could he a hint for the default canvas selector, but that would have the same problems unless you also set (The default canvas "id" is |
Oh, it is? I'm only digging into those APIs and having hard time figuring out which methods are new and which are deprecated, or how
Yeah it works with the default shell, but not when you want to ship a reusable and isolated JS module - that's when Do you have plans to revive those patches? They seem promising. |
Btw, I've noticed that SDL doesn't work with OffscreenCanvas mode either (emscripten-core/emscripten#13652). I wonder if that's for the same reasons - not supporting custom WebGL contexts - or a separate issue? |
I see the same, here's the error:
@Daft-Freak is that branch that you linked to the most up to date, or do you happen to have something newer I could tinker with? |
Newer branch: https://github.com/Daft-Freak/SDL/commits/create-window-from-2 (commits up to adding the hint should be useful here, the rest is WIP multi-window stuff) Has some issues in cursor/framebuffer handling... |
Wow, thanks, this works! I was able to compile my SDL application which previously was failing w/ PROXY_TO_PTHREAD/offscreen canvas when it tried to configure GL options. I only had to make a single tweak to your branch: https://github.com/Daft-Freak/SDL/blob/a93fc312a87cc2a94ce19bedec8ba846a6ee50e4/src/audio/emscripten/SDL_emscriptenaudio.c#L259 should use Without that change, SDL would fail at init (unless you excluded the audio subsystem).
Didn't see any issue with custom cursor or mouse lock FWIW. this pr recently fixed some cursor issues. I'm gonna point my local SDL fork to this for now and keep playing with it. But so far... this is beautiful. So good to get off that main thread! |
Ah nice, skipping the EGL layer also fixes thread/proxying issues. (The cursor issues are that everything else is going through the html5 API/selectors and cursors are still using |
there is no need to add another sdl call, you can pass the canvas id in ENV (and calling |
Yes, adding a hint sounds like a good idea. Feel free to create a PR with the relevant changes. |
after: 24d7f9c Switch code to SDL2. fixes: webp_wasm.js:1 Uncaught TypeError: Cannot read properties of null (reading 'addEventListener') at Object.registerOrRemoveHandler (webp_wasm.js:1:101330) at registerMouseEventCallback (webp_wasm.js:1:154227) at _emscripten_set_mousemove_callback_on_thread (webp_wasm.js:1:155015) ... The SDL2 port forces the canvas id to '#canvas': https://github.com/emscripten-ports/SDL2/blob/324df6865ae3c7d194ed233a86867c48ec96c6a3/src/video/emscripten/SDL_emscriptenvideo.c#L210 This change maps '#output_canvas' to this entry in specialHTMLTargets[]: https://emscripten.org/docs/api_reference/html5.h.html libsdl-org/SDL#5260 & emscripten-ports/SDL2#130 may also be related. Change-Id: I26f4aa22b9d68b0fc45b83edfe6fe074b59a82a7 Test: emscripten 3.1.16
Emscripten allows customizing the canvas element used for graphics via the
Module.canvas
property.However, in SDL the canvas ID is currently hardcoded:
SDL/src/video/emscripten/SDL_emscriptenvideo.c
Line 204 in 71e06a5
This results in undecipherable errors during start-up when
#canvas
element does not exist on the page:Looking further through Emscripten docs, I see that
#canvas
used to mean "whatever element is currently set as the default canvas" in the past, and I'm guessing SDL's hardcoded string was added before that behaviour has changed:Indeed, compiling with
-s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=0
works around the issue and draws to the canvas set inModule.canvas
instead of trying to find#canvas
element on the page.However, this is just a workaround and, I believe SDL should support the non-deprecated behaviour and respect canvas customizations set in
Module.canvas
or viaemscripten_webgl_make_context_current
.cc @Daft-Freak @juj @kripken
The text was updated successfully, but these errors were encountered: