Directly activate a WebGL context from JS

Aperta
#27,776 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
38/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
javascript, wasm

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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?
Lingua principale
C++
Stelle
27.8k
Fork
3.6k
Merge medio
1g 3h
PR unite (30g)
179

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di emscripten-core/emscripten

Tutte le issue di emscripten-core/emscripten

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.