2d vector graphics speed
August 31, 2006Fast rendering of simple 2d vector graphics such as maps shouldn’t pose a problem for modern computers. They even do 3d pretty good. However, I was looking for a solution that doesn’t rely on the GPU since it is already more than busy in my applications. The additional requirements were anti-aliasing and portability to Windows, Linux and Mac OS X. This reduced the solution space significantly and only two candidates remained: Cairo and Anti-Grain. Cairo is quite well known for being the vector graphics library. Quite a lot of projects are using it, and the documentation is quite reasonable. Implementing a simple map renderer with it was a breeze as the interface is extremely clear and the implementation just does the right thing. But (literally) at the end of the day I noticed that Cairo seemed somewhat slow. The complete break down came when I plugged it into the a real-time terrain rendering system where it had to draw about a hundred concave polygons on about a hundred map tiles of 256×256 each. When I had a look at the profiler output, there was nothing but cairo taking up CPU time. The decompression of a few GB satellite imagery came virtually for free. Cairo seems to have a special fondness for 64bit integer divisions, but I didn’t investigate this issue any further. On the next day I replaced it by Anti-Grain which comes with an incomplete introduction and no reference manual at all. The interface is very low-level, but the numerous examples provide enough material to get a grip on it if you stay focussed. As soon as you get a rough idea of what’s going on, you are rewarded with a really fast renderer. To cut a long story short: If you just need vector graphics, use Cairo. If you need them fast and if you are willing to trade a high level interface and a good documentation for speed, go for Anti-Grain. Btw, I didn’t notice any difference in quality on the first sight, both produce very good looking images.