Documentation
¶
Overview ¶
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). Every op of a scene is an instanced quad drawn by one shader (shader.metal, compiled ahead of time into shaderlib.go), from the instances package gpu builds; clips are scissor rectangles, with the innermost rounded clip computed in the shader, as in package d3d11.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompileLibrary ¶
CompileLibrary compiles Metal Shading Language into a Metal library with Xcode's metal tools, for code compiled ahead of time: go generate runs it, for the renderer's shader (shaderlib.go) and effects' (EffectSource).
func EffectSource ¶
EffectSource returns the source of an effect's library: shader.metal with EFFECT defined, the head of effect.metal, the effect's shader (see scene.Effect), and the tail, which draws its instances with it (effect_ps). Effects compile it ahead of time with CompileLibrary.
func PrecompileShader ¶
func PrecompileShader(src string)
PrecompileShader starts making what a shader of package ui/shader draws with, whose library's source is src (ShaderSource), on a goroutine of its own, with the system's default GPU: its library, which Metal compiles from the source in about 0.1 s, and its pipeline for windows of 8-bit color, about as long again. Renderers on that GPU then draw with them, waiting for what is left, rather than make them on the shader's first draw. Metal keeps both on disk for the next launches. Package ui/shader calls it as it compiles a shader.
func RenderOffscreen ¶
RenderOffscreen draws s with a renderer of its own into a texture, without a layer, and returns its premultiplied BGRA rows: for tests, as packages drawing effects have.
func ShaderSource ¶
ShaderSource returns the source of the library of a shader of package ui/shader, whose code src ends with shaderMain: as an effect's, with a tail of its own (shader_ps), which reads the shader's uniforms and images. The shader's effect holds it whole (scene.Effect's Metal), so that apps drawing no shader do not carry the tail.
Types ¶
type Offscreen ¶
type Offscreen struct {
// contains filtered or unexported fields
}
Offscreen draws frames with a renderer of its own into a texture, without a layer, waiting for each and timing it on the GPU: for benchmarks, as those of package ui drawing its frames.
func NewOffscreen ¶
NewOffscreen returns an Offscreen drawing frames of w×h pixels.
func (*Offscreen) Encoded ¶
Encoded returns how long the CPU took to encode the last frame Render drew: building its instances (gpu.Builder), uploading what changed in its atlases, and encoding its passes, before committing them.
type Renderer ¶
type Renderer struct {
// contains filtered or unexported fields
}
Renderer draws scenes into a CAMetalLayer it adds to a view's layer.
func New ¶
New creates a renderer drawing into a CAMetalLayer that it adds to layer, the layer of a view, and sizes as it.
func (*Renderer) Ready ¶
Ready reports whether a frame following the last one can draw at once, as none waits for its drawable (present.go); otherwise wake runs, on the main thread, once it has.
func (*Renderer) Release ¶
func (r *Renderer) Release()
Release frees the renderer's GPU objects and takes its layer out.
func (*Renderer) SetPost ¶
func (r *Renderer) SetPost(post func(func()))
SetPost gives the renderer post, which runs a function on the main thread from any goroutine: a frame following another builds while its drawable is being fetched, and draws once the presenter has it, through post. Without it, frames wait for their drawable.
func (*Renderer) SetWide ¶
SetWide has the frames drawn from now on show the colors of scenes outside the sRGB gamut (scene.Scene.Wide), into drawables of RGBA16Float in the extended sRGB color space, which keeps components beyond 0 to 1 and which the system shows in the display's gamut, or their nearest sRGB colors, into drawables of BGRA8, as without; and reports whether they do. The pipelines drawing the wide colors are made the first time.