Asynchronous texture loading ?

Started by
2 comments, last by uto314 18 years, 4 months ago
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.
- a human beyond the bug -
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.
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
visit my website at www.kalmiya.com
Thanks for the reply,
the thread option is pretty much what I will do.
Cool.
-u.
- a human beyond the bug -

This topic is closed to new replies.

Advertisement