Skip to main content
gamedev.net
🔒 Locked

Asynchronous texture loading ?

Started by uto314 Dec 1, 2005 at 5:46 PM 2 replies 1.2k views
Original Post
uto314
uto314
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 -
bluntman
bluntman
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.
Kitt3n
Kitt3n
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
uto314
uto314
Thanks for the reply,
the thread option is pretty much what I will do.
Cool.
-u.
a human beyond the bug -

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.