Best 2D sprite animation performance

Whats the best way to do or make 2D animations using sprites?

I am thinking about having a sprite sheet that has all the frames needed for it’s animation.
Then just changing what frame to look at when I’m actually running the animation after X amount of time.

The only other way I can think of doing it is to load in all the frames as textures and the bind them,
but that’s like shooting my self in the foot when it comes to performance

Whats the best way to do this for the best performance in openGL?

SpriteSheets, yes. And if possible combining SpriteSheets on a TextureAtlas to reduce texture swapping even further.

Bach

These days a texture atlas is only one small part of the equation. You also need to look into VBOs, mapped byte buffers, state change minimisation, and asynchronicity.

Cas :slight_smile:

Could you explain what you mean :smiley: ?

I only know what VBOs and possibly asynchronicity are if you talking about making a multi-threaded program :frowning:

Plenty of stuff here on JGO about VBOs and performance if you do some searches.

In a nutshell: VBOs are for writing your sprite vertex geometry in to. You can write into a VBO while the GPU is drawing sprites; there’s your asynchronicity.

Cas :slight_smile:

princec is right if you want bleeding-edge performance. However, vertex arrays are still very fast (surely fast enough for most 2D games). VBOs are generally faster. Mapped VBOs seemed to be the fastest, aside from GL3 solutions like instancing, texture arrays or geometry shaders.

If you want to start writing your own sprite batcher, you have a bit of work in store for you. Especially if you choose the programmable pipeline (which will give you much more power and flexibility).

Understanding Textures is an essential first step. You can see my intro to sprite batchers here. The API source code is relatively minimal and will give you all you need for a high performant (shader based) sprite batcher.