ontex

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 8 Imported by: ? modules, 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 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

View Source
const (
	// Extension is the suffix the build pipeline writes.
	Extension = ".ontex"
	// Version is the container revision carried by the magic.
	Version = 1
)
View Source
const (
	// FlagPremultipliedAlpha marks colour channels already scaled by alpha.
	// Compressed payloads bake this in, so the runtime cannot infer it.
	FlagPremultipliedAlpha = 1 << 0
)

Flags recorded alongside the compressed payload.

Variables

This section is empty.

Functions

func Decode

func Decode(data []byte, options graphics.TextureOptions) (*graphics.Texture, error)

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

func Marshal(image Image) ([]byte, error)

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) DecodeImage(data []byte, options graphics.TextureOptions) (*graphics.Texture, error)

func (Decoder) ImageContainerMagic

func (Decoder) ImageContainerMagic() []byte

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

func (Decoder) ImageExtension() string

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.

type Image

type Image struct {
	Data          []byte
	Width, Height int
	Levels        int
	Format        render.TextureFormat
	Premultiplied bool
}

Image is a container payload. Data holds every mip level concatenated from the largest down to 1x1, which is the order the device uploads them in.

func Unmarshal

func Unmarshal(data []byte) (Image, error)

Unmarshal reads a container header and borrows the payload from data. Decode takes its own copy so the source can be released before GPU upload.

Jump to

Keyboard shortcuts

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