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.
Namespace: UnityEngine.Rendering
Syntax
public class Texture2DAtlas
Constructors
Texture2DAtlas(Int32, Int32, GraphicsFormat, FilterMode, Boolean, String, Boolean)
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 |
---|---|---|
Int32 | width | Width of the atlas in pixels. |
Int32 | height | Height of atlas in pixels. |
GraphicsFormat | format | GraphicsFormat of the atlas. |
FilterMode | filterMode | Filtering mode of the atlas. |
Boolean | powerOfTwoPadding | Power of two padding. |
String | name | Name of the atlas |
Boolean | 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 |
---|---|
Int32 |
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 |
---|---|
Boolean | True if the atlas contains the texture, false otherwise. |
AllocateTexture(CommandBuffer, ref Vector4, Texture, Int32, Int32, Int32)
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, int overrideInstanceID = -1)
Parameters
Type | Name | Description |
---|---|---|
CommandBuffer | cmd | Target command buffer for graphics commands. |
Vector4 | scaleOffset | Destination scale (.xy) and offset (.zw) |
Texture | texture | Source Texture |
Int32 | width | Request width in pixels. |
Int32 | height | Request height in pixels. |
Int32 | overrideInstanceID | Override texture instance ID. |
Returns
Type | Description |
---|---|
Boolean |
AllocateTextureWithoutBlit(Int32, Int32, Int32, ref Vector4)
Allocate space from the atlas for a texture.
Declaration
public virtual bool AllocateTextureWithoutBlit(int instanceId, int width, int height, ref Vector4 scaleOffset)
Parameters
Type | Name | Description |
---|---|---|
Int32 | instanceId | Source texture instance ID. |
Int32 | width | Request width in pixels. |
Int32 | height | Request height in pixels. |
Vector4 | scaleOffset | Allocated scale (.xy) and offset (.zw). |
Returns
Type | Description |
---|---|
Boolean | True on success, false otherwise. |
AllocateTextureWithoutBlit(Texture, Int32, Int32, 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. |
Int32 | width | Request width in pixels. |
Int32 | height | Request height in pixels. |
Vector4 | scaleOffset | Allocated scale (.xy) and offset (.zw). |
Returns
Type | Description |
---|---|
Boolean | True on success, false otherwise. |
BlitCubeTexture2D(CommandBuffer, Vector4, Texture, Boolean, Int32)
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, int overrideInstanceID = -1)
Parameters
Type | Name | Description |
---|---|---|
CommandBuffer | cmd | Target command buffer for graphics commands. |
Vector4 | scaleOffset | Destination scale (.xy) and offset (.zw) |
Texture | texture | Source Texture |
Boolean | blitMips | Blit mip maps. |
Int32 | overrideInstanceID | Override texture instance ID. |
BlitOctahedralTexture(CommandBuffer, Vector4, Texture, Vector4, Boolean, Int32)
Blit octahedral texture into the atlas.
Declaration
public virtual void BlitOctahedralTexture(CommandBuffer cmd, Vector4 scaleOffset, Texture texture, Vector4 sourceScaleOffset, bool blitMips = true, int overrideInstanceID = -1)
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). |
Boolean | blitMips | Blit mip maps. |
Int32 | overrideInstanceID | Override texture instance ID. |
BlitTexture(CommandBuffer, Vector4, Texture, Vector4, Boolean, Int32)
Blit 2D texture into the atlas.
Declaration
public virtual void BlitTexture(CommandBuffer cmd, Vector4 scaleOffset, Texture texture, Vector4 sourceScaleOffset, bool blitMips = true, int overrideInstanceID = -1)
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). |
Boolean | blitMips | Blit mip maps. |
Int32 | overrideInstanceID | Override texture instance ID. |
ClearTarget(CommandBuffer)
Clear atlas texture. Target command buffer for graphics commands.
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
public int GetTextureID(Texture texture)
Parameters
Type | Name | Description |
---|---|---|
Texture | texture | Source texture. |
Returns
Type | Description |
---|---|
Int32 | Texture instance ID. |
GetTextureID(Texture, Texture)
Get sub-texture ID for the atlas.
Declaration
public int GetTextureID(Texture textureA, Texture textureB)
Parameters
Type | Name | Description |
---|---|---|
Texture | textureA | Source texture A. |
Texture | textureB | Source texture B. |
Returns
Type | Description |
---|---|
Int32 | Combined texture instance ID. |
IsCached(out Vector4, Int32)
Check if the atlas contains the texture.
Declaration
public bool IsCached(out Vector4 scaleOffset, int id)
Parameters
Type | Name | Description |
---|---|---|
Vector4 | scaleOffset | Texture scale (.xy) and offset (.zw). |
Int32 | id | Source texture instance ID. |
Returns
Type | Description |
---|---|
Boolean |
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 |
---|---|
Boolean | 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 |
---|---|
Boolean | True if the texture is in the atlas, false otherwise. |
NeedsUpdate(Texture, Boolean)
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. |
Boolean | needMips | Texture uses mips. |
Returns
Type | Description |
---|---|
Boolean | True if texture needs update, false otherwise. |
NeedsUpdate(Texture, Texture, Boolean)
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. |
Boolean | needMips | Texture uses mips. |
Returns
Type | Description |
---|---|
Boolean | True if texture needs update, false otherwise. |
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, Boolean, Boolean)
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). |
Boolean | updateIfNeeded | Enable texture blit. |
Boolean | blitMips | Blit mip maps. |
Returns
Type | Description |
---|---|
Boolean | True on success, false otherwise. |
UpdateTexture(CommandBuffer, Texture, ref Vector4, Boolean, Boolean)
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) |
Boolean | updateIfNeeded | Enable texture blit. |
Boolean | blitMips | Blit mip maps. |
Returns
Type | Description |
---|---|
Boolean | True on success, false otherwise. |