Firestorm
Firestorm

Reputation: 157

When requesting WebGL2, any browser gives me a WebGL1 context (emscripten)

I am trying to receive a WebGL 2.0 context. I am using -s USE_WEBGL2=1 -s MIN_WEBGL_VERSION=2 and have tried adding -s FULL_ES3=1. Compiling gives neither warnings nor errors. I use the GLES3/ headers.

Furthermore:

EmscriptenWebGLContextAttributes atrs;
emscripten_webgl_init_context_attributes(&atrs);
atrs.alpha = true;
atrs.depth = true;
atrs.stencil = false;
atrs.majorVersion = 2;
atrs.minorVersion = 0;

emctx = emscripten_webgl_create_context(id, &atrs);
emscripten_webgl_make_context_current(emctx);
std::cout << "GL_VERSION=" << glGetString(GL_VERSION) << std::endl;

The result in Chrome's console:

OpenGL ES 2.0 (WebGL 1.0 (OpenGL ES 2.0 Chromium))

And a very similar result in Firefox.

I've been searching for about a week already how to get this right.

Upvotes: 1

Views: 1406

Answers (3)

Noah Cohn
Noah Cohn

Reputation: 1

I just ran in to an issue like that. Could it be that you need to edit the library_browser.js in Emscripten to give you a 'webgl2' context rather than '2d'?

It writes getContext('2d') when compiling and has to be edited to getContext('webgl2',yourSettings) in library_browser.js before compiling.

Upvotes: 0

Firestorm
Firestorm

Reputation: 157

So finally I have tried everything, and found the solution. My problem was, that I had been compiling with a makefile, and that my .cpp turned to .o files with all the appropriate flags, but in the linker step, you also need to specify those flags, or WebGL2.0 won't be available.

Upvotes: 3

Zhi An Ng
Zhi An Ng

Reputation: 89

This looks a bit like [0], try adding -lGL to your link flags.

[0] https://github.com/emscripten-core/emscripten/issues/12118

Upvotes: 0

Related Questions