Standard Library: std.gpu
● Intermediate5 min
Every type, method and function of std.gpu: what the spec lists, then each declaration in its source, with its examples and the line that declares it.
Spec 14.24 · learn it in GPU Screens.
A declaration below shows what a program writes against: a type's fields, a function's parameters, what it gives, its contracts (require, ensure) and its examples. kavach test runs every example, so each one is true of the code.
What the spec lists
| Function or method | Gives |
|---|---|
gpu.screen(win) -> Screen ! GpuError | What draws into the window win, using the program's GPU |
screen.frame() -> Frame ! GpuError | The next picture to draw, as big as the window is now. It waits for the screen's next refresh when the last picture isn't shown yet (vsync), so a loop of frames runs at the screen's rate |
frame.clear(r, g, b) | Fills the picture with one color; each part is a Float32 from 0 to 1 |
frame.draw(pipeline, vertices) | Draws vertices through pipeline (15.3) |
frame.draw(pipeline, vertices, instances: items) | The same once for each item of items, which the vertex fn gets as its second parameter |
frame.draw(pipeline, vertices, instances: items, with: shared) | The same, shared given to every vertex as the vertex fn's last parameter |
frame.show() | Puts the picture on the screen |
gpu.pipeline(vertex_fn, fragment_fn) -> Pipeline | A pipeline drawing triangles with a gpu vertex fn and a gpu fragment fn (15.3) |
std.gpu · gpu.kav
use std.gpu: 3 types and 1 function. stdlib/gpu/gpu.kav
GpuError type
Why there is nothing to draw into: no GPU, a window that can't be drawn into, or a frame that can't be had now.
pub type GpuError = Unavailable(reason: String)Screen type
What draws into a window.
pub type Screen: Drop {
id: Int
window: Int
}frame method
The next picture to draw, as big as the window is now; it waits for the screen's next refresh when the last picture isn't shown yet.
pub fn frame(self) -> Frame ! GpuError uses WindowFrame type
A picture being drawn. One not shown before its last holder ends is thrown away.
pub type Frame: Drop {
id: Int
}clear method
Fills the picture with one color, each part from 0 to 1.
pub fn clear(self, r: Float32, g: Float32, b: Float32) uses Window
require r >= 0.0 and r <= 1.0 and g >= 0.0 and g <= 1.0 and b >= 0.0 and b <= 1.0screen function
What draws into the window win, using the program's GPU.
pub fn screen(win: AppWindow) -> Screen ! GpuError uses Window