Jump to content
  • Advertisement
Sign in to follow this  
uto314

Asynchronous texture loading ?

This topic is 4859 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'm wondering if there is a common way to load texture into the graphics hardware (glTexImage2D) in a asychrone way. For instance if I know that at time T I'll need a texture to be accessible, I'd like to start transfering the data at T - t to not slow down the frame rate of the application. My idea is to use a specialized thread that cares only about the textures management, but if someone knows a simplest way that would be greaaat :) Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Well you can load bits of the texture at a time using glTexSubImage2D, so you just need to decide how much loading you can do for time t, then calculate how early you need to start loading based on the size of the texture.

Share this post


Link to post
Share on other sites
Start a thread with have a mutex-protected queue of files to read.
Use signals to let the thread run or stop when no files in the queue.

Main thread posts a filename + a callback-function-ptr, thread will
wake-up and start reading in a vector and call the callback function
when if finishes reading the file, passing the data it read.

The callback has to handle this somehow (interpret data or whatever),
remember that the 'data you gave to the callback is only valid during
the callback, so don't store a pointer to it or sth)...

Regards

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!