How to create a webgl2 canvas in emscripten

450 views
Skip to first unread message

Brian Gavin

unread,
Jun 26, 2017, 5:09:04 PM6/26/17
to emscripten-discuss
Hi everyone,
I want to create a webl2 canvas.   I create my canvas doing something similar to emscripten/tests/test_egl.c   I pass the linker flag -s USE_WEBGL2=1 

I create a context setting the attributes like this to create a webgl version 1

EGLint contextAttribs[] =
{
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
 I would assume that I would change to this EGL_CONTEXT_CLIENT_VERSION, 3 ?

I would like to create a webgl 1 canvas since some platforms do not support WebGL.


What is the correct way to do this?

Thanks,
Brian Gavin

Floh

unread,
Jun 27, 2017, 9:00:50 AM6/27/17
to emscripten-discuss
From glancing over the EGL wrapper code here: https://github.com/kripken/emscripten/blob/master/src/library_egl.js#L270

...it looks to me like there's no support for setting up a WebGL2 context.

You could use the emscripten_webgl_*() functions instead of EGL, these map directly to the HTML5 APIs, for instance here's my code to setup a WebGL2 context, and if this fails fall back to WebGL1:


(you still need to link with "-s USE_WEBGL2=1")

Cheers,
-Floh.

Brian Gavin

unread,
Jun 27, 2017, 9:41:44 AM6/27/17
to emscripten-discuss
Thanks for the information Floh :)

Brian Gavin
Reply all
Reply to author
Forward
0 new messages