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 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
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
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
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
NonPow2Height
Gets the non-power-of-2 height value, if different from the main height.
public ushort NonPow2Height { get; }Property Value
NonPow2Width
Gets the non-power-of-2 width value, if different from the main width.
public ushort NonPow2Width { 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.
public uint Picmip0Res { 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.
CalculateTextureDataSize()
Calculates the total size of texture data across all mip levels.
public int CalculateTextureDataSize()Returns
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
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.
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.
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 IndentedTextWriter.
public override void WriteText(IndentedTextWriter writer)Parameters
writer IndentedTextWriter
IndentedTextWriter.
Remarks
Outputs detailed texture metadata including dimensions, format, and flags.

