Texture Dirty Regions

Applications can optimize which subset of a texture is copied by specifying dirty regions on textures. Only those regions marked as dirty are copied by a call to Device.UpdateTexture. However, the dirty regions can be expanded to optimize alignment. When a texture is created, the entire texture is considered dirty. Only the following operations affect this state.

  • Adding a dirty region to a texture.
  • Locking some buffer in the texture. This operation adds the locked region as a dirty region. The application can turn off this automatic dirty-region update if it has better knowledge of the actual dirty regions.
  • Using a surface level of the texture as a destination in Device.UpdateSurface marks the entire texture as dirty.
  • Using the texture as a source in Device.UpdateTexture clears all dirty regions on the source texture.
  • Using Surface.GetGraphics to return a device context.
  • Calling BaseTexture.GenerateMipSubLevels marks the entire texture as dirty.
  • Setting BaseTexture.AutoGenerateFilterType marks the entire texture as dirty.

Dirty regions are set on the top level of a mipmapped texture, and Device.UpdateTexture can expand the dirty region down the mip chain to minimize the number of bytes copied for each sublevel. Note that the sublevel dirty region coordinates are rounded outward; that is, their fractional parts are rounded toward the nearest edge of the texture.

Because each type of texture has different types of dirty regions, there are methods on each texture type, as shown in the following list. Two-dimensional (2-D) textures use dirty rectangles, and volume textures use boxes.

Omitting the rect or box parameters for the above methods expands the dirty region to cover the entire texture.

Each lock method can take LockFlags.NoDirtyUpdate, which prevents any changes to the dirty state of the texture. For more information, see Locking Resources.

When more information about the true set of regions that are changed during a lock operation is available, applications should use LockFlags.NoDirtyUpdate. Note that a lock or a copy to a texture sublevel only (that is, without locking or copying to the top level) does not update the dirty regions for that texture. Applications assume the same responsibility for updating dirty regions when they lock lower levels without locking the topmost level.