Texture Resourcefulness?

Blitz3D Forums/Blitz3D Programming/Texture Resourcefulness?

ClayPigeon(Posted 2012) [#1]
Simple question, if two different meshes are loaded that use the same texture, will Blitz load the texture twice, or will it load the texture once and reuse it?


Yasha(Posted 2012) [#2]
It will load the texture once and reuse it.

Sometimes this can actually cause bugs, as you can't always rely on it to re-load a texture file that's been modified. Obviously this is a rare situation.


ClayPigeon(Posted 2012) [#3]
Thank you. Also, would this mean that if I load the textures manually (that I know the models use) before loading any meshes, they will adopt my preloaded textures? Or will they just load their own copies of the textures?


Yasha(Posted 2012) [#4]
There's just the one texture system, so they ought to be using the same copies.

Note however that when I say "once", I mean some internal engine structure that never gets passed out to the end user, the one that actually contains the pixel data, is loaded only once and then cached; you should get a different texture container object (i.e. the thing that the returned int handle addresses) every time. The engine is designed to be used as if it's loading the texture anew each time, with the caching being an optimisation: that's why the possible odd behaviour mentioned in post #2 is a bug.

Last edited 2012


Kryzon(Posted 2012) [#5]
Hmm, you should do some tests with the AvailVidMem() function. EDIT: that is, you should test several cases and see which one uses the least video memory.

I can only speculate how the internals work. I think it's safer to assume it's a conservative engine: any texture that's loaded is considered 'different', even if you load the same file several times.

- If you load two untextured meshes and then manually load a single texture and apply to them both, they both will reference the same texture - efficient.
- If you load two *textured* meshes, even if they reference the same texture file, the internal mesh loader will load\build the texture twice (once for each mesh you load) - superfluous.

Last edited 2012


Yasha(Posted 2012) [#6]
any texture that's loaded is considered 'different', even if you load the same file several times


Filename is one of the elements used to check whether the same texture has been loaded twice (trust me on this, I ...have inside information on the engine).

Last edited 2012