Table of Contents

Class Texture

Namespace
ValveResourceFormat.ResourceTypes
Assembly
ValveResourceFormat.dll

Represents a texture resource containing image data with various formats and metadata.

public class Texture : Block

Inheritance

Inherited Members

Extension Methods

Constructors

Texture()

Initializes a new instance of the ValveResourceFormat.ResourceTypes.Texture class.

public Texture()

Fields

DefaultBitmapColorType

The default color type used for standard dynamic range bitmaps.

public const SKColorType DefaultBitmapColorType = Bgra8888

Field Value

SKColorType

HdrBitmapColorType

The color type used for high dynamic range bitmaps.

public const SKColorType HdrBitmapColorType = RgbaF32

Field Value

SKColorType

Properties

ActualHeight

Gets the actual height of the texture, using NonPow2Height if available and valid, otherwise Height. Some textures have displayrect set to 1x1, but that's not the expected size. If it's set to 1x1, but the real size does not expand to 4x4 (the usual block compression size), it's ignored.

public ushort ActualHeight { get; }

Property Value

ushort

ActualWidth

Gets the actual width of the texture, using NonPow2Width if available and valid, otherwise Width. Some textures have displayrect set to 1x1, but that's not the expected size. If it's set to 1x1, but the real size does not expand to 4x4 (the usual block compression size), it's ignored.

public ushort ActualWidth { get; }

Property Value

ushort

BlockSize

Gets the block size in bytes for the current texture format.

public int BlockSize { get; }

Property Value

int

Depth

Gets the depth of the texture for volume textures, or the number of array slices.

public ushort Depth { get; }

Property Value

ushort

ExtraData

Gets the dictionary containing extra data blocks associated with the texture.

public Dictionary<VTexExtraData, byte[]> ExtraData { get; }

Property Value

Dictionary<VTexExtraData, byte[]>

Flags

Gets the texture flags that define various properties and behaviors.

public VTexFlags Flags { get; }

Property Value

VTexFlags

Format

Gets the pixel format of the texture data.

public VTexFormat Format { get; }

Property Value

VTexFormat

Height

Gets the height of the texture in pixels.

public ushort Height { get; }

Property Value

ushort

IsHighDynamicRange

Gets a value indicating whether this texture uses a high dynamic range format.

public bool IsHighDynamicRange { get; }

Property Value

bool

IsRawAnyImage

Gets a value indicating whether this texture contains raw image data, not block data.

public bool IsRawAnyImage { get; }

Property Value

bool

IsRawJpeg

Gets a value indicating whether this texture contains raw JPEG data.

public bool IsRawJpeg { get; }

Property Value

bool

IsRawPng

Gets a value indicating whether this texture contains raw PNG data.

public bool IsRawPng { get; }

Property Value

bool

IsRawWebp

Gets a value indicating whether this texture contains raw WebP data.

public bool IsRawWebp { get; }

Property Value

bool

NonPow2Height

Gets the non-power-of-2 height value, if different from the main height.

public ushort NonPow2Height { get; }

Property Value

ushort

NonPow2Width

Gets the non-power-of-2 width value, if different from the main width.

public ushort NonPow2Width { get; }

Property Value

ushort

NumMipLevels

Gets the number of mip levels in the texture.

public byte NumMipLevels { get; }

Property Value

byte

Picmip0Res

Gets the picmip 0 resolution value.

public uint Picmip0Res { get; }

Property Value

uint

Reflectivity

Gets the reflectivity values as a 4-component vector (RGBA).

public float[] Reflectivity { get; }

Property Value

float[]

Type

Gets the block type.

public override BlockType Type { get; }

Property Value

BlockType

Version

Gets the texture version number.

public ushort Version { get; }

Property Value

ushort

Width

Gets the width of the texture in pixels.

public ushort Width { get; }

Property Value

ushort

Methods

CalculateBufferSizeForMipLevel(uint)

Calculate buffer size that is required to hold data of specified mip level.

public int CalculateBufferSizeForMipLevel(uint mipLevel)

Parameters

mipLevel uint

Mip level for which to calculate buffer size.

Returns

int

Buffer size.

CalculateTextureDataSize()

Calculates the total size of texture data across all mip levels.

public int CalculateTextureDataSize()

Returns

int

The total size in bytes.

GenerateBitmap(uint, CubemapFace, uint, TextureCodec)

Generate a bitmap for given parameters.

public SKBitmap GenerateBitmap(uint depth = 0, Texture.CubemapFace face = CubemapFace.PositiveX, uint mipLevel = 0, TextureCodec decodeFlags = TextureCodec.Auto)

Parameters

depth uint

The depth to extract.

face Texture.CubemapFace

The face to extract for cube textures.

mipLevel uint

The mip level to extract.

decodeFlags TextureCodec

The preferred codec to use when decoding the texture.

Returns

SKBitmap

Skia bitmap.

GetBiggestBufferSize()

Biggest buffer size to be used with ValveResourceFormat.ResourceTypes.Texture.GetEveryMipLevelTexture(System.Byte[],System.Int32).

public int GetBiggestBufferSize()

Returns

int

The size of the largest mip level (mip 0) in bytes.

GetEveryMipLevelTexture(byte[], int)

Get every mip level size starting from the smallest one. Used when uploading textures to the GPU. This writes into the buffer for every mip level, so the buffer must be used before next texture is yielded.

public IEnumerable<(uint Level, int Width, int Height, int Depth, int BufferSize)> GetEveryMipLevelTexture(byte[] buffer, int minMipLevelAllowed = 0)

Parameters

buffer byte[]

Buffer to use when yielding textures, it should be size of ValveResourceFormat.ResourceTypes.Texture.GetBiggestBufferSize or bigger. This buffer is reused for every mip level.

minMipLevelAllowed int

The minimum mip level for which to read texture data.

Returns

IEnumerable<(uint Level, int Width, int Height, int Depth, int BufferSize)>

GetSpriteSheetData()

Retrieves sprite sheet data if available in the texture's extra data.

public Texture.SpritesheetData GetSpriteSheetData()

Returns

Texture.SpritesheetData

The sprite sheet data, or null if not available.

Read(BinaryReader)

Reads the block data from a binary reader.

public override void Read(BinaryReader reader)

Parameters

reader BinaryReader

The binary reader to read from.

ReadTextureMipLevel(Span<byte>, uint)

Read single mip level of texture. Buffer size must be at least ValveResourceFormat.ResourceTypes.Texture.CalculateBufferSizeForMipLevel(System.UInt32).

public void ReadTextureMipLevel(Span<byte> output, uint mipLevel)

Parameters

output Span<byte>

Buffer that will receive texture data.

mipLevel uint

Mip level for which to read texture data.

RetrieveCodecFromResourceEditInfo()

Retrieves the texture codec information from the resource's edit info.

public TextureCodec RetrieveCodecFromResourceEditInfo()

Returns

TextureCodec

The texture codec flags derived from the edit info.

Serialize(Stream)

Writes the binary representation of the object to Stream.

public override void Serialize(Stream stream)

Parameters

stream Stream

Stream.

WriteText(IndentedTextWriter)

Writes the correct text dump of the object to IndentedTextWriter.

public override void WriteText(IndentedTextWriter writer)

Parameters

writer IndentedTextWriter

IndentedTextWriter.

Remarks

Outputs detailed texture metadata including dimensions, format, and flags.