Directly activate a WebGL context from JS

Abierto
#27,776 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
38/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
javascript, wasm

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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?
Lenguaje dominante
C++
Estrellas
27.8k
Forks
3.6k
Merge medio
1 d 3 h
PR fusionados (30 d)
179

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de emscripten-core/emscripten

Todos los issues de emscripten-core/emscripten

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.