render

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 11 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

Index

Constants

View Source
const (
	MeshPassLit = iota
	MeshPassShadowDepth
	MeshPassOcclusionDepth
	MeshPassReflectionCapture
	MeshPassReflectionResolve
	MeshPassReflectionDepth
	MeshPassReflectionOcclusion
	MeshPassFXAA
)

Mesh passes reuse the same texture/uniform ABI. SSR resolve aliases shadow records and bindings after capturing direct/indirect illumination.

View Source
const MaxMeshLights = 16

MaxMeshLights is the fixed number of extracted lights uploaded to a mesh shader. Keeping the limit stable lets every backend use stack or reused storage and avoids per-frame growth while still allowing mixed light kinds.

View Source
const MaxShadowMaps = 16

MaxShadowMaps keeps the complete fragment uniform block within GLES3's minimum 224 vec4 uniforms and Metal's 4 KiB setFragmentBytes limit.

View Source
const MeshExtraTextureSlots = MeshSurfaceTextureSlots + 3
View Source
const MeshFlagNoReflection = 1 << 22
View Source
const MeshSurfaceTextureSlots = 10
View Source
const SpriteTextureSlots = 4

SpriteTextureSlots is the built-in sprite pipeline's per-draw texture limit.

Variables

View Source
var LCDTextBlend = BlendState{
	RGB:   Blend{Src: BlendConstantColor, Dst: BlendOneMinusSrcColor},
	Alpha: Blend{Src: BlendZero, Dst: BlendOne},
}

LCDTextBlend combines RGB coverage with Constant foreground color in one pass: coverage*foreground + destination*(1-coverage). Surface alpha is kept.

View Source
var PremultipliedAlphaBlend = BlendState{
	RGB:   Blend{Src: BlendOne, Dst: BlendOneMinusSrcAlpha},
	Alpha: Blend{Src: BlendOne, Dst: BlendOneMinusSrcAlpha},
}

Functions

func Install

func Install(driver Driver) error

Install replaces the standalone default device. Window-owned devices have independent lifetimes and are never destroyed by this operation.

func MeshSurfaceTextureFlag

func MeshSurfaceTextureFlag(slot int) uint32

func MipLevels

func MipLevels(width, height int) int

MipLevels reports how many levels a full chain down to 1x1 contains.

func Present

func Present() error

func ResetStatistics

func ResetStatistics()

ResetStatistics starts a new frame statistics window.

func ResizeSurface

func ResizeSurface(width, height int) error

func SetSurfaceCornerRadius

func SetSurfaceCornerRadius(radius int)

func SetVSync

func SetVSync(enabled bool)

func Uninstall

func Uninstall()

Types

type Backend

type Backend string

Backend is selected at compile time with an onix_<backend> build tag.

const (
	BackendDirectX Backend = "directx"
	BackendMetal   Backend = "metal"
	BackendVulkan  Backend = "vulkan"
	BackendOpenGL  Backend = "opengl"
	BackendWebGPU  Backend = "webgpu"
	BackendWebGL   Backend = "webgl"
)
const CompiledBackend Backend = BackendOpenGL

func Backends

func Backends(platform string) []Backend

Backends lists a platform's renderers, with its default first.

func ResolveBackend

func ResolveBackend(platform string, backend Backend) (Backend, error)

func (Backend) BuildTag

func (backend Backend) BuildTag() string

func (Backend) String

func (backend Backend) String() string

type Blend

type Blend struct {
	Src BlendFactor
	Dst BlendFactor
}

type BlendFactor

type BlendFactor uint8
const (
	BlendZero BlendFactor = iota
	BlendOne
	BlendSrcColor
	BlendOneMinusSrcColor
	BlendSrcAlpha
	BlendOneMinusSrcAlpha
	BlendDstAlpha
	BlendOneMinusDstAlpha
	BlendDstColor
	BlendOneMinusDstColor
	BlendSrcAlphaSaturate
	BlendConstantColor
	BlendOneMinusConstantColor
	BlendConstantAlpha
	BlendOneMinusConstantAlpha
)

type BlendState

type BlendState struct {
	RGB      Blend
	Alpha    Blend
	Constant Color
}

type BufferMemoryStatistics

type BufferMemoryStatistics struct {
	InstanceBytes      uint64
	StagingBytes       uint64
	ReadbackBytes      uint64
	NativeScratchBytes uint64
	ScratchBytes       uint64
}

