jdryg / vg-renderer

A vector graphics renderer for bgfx, based on ideas from NanoVG and ImDrawList (Dear ImGUI)
BSD 2-Clause "Simplified" License
503 stars 55 forks source link

A few bugfixes, fontstash improvements, and REAME update. #27

Closed mcourteaux closed 5 months ago

mcourteaux commented 5 months ago

I recently switched SilverNode from NanoVG to vg-renderer, which was a fun experience. The API is good, and I like the library. I did however run into a few problems which I fixed along the way. This is a PR with all the fixes and improvements.

Notably, regarding fontstash, there is a problem with the way the kern array was constructed if the range of ASCII characters is huge. A font I was testing with has some ASCII letters in really low glyph indexes, and some other ASCII characters in really high glyph indices. The result was a range of 2500 glyphs. The kern array gets allocated as the square of that, which was super slow to both allocate and then fill the kern array with 2500*2500 looked up kern values.

So to fix this, I did four things:

Overall, I got font loading back from 500ms for the font to 3ms, doing these changes.