Hacker News new | ask | show | jobs
by leeoniya 2232 days ago
you may find this interesting:

"Why are 2D vector graphics so much harder than 3D?"

https://blog.mecheye.net/2019/05/why-is-2d-graphics-is-harde...

1 comments

I think I've read that article already! Computer graphics has always been an interest of mine, and I've written 3D engines before.

Admittedly, not a 2D text engine, but I keep up with the research.

The difference between the blog post you linked and a programmer's text editor is night & day.

There's a huge difference between arbitrary 2D graphics and fixed-width text rendering. The former has crazy complex corner-cases, and also has to deal with all of the fun things 3D engines do such as arbitrary transformations and transparency.

A web browser has to deal with the arbitrary case, which is why Firefox's new Rust-based renderer took so many years of hard work to write. It's a complex beast.

A fixed-width text editor is more or less just putting sprites on a grid. Sure, there's subpixel alignment, antialiasing, and maybe even ligatures, but this is nothing really in comparison. They're all "local" issues where typically at most a few hundred pixels are affected per character update.

Or to put it another way, text editor rendering is "embarrassingly parallel". The screen can be split up into lines or char blocks and each can be drawn separately and updated individually when modified.

Compare this to 3D games that are pumping out 4K pixels every frame, updating all of them every time. Web browsers do the same thing, they have to update the entire screen every frame in a lot of scenarios and can manage this at 60 Hz too. Firefox and Chrome both can do this now for much more complex scenarios than text editing.

We are very sensitive when it comes to text. 3d games doesn't need to be accurate, compared to text that needs sub pixel perfection. 3d is closer to the metal and thus faster. Ive made a web based text editor that parse the entire file on each key press to get language intellisense and semantic coloring, that however only takes 1ms. Rendering one full screen of text takes around 10ms. That's how slow text rendering is. Taking into account random GC pauses and graphics layering overhead there's little budget left for parenthesis matching highlighting, auto completion suggestions, auto quote insertion, spellchecking, etc.