Jump to content
  • Advertisement
Sign in to follow this  
programmer_tom

Threaded Texture Loading

This topic is 3362 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

Hey All I'm loading textures on a thread using D3DXCreateTextureFromFileEx(). When the thread completes, I need to swap textures. I'm doing it like this: pOldTexture->Release(); pOldTexture = pNewTexture; This works great, except for once in a while it crashes, as you might expect because I've done nothing to prevent the thread from completing at random times. What do I need to do to make texture loading in DX thread safe? -programmer_tom

Share this post


Link to post
Share on other sites
Advertisement
Are you using D3DCREATE_MULTITHREADED? That's the main thing required for using D3D from multiple threads.

If you want to avoid using that flag (which can affect performance somewhat) then load the texture on the thread into memory using say fread(), and once that's complete on the main thread call D3DXCreateTextureFromFileInMemoryEx().

Share this post


Link to post
Share on other sites
With D3D9 you really want to keep all of your code that accesses D3D interfaces on a single thread (the thread that created the window and pumps messages). You can use the MULTITHREADED flag to make the device thread safe, but this will slow things down significantly. This means that for loading textures you best option is to do all of the file i/o on a separate thread, and read the image data into memory. Then you can pass that data off to your main thread, which can use the device or D3DX functions to make the actual texture object.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!