BufferMemoryStatistics reports reserved transient buffers, including all frames in flight. It excludes textures, resident meshes and driver allocations. NativeScratchBytes reports native buffer, upload and descriptor metadata, retirement queues and CPU snapshots. ScratchBytes is Go memory and is already included in runtime.HeapAlloc.

func CurrentBufferMemoryStatistics

func CurrentBufferMemoryStatistics() BufferMemoryStatistics

CurrentBufferMemoryStatistics must be called on the rendering thread.

func (BufferMemoryStatistics) NativeBytes

func (s BufferMemoryStatistics) NativeBytes() uint64

type Color

type Color struct {
	R float32
	G float32
	B float32
	A float32
}

type Device

type Device struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Device owns one driver. Activation only selects the immediate rendering context; lifetime belongs to the window or host that created the device.

func ActiveDevice

func ActiveDevice() *Device

func NewDevice

func NewDevice(driver Driver) (*Device, error)

func (*Device) Activate

func (device *Device) Activate()

func (*Device) BufferMemoryStatistics

func (device *Device) BufferMemoryStatistics() BufferMemoryStatistics

func (*Device) Destroy

func (device *Device) Destroy()

func (*Device) Driver

func (device *Device) Driver() Driver

func (*Device) Present

func (device *Device) Present() error

func (*Device) RendererInfo

func (device *Device) RendererInfo() RendererInfo

func (*Device) ResetStatistics

func (device *Device) ResetStatistics()

func (*Device) ResizeSurface

func (device *Device) ResizeSurface(width, height int) error

func (*Device) SetSurfaceCornerRadius

func (device *Device) SetSurfaceCornerRadius(radius int)

func (*Device) SetVSync

func (device *Device) SetVSync(enabled bool)

func (*Device) Statistics

func (device *Device) Statistics() FrameStatistics

func (*Device) SupportsIdleBufferTrim

func (device *Device) SupportsIdleBufferTrim() bool

func (*Device) TrimIdleBuffers

func (device *Device) TrimIdleBuffers() error

type DeviceValues

type DeviceValues[T any] struct {
	// contains filtered or unexported fields
}

DeviceValues keeps the common single-device residency inline. Additional devices allocate once on first use; warmed lookups and iteration allocate nothing.

func (*DeviceValues[T]) Clear

func (values *DeviceValues[T]) Clear()

func (*DeviceValues[T]) Each

func (values *DeviceValues[T]) Each(visit func(*Device, T) error) error

func (*DeviceValues[T]) Get

func (values *DeviceValues[T]) Get(device *Device) (T, bool)

func (*DeviceValues[T]) Release

func (values *DeviceValues[T]) Release(dispose func(*Device, T) error) error

func (*DeviceValues[T]) Remove

func (values *DeviceValues[T]) Remove(device *Device) (T, bool)

Remove transfers one device's value to the caller, including values whose device has already been destroyed. Other device residencies remain intact.

func (*DeviceValues[T]) Set

func (values *DeviceValues[T]) Set(device *Device, value T)

type Driver

type Driver interface {
	RendererInfo() RendererInfo
	BeginFrame(clear Color) error
	SetViewport(Rect)
	Viewport() Rect
	SetBlend(BlendState) error
	SetScissor(*Rect)
	// CreateTexture consumes pixels before returning; it must copy any bytes
	// needed by deferred work. The caller may immediately reuse the slice.
	CreateTexture(TextureDescriptor, []byte) (TextureHandle, error)
	// UpdateTextures consumes every update's pixels before returning.
	UpdateTextures([]TextureUpdate) error
	DestroyTexture(TextureHandle) error
	DrawSprites(SpriteBatch) error
	DrawShapes(ShapeBatch) error
	Present() error
	ResizeSurface(width, height int) error
	SetVSync(enabled bool)
	Destroy()
}

Driver is the complete platform rendering boundary. Implementations submit native draw commands; callers never depend on API-specific constants.

func Current

func Current() Driver

func NewOpenGLDriver

func NewOpenGLDriver(surface NativeSurface) (Driver, error)

type EnvironmentEncoding

type EnvironmentEncoding uint8

EnvironmentEncoding describes radiance in the first seven atlas tiles. The eighth tile always stores a linear BRDF LUT.

const (
	EnvironmentRGBM EnvironmentEncoding = iota
	EnvironmentRGBE
)

type ExternalTextureDescriptor

