Canvas vs OpenGL for 2D Games

After having spent 1 month rewriting one of our 2D games from Canvas to OpenGL we got the idea we should have had before starting the work: To investigate if this actually would give a higher FPS or not. The short answer is “no”. The long answer is that it (big surprise) depends alot on the device. Wanted to post our findings here. Maybe someone can learn from them or has some comments.

Executive summary

It is a world of compromise:

  • The high-end, 1Ghz devices out there have way better performance on Canvas than OpenGL
  • The low-end (G1, dream, hero,…) devices have best performance on OpenGL
  • If you start doing rotations, scaling, applying semi-transparancy OpenGL gains on Canvas

Test Cases

You can download the test here:

http://logisoftgames.com/downloads/

It is an extension of Chris Pruetts Sprite Method Test. You can also find data from the phones we ran it on - G1, Nexus 1, Droid.

If you are in posession of another device we would be VERY interested in having you run the test on that device and let us know the output (found in LogCat). Just install the APK and press “Run Batch”. It will go for a while - up to 2 hours. Could be cool to get more data to get a clearer picture of the situation.

/Martin

Interesting stuff, I had naturally assumed that openGL would be faster on all hardware.

Actually, this suggests it was totally worth it. You made the worst case scenario less bad. I.e. you can now draw a bit more and it will still work fine on both generations of devices.

The best case scenario is usually not very interesting. E.g. in a first person shooter no one cares if you get 200 or 1000 frames when facing a wall.

Yes that is a good point oNyx. Forgot to mention the devices running a Software renderer (HTC Tattoo among others). They are almost 5-10% of our players. They emulate hardware acceleration in software and thus have pretty poor OpenGL performance. On Tattoo the framerate was reduced to 10 which is not very playable.

I think if you want to give all players the best possible experience it is a good idea to implement both a software renderer and an OpenGL renderer and make an automatic choice on startup which the user can alter in a settings page in case the app chose poorly.