Sign in to follow this  
blaze02

texture loading and waiting

Recommended Posts

So now that it is unfeasible to load all textures before the game starts, how do professional games handle textures? I've noticed in Halo 2 that sometimes textures do not get loaded and objects are rendered in a black color. My idea: Have a class that spawns threads to load textures and keeps track of all loaded textures. If a texture is unused for x seconds, unload the texture. One method will need to return textures based on some texture ID (or load the texture if it was previously unloaded). Of course this will all require threading / mutexes, but nothing too complicated. The only downside is that loading textures on the fly will generate misses (requesting a texture that is not loaded). The game can handle this by not drawing the object until the texture is loaded. Or, the game can "ping" textures before use and during their lifetime. Anybody see a problem with this technique, or is this basically what the industry uses?

Share this post


Link to post
Share on other sites
To start, I've no idea what the industry uses.

Personally, I'd at least make straight blocking texture loads available. Thread setup and teardown is not trivial, and often more work than just loading the texture. Using thread pools can minimize the overhead, but complicate matters a bit.

Again personally, I just render a default texture [solid white] until the threaded loader returns the proper texture, just as if the texture load had failed.

Share this post


Link to post
Share on other sites
Well there are two possible ways to talk about texture loading.

First of all, there is loading from main memory to video memory. The easiest way to handle this is just to let OpenGL or DirectX take care of it for you. They will use a least used algorithm to load textures between main memory and video memory.

Second there is loading from harddrive. I would suggest just having a loader thread which grabs textures from the harddrive and puts them in main memory based on the chance that the texture might be needed soon. Perhaps you have some kind of spatial division of the world and you assign textures to your visibility regions. Then you just load the textures for the regions visible, and the regions in the near vicinity since they are likely to be needed next.

And rather than rendering a white texture, why not just always keep a low res version of every texture in a level or area in memory at all times? A 64x64 texture in RGBA with 32 bits per pixel still only takes 16kb of memory. You could fit a hundred of those in less than 2MB of memory. If you're really desperate, store 400 32*32 textures instead in the same memory. It will still look better than solid white!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this