iMiniB3D: thread safe texture2d

BlitzMax Forums/MiniB3D Module/iMiniB3D: thread safe texture2d

ima747(Posted 2010) [#1]
This is a modification I've made to texture2d (the os specific underpinning for Texture) for iMiniB3D. It's every so slightly slower than the official texture2d (not noticable, talking millisecs) but it allows you to create textures from threads other than the main (opengl) thread.

It does as much as it can processing wise on the calling thread, but when it gets to the final step of creating the texture it bundles the texture data into an object and shoves that to the main thread. It will still work for "normal" calls as well, and could be optimized slightly (do traditional call if it's already on the main thread, and threaded call on a child thread...) but it doesn't really need it.

Texture2D.h



Texture2D.mm


Last edited 2010


jhocking(Posted 2010) [#2]
Thanks for sharing, but could you maybe explain what this is for? I'm not too familiar with multithreading; I'm thinking this is to load textures in the background while the game is running but I'm not sure.


ima747(Posted 2010) [#3]
that's one use. the threading system in iOS is actually really good at load balancing so you could also use this (like I do) for dynamic quality adjustment. e.g. load low res textures to conserver the very limited vram, and when you get close to something, or the user triggers something load a higher res version.

You could also use it to load textures on a child thread while you use the main application thread to display a loading animation or what have you.