[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Public WebGL] using the same context with multiple canvases



I'd like to pursue this idea further that Florian brought up which is that, for drawing to multiple canvases, rather than share resources across contexts it would be much nicer to just be able to use the same context with multiple canvases. Something like

    ctx1 = canvas1.getContext("webgl");
    ctx1.clearColor(0,1,0,1);
    ctx1.clear(gl.COLOR_BUFFER_BIT);
    canvas2.setContext(ctx1);
    ctx1.clear(gl.COLOR_BUFFER_BIT);

Clear's both canvas1 and canvas2 to green

Issues: Under the current WebGL the only way to setup a canvas is by calling getContext(..., contextCreationParameters). Whether the canvas is RGB or RGBA, has depth or stencil, is premultiplied or not, has it's backbuffer preserved or not, etc..

Which leads to some questions.

Is the current API okay. You'd create 2 contexts still but just use one of them as in

    ctx1 = canvas1.getContext("webgl". { alpha: true } );
    ctx2 = canvas1.getContext("webgl". { alpha: false } );
    ctx1.clearColor(0,1,0,1);
    ctx1.clear(gl.COLOR_BUFFER_BIT);
    canvas2.setContext(ctx1);
    ctx1.clear(gl.COLOR_BUFFER_BIT);

After the cal to cavnas2.setContext(ctx1) what does ctx2 do? Does it still draw to cavnas2 as well? Does it get GL_INVALID_FRAMEBUFFER_OPERATION if a draw/clear function is called and no FBO is bound? Does it become lost? What does ctx1.canvas reference and what does ctx2.canvas reference? What does ctx1.getContextAttributes() return? The attributes for canvas1 or canvas2? 

I think arguably being able to setContext on a canvas is the right way to solve drawing to multiple canvas with the same resources but there are some unfortunate existing API choices.

Thoughts?