3 ms·
Why canvas2d when WebGL is much faster?
by bufferoverflow 6y ago
Why canvas2d when WebGL is much faster?
- leeoniya 6y agoa few reasons. the main one is that i know canvas and can implement everything i need, but would need to learn a lot of webgl to get any further than a basic PoC. browsers limit how many webgl contexts you can acquire. chrome is capped at 16, so if you need more than 16 charts on a page, you're out of luck. initializing webgl is actually slower than canvas 2d. it's difficult to draw lines of different thicknesses in raw webgl - it takes a lot of code. there are projects which abstract webgl nicely to provide canvas-like ergonomics, like Two.js, Pixi.js, or Canvas2DtoWebGL/litegl [1], but they would make the codebase much larger and more complex. [1] https://github.com/jagenjo/Canvas2DtoWebGL https://github.com/jagenjo/Canvas2DtoWebGL