Help With Drawing To Canvas In Pthreads

231 views
Skip to first unread message

Andrew Lay

unread,
Sep 2, 2022, 7:14:44 AM9/2/22
to emscripten-discuss
Can someone please help with out?

I am having trouble correctly drawing to Canvas on Pthreads.

There is nothing being drawn to the canvas on the screen while the application is running, however if I freeze the code with the Dev tools in the debugger the Canvas updates.

I have created an example in this git hub repo: 

https://github.com/alayGit/DummyEmscriptenCanvasForumExample

It is not pretty but I hope it will demonstrate the issue.

If anything is not clear please let me know.




Sam Clegg

unread,
Sep 2, 2022, 8:01:01 AM9/2/22
to emscripte...@googlegroups.com
Seems likely related to `explicitSwapControl`, `renderViaOffscreenBackBuffer` and `proxyContextToMainThread` which are part of `EmscriptenWebGLContextAttributes`:

Have you read the documentation related to those?



--
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/94127203-44fc-45f5-9fcc-402a231b49e9n%40googlegroups.com.

Andrew Lay

unread,
Sep 2, 2022, 8:46:18 AM9/2/22
to emscripte...@googlegroups.com
Hi Sam,
Thank you for your quick response.

I have seen the struct params that you speak of, but all of the examples that I have seen relate to GLES2 C api.  For example I looked at 'webgl_draw_triangle.c' example file in the Emscripten folder.

When I saw the complexity of the library, I thought it seemed like overkill for what I wanted to do, simply draw a buffer of rgba values to a canvas. 

This is why I tried to call the ordinary JavaScript API from an Emscripten PThread. See here: https://github.com/alayGit/DummyEmscriptenCanvasForumExample/blob/main/Emscripten/EmscriptenCanvasWorker.cpp

I am wasting my time trying to do things this way?

Should I use the GLES2 library, or are the things you pointed me too and the stuff in the draw triangle example needed for the JavaScript API method too?

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/ie7N7EL1atk/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/CAL_va2_b7L7AtRNzOKiH9V4L4HbHc-TxBzf7Sq2c8iy0xzqL9Q%40mail.gmail.com.

Sam Clegg

unread,
Sep 5, 2022, 2:56:57 PM9/5/22
to emscripte...@googlegroups.com
On Fri, Sep 2, 2022 at 5:46 AM Andrew Lay <andrew...@gmail.com> wrote:
Hi Sam,
Thank you for your quick response.

I have seen the struct params that you speak of, but all of the examples that I have seen relate to GLES2 C api.  For example I looked at 'webgl_draw_triangle.c' example file in the Emscripten folder.

When I saw the complexity of the library, I thought it seemed like overkill for what I wanted to do, simply draw a buffer of rgba values to a canvas. 

This is why I tried to call the ordinary JavaScript API from an Emscripten PThread. See here: https://github.com/alayGit/DummyEmscriptenCanvasForumExample/blob/main/Emscripten/EmscriptenCanvasWorker.cpp

I am wasting my time trying to do things this way?

I would stick to using the emscripten opengl implementation, unless you really know what you are doing and want to get into the weeds.  Otherwise, you likely end up running into issues that emscripten has already solved in its implementation.   I imagine this is one of those cases but I'm not an expert on this part of the code.

 

Andrew Lay

unread,
Sep 6, 2022, 11:07:33 PM9/6/22
to emscripte...@googlegroups.com
Hi Sam,
Thanks for replying. When I have time I will try the Emscripten way.
I will let you know how I go.

Andrew Lay

unread,
Sep 9, 2022, 7:14:54 AM9/9/22
to emscripten-discuss
Hi Sam,
No luck with this approach either. Same problem.
I outlined it in this forum. https://github.com/emscripten-core/emscripten/issues/17816

Let me know if you have any ideas.

Also can you let me know if there is a better place to get technical assistance?

Am frustrating people in the way I write my questions, causing people to skip over them?

Thanks,
Andrew Lay

Andrew Lay

unread,
Sep 9, 2022, 7:18:37 AM9/9/22
to emscripten-discuss
Oh, by the way, I am assuming I don't need the 'renderViaOffScreenBackBuffer' as I am using an offscreen canvas. I looked at the other two attributes though.

Sam Clegg

unread,
Sep 13, 2022, 9:39:03 AM9/13/22
to emscripte...@googlegroups.com
On Fri, Sep 9, 2022 at 4:14 AM Andrew Lay <andrew...@gmail.com> wrote:
Hi Sam,
No luck with this approach either. Same problem.
I outlined it in this forum. https://github.com/emscripten-core/emscripten/issues/17816

Let me know if you have any ideas.

Also can you let me know if there is a better place to get technical assistance?

Am frustrating people in the way I write my questions, causing people to skip over them?


No, this forum, and github issues are the recommended support channels and your question seem reasonable to me :)
You could also try to discord server.

I myself have very little knowledge of how the offscreen canvas stuff works so I don't have any easy answers for you I'm afraid.  One thing I would recommend is looking through `test/test_browser.py` for examples/tests that use the offscreen canvas setting.  Do they work as expected for you?  

cheers,
sam

 

Andrew Lay

unread,
Sep 14, 2022, 12:46:01 AM9/14/22
to emscripte...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages