1glayfan Posted March 20, 2018 Share Posted March 20, 2018 Hello, In webgl app in general, assuming running on multi-core cpu, are the apps multi-threaded ? If so, technically your callback function (like from user input) can be executed by a thread which is different from the one executing the main rendering loop. Then is it not safe to edit a mesh directly in the callback ? Like disposing a mesh in the callback when the mesh is still in the scene being rendered continuously. Does babylonjs provide the thread-safe synchronization for you, or you need to do this yourself ? Thanks Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted March 20, 2018 Share Posted March 20, 2018 Hi @1glayfan Javascript is single-threaded Quote Link to comment Share on other sites More sharing options...
Guest Posted March 20, 2018 Share Posted March 20, 2018 Unfortunately Quote Link to comment Share on other sites More sharing options...
1glayfan Posted March 20, 2018 Author Share Posted March 20, 2018 Even in webgl 2.0? Hmmm... Quote Link to comment Share on other sites More sharing options...
Guest Posted March 20, 2018 Share Posted March 20, 2018 Yep Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted March 20, 2018 Share Posted March 20, 2018 https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers Though... if you wanna kinda simulate multi thread. Quote Link to comment Share on other sites More sharing options...
1glayfan Posted March 20, 2018 Author Share Posted March 20, 2018 Thanks for the web worker info. So it looks to me that web workers are indeed multi-threaded but run in different space from your web page so it can't access the dom and presumably the gl context. So this won't help in terms of parallelizing the rendering, but at least we can use them for other computation like doing AI or IO-bound ops like launching post/get to web services etc. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted March 20, 2018 Share Posted March 20, 2018 no it can not, but you can create glContext with some hackyness on the separate space, parse the context to a binary array pass that to your dom, the effectiveness of that may be questionable. But yeah webworkers are for your IO ops. Quote Link to comment Share on other sites More sharing options...
1glayfan Posted March 20, 2018 Author Share Posted March 20, 2018 What I meant to say was the web workers can't access the Dom nor webgl context. But similar to what you said, I believe it's technically possible to split the 3d computations into several web workers and combine the results in the end and feed it to the main rendering thread. Right?? Still an improvement than single thread for everything. Pryme8 1 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted March 20, 2018 Share Posted March 20, 2018 You can simulate multithread with timeout functions as well. (it has its limits) Quote Link to comment Share on other sites More sharing options...
1glayfan Posted March 20, 2018 Author Share Posted March 20, 2018 Ah yes I tried that. At the time I thought it was running on real, separate thread. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted March 20, 2018 Share Posted March 20, 2018 https://en.wikipedia.org/wiki/OpenCL might be what you would look into. 1glayfan 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.