Directly activate a WebGL context from JS

未关闭
#27,776 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
38/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
javascript, wasm

调研方向

Start with test/browser/test_preinitialized_webgl_context.c and trace the existing preinitializedWebGLContext and emscripten_webgl_context_create() path. Compare that behavior with the --pre-js makeWebGL2ContextCurrent extension described here. Done should establish whether direct activation and multiple dynamically created WebGL contexts can be supported through a clear, tested API.

由索引模型根据 Issue 内容生成。

描述

Using an already existing WebGL context requires a somewhat confusing dance with preinitializedWebGLContext.

To activate a GL context (as in https://github.com/emscripten-core/emscripten/blob/25c255b66fe553a4bff3761cbeb7add8f1583d25/test/browser/test_preinitialized_webgl_context.c):

  1. set preinitalizedWebGLContext on module creation
  2. call emscripten_webgl_context_create(), necessarily passing a valid canvas element reference and context attributes. These arguments will not really be used, this function returns (a handle to) the preinitializedWebGLContext.
  3. call emscripten_webgl_make_context_current(handle)

This appears more confusing than necessary. Also, this process does not seem to allow using the module with more than one WebGL context. This is something that we'd like to, to reuse our module to render into multiple (dynamically created) canvases.

To work around this, we've extended the Module with this --pre-js file.

// Activates the given WebGL context for rendering. Does _not_ register a context handle for the context and thus it cannot be referenced from WASM.
Module.makeWebGL2ContextCurrent = (ctx) => {
    GL.currentContext = {
        handle: -1, // unused?
        attributes: {}, // unused?
        version: 2,
        GLctx: ctx
    };
    Module['ctx'] = GLctx = GL.currentContext?.GLctx;
}

With this, we don't need any of the steps 1. - 3. above; we only call module.makeWebGL2ContextCurrent(gl) for our canvas and proceed to call into the WASM to render.


Questions:

  • Is there a pre-existing functionality that already achieves what our --pre-js extension does?
  • If not, would it be useful to add this to emscripten directly?
主要语言
C++
星标
27.8k
派生
3.6k
平均合并
1 天 3 小时
30 天内合并 PR
179

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

emscripten-core/emscripten 的其他 Issue

查看 emscripten-core/emscripten 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。