> I wasn't able to find one that passes back and forth control over the
same canvas between a thread and the main thread.

This is something that web browsers do not natively support.

A canvas is accessible from the main browser thread, and from a Worker only
if using the OffscreenCanvas feature. But it cannot be accessed from both
simultaneously, or access quickly switched between Worker and a main thread.

One model might be to build with -pthread, and then do rendering on the
main browser thread, and then pthread_create() a background computation
thread, and then have the background computation thread send a message to
the main browser thread to pull whatever data it needs from the canvas over
to the background pthread. This message sending can be implemented
manually, or by using Emscripten's foo__proxy: 'sync' JS directives.

Another model would be to build with -pthread -sOFFSCREEN_CANVAS, and then
create the rendering context in one worker, and the background computation
thread in another worker. Then you can use possibly faster synchronization
primitives to ask data from the rendering thread over to the background
thread, since the main browser thread cannot synchronously wait to receive
any messages, only Workers can.


On Mon, Jul 31, 2023 at 5:27 PM 'Dieter Weidenbrück' via emscripten-discuss
<emscripten-discuss@googlegroups.com> wrote:

> Understood, thanks. So PROXY_TO_THREAD doesn't make sense for my usecase.
>
> All I want to do is
> - draw WebGL content in one thread (could be the main thread because
> rendering doesn't need much time, and there is no animation loop)
> - do some work in the background that makes use of the same canvas
> including the uploaded geometry for depth calculations
> I am struggling to find the right way through all the context and proxy
> options. Any suggestions would be very welcome. The test cases are helpful,
> however, I wasn't able to find one that passes back and forth control over
> the same canvas between a thread and the main thread.
>
> --
> 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-discuss+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/emscripten-discuss/a36c042f-3b33-4f52-ad18-75ca480394e7n%40googlegroups.com
> <https://groups.google.com/d/msgid/emscripten-discuss/a36c042f-3b33-4f52-ad18-75ca480394e7n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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-discuss+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/CA%2B6sJ-1geznk8kcV1gbGtRB2PG7QF%3D3eFF0MuB%3D%3DMJW08mTyeQ%40mail.gmail.com.

Reply via email to