- From: Greggman <notifications@github.com>
- Date: Thu, 17 May 2018 00:47:41 -0700
- To: w3ctag/design-reviews <design-reviews@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <w3ctag/design-reviews/issues/141/389776444@github.com>
I feel like the problem with the current APIs are they ignore what's really happening under the hood. That canvas are just pairs of textures attached to framebuffers. WebGL just followed the path of least resistance and though of canvases like OS windows. Parts of if it were not actually designed, they were just done without thinking about it based on what 2D canvas was doing (if thought was given I'm sorry I'm just trying to provoke some thought now). In particular the way contexts work right now it was assumed every canvas should have it's own context. Did anyone question that? It would have been just as valid to create contexts separately from canvases and then bind that context to whatever canvas you currently want to render to. If important it could have been which ever context is first bound to that canvas is the only context that can ever be bound to that canvas but that the same context can be used with as many canvases as you want. That design would have solved sharing resources and broken absolutely nothing. So it seems like we now have a chance to fix that but instead we're going down the path of "follow what was undesigned before because tradition". Imagine the WebGL API was this ``` const gl = new WebGLRenderingContext(); gl.bindCanvas(someCanvas); // we're now rendering to someCanvas gl.draw(...) gl.bindCanvas(someOtherCanvas); // an implicit GL flush, and copy/flip to someCanvas happens here gl.draw(...); // renders to someOtherCanvas ``` Similarly people have wanted to be able to not commit the changes (no implicit swapbuffers/resolve). So `commit` could have been part of the original API ``` const gl = new WebGLRenderingContext(); gl.bindCanvas(someCanvas); // we're now rendering to someCanvas gl.draw(...) g.commit(); // does swapbuffers/resolve for someCanvas gl.bindCanvas(someOtherCanvas); gl.draw(...); // renders to someOtherCanvas g.commit(); // does swapbuffers/resolve for someOtherCanvas ``` That would have solved all of the resource sharing issues. It would also have solved rendering over multiple frames without having to manually render to a framebuffer. Note that native apps expect this behavior, nothing shows up until they call swapbuffers. They don't have that option in the current WebGL API and instead have to write other solutions. If that was how WebGL worked before workers would the suggested APIs for workers change? My point is that canvases are just really 2 textures. A displayBuffer and a drawingBuffer. They don't really need a context per canvas and they don't need to implicitly swap. We went that way mostly because we followed canvas 2d. If we were to imagine a past where we had chosen this other path would we be coming up with better/simpler solutions? I worry about an API where I'm told "browsers will figure out magic behind the scenes to make things performant" when it's possible a different API could remove the magic and just be performant by design. -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/w3ctag/design-reviews/issues/141#issuecomment-389776444
Received on Thursday, 17 May 2018 07:48:05 UTC