TextureAtlas
Description
- Derived from
-
ResourceBase abstract
IVersioned
IEventListenerGeneric<PyramidEventArgs>
IMemoryConsumption
ICapacity
The TextureAtlas class provides GPU-caching for texture tiles that have been fetched from one or more texel pyramids.
A texture atlas maintains a series of square textures, all having the same size, mipmap level count and texture format. Each texture is divided into equally sized slots, which store tiles that have been fetched from texel pyramids.
+---+---+---+---+ | V | S | T | U | +---+---+---+---+ -+ | R | W | N | P | | A..X := Texel pyramid tiles, +---+---+---+---+ -+ -+ stuffed into cache textures | A | D | F | I | | | +---+---+---+---+ -+ -+ | J | B | C | H | | | +---+---+---+---+ -+ -+ \ | K | E | G | L | | | +---+---+---+---+ -+ | textureCount | X | M | O | Q | | +---+---+---+---+ / \___/ tileSize \_______________/ textureSize
Texel pyramids must be registered with a texture atlas before they can be used (see PyramidIdAllocate and PyramidIdRelease). Pyramid tiles can then be requested via TileLookup. For rendering, use the TileSetup method to obtain texturing coefficients. Tiles are loaded in background tasks; call the TextureUpdate method from the render thread to incrementally upload new texture data to the GPU.
Public / Constructors
TextureAtlas
Creates a new instance of TextureAtlas.
- RenderException
-
If a graphics subsystem error has occurred.
Public / Methods
PyramidIdAllocate
Allocates a pyramid ID for the given tile pyramid.
The first pyramid ID is always 0
. Pyramid IDs that have been released can be reused later.
If a pyramid ID has already been allocated for the given tile pyramid, the same ID will be returned. The PyramidIdRelease must be called once for each call to PyramidIdAllocate in this case.
Pyramid IDs can be allocated and released in any order.
- See also
PyramidIdRelease
Releases a previously allocated pyramid ID.
If the given pyramid ID is not valid, the method silently returns.
Pyramid IDs can be allocated and released in any order.
The TextureAtlas will retain ownership on the released ITexelPyramid as long as there are still background tasks running which are using it. If there are no such tasks, ownership will be released when PyramidIdRelease or TextureUpdate is called. To further control disposal of the released ITexelPyramid, the calling code can keep ownership on it and use IDisposable.IsSoleOwnership: if the code holds the sole ownership, it may safely proceed with disposal (for example calling IDisposable.Dispose in a separate thread, to avoid blocking).
- See also
TextureSlice
Returns the slice index in the texture object that contains the index in -th cache texture.
TextureUpdateBytes
Polls the amount of texture data that has been uploaded via TextureUpdate so far.
This method will clear the byte counter, i.e. calling this method twice will return zero the second time.
TileFadeFactor
Computes the fade-in factor for the given texture tile, based on its birthday.
- See also
TileLookup
Performs a tile texture lookup for the given pyramid tile.
The tile texture handles that are returned by this method are valid until the next call to TextureUpdate is made.
Public / Attributes
IsIdle
Is this texture atlas idle?
Idle means that there are no buffered texture tile updates (i.e. the next call to TextureUpdate will do nothing and always return true
), that there are no pending background tasks which are loading texture tiles from a ITexelPyramid (i.e. TileLookup will never return -2
).
TextureCount
The number of cache textures.
Each cache texture contains N*N
tile textures, where N
is given by TextureSize/TileSize. Cache textures are packed into texture objects with a fixed number of texture array slices (see TextureSliceCount).
- See also
TextureSliceCount
The number of slices per texture object.
One or more cache textures may be packed into a single texture object (see ITexture2D). The number of cache textures per texture object must be specified when constructing a TextureAtlas object.
- See also