Table of Contents

Class Etc2TileCodec

Disk-format codec for ETC2 GPU blocks already stored in a cache blob: no image decode, extract the mip levels an upload needs.

public sealed class Etc2TileCodec : ITileBlockCodec, ITileCodec
Inheritance
object
Etc2TileCodec
Implements

Properties

Format

The TileCacheBlob.Format tag this codec recognizes.

public TileCacheBlob.Format Format { get; }

Property Value

TileCacheBlob.Format

Id

Stable lowercase identifier for this codec, for example "bc1", "etc2", or "astc4x4".

public string Id { get; }

Property Value

string

Remarks

Serialized scenes carry this string. Do not localize it, and do not change the spelling once shipped. One id is one GPU block format including its parameters: a family such as ASTC ships as separate ids ("astc4x4", "astc6x6"), never a bare "astc".

RequiresDecode

True when the payload is still compressed (PNG/JPEG) and needs an image decode; false when it is already GPU-ready blocks.

public bool RequiresDecode { get; }

Property Value

bool

Methods

DecodeLevel(byte[], int, int, int, byte[], int)

Decodes one already-extracted mip level's raw blocks back to RGBA8888.

public void DecodeLevel(byte[] blocks, int offset, int width, int height, byte[] outRgba, int outOffset)

Parameters

blocks byte[]

Level bytes, LevelBlockBytes(int, int) readable from offset.

offset int

Start of this level in blocks, in bytes.

width int

Level width in texels.

height int

Level height in texels.

outRgba byte[]

Destination, widthheight4 RGBA8888 bytes row-major from outOffset.

outOffset int

Start write index in outRgba, in bytes.

Remarks

Cache migration only needs the base level; the rest of a stored chain is discarded and rebuilt by the new codec's WritePayload(int, int, byte[], byte[], byte[], int). The default throws NotSupportedException so a codec that has not overridden this still compiles and simply skips local migration.

LevelBlockBytes(int, int)

Byte count of one mip level as raw blocks, block-rounded.

public int LevelBlockBytes(int widthTexels, int heightTexels)

Parameters

widthTexels int

Level width in texels.

heightTexels int

Level height in texels.

Returns

int

Size in bytes of each TryBuildMips(byte[], int, int, int, int, byte[][]) buffer for this level. A tail smaller than one block still costs one whole block.

RequiredPayloadBytes(int, int)

Byte count of one whole disk payload (header plus every mip of a full chain) for a base level of the given dimensions.

public int RequiredPayloadBytes(int width, int height)

Parameters

width int

Base-level width in texels.

height int

Base-level height in texels.

Returns

int

Payload size in bytes.

TryBuildMips(byte[], int, int, int, int, byte[][])

Extracts requiredLevels mip levels from a GPU-ready disk payload into caller-owned buffers.

public bool TryBuildMips(byte[] payload, int offset, int length, int tileSizePx, int requiredLevels, byte[][] mips)

Parameters

payload byte[]

Disk payload bytes, not copied.

offset int

Start of this tile's payload in payload, in bytes.

length int

Readable byte count from offset.

tileSizePx int

Expected base-level edge length in texels.

requiredLevels int

Mip levels to copy, 1 or more.

mips byte[][]

Caller-owned buffers, one per level; each entry must already hold that level's block-byte count.

Returns

bool

True when the payload parsed and the levels were copied; false (never throws) on a corrupt or foreign-written entry.

Remarks

Only meaningful when RequiresDecode is false. The buffers in mips are reused across calls: size them before calling, do not allocate here.

WritePayload(int, int, byte[], byte[], byte[], int)

Encodes base-level RGBA8888 into a full mip-chain disk payload.

public int WritePayload(int width, int height, byte[] rgba, byte[] scratchRgba, byte[] outPayload, int outOffset)

Parameters

width int

Base-level width in texels.

height int

Base-level height in texels.

rgba byte[]

Base-level widthheight4 RGBA8888 bytes; a working buffer, not preserved.

scratchRgba byte[]

Caller-owned scratch of at least widthheight4 bytes; a working buffer, not preserved.

outPayload byte[]

Caller-owned destination, at least RequiredPayloadBytes(int, int) bytes from outOffset.

outOffset int

Start write index in outPayload, in bytes.

Returns

int

Bytes written, equal to RequiredPayloadBytes(int, int).

Remarks

rgba and scratchRgba are ping-pong working buffers. After return, neither holds the original level-0 pixels. Pass a copy if you still need them.