Documentation
¶
Overview ¶
Package gpu turns scenes into what the GPU renderers draw: one instanced quad per operation, for a shader that computes rounded rectangles, borders, gradients, stripes, shadows and atlas coverage itself, in batches that share a scissor rectangle and an image. Every renderer (d3d11, metal, gl) draws the same instances, the way internal/raster draws scenes on the CPU.
An effect (scene.Effect) draws with a pipeline of its own, made from its shader, in a batch of its own. One reading its backdrop has its batch start after a Backdrop step, which renderers take between batches: they read the backdrop's area of what they drew so far, average it over squares (the pass "down") into a texture, blur that along rows into another and along columns back (the pass "blur"), keeping 8 bits a channel, and bind it for the batch (the shaders' backdrop texture), as internal/raster computes it.
The shaders write a second color for blending, the source's alpha for each channel: the alpha of the color for everything but subpixel glyphs, whose subpixels cover each channel by its own. Renderers blend with dual-source blending: the destination times one minus the second color, plus the first.
Index ¶
Constants ¶
const InstanceSize = int(unsafe.Sizeof(Instance{}))
InstanceSize is the size of an Instance in bytes.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Batch ¶
type Batch struct {
Start, Count int
Scissor Scissor
// Image is the renderer's texture of the batch's image, or 0.
Image uintptr
// Effect is the effect of the batch's one instance, drawn with a
// pipeline of its own, and Backdrop, unless 0, 1 + the index in
// Builder.Backdrops of its backdrop, which the renderer reads before
// drawing it.
Effect *scene.Effect
Backdrop int
}
Batch is a run of instances that draw with the same scissor rectangle and image.
type Builder ¶
type Builder struct {
Instances []Instance
Batches []Batch
Backdrops []scene.Backdrop
// Wide draws the colors of scenes outside the sRGB gamut
// (Scene.Wide), for a target that keeps them, as Metal's float16
// drawables do; without it, their nearest sRGB colors.
Wide bool
// contains filtered or unexported fields
}
Builder builds the instances and batches of scenes, reusing its memory from frame to frame.
func (*Builder) BackdropSize ¶ added in v0.2.10
BackdropSize returns how large the textures of the backdrops of the last scene built must be, in texels: as the largest.
type Instance ¶
type Instance struct {
// Rect is x, y, width, height; Radii the corners' radii (top-left,
// top-right, bottom-right, bottom-left), negative for continuous
// corners (scene.Corners), which only Metal's shader draws, or a
// glyph's gamma ratios
// (scene.TextParams); Inner those of a border's inner edge, or of the
// box casting a shadow, or a glyph's contrast and thin boost in Inner[0]
// and Inner[1].
Rect, Radii, Inner [4]float32
// Color and Color2 (a gradient's end) and Border are straight RGBA.
Color, Color2, Border [4]float32
// Grad holds a gradient's start and end points, or the stripes' unit
// vector across them, width and period; UV the texture rectangle,
// normalized, a fill's border widths (top, right, bottom, left), or
// the box casting a shadow, which shows only outside it (none when
// empty).
//
// An effect has its parameters (scene.EffectOp.Params) in Inner,
// Color, Color2, Border and Grad, and in UV where its backdrop's area
// starts in the frame and its size in texels.
Grad, UV [4]float32
// Clip and ClipRadii are the innermost clip, which the shader cuts.
Clip, ClipRadii [4]float32
// Params is the kind (0 fill, 1 shadow, 2 mask glyph, 3 color glyph, 4
// image, 5 subpixel glyph, 6 effect); 1 for a dashed border or a
// grayscale image; the shadow's sigma (0 for none), the paint
// (scene.Paint) or the size of the squares an effect's backdrop
// averages; and the opacity.
Params [4]float32
}
Instance is the data of one quad, in device pixels, as the shaders read it: eleven float4s.
type Pass ¶ added in v0.2.10
type Pass struct {
Origin, Limit, Shift, Dir [2]int32
Down, Radius int32
Sigma float32
// contains filtered or unexported fields
}
Pass is what a pass computing a backdrop reads, the layout of the shaders' Pass: down reads the area from Origin to Limit, frame pixels, at their place less Shift in its source, and averages squares of Down pixels a side; blur reads texels up to Limit, Radius of them each way along Dir, weighted by a Gaussian of standard deviation Sigma.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package d3d11 draws scenes with Direct3D 11 into a window through a DXGI flip model swap chain, called through syscall like the rest of the Windows backend (no cgo).
|
Package d3d11 draws scenes with Direct3D 11 into a window through a DXGI flip model swap chain, called through syscall like the rest of the Windows backend (no cgo). |
|
device
Package device creates Direct3D 11 devices: the device of package d3d11's renderer, and that of the Windows backend, which shows the controls of windows with a material through DirectComposition without the renderer.
|
Package device creates Direct3D 11 devices: the device of package d3d11's renderer, and that of the Windows backend, which shows the controls of windows with a material through DirectComposition without the renderer. |
|
Package gl draws scenes with OpenGL 3.3 or OpenGL ES 3.0 into the framebuffer bound when Render is called: the one GTK's GtkGLArea binds while it emits its render signal.
|
Package gl draws scenes with OpenGL 3.3 or OpenGL ES 3.0 into the framebuffer bound when Render is called: the one GTK's GtkGLArea binds while it emits its render signal. |
|
Package gputest has what the tests of the GPU renderers share: a scene that draws every kind of operation, and a comparison of what a renderer drew with what the CPU renderer draws, which the renderers must match.
|
Package gputest has what the tests of the GPU renderers share: a scene that draws every kind of operation, and a comparison of what a renderer drew with what the CPU renderer draws, which the renderers must match. |
|
Package metal draws scenes with Metal into a CAMetalLayer, called through the Objective-C runtime with purego like the rest of the macOS backend (no cgo).
|
Package metal draws scenes with Metal into a CAMetalLayer, called through the Objective-C runtime with purego like the rest of the macOS backend (no cgo). |