type ExternalTextureDescriptor struct {
	Handle   uint64
	Width    int
	Height   int
	Modifier uint64
	Stride   uint32
	Offset   uint32
	Kind     ExternalTextureKind
	Format   ExternalTextureFormat
}

ExternalTextureDescriptor identifies a texture owned by a platform media pipeline. Handle is opaque to the render package and is interpreted only by a driver implementing ExternalTextureDriver.

func (ExternalTextureDescriptor) Validate

func (d ExternalTextureDescriptor) Validate() error

type ExternalTextureDriver

type ExternalTextureDriver interface {
	CreateExternalTexture(ExternalTextureDescriptor) (TextureHandle, error)
}

ExternalTextureDriver is optional. Existing renderers continue to use the CPU upload path unless they explicitly support importing platform surfaces.

type ExternalTextureFormat

type ExternalTextureFormat uint8
const (
	ExternalTextureBGRA8 ExternalTextureFormat = iota + 1
	ExternalTextureRGBA8
)

type ExternalTextureKind

type ExternalTextureKind uint8
const (
	ExternalTextureD3D11 ExternalTextureKind = iota + 1
	ExternalTextureDMABuf
	ExternalTextureVulkan
	ExternalTextureMetal
)

type ExternalTextureRefreshDriver

type ExternalTextureRefreshDriver interface {
	RefreshExternalTexture(TextureHandle) error
}

ExternalTextureRefreshDriver marks an imported texture as having new producer content. Renderers use this hook to attach cross-API synchronization only to frames that actually consume a new surface.

type FrameStatistics

type FrameStatistics struct {
	SurfaceWidth  uint64
	SurfaceHeight uint64

	DrawCalls uint64
	Sprites   uint64
	Shapes    uint64
	Meshes    uint64
	Vertices  uint64
	Triangles uint64

	SpriteDrawCalls uint64
	ShapeDrawCalls  uint64
	MeshDrawCalls   uint64

	BufferUploadBytes uint64

	DynamicMeshDrawCalls   uint64
	DynamicMeshVertices    uint64
	DynamicMeshIndices     uint64
	DynamicMeshUploadBytes uint64

	TextureUploads     uint64
	TextureUploadBytes uint64
}

FrameStatistics describes the work submitted to the GPU in the current frame. It reports submission and upload counts, not fragment count or GPU execution time; use a platform GPU capture for those measurements.

func Statistics

func Statistics() FrameStatistics

Statistics returns a snapshot of the draw work submitted so far this frame.

type GenerationPool

type GenerationPool[R, V any] struct {
	// contains filtered or unexported fields
}

func (*GenerationPool[R, V]) Clear

func (p *GenerationPool[R, V]) Clear()

func (*GenerationPool[R, V]) Get

func (p *GenerationPool[R, V]) Get(handle Handle[R]) (V, bool)

func (*GenerationPool[R, V]) Insert

func (p *GenerationPool[R, V]) Insert(value V) Handle[R]

func (*GenerationPool[R, V]) Len

func (p *GenerationPool[R, V]) Len() int

func (*GenerationPool[R, V]) Range

func (p *GenerationPool[R, V]) Range(yield func(V) bool)

func (*GenerationPool[R, V]) Remove

func (p *GenerationPool[R, V]) Remove(handle Handle[R]) (V, bool)

type Handle

type Handle[T any] struct {
	// contains filtered or unexported fields
}

Handle is a typed GPU resource reference.

func NewHandle

func NewHandle[T any](id, generation uint32) Handle[T]

func (Handle[T]) Generation

func (h Handle[T]) Generation() uint32

func (Handle[T]) ID

func (h Handle[T]) ID() uint32

func (Handle[T]) String

func (h Handle[T]) String() string

func (Handle[T]) Valid

func (h Handle[T]) Valid() bool

type IdleBufferTrimmer

type IdleBufferTrimmer interface{ TrimIdleBuffers() error }

IdleBufferTrimmer releases transient storage after submitted work completes. App calls it on the rendering thread, outside any active frame.

type Instance2D

type Instance2D struct {
	Model        [6]float32
	TextureModel [6]float32
	Color        [4]float32
	Custom       [4][4]float32
	// TextureSlot selects a SpriteDraw texture in [0, SpriteTextureSlots).
	TextureSlot float32
}

type Instance3D

