benvanik/WebGL-Inspector

Dealing with multiple contexts

Opened this issue · 0 comments

I'm not sure what's really supposed to happen or if we should just ignore this case or what.

The issue seems to be if there's more than one webgl context used there are issues. It used to work somewhat though I'm not sure how since the old code would call

var hostUI = new gli.host.HostUI(result);

For each newly wrapped context suggesting that it made a separate UI per context.

I think that explains why the UI is slightly messed up on this page (http://twgljs.org/)

screen shot 2017-01-22 at 3 05 25 pm

but not this page (http://twgljs.org/examples/twgl-cube.html).

screen shot 2017-01-22 at 3 05 11 pm

The reason is there's 2 contexts on the first page, one for webglstats.com and another for the background where as the second page doesn't have webglstats.com

In any case the new issue is that a page that uses both webgl and webgl2 has big issues because all the windows/tabs/etc make a context and that context has to be compatible with whatever they're inspecting.

It's making me wonder how much I should refactor or if I should start over or what. I went through and tried to fix the webgl/webgl2 issue but then realized that won't fix it because the code currently expects it's inspecting one context. All the tabs/windows etc get passed the one context they are inspecting. To make it work with multiple contexts seems like there would need to be some global object or something that gets passed around the inspector uses to know which context is being displayed in the UI and then a drop down or something to let you select contexts.

Or I could just make it inspect only one context. In that case thought maybe it should generate a warning or alert (can't inspect multiple contexts) or maybe it should just inspect the first one with a warning or alert on any past that and not inspect them.

This brings up another issue in that the inspector makes lots of contexts. At least one for each BufferPreview, another for each TexturePreview, another for each SurfaceInspector. At the moment I think it makes at least 8 contexts. Since the browser only allows a limited number before it starts losing the context on old ones I'm wondering if the UI should just use one extra context every where if possible. I guess the hard part there is each of those UI elements has it's own canvas so there's probably no easy work around for that short of using one offscreen context and using 2d canvases in all those elements then render to the offscreen canvas and copy.

Here's another idea, only inspect 1 context but in some options somewhere let you select which one gets inspected. The easiest would be by number, the first one created would get inspected but you could set it to 2nd or 3rd etc. The issue there is with so much being async order might not be predictable. It probably is most of the time though so maybe that would be enough