PolygonSpriteBatch implements Batch

We have a little-known class called PolygonSpriteBatch which renders textured polygons. This can be used to save fill rate by avoiding drawing transparent pixels. A while ago we refactored SpriteBatch to use an interface called Batch (which should probably be called QuadBatch). This lets you change the SpriteBatch implementation, which is pretty neat. Today I made PolygonSpriteBatch implement Batch, which means you can use it anywhere that takes a Batch.

For example, you can now use scene2d with a PolygonSpriteBatch. Why do that? Maybe inside scene2d you are using Spine skeletons that have meshes. Rendering meshes requires PolygonSpriteBatch, so by using a PolygonSpriteBatch for the whole scene you won’t have to switch back and forth between SpriteBatch and PolygonSpriteBatch, which would cause many batch flushes.

There are some performance differences between SpriteBatch and PolygonSpriteBatch. SpriteBatch uses indices set up for quads, so it only needs to transfer vertex colors and positions to the GPU each frame. PolygonSpriteBatch has to transfer indices, vertex colors, and positions. How much does this affect things? It depends, so give it a try!

Edit: Cuellarjmcg reports the performance difference is minimal, even on an antique device.

4 thoughts on “PolygonSpriteBatch implements Batch

Leave a Reply

Your email address will not be published.