type Instance3D struct {
	Model            [16]float32
	BaseColor        [4]float32
	EmissiveMetallic [4]float32 // emissive RGB after strength, metallic
	Material         [4]float32 // roughness, IOR, alpha cutoff, flags
	UVTransform      [4]float32
	Custom           [4][4]float32
}

func (Instance3D) PickingID

func (instance Instance3D) PickingID() uint32

func (*Instance3D) SetPickingID

func (instance *Instance3D) SetPickingID(id uint32)

SetPickingID stores an exact uint32 bit pattern in the instance lane used by the dedicated picking shaders. Picking batches are copies, so material custom data in the simulation world is never modified.

type Light3D

type Light3D struct {
	Kind              Light3DKind
	Right             [4]float32
	Up                [4]float32
	PositionDirection [4]float32
	Direction         [4]float32
	Color             [4]float32
	Params            [4]float32
}

Light3D is a renderer-independent extracted light. PositionDirection uses xyz as a position for local lights and as a direction for directional lights. Color.rgb is linear; Color.w is the source radius. Params stores range, candela/nits (lux for box), and cone cosines. Right/Up carry orthonormal axes and shape dimensions in w.

type Light3DKind

type Light3DKind uint32
const (
	Light3DAmbient Light3DKind = iota
	Light3DDirectional
	Light3DPoint
	Light3DSpot
	Light3DPyramid
	Light3DBox
	Light3DRectangle
	Light3DDisc
	Light3DTube
)

type Material2DShaderDriver

type Material2DShaderDriver interface {
	CreateMaterial2DShader(ShaderDescriptor) (Material2DShaderHandle, error)
	DestroyMaterial2DShader(Material2DShaderHandle) error
}

Material2DShaderDriver is implemented by sprite renderers that can compile user-provided Material2D pipelines.

type Material2DShaderHandle

type Material2DShaderHandle = Handle[Material2DShaderResource]

type Material2DShaderResource

type Material2DShaderResource struct{}

type MeshBatch3D

type MeshBatch3D struct {
	Lights           []Light3D
	Vertices         []Vertex3D
	Indices          []uint32
	Instances        []Instance3D
	Draws            []MeshDraw3D
	Deformations     []MeshDeformationData
	Lighting         MeshLighting
	ViewProjection   [16]float32
	CameraPosition   [4]float32
	AmbientLight     [4]float32
	LightDirection   [4]float32
	DirectionalLight [4]float32
}

type MeshBlendMode

type MeshBlendMode uint32
const (
	MeshBlendNormal MeshBlendMode = iota
	MeshBlendAdditive
	MeshBlendMultiply
	MeshBlendScreen
)

type MeshDeformationData

type MeshDeformationData struct {
	JointMatrices []mgl32.Mat4
	MorphWeights  []float32
	Mesh          MeshHandle
}

MeshDeformationData borrows only the animated parameters for this submission. Static skin and morph streams reside in Mesh until DestroyMesh.

type MeshDeformationDescriptor

type MeshDeformationDescriptor struct {
	Skin         []MeshSkinVertex
	MorphTargets []MeshMorphVertex
	VertexCount  uint32
	TargetCount  uint32
}

MeshDeformationDescriptor is uploaded once and owned by the mesh resource. SetMeshDeformation copies its slices; changing the streams requires a new mesh.

type MeshDraw3D

type MeshDraw3D struct {
	// SurfaceTextures follow MaterialSurface.Textures order.
	SurfaceTextures [MeshSurfaceTextureSlots]TextureHandle
	Mesh            MeshHandle
	Shader          MeshShaderHandle
	Texture         TextureHandle
	NormalTexture   TextureHandle
	// MetallicRoughnessTexture stores glTF's occlusion-independent
	// metallic (B) and roughness (G) channels. A zero handle makes the
	// renderer use the scalar material factors.
	MetallicRoughnessTexture TextureHandle
	FirstIndex               uint32
	IndexCount               uint32
	BaseVertex               int32
	FirstInstance            uint32
	InstanceCount            uint32
	AlphaMode                uint32
	BlendMode                MeshBlendMode
	// DeformationIndex is one-based into MeshBatch3D.Deformations. Zero
	// means that the draw uses its original vertex attributes.
	DeformationIndex uint32
}

func (MeshDraw3D) ExtraTextures

func (draw MeshDraw3D) ExtraTextures(lighting *MeshLighting) [MeshExtraTextureSlots]TextureHandle

type MeshDriver

