Class Texture
Namespace: ValveResourceFormat.ResourceTypes
Assembly: ValveResourceFormat.dll
Represents a texture resource containing image data with various formats and metadata.
public class Texture : BlockInheritance
Inherited Members
Block.Type, Block.Offset, Block.Size, Block.Resource, Block.Read(BinaryReader), Block.ToString(), Block.WriteText(IndentedTextWriter), Block.Serialize(Stream)
Extension Methods
ResourceDataExtensions.AsKeyValueCollection(Block)
Constructors
Texture()
Initializes a new instance of the class.
public Texture()Fields
DefaultBitmapColorType
The default color type used for standard dynamic range bitmaps.
public const SKColorType DefaultBitmapColorType = Bgra8888Field Value
HdrBitmapColorType
The color type used for high dynamic range bitmaps.
public const SKColorType HdrBitmapColorType = RgbaF32Field Value
Properties
ActualHeight
Gets the actual height of the texture, using if available and valid, otherwise . 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
ActualWidth
Gets the actual width of the texture, using if available and valid, otherwise . 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
BlockSize
Gets the block size in bytes for the current texture format.
public int BlockSize { get; }Property Value
Depth
Gets the depth of the texture for volume textures, or the number of array slices.
public ushort Depth { get; }Property Value
DisplayRectHeight
Gets the height of the sub-rect of the texture that should actually be displayed. Zero when it does not fit within .
public ushort DisplayRectHeight { get; }Property Value
DisplayRectWidth
Gets the width of the sub-rect of the texture that should actually be displayed. Zero when it does not fit within .
public ushort DisplayRectWidth { get; }Property Value
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
Format
Gets the pixel format of the texture data.
public VTexFormat Format { get; }Property Value
Height
Gets the height of the texture in pixels.
public ushort Height { get; }Property Value
IsHighDynamicRange
Gets a value indicating whether this texture uses a high dynamic range format.
public bool IsHighDynamicRange { get; }Property Value
IsRawAnyImage
Gets a value indicating whether this texture contains raw image data, not block data.
public bool IsRawAnyImage { get; }Property Value
IsRawJpeg
Gets a value indicating whether this texture contains raw JPEG data.
public bool IsRawJpeg { get; }Property Value
IsRawPng
Gets a value indicating whether this texture contains raw PNG data.
public bool IsRawPng { get; }Property Value
IsRawWebp
Gets a value indicating whether this texture contains raw WebP data.
public bool IsRawWebp { get; }Property Value
MotionVectorsMaxDistance
Gets the maximum distance in pixels that a motion vector texture may displace per frame. Zero for regular textures.
public short MotionVectorsMaxDistance { get; }Property Value
NumMipLevels
Gets the number of mip levels in the texture.
public byte NumMipLevels { get; }Property Value
Picmip0Res
Gets the picmip 0 resolution value. Unused, always 0 in modern files.
public uint Picmip0Res { get; }Property Value
RadianceCoefficients
Gets the baked radiance of each cube map in the array as an L2 spherical harmonic, 9 coefficients per channel stored planar, 27 per cube map. Null unless the texture carries .
public float[]? RadianceCoefficients { get; }Property Value
float[]?
RangeMax
Gets the upper bound of the value range each channel was remapped from, only used by textures that store range compressed data such as spherical harmonics.
public Vector4 RangeMax { get; }Property Value
RangeMin
Gets the lower bound of the value range each channel was remapped from, only used by textures that store range compressed data such as spherical harmonics.
public Vector4 RangeMin { get; }Property Value
Reflectivity
Gets the reflectivity values as a 4-component vector (RGBA).
public Vector4 Reflectivity { get; }Property Value
Type
Gets the block type.
public override BlockType Type { get; }Property Value
Version
Gets the texture version number.
public ushort Version { get; }Property Value
Width
Gets the width of the texture in pixels.
public ushort Width { get; }Property Value
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
Buffer size.
CalculateInPlaceDecompressionBufferSize(uint)
Calculate decompression buffer size for .
public int CalculateInPlaceDecompressionBufferSize(uint mipLevel)Parameters
mipLevel uint
Returns
CalculateTextureDataSize()
Calculates the total size of texture data across all mip levels.
public int CalculateTextureDataSize()Returns
The total size in bytes.
DecodeTexture(ReadOnlySpan<byte>, Span<byte>, int, int, int)
Decompress every slice of one block compressed mip level into RGBA8.
public void DecodeTexture(ReadOnlySpan<byte> compressedSource, Span<byte> dest, int width, int height, int depth = 1)Parameters
compressedSource ReadOnlySpan<byte>
Compressed mip level, as returned by .
Buffer of at least width * height * depth * 4 bytes.
width int
Width of the mip level.
height int
Height of the mip level.
depth int
Number of slices in the mip level to decode if this is 2DArray or 3D.
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
Skia bitmap.
GetBiggestBufferSize()
Biggest buffer size to be used with .
public int GetBiggestBufferSize()Returns
The size of the largest mip level (mip 0) in bytes.
GetEveryMipLevelMetrics()
Get metrics like dimensions and buffer size for every mip level.
public IEnumerable<(uint Level, int Width, int Height, int Depth, int BufferSize)> GetEveryMipLevelMetrics()Returns
IEnumerable<(uint Level, int Width, int Height, int Depth, int BufferSize)>
An enumerable of tuples containing mip level, width, height, depth, and buffer size for each mip level, from smallest to largest.
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 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
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 .
public void ReadTextureMipLevel(Span<byte> output, uint mipLevel)Parameters
Buffer that will receive texture data.
mipLevel uint
Mip level for which to read texture data.
ReadTextureMipLevelInPlace(Span<byte>, uint)
Read single mip level of texture into the front of buffer. LZ4 compressed mips are read into the buffer's tail and decompressed in place, so no scratch buffer is needed.
public void ReadTextureMipLevelInPlace(Span<byte> buffer, uint mipLevel)Parameters
Buffer that will receive texture data. Must be at least bytes.
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
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 .
public override void WriteText(IndentedTextWriter writer)Parameters
writer IndentedTextWriter
Remarks
Outputs detailed texture metadata including dimensions, format, and flags.

