请求 WebGL2 时,任何浏览器都会给我一个 WebGL1 上下文 (emscripten)

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

我正在尝试接收 WebGL 2.0 上下文。 我正在使用 -s USE_WEBGL2=1 -s MIN_WEBGL_VERSION=2 并尝试添加 -s FULL_ES3=1。编译既不给出警告也不给出错误。我用的是 GLES3/ headers.

此外:

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;

Chrome 控制台中的结果:

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

Firefox 中的结果非常相似。

我已经搜索了大约一个星期如何正确处理这个问题。

这看起来有点像 [0],请尝试将 -lGL 添加到您的 link 标志中。

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

所以最后我什么都试过了,找到了解决办法。我的问题是,我一直在使用 makefile 进行编译,并且我的 .cpp 转换为具有所有适当标志的 .o 文件,但是在链接器步骤中,您还需要指定这些标志,否则 WebGL2.0 不会可用。

我只是 运行 遇到了这样的问题。难道你需要在 Emscripten 中编辑 library_browser.js 来给你一个 'webgl2' 上下文而不是 '2d'?

编译时写getContext('2d'),编译前必须在library_browser.js中编辑成getContext('webgl2',yourSettings)