type MeshDriver interface {
	CreateMesh([]Vertex3D, []uint32) (MeshHandle, error)
	DestroyMesh(MeshHandle) error
	DrawMeshes(MeshBatch3D) error
}

MeshDriver is implemented by drivers that expose Onix's indexed 3D mesh pipeline. It is separate from Driver so headless and specialized 2D drivers do not need meaningless 3D methods.

type MeshGPUDeformationDriver

type MeshGPUDeformationDriver interface {
	SetMeshDeformation(MeshHandle, MeshDeformationDescriptor) error
	DrawMeshesDeformed(MeshBatch3D) error
}

MeshGPUDeformationDriver is implemented by renderers that evaluate skin and morph data in GPU buffers. Drivers that do not implement it use the CPU fallback assembled by scene.ExtractRender3DSystem.

type MeshHandle

type MeshHandle = Handle[MeshResource]

type MeshLighting

type MeshLighting struct {
	FogColor                   [3]float32 // linear radiance in nits
	FogParams                  [4]float32 // start, end, density, mode (0 disabled, 1 linear, 2 exp2)
	ToneMapping                float32    // 0 Reinhard, 1 ACES filmic fit
	OcclusionInverseProjection [16]float32
	OcclusionParams            [4]float32 // world radius, world bias, strength, sample count
	OcclusionTexture           TextureHandle
	Shadows                    [MaxShadowMaps]ShadowMap3D
	LightShadows               [MaxMeshLights][4]float32 // one-based first map, map count, cascade blend; W carries camera color/fog and environment encoding on upload
	CameraForward              [4]float32                // world direction used to select directional cascades; W is replaced by SSAO sample count on upload
	Environment                [4]float32                // intensity, rotation, atlas inverse width, inverse tile height
	EnvironmentEncoding        EnvironmentEncoding
	Params                     [4]float32 // exposure (0 means 1), MeshPass*, SSAO strength on upload, backend winding flip
	EnvironmentTexture         TextureHandle
	ShadowTexture              TextureHandle
}

MeshLighting is shared by all backends. Shadow depth is encoded in an RGBA8 color target, allowing filtering without requiring sampleable depth support.

type MeshMorphVertex

type MeshMorphVertex struct {
	Position [3]float32
	Normal   [3]float32
	Tangent  [3]float32
}

MeshMorphVertex stores one morph target delta for one vertex.

type MeshPickingDriver

type MeshPickingDriver interface {
	DrawMeshPicking(MeshBatch3D) error
}

MeshPickingDriver draws mesh instances as uint32 entity IDs into the active R32Uint render target.

type MeshResource

type MeshResource struct{}

type MeshShaderDriver

type MeshShaderDriver interface {
	CreateMeshShader(ShaderDescriptor) (MeshShaderHandle, error)
	DestroyMeshShader(MeshShaderHandle) error
}

MeshShaderDriver is implemented by mesh renderers that can compile and own user-provided mesh pipelines.

type MeshShaderHandle

type MeshShaderHandle = Handle[MeshShaderResource]

type MeshShaderResource

type MeshShaderResource struct{}

type MeshSkinVertex

type MeshSkinVertex struct {
	Joints  [4]uint32
	Weights [4]float32
}

MeshSkinVertex stores the four influences used by GPU linear-blend skinning. The layout is intentionally renderer-independent so backends can pack it into a storage buffer without importing graphics types.

type NativeSurface

type NativeSurface struct {
	Display        unsafe.Pointer
	Kind           NativeSurfaceKind
	Window         uintptr
	Width          int
	Height         int
	DRMFD          int
	DRMConnectorID uint32
	DRMRefreshRate uint32 // Millihertz; zero selects the highest rate at Width x Height.
	Transparent    bool
}

type NativeSurfaceKind

type NativeSurfaceKind int
const (
	NativeSurfaceXlib NativeSurfaceKind = iota + 1
	NativeSurfaceWayland
	NativeSurfaceAndroid
	NativeSurfaceWin32
	NativeSurfaceDRM
	NativeSurfaceMetal
)

type Pipeline

type Pipeline uint8
const (
	PipelineSprite Pipeline = iota
	PipelineShape
	PipelineMesh
)

type Rect

type Rect struct {
	X      int32
	Y      int32
	Width  int32
	Height int32
}

func (Rect) Empty

func (r Rect) Empty() bool

type RenderTarget

type RenderTarget struct {
	// contains filtered or unexported fields
}

RenderTarget owns a renderer-neutral offscreen color attachment and optional depth attachment. Resize is deferred until the target is next used.

