canvasshade

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 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 canvasshade lays out the GPU pass of a canvas op that shades with a program (driver.DrawShader, or an image op under SetShader), for the backends whose canvases draw on the CPU: each renders the pass's triangles into a transparent texture of its own, source over, and draws the texture into the canvas at the pass's bounds, in the target's pixels, under the canvas's clip, alpha and operator.

The program's dst and pos are what the vertices carry rather than the pixel's place in the texture: a DrawShader's rectangle in its own points, or the point of the image an image op draws, so a rotated or scaled op shades its own space. The pass's color is the program's, premultiplied, times the vertex's color: a sprite's alpha, a mesh vertex's color or a tint.

Index

Constants

View Source
const Floats = 10

Floats is how many floats Pack writes for a vertex: its position in clip space, dst, pos and color.

Variables

This section is empty.

Functions

func Shades

func Shades(d *driver.Drawing, op *driver.DrawOp) bool

Shades reports whether op shades with a program a backend can run: a DrawShader, or an image op with a shader.

Types

type Affine

type Affine struct{ A, B, C, D, E, F float64 }

Affine maps canvas points to the target's pixels, as the web's transform(a, b, c, d, e, f): (x, y) to (A*x + C*y + E, B*x + D*y + F).

func (Affine) Apply

func (m Affine) Apply(x, y float64) (float64, float64)

Apply maps the point x, y.

func (Affine) Invert

func (m Affine) Invert() Affine

Invert returns the inverse of m, the identity when m has none.

func (Affine) Then

func (m Affine) Then(n Affine) Affine

Then returns m after n: n maps first.

type Image

type Image struct{ W, H, PixelsW, PixelsH float64 }

Image is the size of the image an image op draws, in its points and in its pixels.

type Pass

type Pass struct {
	// Bounds is where the pass's texture goes, in the target's pixels.
	Bounds image.Rectangle
	// Vertices are triangles, three vertices each.
	Vertices []Vertex
	// Size and Scale are what the program's rectSize and pixelScale
	// return.
	Size  [2]float64
	Scale float64
	// Images are what the program reads as image0 on: an image op's
	// image first, then the shader's own.
	Images []driver.ImageSource
	// Shader is the op's.
	Shader *driver.Shader
}

Pass is what a backend renders for one op.

func Plan

func Plan(d *driver.Drawing, op *driver.DrawOp, m Affine, clip image.Rectangle, img Image) (Pass, bool)

Plan lays out op under m, within clip, the target's pixels the canvas may change; img is the size of an image op's image. It reports false when op shades nothing there.

func (*Pass) Lanes

func (p *Pass) Lanes(textures int, size func(i int) (w, h float64)) []float64

Lanes returns the lanes of the program's uniforms: the bridge's, which are rectSize, pixelScale and the size in pixels of each of the textures images the program reads (size), then the shader's own.

func (*Pass) Pack

func (p *Pass) Pack(buf []float32, flipY bool) []float32

Pack appends the pass's vertices to buf as Floats floats each: the position in clip space, y up as Metal, Direct3D and OpenGL take it, or down when flipY is set, for a texture OpenGL reads bottom row first; then dst, pos and the color.

type Vertex

type Vertex struct {
	X, Y       float32
	DstX, DstY float32
	PosX, PosY float32
	R, G, B, A float32
}

Vertex is a corner of a triangle of a pass: X, Y in the pass's pixels from its top left corner, what the program's dst and pos interpolate, and the premultiplied color its color is multiplied by.

Jump to

Keyboard shortcuts

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