WebGL API is only available in main browser thread by default.

If you build with -s OFFSCREEN_FRAMEBUFFER=1, then WebGL will be
available from pthreads via the Emscripten WebGL runtime proxying all
the GL calls to the main thread.

If you build with -s OFFSCREENCANVAS_SUPPORT=1, then WebGL will be
available from pthreads via the OffscreenCanvas web api. Check
https://caniuse.com/#feat=offscreencanvas for availability.

Browsers are really bad at printing JS errors: the error "Cannot read
property 'enable' of undefined" should read something like "GLctx is
undefined in GLctx.enable(x) at function _glEnable". That is, there is
no active GL context in the current thread where the GL call was
attempted.

ti 2. kesäk. 2020 klo 0.34 Greg Baxes ([email protected]) kirjoitti:
>
> Hi everyone,
>
> I have been working successfully with Emscripten over the past few weeks 
> porting a fairly heavy C++ GLES2 3D terrain-rendering engine and small 
> glut-based application layer. It uses pthreads. Everything runs incredibly 
> well in Chrome! I have always seen the JS console throw the warning: 
> "Blocking on the main thread is very dangerous." To correct this 
> blocking-on-main issue and to be able to add websockets support to the 
> application, I have added the -s PROXY_TO_PTHREAD=1 flag to my build. With 
> this, the application crashes with a pthread error when it first encounters a 
> glGetString call. I have tried using the -s OFFSCREEN_FRAMEBUFFER=1 flag and 
> things get further, but then crash on a glTexImage2D call.
>
> To emulate the problem in a simpler context, I went back to my first simple 
> GLES2 test, standard es2gears.c, which I successfully built using:
>
> emcc -s WASM=1 -g es2gears.c -o demo.html
>
> Similarly with it, when I add the -s PROXY_TO_PTHREAD=1 and -s USE_PTHREADS=1 
> flags, it crashes the same way when it encounters a glEnable call, throwing 
> the same kind of error:
>
> "pthread sent an error! ... Uncaught TypeError: Cannot read property 'enable' 
> of undefined at _glEnable"
>
> So, I think the es2gears.c build is a good test case of the issue I'm seeing.
>
> Any suggestions to fix this? Is WebGL not able to run in a thread under main? 
> Thank you for any insights!
>
> --
> 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 [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/emscripten-discuss/b7bf634d-aaf2-4acd-988c-13058fdda1e5%40googlegroups.com.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/CA%2B6sJ-20pmv9GOQQwXA6iF5Q8GtaXP%2BrLu7fpK_yxABx1ym8Ow%40mail.gmail.com.

Reply via email to