Skip to main content
GameDev.net gamedev.net
🔒 Locked

texture uploading slow

Started by ehmdjii Jan 29, 2007 at 2:53 PM 3 replies 1k views
Original Post
ehmdjii
ehmdjii
hello, in my game a lot of textures are generated and disposed during runtime, which stutters the game. the problem is, that whenever i call glTexImage2D the upload lags a lot. it interrupts the game for about half a second, which is extremely noticeable and very annoying for a smooth gameplay. no texture is larger than 256x256 and i am running a GF7200 so i think it shouldnt lag that much. are there maybe any tricks to accelerate this upload?
DMINATOR
DMINATOR
Well as far as I know you may try to use separate thread for this, I haven't tried it myself, but it may help a bit.
soconne
soconne
Quote:
Original post by DMINATOR
Well as far as I know you may try to use separate thread for this, I haven't tried it myself, but it may help a bit.


You'll run into major problems if you try updating a texture in a different thread than your rendering thread.

The best thing to do is upon startup, create and initialize several textures of various sizes, in your case a bunch of 256x256 textures. Then store them in some array. Create an corresponding array that contains flags to tell you whether or not that particular texture is in use.

Then when you need to allocate a texture, loop through your flag array looking for a texture that is not in use. If you find one, mark it as in use and retrieve the pointer to the texture object. Then call glTexSubImage2D to fill the texture with the needed data.

The basic point is that glTexSubImage2D is MUCH faster than glTexImage2D. glTexImage2D must allocate memory on the graphics card, while glTexSubImage2D does not, it simply assumes the memory has already been allocated.

Try this and it should solve all your problems.

Author Freeworld3Dhttp://www.freeworld3d.org
ehmdjii
ehmdjii
that is an interesting idea, i will try that.

btw: i have about 200 (plus/minus 50) different 256-textures at runtime.

Topic Locked

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

Sign in to reply to this topic.