soft

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 6 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 soft is a CPU renderer: it draws scene primitives into memory in pure Go, with no GPU and no system library.

It follows the Direct3D 11 renderer's shaders (see render/d3d11): the same signed-distance coverage for rounded rectangles, borders and clips, the same blurred-shadow and gradient formulas, the same glyph contrast correction, and premultiplied blending in sRGB space into an 8-bit target. A scene therefore looks the same drawn by either renderer, to within rounding.

It is the renderer of platforms that have no GPU backend yet, and it draws the frames of headless screenshot tests on every platform.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Renderer

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

Renderer implements render.Renderer on the CPU.

func New

func New(t Target) *Renderer

New returns a renderer that draws into t's buffers, or into memory of its own when t is nil (see Image).

func (*Renderer) BeginFrame

func (r *Renderer) BeginFrame(width, height int, clear scene.Color) error

BeginFrame implements render.Renderer.

func (*Renderer) CaptureNextFrame

func (r *Renderer) CaptureNextFrame(fn func(*image.RGBA, error))

CaptureNextFrame implements render.Renderer.

func (*Renderer) Close

func (r *Renderer) Close()

Close implements render.Renderer.

func (*Renderer) DrawGlyphs

func (rr *Renderer) DrawGlyphs(run scene.GlyphRun)

DrawGlyphs implements render.Renderer.

func (*Renderer) DrawImages

func (rr *Renderer) DrawImages(ims []scene.ImageDraw)

DrawImages implements render.Renderer.

func (*Renderer) DrawQuads

func (rr *Renderer) DrawQuads(qs []scene.Quad)

DrawQuads implements render.Renderer.

func (*Renderer) EndFrame

func (r *Renderer) EndFrame() error

EndFrame implements render.Renderer. It rasterizes the frame and hands it to the target; a window's target paces frames to its display.

func (*Renderer) Image

func (r *Renderer) Image() *image.RGBA

Image returns a copy of the latest frame, premultiplied as image.RGBA is, with the alpha the frame has (opaque where an opaque clear color or fill covers it). It returns nil before the first frame.

func (*Renderer) PopClip

func (r *Renderer) PopClip()

PopClip implements render.Renderer.

func (*Renderer) PushClip

func (r *Renderer) PushClip(c scene.Rect)

PushClip implements render.Renderer.

func (*Renderer) PushRoundedClip

func (r *Renderer) PushRoundedClip(c scene.Rect, radii scene.Corners)

PushRoundedClip implements render.Renderer.

type Target

type Target interface {
	// Buffer returns the pixels to draw the next width×height frame into, as
	// premultiplied BGRA (Wayland's and DRM's ARGB8888 on a little-endian
	// machine), stride bytes per row. The contents need not be kept from the
	// previous frame: each frame is drawn in full.
	Buffer(width, height int) (pix []byte, stride int, err error)
	// Present shows the frame drawn into the latest buffer.
	Present() error
}

A Target shows the frames a Renderer draws, for example a window's shared memory buffers. Without one, a Renderer draws into memory of its own.

Jump to

Keyboard shortcuts

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