playing with Cairo
I was recently reading a brilliant post A first-person engine in 265 lines by Hunter Loftis, and instantly wanted to port it to Perl. After doing half of work, though, I figured out that the original code uses alpha blending technique to achieve wall shading, rain, and drawing images with 8-bit transparency channel.
I've used Prima to write the port, even though it doesn't support alpha channel, because native x11 API doesn't do that. Googling led me to XRender that can do the stuff, but that sounded too heavy. However Cairo (which is also used by firefox to implement Canvas rendering) is exactly the tool for the job. So I needed to spend some days creating a bridge between Prima and Cairo, and here it is on github.
The programming itself went unexpectedly smooth, because of the Cairo's API design quality .. Unfortunately the perl demo resulted to be very slow, because perl's own speed - profiling shows that pure-perl calculations eat the biggest part of speed. The next biggest CPU eater is a set of calls to Cairo that draw rain drops - each drop requires two calls, $cairo->rectangle(..) and $cairo->fill and that is also expensive.
So I wonder if there can be done something to it. Any ideas?