next up previous contents
Next: 6.8.2 Paging Images in Up: 6.8 Paging Textures Previous: 6.8 Paging Textures   Contents

6.8.1 Texture Subloading

While this technique works, it is a very inefficient user of texture bandwidth. Even if the viewer moves a small amount, the entire texture level is reloaded. Performance can be improved by taking advantage of texture subloading.

If the viewer is smoothly traversing textured terrain, you can take advantage of the fact by incrementally updating the contents of texture memory. Instead of completely reloading the contents of texture memory, you can reload the section that has gone out of view from the last frame with the portion of the image that has just come into view this frame. This technique works because of texture coordinate wrapping. When GL_ TEXTURE_WRAP_S and GL_ TEXTURE_WRAP_T are set to GL_ REPEAT (the default), the integer part of texture coordinates are discarded when mapping into texture memory. In effect, texture coordinates the go off the edge of texture memory on one side, ``wrap around'' to the opposite side. Using subloading, the updating technique looks like this:

  1. Given the current and previous view frustum, compute how the range of texture coordinates have changed.
  2. Transform the change of texture coordinates into one or more regions of texture memory that need to be updated.
  3. Use glTexSubImage() to update the appropriate regions of texture memory, use GL_ SKIP_PIXELS and GL_ SKIP_ROWS to index into the texture image.

If the subloads are computed properly, this technique does not require transforming texture coordinates using the the texture transform matrix. Updating texture memory can take from 1 to 4 subloads.

On many systems, texture subloads can be very inefficient when narrow regions are being loaded. The subloading method can be modified ensure that only subloads above a minimum size are allowed, at the cost of some additional texture memory. The change is simple. Instead of updating every time the view position changes, ignore position changes until the accumulated change requires a subload above the minimum size. Normally this will result in out of date texture data being visible around the edges of the textured geometry. To avoid this, an invalid region is specified around the periphery of the texture level, and the view frustum is adjusted so the that geometry textured from the texels from the invalid region are never visible. This technique allows updates to be cached, improving performance.

This paging technique depends on only a limited region of the textured geometry being visible. In this example we are depending on the limits of the view frustum to only allow properly textured geometry to be visible. If the view frustum were expanded, we'd see the texture image wrapping over the surrounding geometry. Even with these limitations, this technique can be expanded to include mipmapped textures.

Since OpenGL does not understand paged mipmaps, the application can not simply define a very large mipmap and not expect the OpenGL implementation to try to allocate the texture memory needed for all the mipmap levels. Instead the application must use the texture LOD control functionality in OpenGL 1.2 (or the EXT_texture_lod extension) to define a small number of active levels, using the GL_ TEXTURE_BASE_LEVEL, GL_ TEXTURE_MAX_LEVEL, GL_ TEXTURE_MIN_LOD and GL_ TEXTURE_MAX_LOD with the glTexParameter() call. An invalid region must be established and a minimum size update must be set so that all levels can be kept in sync with each other when updated. For example, a subload 32 texels wide at the top level must be accompanied by a subload 16 texels wide at the next coarser level, if mipmapping is going to filter properly. Multiple images at different resolutions will have to be kept in system memory as source images to load texture memory.

If the viewer zooms in or zooms out of the geometry, the texturing system may require levels that are not available in the paged mipmap. The application can avoid this problem by computing the mipmap levels that are needed for any given viewer position, and keeping a set of paged mipmaps available, each representing a different set of LOD levels. The coarsest set could be a normal mipmap, for when the viewer is very far away from the geometry.

next up previous contents
Next: 6.8.2 Paging Images in Up: 6.8 Paging Textures Previous: 6.8 Paging Textures   Contents