webgl

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 4 Imported by: 0 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 webgl runs KindGPU views over WebGL 2 for the web backend and mini games (docs/architecture/gpu.md): the view's lifecycle (Controller), plain Go and testable anywhere, and the backend that plays its frames on a context it is given (Backend, js/wasm), with no DOM, so a host that has canvases but no document can use it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClampLimits

func ClampLimits(l driver.GPULimits) driver.GPULimits

ClampLimits fills zero fields with conservative Stage 1 defaults.

func MipDim

func MipDim(base, mip uint32) uint32

MipDim returns the dimension of mip level m for a base texture size, clamped to at least 1 per the WebGPU and WebGL 2 specifications.

Types

type BackendKind

type BackendKind uint8

BackendKind identifies which browser GPU API backs a KindGPU view.

const (
	BackendNone BackendKind = iota
	BackendWebGPU
	BackendWebGL2
)

func (BackendKind) String

func (k BackendKind) String() string

type Controller

type Controller struct {
	Config driver.GPUViewConfig

	State      State
	Backend    BackendKind
	Generation uint32

	Width  int
	Height int
	// contains filtered or unexported fields
}

Controller manages the portable lifecycle, pixel sizing, generation tracking, and resource accounting for one mounted KindGPU view.

func NewController

func NewController(id driver.NodeID) *Controller

NewController returns the controller of KindGPU view id, uninitialized.

func (*Controller) AcceptFrame

func (c *Controller) AcceptFrame(frame driver.GPUFrame) bool

AcceptFrame checks whether frame targets the live generation and records resource create/destroy ops for leak accounting.

func (*Controller) BeginInit

func (c *Controller) BeginInit() bool

BeginInit starts initializing the view, reporting false when it is initializing, ready or destroyed.

func (*Controller) Configure

func (c *Controller) Configure(cfg driver.GPUViewConfig)

Configure sets the view's formats and sample count (ItemGPU).

func (*Controller) Destroy

func (c *Controller) Destroy()

Destroy ends the view for good.

func (*Controller) MakeError

func (c *Controller) MakeError(code driver.GPUErrorCode, message string) *driver.GPUEvent

MakeError returns an error event of the live generation, nil once the view is destroyed.

func (*Controller) MarkLost

func (c *Controller) MarkLost(reason driver.GPUDeviceLostReason, message string) *driver.GPUEvent

MarkLost transitions to Lost, clears tracked live resources, and returns the GPUEventDeviceLost payload (nil if not currently Ready or already Destroyed).

func (*Controller) MarkReady

func (c *Controller) MarkReady(backend BackendKind, surfaceFmt driver.GPUTextureFormat, limits driver.GPULimits, features driver.GPUFeatures) *driver.GPUEvent

MarkReady transitions to Ready, bumps the device generation, and returns the GPUEventDeviceReady payload (nil if already destroyed).

func (*Controller) Resize

func (c *Controller) Resize(cssW, cssH driver.Points, pixelRatio float32) (w, h int, changed bool, ev *driver.GPUEvent)

Resize updates the controller's physical pixel dimensions and returns a GPUEventResize when the view is already ready and the size changed.

func (*Controller) ResourceCounts

func (c *Controller) ResourceCounts() ResourceCounts

ResourceCounts are how many of each resource the app's frames left alive.

type ResourceCounts

type ResourceCounts struct {
	Buffers          int
	Textures         int
	Samplers         int
	BindGroupLayouts int
	BindGroups       int
	Pipelines        int
}

ResourceCounts are counts of GPU resources by kind.

type State

type State uint8

State is where a GPU view is in its lifecycle.

const (
	StateUninitialized State = iota
	StateInitializing
	StateReady
	StateLost
	StateDestroyed
)

Jump to

Keyboard shortcuts

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