SFML community forums

Help => Graphics => Topic started by: Stone on May 28, 2017, 01:51:03 am

Title: [SOLVED] Loading textures multiple times
Post by: Stone on May 28, 2017, 01:51:03 am
Hi,

I tried to find my answer through search but can't find exactly what I'm after just yet.
I'm wondering if sfml will load a texture multiple times if I have multiple different object instances that call the load function, asking for the same texture? Or will it detect that it has already been loaded and use the same texture? If not, then I assume loading the same texture multiple times is not the most optimal solution.

Given this scenario, would it be a good idea to create a sprite manager class, load all textures I need on game start, encapsulate them in sprites, store them, and then assign them to these object instances?

Thanks in advance.
Title: Re: Loading textures multiple times
Post by: Hapax on May 28, 2017, 02:08:23 am
If you ask the a file to be loaded and stored, it will be loaded and stored regardless of whether or not that file has been loaded and stored already.

If you wish to re-use resources such as textures, you can use some form of resource manager and make that accessible to all functions and objects that need them. However, for simple applications with a single resource, for example, you can load the file once and then pass a reference (or pointer) to that texture around to your functions.
Title: Re: [SOLVED] Loading textures multiple times
Post by: Stone on May 28, 2017, 02:13:17 am
That's the confirmation I needed.

Thanks for the quick answer :D