Class Texture2DAtlas
A generic Atlas texture of 2D textures. An atlas texture is a texture collection that collects multiple sub-textures into a single big texture. Sub-texture allocation for Texture2DAtlas is static and will not change after initial allocation. Does not add mipmap padding for sub-textures.
Inherited Members
Namespace: UnityEngine.Rendering
Assembly: Unity.RenderPipelines.Core.Runtime.dll
Syntax
public class Texture2DAtlas
Constructors
Texture2DAtlas(int, int, GraphicsFormat, FilterMode, bool, string, bool)
Creates a new empty texture atlas.
Declaration
public Texture2DAtlas(int width, int height, GraphicsFormat format, FilterMode filterMode = FilterMode.Point, bool powerOfTwoPadding = false, string name = "", bool useMipMap = true)
Parameters
| Type | Name | Description |
|---|---|---|
| int | width | Width of the atlas in pixels. |
| int | height | Height of atlas in pixels. |
| GraphicsFormat | format | GraphicsFormat of the atlas. |
| FilterMode | filterMode | Filtering mode of the atlas. |
| bool | powerOfTwoPadding | Power of two padding. |
| string | name | Name of the atlas |
| bool | useMipMap | Use mip maps |
Properties
AtlasTexture
Handle to the texture of the atlas.
Declaration
public RTHandle AtlasTexture { get; }
Property Value
| Type | Description |
|---|---|
| RTHandle |
maxMipLevelPadding
Maximum mip padding (pow2) that can be applied to the textures in the atlas
Declaration
public static int maxMipLevelPadding { get; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
AddTexture(CommandBuffer, ref Vector4, Texture)
Add a texture into the atlas.
Declaration
public virtual bool AddTexture(CommandBuffer cmd, ref Vector4 scaleOffset, Texture texture)
Parameters
| Type | Name | Description |
|---|---|---|
| CommandBuffer | cmd | Command buffer used for texture copy. |
| Vector4 | scaleOffset | Sub-texture rectangle for the added texture. Scale in .xy, offset int .zw |
| Texture | texture | The texture to be added. |
Returns
| Type | Description |
|---|---|
| bool | True if the atlas contains the texture, false otherwise. |
AllocateTexture(CommandBuffer, ref Vector4, Texture, int, int, int)
Allocate space from the atlas for a texture and copy texture contents into the atlas.
Declaration
[Obsolete("AllocateTexture(CommandBuffer, ref Vector4, Texture, int, int, int) is obsolete, use AllocateTexture(CommandBuffer, ref Vector4, Texture, int, int, TextureIdentifier) instead.", true)]
public virtual bool AllocateTexture(CommandBuffer cmd, ref Vector4 scaleOffset, Texture texture, int width, int height, int overrideInstanceID)
Parameters
| Type | Name | Description |
|---|---|---|
| CommandBuffer | cmd | Target command buffer for graphics commands. |
| Vector4 | scaleOffset | Destination scale (.xy) and offset (.zw) |
| Texture | texture | Source Texture |
| int | width | Request width in pixels. |
| int | height | Request height in pixels. |
| int | overrideInstanceID | Override texture instance ID. |
Returns
| Type | Description |
|---|---|
| bool | True if the texture was successfully allocated and copied; false otherwise. |
AllocateTexture(CommandBuffer, ref Vector4, Texture, int, int, TextureIdentifier)
Allocate space from the atlas for a texture and copy texture contents into the atlas.
Declaration
public virtual bool AllocateTexture(CommandBuffer cmd, ref Vector4 scaleOffset, Texture texture, int width, int height, Texture2DAtlas.TextureIdentifier overrideIdentifier = default)
Parameters
| Type | Name | Description |
|---|---|---|
| CommandBuffer | cmd | Target command buffer for graphics commands. |
| Vector4 | scaleOffset | Destination scale (.xy) and offset (.zw) |
| Texture | texture | Source Texture |
| int | width | Request width in pixels. |
| int | height | Request height in pixels. |
| Texture2DAtlas.TextureIdentifier | overrideIdentifier | Override texture identifier. |
Returns
| Type | Description |
|---|---|
| bool | True if the texture was successfully allocated and copied; false otherwise. |
AllocateTextureWithoutBlit(int, int, int, ref Vector4)
Allocate space from the atlas for a texture.
Declaration
[Obsolete("AllocateTextureWithoutBlit(int, int, int, ref Vector4) is obsolete, use AllocateTextureWithoutBlit(TextureIdentifier, int, int, ref Vector4) instead.", true)]
public virtual bool AllocateTextureWithoutBlit(int instanceId, int width, int height, ref Vector4 scaleOffset)
Parameters
| Type | Name | Description |
|---|---|---|
| int | instanceId | Source texture instance ID. |
| int | width | Request width in pixels. |
| int | height | Request height in pixels. |
| Vector4 | scaleOffset | Allocated scale (.xy) and offset (.zw). |
Returns
| Type | Description |
|---|---|
| bool | True on success, false otherwise. |
AllocateTextureWithoutBlit(TextureIdentifier, int, int, ref Vector4)
Allocate space from the atlas for a texture.
Declaration
public virtual bool AllocateTextureWithoutBlit(Texture2DAtlas.TextureIdentifier identifier, int width, int height, ref Vector4 scaleOffset)
Parameters
| Type | Name | Description |
|---|---|---|
| Texture2DAtlas.TextureIdentifier | identifier | Source texture identifier. |
| int | width | Request width in pixels. |
| int | height | Request height in pixels. |
| Vector4 | scaleOffset | Allocated scale (.xy) and offset (.zw). |
Returns
| Type | Description |
|---|---|
| bool | True on success, false otherwise. |
AllocateTextureWithoutBlit(Texture, int, int, ref Vector4)
Allocate space from the atlas for a texture.
Declaration
public bool AllocateTextureWithoutBlit(Texture texture, int width, int height, ref Vector4 scaleOffset)
Parameters
| Type | Name | Description |
|---|---|---|
| Texture | texture | Source texture. |
| int | width | Request width in pixels. |
| int | height | Request height in pixels. |
| Vector4 | scaleOffset | Allocated scale (.xy) and offset (.zw). |
Returns
| Type | Description |
|---|---|
| bool | True on success, false otherwise. |
BlitCubeTexture2D(CommandBuffer, Vector4, Texture, bool, int)
Blit and project Cube texture into a 2D texture in the atlas.
Declaration
[Obsolete("BlitCubeTexture2D(CommandBuffer, Vector4, Texture, bool blitMips, int ) is obsolete, use BlitCubeTexture2D(CommandBuffer, Vector4, Texture, bool, TextureIdentifier) instead.", true)]
public virtual void BlitCubeTexture2D(CommandBuffer cmd, Vector4 scaleOffset, Texture texture, bool blitMips, int overrideInstanceID)
Parameters
| Type | Name | Description |
|---|---|---|
| CommandBuffer | cmd | Target command buffer for graphics commands. |
| Vector4 | scaleOffset | Destination scale (.xy) and offset (.zw) |
| Texture | texture | Source Texture |
| bool | blitMips | Blit mip maps. |
| int | overrideInstanceID | Override texture instance ID. |
BlitCubeTexture2D(CommandBuffer, Vector4, Texture, bool, TextureIdentifier)
Blit and project Cube texture into a 2D texture in the atlas.
Declaration
public virtual void BlitCubeTexture2D(CommandBuffer cmd, Vector4 scaleOffset, Texture texture, bool blitMips = true, Texture2DAtlas.TextureIdentifier overrideIdentifier = default)
Parameters
| Type | Name | Description |
|---|---|---|
| CommandBuffer | cmd | Target command buffer for graphics commands. |
| Vector4 | scaleOffset | Destination scale (.xy) and offset (.zw) |
| Texture | texture | Source Texture |
| bool | blitMips | Blit mip maps. |
| Texture2DAtlas.TextureIdentifier | overrideIdentifier | Override texture identifier. |
BlitCubeTexture2D(CommandBuffer, Vector4, Texture, int)
Blit and project Cube texture into a 2D texture in the atlas.
Declaration
[Obsolete("BlitCubeTexture2D(CommandBuffer, Vector4, Texture, int) is obsolete, use BlitCubeTexture2D(CommandBuffer, Vector4, Texture, bool, TextureIdentifier) instead.", true)]
public virtual void BlitCubeTexture2D(CommandBuffer cmd, Vector4 scaleOffset, Texture texture, int overrideInstanceID)
Parameters
| Type | Name | Description |
|---|---|---|
| CommandBuffer | cmd | Target command buffer for graphics commands. |
| Vector4 | scaleOffset | Destination scale (.xy) and offset (.zw) |
| Texture | texture | Source Texture |
| int | overrideInstanceID | Override texture instance ID. |
BlitOctahedralTexture(CommandBuffer, Vector4, Texture, Vector4, bool, int)
Blit octahedral texture into the atlas.
Declaration
[Obsolete("BlitOctahedralTexture(CommandBuffer, Vector4, Texture, Vector4, bool, int) is obsolete, use BlitOctahedralTexture(CommandBuffer, Vector4, Texture, Vector4, bool, TextureIdentifier) instead.", true)]
public virtual void BlitOctahedralTexture(CommandBuffer cmd, Vector4 scaleOffset, Texture texture, Vector4 sourceScaleOffset, bool blitMips, int overrideInstanceID)
Parameters
| Type | Name | Description |
|---|---|---|
| CommandBuffer | cmd | Target command buffer for graphics commands. |
| Vector4 | scaleOffset | Destination scale (.xy) and offset (.zw) |
| Texture | texture | Source Texture |
| Vector4 | sourceScaleOffset | Source scale (.xy) and offset(.zw). |
| bool | blitMips | Blit mip maps. |
| int | overrideInstanceID | Override texture instance ID. |
BlitOctahedralTexture(CommandBuffer, Vector4, Texture, Vector4, bool, TextureIdentifier)
Blit octahedral texture into the atlas.
Declaration
public virtual void BlitOctahedralTexture(CommandBuffer cmd, Vector4 scaleOffset, Texture texture, Vector4 sourceScaleOffset, bool blitMips = true, Texture2DAtlas.TextureIdentifier overrideIdentifier = default)
Parameters
| Type | Name | Description |
|---|---|---|
| CommandBuffer | cmd | Target command buffer for graphics commands. |
| Vector4 | scaleOffset | Destination scale (.xy) and offset (.zw) |
| Texture | texture | Source Texture |
| Vector4 | sourceScaleOffset | Source scale (.xy) and offset(.zw). |
| bool | blitMips | Blit mip maps. |
| Texture2DAtlas.TextureIdentifier | overrideIdentifier | Override texture identifier. |
BlitOctahedralTexture(CommandBuffer, Vector4, Texture, Vector4, int)
Blit octahedral texture into the atlas.
Declaration
[Obsolete("BlitOctahedralTexture(CommandBuffer, Vector4, Texture, Vector4, int) is obsolete, use BlitOctahedralTexture(CommandBuffer, Vector4, Texture, Vector4, bool, TextureIdentifier) instead.", true)]
public virtual void BlitOctahedralTexture(CommandBuffer cmd, Vector4 scaleOffset, Texture texture, Vector4 sourceScaleOffset, int overrideInstanceID)
Parameters
| Type | Name | Description |
|---|---|---|
| CommandBuffer | cmd | Target command buffer for graphics commands. |
| Vector4 | scaleOffset | Destination scale (.xy) and offset (.zw) |
| Texture | texture | Source Texture |
| Vector4 | sourceScaleOffset | Source scale (.xy) and offset(.zw). |
| int | overrideInstanceID | Override texture instance ID. |
BlitTexture(CommandBuffer, Vector4, Texture, Vector4, bool, int)
Blit 2D texture into the atlas.
Declaration
[Obsolete("BlitTexture(CommandBuffer, Vector4, Texture, Vector4 , bool , int) is obsolete, use BlitTexture(CommandBuffer, Vector4, Texture, Vector4, bool, TextureIdentifier) instead.", true)]
public virtual void BlitTexture(CommandBuffer cmd, Vector4 scaleOffset, Texture texture, Vector4 sourceScaleOffset, bool blitMips, int overrideInstanceID)
Parameters
| Type | Name | Description |
|---|---|---|
| CommandBuffer | cmd | Target command buffer for graphics commands. |
| Vector4 | scaleOffset | Destination scale (.xy) and offset (.zw) |
| Texture | texture | Source Texture |
| Vector4 | sourceScaleOffset | Source scale (.xy) and offset(.zw). |
| bool | blitMips | Blit mip maps. |
| int | overrideInstanceID | Override texture instance ID. |
BlitTexture(CommandBuffer, Vector4, Texture, Vector4, bool, TextureIdentifier)
Blit 2D texture into the atlas.
Declaration
public virtual void BlitTexture(CommandBuffer cmd, Vector4 scaleOffset, Texture texture, Vector4 sourceScaleOffset, bool blitMips = true, Texture2DAtlas.TextureIdentifier overrideIdentifier = default)
Parameters
| Type | Name | Description |
|---|---|---|
| CommandBuffer | cmd | Target command buffer for graphics commands. |
| Vector4 | scaleOffset | Destination scale (.xy) and offset (.zw) |
| Texture | texture | Source Texture |
| Vector4 | sourceScaleOffset | Source scale (.xy) and offset(.zw). |
| bool | blitMips | Blit mip maps. |
| Texture2DAtlas.TextureIdentifier | overrideIdentifier | Override texture identifier. |
BlitTexture(CommandBuffer, Vector4, Texture, Vector4, int)
Blit 2D texture into the atlas.
Declaration
[Obsolete("BlitTexture(CommandBuffer, Vector4, Texture, Vector4, int) is obsolete, use BlitTexture(CommandBuffer, Vector4, Texture, Vector4, bool, TextureIdentifier) instead.", true)]
public virtual void BlitTexture(CommandBuffer cmd, Vector4 scaleOffset, Texture texture, Vector4 sourceScaleOffset, int overrideInstanceID)
Parameters
| Type | Name | Description |
|---|---|---|
| CommandBuffer | cmd | Target command buffer for graphics commands. |
| Vector4 | scaleOffset | Destination scale (.xy) and offset (.zw) |
| Texture | texture | Source Texture |
| Vector4 | sourceScaleOffset | Source scale (.xy) and offset(.zw). |
| int | overrideInstanceID | Override texture instance ID. |
ClearTarget(CommandBuffer)
Clear atlas texture.
Declaration
public void ClearTarget(CommandBuffer cmd)
Parameters
| Type | Name | Description |
|---|---|---|
| CommandBuffer | cmd | Target command buffer for graphics commands. |
GetTextureID(Texture)
Get sub-texture ID for the atlas.
Declaration
[Obsolete("int GetTextureID(Texture texture) is obsolete, use GetTextureIdentifier(Texture texture) instead.", true)]
public int GetTextureID(Texture texture)
Parameters
| Type | Name | Description |
|---|---|---|
| Texture | texture | Source texture. |
Returns
| Type | Description |
|---|---|
| int | Texture instance ID. |
GetTextureID(Texture, Texture)
Get sub-texture ID for the atlas.
Declaration
[Obsolete("GetTextureID(Texture textureA, Texture textureB) is obsolete , use GetTextureIdentifier(Texture textureA, Texture textureB) instead.", true)]
public int GetTextureID(Texture textureA, Texture textureB)
Parameters
| Type | Name | Description |
|---|---|---|
| Texture | textureA | Source texture A. |
| Texture | textureB | Source texture B. |
Returns
| Type | Description |
|---|---|
| int | Combined texture instance ID. |
GetTextureIdentifier(Texture)
Get sub-texture ID for the atlas.
Declaration
public Texture2DAtlas.TextureIdentifier GetTextureIdentifier(Texture texture)
Parameters
| Type | Name | Description |
|---|---|---|
| Texture | texture | Source texture. |
Returns
| Type | Description |
|---|---|
| Texture2DAtlas.TextureIdentifier | The TextureIdentifier, which stores the EntityId of the texture. |
GetTextureIdentifier(Texture, Texture)
Get sub-texture ID for the atlas.
Declaration
public Texture2DAtlas.TextureIdentifier GetTextureIdentifier(Texture textureA, Texture textureB)
Parameters
| Type | Name | Description |
|---|---|---|
| Texture | textureA | Source texture A. |
| Texture | textureB | Source texture B. |
Returns
| Type | Description |
|---|---|
| Texture2DAtlas.TextureIdentifier | Combined texture instance ID. |
IsCached(out Vector4, int)
Check if the atlas contains the texture.
Declaration
[Obsolete("IsCached(out Vector4, int) is obsolete, use IsCached(out Vector4, TextureIdentifier) instead.", true)]
public bool IsCached(out Vector4 scaleOffset, int id)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector4 | scaleOffset | Texture scale (.xy) and offset (.zw). |
| int | id | Source texture instance ID. |
Returns
| Type | Description |
|---|---|
| bool | True if the texture is in the atlas, false otherwise |
IsCached(out Vector4, TextureIdentifier)
Check if the atlas contains the texture.
Declaration
public bool IsCached(out Vector4 scaleOffset, Texture2DAtlas.TextureIdentifier identifier)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector4 | scaleOffset | Texture scale (.xy) and offset (.zw). |
| Texture2DAtlas.TextureIdentifier | identifier | Source texture identifier. |
Returns
| Type | Description |
|---|---|
| bool | True if the texture is in the atlas, false otherwise. |
IsCached(out Vector4, Texture)
Check if the atlas contains the textures.
Declaration
public bool IsCached(out Vector4 scaleOffset, Texture texture)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector4 | scaleOffset | Texture scale (.xy) and offset (.zw). |
| Texture | texture | Source texture |
Returns
| Type | Description |
|---|---|
| bool | True if the texture is in the atlas, false otherwise. |
IsCached(out Vector4, Texture, Texture)
Check if the atlas contains the textures.
Declaration
public bool IsCached(out Vector4 scaleOffset, Texture textureA, Texture textureB)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector4 | scaleOffset | Texture scale (.xy) and offset (.zw). |
| Texture | textureA | Source texture A. |
| Texture | textureB | Source texture B. |
Returns
| Type | Description |
|---|---|
| bool | True if the texture is in the atlas, false otherwise. |
NeedsUpdate(int, int, bool)
Check if a slot needs to be updated in the atlas.
Declaration
[Obsolete("NeedsUpdate(int, int, bool) is obsolete, use NeedsUpdate(TextureIdentifier, int, bool) instead.", true)]
public virtual bool NeedsUpdate(int id, int updateCount, bool needMips)
Parameters
| Type | Name | Description |
|---|---|---|
| int | id | The id. |
| int | updateCount | The update count. |
| bool | needMips | Texture uses mips. |
Returns
| Type | Description |
|---|---|
| bool | True if slot needs update, false otherwise. |
NeedsUpdate(TextureIdentifier, int, bool)
Check if a slot needs to be updated in the atlas.
Declaration
public virtual bool NeedsUpdate(Texture2DAtlas.TextureIdentifier identifier, int updateCount, bool needMips = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Texture2DAtlas.TextureIdentifier | identifier | The textureIdentifier. |
| int | updateCount | The update count. |
| bool | needMips | Texture uses mips. |
Returns
| Type | Description |
|---|---|
| bool | True if slot needs update, false otherwise. |
Remarks
This call is not side effect free: it refreshes the cached update count as it compares it, so two consecutive calls do not necessarily return the same value.
NeedsUpdate(Texture, bool)
Check if contents of a texture needs to be updated in the atlas.
Declaration
public virtual bool NeedsUpdate(Texture texture, bool needMips = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Texture | texture | Source texture. |
| bool | needMips | Texture uses mips. |
Returns
| Type | Description |
|---|---|
| bool | True if texture needs update, false otherwise. |
Remarks
This call is not side effect free: it refreshes the cached render texture update count as it compares it, so two consecutive calls do not necessarily return the same value.
NeedsUpdate(Texture, Texture, bool)
Check if contents of a texture needs to be updated in the atlas.
Declaration
public virtual bool NeedsUpdate(Texture textureA, Texture textureB, bool needMips = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Texture | textureA | Source texture A. |
| Texture | textureB | Source texture B. |
| bool | needMips | Texture uses mips. |
Returns
| Type | Description |
|---|---|
| bool | True if texture needs update, false otherwise. |
Remarks
This call is not side effect free: it refreshes the cached render texture update count as it compares it, so two consecutive calls do not necessarily return the same value.
Release()
Release atlas resources.
Declaration
public void Release()
ResetAllocator()
Clear atlas sub-texture allocations.
Declaration
public void ResetAllocator()
UpdateTexture(CommandBuffer, Texture, Texture, ref Vector4, Vector4, bool, bool)
Update a texture in the atlas.
Declaration
public virtual bool UpdateTexture(CommandBuffer cmd, Texture oldTexture, Texture newTexture, ref Vector4 scaleOffset, Vector4 sourceScaleOffset, bool updateIfNeeded = true, bool blitMips = true)
Parameters
| Type | Name | Description |
|---|---|---|
| CommandBuffer | cmd | Target command buffer for graphics commands. |
| Texture | oldTexture | Texture in atlas. |
| Texture | newTexture | Replacement source texture. |
| Vector4 | scaleOffset | Destination scale (.xy) and offset (.zw) |
| Vector4 | sourceScaleOffset | Source scale (.xy) and offset(.zw). |
| bool | updateIfNeeded | Enable texture blit. |
| bool | blitMips | Blit mip maps. |
Returns
| Type | Description |
|---|---|
| bool | True on success, false otherwise. |
UpdateTexture(CommandBuffer, Texture, ref Vector4, bool, bool)
Update a texture in the atlas.
Declaration
public virtual bool UpdateTexture(CommandBuffer cmd, Texture texture, ref Vector4 scaleOffset, bool updateIfNeeded = true, bool blitMips = true)
Parameters
| Type | Name | Description |
|---|---|---|
| CommandBuffer | cmd | Target command buffer for graphics commands. |
| Texture | texture | Texture in atlas. |
| Vector4 | scaleOffset | Destination scale (.xy) and offset (.zw) |
| bool | updateIfNeeded | Enable texture blit. |
| bool | blitMips | Blit mip maps. |
Returns
| Type | Description |
|---|---|
| bool | True on success, false otherwise. |