fserb / canvas2D

Update Canvas 2D API
Other
148 stars 23 forks source link

[Mesh] are the objects necessary at all? #47

Open domenic opened 1 month ago

domenic commented 1 month ago

drawMesh() accepts Mesh2DVertexBuffer, Mesh2DUVBuffer, Mesh2DIndexBuffer, and Mesh2DColorBuffer objects. But those objects appear to be just thin wrappers over Float32Arrays.

Could it just accept Float32Arrays directly? Then those objects don't need to be defined.

If those objects existing is especially useful because they represent some sort of pre-computation that happens at construction time, then it would be good to explain that in the explainer.

fmalita commented 4 weeks ago

The intent is to facilitate implementation perf optimizations.

One common taxing use case is animating a huge number of vertices - which implies large buffers, some of which are static inter-frame (e.g. most of the time the vertex positions get updated while the UV mapping remains fixed).

Having a persistent handle allows implementations to store buffer data in a format/layer as close to the HW as possible, and to avoid copying/processing large amounts of static data redundantly for each frame. E.g. in the current Chromium prototype we elide two copies: re-drawing the same buffer is "free" down to the paint op serialization layer, and with some additional work we could push the data even further, all the way to the GPU process and potentially all the way to VRAM.

I'll look into adding additional context to the explainer.