Search code examples
performancegraphicstexturessfml

Does the number of texture(s) used effect performance?


I am creating a small 2D game with SFML and met some warnings on the internet saying that I should use as few different textures as possible to achieve maximum performance.

What does the word use mean here? Is it just how many textures I have, or how many my sprites ask for per frame? Can I use a bunch of textures for the menu (like over 5), or only one while the game runs (the menu textures still exist) and not have performance impacts?


Solution

  • The amount of textures you use to render a single frame is what can cause performance impact.

    If you use only 5 textures, that means that as long as you draw them as efficiently as possible, you only need to switch between textures 5 times per frame.

    if you're drawing 10.000 objects, all of which could be drawn using the same single texture, it would be a terrible idea to use 10.000 textures that look exactly the same since you would be switching textures 10.000 times per frame for no reason.

    Switching textures isn't free ; it costs times and processor cycles. So especially in games, we want to do it as little as possible.

    Secondly, big textures take up a lot of space. As long as all your textures fit snugly into memory without any swapping or other tricks, you won't experience much impact from texture size.

    But once they become too big, this too starts to have impact.