func NewRenderTarget

func NewRenderTarget(descriptor RenderTargetDescriptor) (*RenderTarget, error)

func (*RenderTarget) Begin

func (target *RenderTarget) Begin(clear RenderTargetClear) error

func (*RenderTarget) BeginFor

func (target *RenderTarget) BeginFor(device *Device, clear RenderTargetClear) error

func (*RenderTarget) ColorTexture

func (target *RenderTarget) ColorTexture() (TextureHandle, error)

func (*RenderTarget) ColorTextureFor

func (target *RenderTarget) ColorTextureFor(device *Device) (TextureHandle, error)

func (*RenderTarget) Descriptor

func (target *RenderTarget) Descriptor() RenderTargetDescriptor

func (*RenderTarget) Dispose

func (target *RenderTarget) Dispose() error

func (*RenderTarget) End

func (target *RenderTarget) End() error

func (*RenderTarget) Read

func (target *RenderTarget) Read(region RenderTargetRegion, destination []byte) error

func (*RenderTarget) Resize

func (target *RenderTarget) Resize(width, height int) bool

func (*RenderTarget) Size

func (target *RenderTarget) Size() (int, int)

func (*RenderTarget) Valid

func (target *RenderTarget) Valid() bool

Valid reports whether the target can be realized, without accessing a device.

type RenderTargetClear

type RenderTargetClear struct {
	Color      Color
	Depth      float32
	ClearColor bool
	ClearDepth bool
}

type RenderTargetColorFormat

type RenderTargetColorFormat uint8
const (
	RenderTargetRGBA8 RenderTargetColorFormat = iota
	RenderTargetUint32
	RenderTargetR8
)

func (RenderTargetColorFormat) TexelBytes

func (format RenderTargetColorFormat) TexelBytes() int

TexelBytes returns the byte size used by color attachment readback.

type RenderTargetDescriptor

type RenderTargetDescriptor struct {
	Width       int
	Height      int
	ColorFormat RenderTargetColorFormat
	Depth       bool
}

func (RenderTargetDescriptor) Validate

func (descriptor RenderTargetDescriptor) Validate() error

type RenderTargetDriver

type RenderTargetDriver interface {
	CreateRenderTarget(RenderTargetDescriptor) (RenderTargetHandle, TextureHandle, error)
	ResizeRenderTarget(RenderTargetHandle, RenderTargetDescriptor) (TextureHandle, error)
	DestroyRenderTarget(RenderTargetHandle) error
	BeginRenderTarget(RenderTargetHandle, RenderTargetClear) error
	EndRenderTarget() error
}

type RenderTargetHandle

type RenderTargetHandle = Handle[RenderTargetResource]

type RenderTargetReadbackDriver

type RenderTargetReadbackDriver interface {
	ReadRenderTarget(RenderTargetHandle, RenderTargetRegion, []byte) error
}

type RenderTargetRegion

type RenderTargetRegion struct {
	// X and Y use the engine's top-left surface origin.
	X      int
	Y      int
	Width  int
	Height int
}

type RenderTargetResource

type RenderTargetResource struct{}

type RenderView

type RenderView[T any] struct {
	Camera   T
	Target   *RenderTarget
	Viewport Rect
	Clear    RenderTargetClear
	Order    int
	Mode     RenderViewMode
	Enabled  bool
}

RenderView binds typed camera data to an optional output target. The camera payload remains owned by the caller, so render does not depend on ECS types.

func NewRenderView

func NewRenderView[T any](camera T) RenderView[T]

func (RenderView[T]) Size

func (view RenderView[T]) Size(fallback Rect) (int, int)

type RenderViewMode

type RenderViewMode uint8
const (
	RenderViewLit RenderViewMode = iota
	RenderViewUnlit
	RenderViewWireframe
	RenderViewPicking
)

type RendererInfo

type RendererInfo struct {
	Backend string
	Device  string
	// RenderTargetBottomLeft reports whether sampled color attachments use a
	// bottom-left origin. RenderTarget.Read always uses a top-left origin.
	RenderTargetBottomLeft bool
}

RendererInfo identifies the active graphics API and physical device.

func CurrentRendererInfo

func CurrentRendererInfo() RendererInfo

CurrentRendererInfo returns metadata reported by the active render driver.

type ShaderDescriptor

