• Advertisement
Sign in to follow this  

texture uploading slow

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

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?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
that is an interesting idea, i will try that.

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

Share this post


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

  • Advertisement