Documentation
¶
Overview ¶
Package ontex reads and writes the ONIXTEX1 container: a block-compressed texture together with the mip chain the build already generated.
The container exists because compressed textures cannot be uploaded the way RGBA8 images are. A sampler cannot generate mips for block data, and a 4x4 block has no meaningful partial update, so the build has to ship the whole chain and the runtime has to hand it to the device untouched.
Index ¶
- Constants
- func Decode(data []byte, options graphics.TextureOptions) (*graphics.Texture, error)
- func Encode(pixels []byte, width, height int, options EncodeOptions) ([]byte, error)
- func Marshal(image Image) ([]byte, error)
- func SelectFormat(pixels []byte, srgb bool) render.TextureFormat
- type Decoder
- type EncodeOptions
- type Image
Constants ¶
const ( // Extension is the suffix the build pipeline writes. Extension = ".ontex" // Version is the container revision carried by the magic. Version = 1 )
const ( // FlagPremultipliedAlpha marks colour channels already scaled by alpha. // Compressed payloads bake this in, so the runtime cannot infer it. FlagPremultipliedAlpha = 1 << 0 // FlagASTCVariant appends a matching ASTC 4x4 mip chain after the BC chain. FlagASTCVariant = 1 << 1 )
Flags recorded alongside the compressed payload.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode validates a container and owns its payload until explicit GPU upload. Resource package views may be released as soon as decoding returns.
func Encode ¶
func Encode(pixels []byte, width, height int, options EncodeOptions) ([]byte, error)
Encode compresses RGBA8 pixels into an ONIXTEX1 container.
func Marshal ¶
Marshal encodes a container. It rejects payloads whose length does not match the mip chain the header describes, so a corrupt build fails loudly instead of uploading garbage.
func SelectFormat ¶
func SelectFormat(pixels []byte, srgb bool) render.TextureFormat
SelectFormat reports the format Encode picks when Format is left zero: BC3 whenever the source has transparency, because BC1 has no alpha channel, and BC1 otherwise.
Types ¶
type Decoder ¶
type Decoder struct{}
Decoder plugs the ONIXTEX1 container into a graphics.ImageDecoderSet.
func (Decoder) DecodeImage ¶
func (Decoder) ImageContainerMagic ¶
ImageContainerMagic claims containers by their leading bytes. A build packs a compressed texture in place of the source image, so a container can sit behind any extension the source used.
func (Decoder) ImageExtension ¶
type EncodeOptions ¶
type EncodeOptions struct {
// Format requests one compressed format. Leave it zero to let Encode choose
// between BC1 and BC3 based on whether the source has transparency.
Format render.TextureFormat
// SRGB marks colour textures. It selects the sRGB sampler variant so the
// device decodes gamma the way the source expects.
SRGB bool
// Premultiplied records that source colour is already scaled by alpha. The
// payload bakes it in, so the runtime cannot infer it later.
Premultiplied bool
// Mipmaps generates the full chain down to 1x1. Without it the container
// carries a single level and the texture aliases when minified.
Mipmaps bool
}
EncodeOptions selects how source pixels are compressed.