type ShaderDescriptor struct {
	MetalSource          string
	WebGL2VertexSource   string
	WebGL2FragmentSource string
	WebGPUVertexSource   string
	WebGPUFragmentSource string
	VulkanVertexSPIRV    []byte
	VulkanFragmentSPIRV  []byte
	DirectXVertexHLSL    []byte
	DirectXFragmentHLSL  []byte
	WebGL2Generated      bool
}

ShaderDescriptor contains the native shader representation for each renderer. A descriptor may target only the platforms shipped by the game; an omitted vertex or fragment stage inherits the pipeline's built-in stage.

func (ShaderDescriptor) Validate

func (d ShaderDescriptor) Validate() error

type ShadowMap3D

type ShadowMap3D struct {
	Matrix [16]float32
	Rect   [4]float32 // top-left atlas UV offset and size
	Params [4]float32 // depth bias, normal bias, cascade near/far distances
}

type ShapeBatch

type ShapeBatch struct {
	Instances  []ShapeInstance2D
	Projection [16]float32
}

type ShapeInstance2D

type ShapeInstance2D struct {
	Model      [6]float32
	LocalModel [6]float32
	Fill       [4]float32
	Border     [4]float32
	Params     [4]float32
	Kind       ShapeKind
}

type ShapeKind

type ShapeKind uint32
const (
	ShapeRoundedRect ShapeKind = iota + 1
	ShapeCheckmark
	ShapeCornerMask
	// ShapeTriangle is a filled directional triangle. Params.w selects the
	// direction: up, down, left, right (0..3).
	ShapeTriangle
)

type SpriteBatch

type SpriteBatch struct {
	Instances  []Instance2D
	Draws      []SpriteDraw
	Projection [16]float32
}

type SpriteDraw

type SpriteDraw struct {
	Shader             Material2DShaderHandle
	Texture            TextureHandle
	AdditionalTextures [SpriteTextureSlots - 1]TextureHandle
	FirstInstance      uint32
	InstanceCount      uint32
}

func (SpriteDraw) TextureAt

func (d SpriteDraw) TextureAt(slot int) TextureHandle

TextureAt fills unused bindings with the primary texture. Custom shaders use only Texture and retain their single-texture sampling contract.

type TextureAddressMode

type TextureAddressMode uint8

TextureAddressMode controls sampling outside normalized texture coordinates.

const (
	TextureAddressClamp TextureAddressMode = iota
	TextureAddressRepeat
	TextureAddressMirror
)

func (TextureAddressMode) Valid

func (m TextureAddressMode) Valid() bool

type TextureBlock

type TextureBlock struct {
	Width  int
	Height int
	Bytes  int
}

TextureBlock is the texel granularity of a format. Uncompressed formats use a 1x1 block; block-compressed formats use 4x4.

type TextureDescriptor

type TextureDescriptor struct {
	Width  int
	Height int
	// Levels is the number of mip levels described by the pixel payload.
	// Zero and one both mean a single level. Compressed formats ship a
	// prebuilt chain because the GPU cannot generate mips for block data.
	Levels       int
	WrapU, WrapV TextureAddressMode
	Filter       TextureFilter
	Format       TextureFormat
}

func (TextureDescriptor) Level

func (d TextureDescriptor) Level(level int) TextureLevel

Level reports where one mip level lives inside the payload. Level 0 is the base level, which starts at offset zero; negative levels clamp to it.

Sequential uploads use MipChain to avoid recalculating preceding levels.

func (TextureDescriptor) MipChain

func (d TextureDescriptor) MipChain(yield func(int, TextureLevel) bool)

MipChain walks the payload once, carrying dimensions and the byte offset forward instead of recomputing all preceding levels for every upload.

func (TextureDescriptor) MipLevels

func (d TextureDescriptor) MipLevels() int

MipLevels reports the mip depth described by the descriptor.

func (TextureDescriptor) Validate

func (d TextureDescriptor) Validate(pixels []byte) error

type TextureFilter

type TextureFilter uint8
const (
	TextureFilterLinear TextureFilter = iota
	TextureFilterLinearMipmapLinear
)

type TextureFormat

type TextureFormat uint8

TextureFormat identifies the texel layout used by a sampled texture. RGBA8 remains the zero value so existing descriptors keep their behavior.

