Off-screen canvas rendering

47 views
Skip to first unread message

Andrea M

unread,
Jul 2, 2024, 9:38:40 AM7/2/24
to emscripten-discuss
Hi,

This is uncharted territory for me so once again apologies if I am asking dull questions.

Is it possible for emscripten to handle 2 canvas elements? One would be used to render the GUI the other one for off-screen rendering of textures/images.

When I look at the Module singleton I get the impression is that there is meant to be at most one canvas element, i.e. `Module['canvas']`.

This is part of me trying to port Maplibre Native to emscripten, whereby the map would be incorporated into my Dear Imgui based GUI - however Maplibre does do async 'headless' rendering of the tiles beforehand.

I hope I have provided enough information, let me know if not.

Thank you!

Andrea

Alon Zakai

unread,
Jul 3, 2024, 2:30:55 PM7/3/24
to emscripte...@googlegroups.com
There is a currently-active context, which GL commands work on, and is stored on Module.canvas. But you can switch the current context between multiple ones. Specifically, when you create a context you can tell it which DOM canvas to use:


and you can set the current context with this:


However, some APIs may not fully support multiple canvases, I'm not sure.

- Alon


--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/683dd80c-85c5-42e6-a6d1-b441366a2564n%40googlegroups.com.

Alon Zakai

unread,
Jul 3, 2024, 2:32:19 PM7/3/24
to emscripte...@googlegroups.com
(Oops, I wrote Module.canvas there, but that's the canvas, not the context. Module.canvas is a way to set the default canvas.)

Andrea M

unread,
Jul 4, 2024, 1:44:30 PM7/4/24
to emscripte...@googlegroups.com
Thank you, will try it out!

You received this message because you are subscribed to a topic in the Google Groups "emscripten-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/emscripten-discuss/gAc7NY4J7DM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CAEX4NpQH%2B2znw_bU-OvYr5GRUOZgu9me%2BN4SgnvDELjq4zB9LA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages