Sign in to follow this  

texture caching system

This topic is 2841 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I use MDX and C#, and I have several textures which only some of them (in fact a small fraction of the textures) should be displayed in each scene, I've been advised not to use the managed pool which is OK, but what is the best way for managing & controlling them, how can I have a balance between performance (i.e. FPS) and memory usage, at the moment when I load two big textures (which I've broken them into several small textures), my memory usage is around 1.7 GB which certainly is not acceptable, in this way I cannot load my third layer (which may add up to several hundred MB to memory usage). This is the scenario that I'm going to implement: Texture myTexture[10,10];// I create a 10x10 (in fact tile_x X tile_y) array of textures in my app init .... then I divide my BIG.BMP (around 6000x6000) into several (10x10) 600x600 small textures. now I have 100 BMPs (or JPEGS) I can load all BMPs into myTexture array which leads to huge memory consumption and limits me in aspects of number of textures so I leave the BMPs and try to load only ONEs needed, in this case I'll have around 4 textures each time in my memory, I'll do so: Render() { ... ... //Finding textures really needed in render process for(int i = 0 ; i < 10 ; i++) { for(int j = 0 ; j < 10 ; j++) { myTexture[i,j] = null;// I set all my textures to null } } //then I load only the needed textures //for instance myTexture[4,5] = TextureLoader.FromFile(.....); myTexture[4,6] = TextureLoader.FromFile(.....); myTexture[5,5] = TextureLoader.FromFile(.....); myTexture[5,6] = TextureLoader.FromFile(.....); //render scene using these textures, as I see only a small part of my scene //of course I'll unload/load the textures only when camera view changes (pan, zoom, tilt...) } is this scenario correct? what does caching mean here? how can I optimize it, I think loading textures at runtime will cause a small delay, how can I decrease this delay? thanks

Share this post


Link to post
Share on other sites
1.7GB sounds like too much for two 6000x6000 images. I'd suggest that you verify that your 600x600 textures aren't scaled to the nearest power of 2 (1024x1024). That'd make your program take about 3 times the necessary memory.

Regarding caching, the idea is that when you need a new texture, you do:
- Check if the texture is already in the cache
- If not:
- If there's an empty slot in the cache, load into it
- Otherwise choose an unused slot, release it and load into it

You can decrease delays by anticipating which textures you're going to use next, and loading them in another thread.

BTW, I'd suggest taking a look at SlimDX as an alternative to MDX.

Share this post


Link to post
Share on other sites

This topic is 2841 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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