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.

  • Yuku Sugianto

    Hurray! Does this mean I can now draw shapes using the same batch?

  • Shylon

    Thanks so much, hope that decal uses ModelBatch too. good lucks

  • Esoteric Software

    ModelBatch and ShapeRenderer are still separate from SpriteBatch and PolygonSpriteBatch.

  • android apk

    Download many Android Paid, Mod & Free games, Launchers, Apps & Live Wallpapers Free for your Android Devices.
    http://appfordownload.blogspot.com