texture

package
v0.1.119 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 6 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package texture reads Source 2 compiled textures (.vtex_c): the header in the resource's DATA block, the mips stored after it, smallest first, and the top mip decoded to an image.

Index

Constants

View Source
const FlagCube = 0x10

FlagCube marks a cube map, whose every mip holds six faces in turn.

Variables

This section is empty.

Functions

This section is empty.

Types

type Format

type Format uint8

Format is how a texture encodes its texels, by the number its header stores.

const (
	// FormatDXT1 is BC1: 4x4 blocks of 8 bytes, two 565 colors.
	FormatDXT1 Format = 1
	// FormatDXT5 is BC3: a BC4 alpha block before a BC1 color block.
	FormatDXT5 Format = 2
	// FormatRGBA8888 stores four bytes per texel, red first.
	FormatRGBA8888 Format = 4
	// FormatBC6H is half-float color in 16 byte blocks.
	FormatBC6H Format = 19
	// FormatBC7 is 8-bit color and alpha in 16 byte blocks.
	FormatBC7 Format = 20
	// FormatATI2N is BC5: two BC4 blocks, red then green.
	FormatATI2N Format = 21
	// FormatATI1N is BC4: one channel in 8 byte blocks.
	FormatATI1N Format = 27
	// FormatBGRA8888 stores four bytes per texel, blue first.
	FormatBGRA8888 Format = 28
)

The texture formats Deadlock ships.

func (Format) BlockBytes

func (f Format) BlockBytes() int

BlockBytes returns the bytes in each 4x4 block of a block-compressed format, and zero for any other.

func (Format) Size

func (f Format) Size(w, h int) (int, bool)

Size returns the bytes one w by h image takes in the format, and false for a format whose size is unknown.

func (Format) String

func (f Format) String() string

String names the format, or gives its number.

type Texture

type Texture struct {
	// AverageColor is the stored linear RGB reflectivity used as the shader's
	// color-correction pivot, without a gamma conversion.
	AverageColor [3]float32
	// Width is the top mip's width in texels.
	Width int
	// Height is the top mip's height in texels.
	Height int
	// Depth is the top mip's depth in slices, at least one.
	Depth int
	// Format is how the mips encode their texels.
	Format Format
	// Mips counts the stored mips, at least one.
	Mips int
	// Flags holds the header's flags, such as FlagCube.
	Flags int
	// VisibleWidth is the width of the image inside any padding.
	VisibleWidth int
	// VisibleHeight is the height of the image inside any padding.
	VisibleHeight int
	// Pixels holds every mip as stored, smallest first, and aliases the
	// resource Read was given.
	Pixels []byte
}

Texture is a compiled texture's header and its stored mips.

func Read

func Read(compiled []byte) (*Texture, error)

Read reads a compiled texture's header and locates its mips.

func (*Texture) Image

func (t *Texture) Image() (*image.NRGBA, error)

Image decodes the top mip's first face or slice, cropped to the visible size. BC4 decodes to gray and BC5 to red and green.

func (*Texture) MipSize

func (t *Texture) MipSize(mip int) (int, bool)

MipSize returns the bytes one mip takes, every face and slice included, and false for a format whose size is unknown.

func (*Texture) Stored

func (t *Texture) Stored(from int) ([]byte, error)

Stored returns the stored bytes of every mip from the given one down to the smallest, smallest first as the file holds them: one range, read in place.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL