New Android app: Snowflakes live wallpaper

Published on 2012-11-24
Tagged: 3d android opengl

Today, I launched my first Android app! It's a live wallpaper which renders falling snowflakes using OpenGL ES 2.0. You can download it at Google Play.

The actual snowflakes are drawn with a particle system. The animation is, unfortunately, mostly done on the CPU side (in Java). Last time I wrote a particle system with OpenGL, there was a trick where you could store all of the particle data in a texture, and write the update code in a shader. You could then update the particles' state by rendering into another texture, which became the new particle texture. In a separate pass, the particles were billboarded, and the vertex attributes were written into a wider texture, which was copied into a vertex buffer object using the pixel buffer object APIs. It was a bit of a hack, but it let me draw 32K particles on 2006 hardware without dropping frames. The entire particle system was done on the GPU side.

Since then, OpenGL 4.0 has added transform feedback, which is a much more elegant and flexible way to do the same thing. Unfortunately, OpenGL ES 2.0 supports neither the PBO APIs nor the transform feedback APIs, so you're basically stuck updating the particles on the CPU side. It's not so bad though, as long as you keep the update calculations really simple, and the particle count low. If you want to get fancy, you could write the update routines in native code and use NEON where possible (ARM SIMD instructions). Having the particle state stored in system memory is fine because mobile devices don't have discrete GPUs, so it's probably as fast as anything else.