const (
	TextureFormatRGBA8 TextureFormat = iota
	TextureFormatR8
	// TextureFormatSRGBA8 decodes RGB from sRGB when sampled; alpha stays linear.
	TextureFormatSRGBA8

	// Block-compressed formats encode independent 4x4 texel blocks, so a
	// texture smaller than the block size still occupies a whole block.
	TextureFormatBC1         // RGB, 4 bits per texel
	TextureFormatBC1SRGB     // BC1 sampled as sRGB
	TextureFormatBC3         // RGB with interpolated alpha, 8 bits per texel
	TextureFormatBC3SRGB     // BC3 sampled as sRGB
	TextureFormatBC4         // single channel, 4 bits per texel
	TextureFormatBC5         // two channel, 8 bits per texel
	TextureFormatBC7         // RGBA, 8 bits per texel
	TextureFormatBC7SRGB     // BC7 sampled as sRGB
	TextureFormatASTC4x4     // RGBA, 8 bits per texel
	TextureFormatASTC4x4SRGB // ASTC 4x4 sampled as sRGB
)

func (TextureFormat) Block

func (f TextureFormat) Block() TextureBlock

Block reports the texel granularity and encoded size of one block.

func (TextureFormat) ChainSize

func (f TextureFormat) ChainSize(width, height, levels int) int

ChainSize reports the encoded byte size of a full or partial mip chain. Levels above the natural depth are clamped.

func (TextureFormat) Compressed

func (f TextureFormat) Compressed() bool

Compressed reports whether the format stores 4x4 blocks. Compressed textures cannot be updated in place, because a partial region does not cover whole blocks.

func (TextureFormat) GLCompressedInternalFormat

func (f TextureFormat) GLCompressedInternalFormat() (int, bool)

GLCompressedInternalFormat maps a compressed format to the GL internal format constant shared by OpenGL ES and WebGL2. The second result is false for uncompressed formats, which take the texel upload path instead.

func (TextureFormat) LevelSize

func (f TextureFormat) LevelSize(width, height int) int

LevelSize reports the encoded byte size of one mip level. Dimensions that are not a whole number of blocks round up, matching every native API.

func (TextureFormat) Name

func (f TextureFormat) Name() string

Name reports a stable identifier used by tooling and error messages.

func (TextureFormat) SRGB

func (f TextureFormat) SRGB() bool

SRGB reports whether sampling decodes RGB from sRGB. Alpha stays linear.

func (TextureFormat) SRGBVariant

func (f TextureFormat) SRGBVariant(srgb bool) TextureFormat

SRGBVariant returns the format that samples the same blocks with the requested colour interpretation.

A block-compressed format and its sRGB variant store identical blocks; only the internal format chosen at upload differs, which is what makes the device decode gamma. A packed payload therefore does not have to be re-encoded to serve a sampler that wants the other interpretation. Formats without a variant, and R8 which carries data rather than colour, are returned as-is.

func (TextureFormat) TexelBytes

func (f TextureFormat) TexelBytes() int

TexelBytes reports the encoded size of one texel. Compressed formats report 0 because their texels are not independently addressable; use LevelSize or ChainSize for those.

func (TextureFormat) Valid

func (f TextureFormat) Valid() bool

type TextureHandle

type TextureHandle = Handle[TextureResource]

type TextureLevel

type TextureLevel struct {
	Width  int
	Height int
	// Offset is the byte offset of the level inside the payload.
	Offset int
	// Bytes is the encoded size of the level. Block-compressed levels round
	// their dimensions up to whole blocks, so a 1x1 level still occupies one
	// full block.
	Bytes int
}

TextureLevel locates one mip level inside the payload a descriptor describes.

type TextureRegion

type TextureRegion struct {
	X      int
	Y      int
	Width  int
	Height int
}

type TextureResource

type TextureResource struct{}

type TextureUpdate

type TextureUpdate struct {
	Pixels  []byte
	Region  TextureRegion
	Texture TextureHandle
}

type Vertex3D

type Vertex3D struct {
	Position [3]float32
	Normal   [3]float32
	UV       [2]float32
	Tangent  [4]float32 // xyz direction; w is bitangent handedness, zero means absent
}

Directories

Path Synopsis
internal
dxbcgen command
Command dxbcgen compiles generated HLSL into builtin DirectX 11 bytecode.
Command dxbcgen compiles generated HLSL into builtin DirectX 11 bytecode.
hlslgen command
Command hlslgen regenerates DirectX builtins from the shared WGSL sources.
Command hlslgen regenerates DirectX builtins from the shared WGSL sources.

Jump to

Keyboard shortcuts

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