Critical Mass :: 3D Action Puzzle Game

Don't Like Ad's?
Click Here


Forum Index - Game Development - Streaming Textures in OpenGL

There are 4 replies to this topic ShareIt! Text-To-Speech





+VarnishedOtter
Admin
VarnishedOtter

2 years ago
I thought I'd share a little something to get this topic started.

Textures are one of the biggets assets in a game, and usually they take a fair while to load them all up.

Do you like to sit there and wait for them?

They also take up alot of RAM on your video card.

Streaming textures allows you to load your textures in the background only when they are needed, while not affecting performance.

This gives significant speed increase because you are writing directly to the video RAM, where the GPU has direct and super fast access to it.

Here's the method I use for streaming textures in OpenGL:

1. Create a work queue
I generally use a vector for this since they are dynamic, but a static array will be fine as long as you don't overrun your buffer.

This queue will hold the filenames and other info about textures that your game is requesting. As your game requests textures, they will go into the queue to be loaded. After they are loaded they will be deleted from the queue and stored in your texture array.

2. Create a texture array
Again I generally use a vector for this as they've got alot of OOP functionality built in, compared to static arrays.

This array holds all the info about what textures you currently have loaded.

Some things you will want to store:

Texture Name
Texture Size
Pixel Buffer ID

Dont worry about the pixel buffer ID yet, just make sure you have a place to store it.

3. Function getStreamingTextureIndex()
This function takes a filename as an input checks our texture array to see if it's already loaded. If it is, it returns the index from the texture array.

If its not present it adds the texture to the work queue and returns a negative response.

You can check for this negative response before you render an object, if the texture isn't loaded yet, then don't render the object.

4. Function updateStreamingTextures()
This function should get fired off every frame. It takes care of actually loading your textures.

It should check if it has already started loading a file.

If not, then get the first file off of the work queue.
Request a new Pixel Buffer Object and save the ID.
Map the Buffer Object to a pointer.

Check the time.
Load bytes from the file straight into the Pixel Buffer pointer until a specified amount of time has passed. I usually use 1/60th of a second.

If the file is done then add it to the texture array and remove it from the work queue.
Unmap the Pixel Buffer
Copy the texture from its Pixel Buffer to a new GL Texture all in one hit.
Delete the pixel buffer so that it can be reused for teh next texture.

5. More stuff
You can add other features to this, such as keeping track of how long since a texture was last used, and if its decidedly old, you can unload the texture, leaving more room for newer textures.

You can do some fancy things like fade the texture in, so its not as jarring when it completes.

You can start preloading textures in the order you think you will use them, right from the time your app first starts up, so by the time the player gets through the intros and the menu system, the textures are all already done, and they can jump straight into the game with no loading screen.

You can also acheive LOD with this, just pre-load all of your low-res textures first, then your high res ones, and test to see whether the high-res textures has been loaded yet, and if not, use the low-res texture.

Please support us and post a [Link to www.digitalartsfront.com] on your website.

--Matt

+VarnishedOtter
Admin
VarnishedOtter

2 years ago
The same principles in Streaming Textures can be applied to geometry though the use of a Vertex Buffer Object.
Please support us and post a [Link to www.digitalartsfront.com] on your website.

--Matt

+Jamie
Admin
Jamie

2 years ago
Good article man. Not sure how useful it will be to current members but it might attract a few new ones.
Please support us and post a [Link to www.digitalartsfront.com] on your website.


+Steve Martin
Moderator
Steve Martin

2 years ago
Agreed. It means very little to me wink.gif. It does get me more interested in seeing what you've been doing for the past few months, you keep mentioning bits and pieces on facebook and such and I've been wondering what you're up to. I'm looking forward to seeing something.
[Link to www.3dprevis.com]

+Jamie
Admin
Jamie

2 years ago
I hope you do find it interesting wink.gif
Please support us and post a [Link to www.digitalartsfront.com] on your website.


Top

Critical Mass :: 3D Action Puzzle Game

Don't Like Ad's?
Click Here