← gpu · version 0.4.3
73 public items, in source order. Generated from the registry index, which re-derives them from the package source at publish time — so a signature here is the one that version actually ships.
pub fn blend(source: integer, destination: integer) -> integer
A draw is combined with what the target holds: its colour times source, plus the target's times destination. blend(SRC_ALPHA, ONE_MINUS_SRC_ALPHA) is plain transparency.
pub struct Source { tag: text, vertex: text, fragment: text }
A shader's text in one shading language. tag names the language as a backend spells it (its README says which it takes); this library compares the tag and never reads it.
pub fn source(tag: text, vertex: text, fragment: text) -> Source
A source for the backend whose shading language is tag.
pub struct Program { vertex: vector<integer>, instance: vector<integer>, block: vector<integer>, textures: integer, sources: vector<Source> }
A shader set: what the shader reads, and its text for each backend it may meet.
pub struct State { shape: integer = 0, depth: integer = 0, blend: integer = 0, cull: integer = 0, into: integer = 0 }
Render state: fixed for a pipeline's life, so two states are two pipelines.
pub fn layout(block: const vector<integer>) -> vector<integer>
Where each field of a block starts, in floats, with the block's whole size as the last entry. Each field starts on the next multiple of its own size (a matrix and an array on 4 floats) and the size is rounded up to 4 — the layout every backend's shading language gives these field kinds, so a program reads the same bytes on each.
pub struct Device { handle: i64, table: i64, pass: integer, pipe: i64, need_block: integer, need_textures: integer, sampled: integer, has_block: boolean, has_vertices: boolean, has_indices: boolean, has_instances: boolean, pipe_instances: boolean, refused: vector<text> }
One window (a page's canvas) and its GPU. Everything made from it is freed when it closes.
pub fn open(table: i64, width: integer, height: integer, title: text) -> Device?
Open a window of width x height pixels through the backend whose table is table (a backend library's table()). Null when the table is none — its stack is absent on this machine — or the window does not open. A game does not call this: its host package asks each backend in turn.
pub fn open_fullscreen(table: i64, title: text) -> Device?
Open a window over the whole screen through the backend whose table is table: no border, the machine's own bars hidden where it has them. Its size is the screen's (width, height). Null as open, and where the backend has no whole-screen window.
pub fn backend(self: const Device) -> text
The name of the backend this device is on, for a message. Never branch on it: ask what the machine has.
pub fn backend_name() -> text
The name of the backend a device was opened on last, for a message in a program that holds one device; dev.backend() says it of a device.
pub fn poll(self: const Device) -> boolean
Hand the machine's events to the window; false once it was closed.
pub fn width(self: const Device) -> integer
The window's width in pixels, as it is now.
pub fn height(self: const Device) -> integer
And its height.
pub fn close(self: Device)
Close the window and free everything made from it.
pub fn key_down(self: const Device, key: integer) -> boolean
Whether key key (a code from 0 to 255) is down now.
pub fn keys(self: const Device) -> vector<boolean>
Which keys are down now: 256 flags by key code, the form screen::keys() answers and input::input_tick_from_state takes, in the same codes (a letter its lower-case character, the arrows 128 to 131, F1 to F12 135 to 146) — so a view in a device's window reads its keys as one in screen's does.
pub fn pointer_x(self: const Device) -> integer
The pointer's place in the window, in pixels from the top left.
pub fn pointer_y(self: const Device) -> integer
pub fn buttons(self: const Device) -> integer
The pointer's buttons held now: 1 the left, 2 the right, 4 the middle, added.
pub fn typed(self: const Device) -> vector<u8>
The bytes typed since the last events (UTF-8, the queued text events end to end). Read them before events, which empties the queue.
pub fn events(self: const Device) -> vector<integer>
The events queued since the last call, oldest first, EVENT_WORDS numbers each; the queue is empty after.
pub fn refusals(self: const Device) -> vector<text>
What was refused so far, oldest first: one line a call, saying which call and why. Empty for a program that keeps the rule.
pub struct Buffer { handle: i64, table: i64, size: integer }
Floats on the GPU: vertices, or the values of drawn copies.
pub fn buffer(self: const Device, data: const vector<single>) -> Buffer
Upload data for a pipeline to read as vertices (vertices) or per copy (instances).
pub fn update(self: Buffer, data: const vector<single>)
Replace the floats; the length may change. For data that changes every frame.
pub fn floats(self: const Buffer) -> integer
How many floats it holds.
pub struct IndexBuffer { handle: i64, table: i64, size: integer }
Vertex numbers on the GPU, for draw_indexed.
pub fn index_buffer(self: const Device, list: const vector<integer>) -> IndexBuffer
Upload a list of vertex numbers.
pub fn count(self: const IndexBuffer) -> integer
How many vertex numbers it holds.
pub struct Texture { handle: i64, table: i64, w: integer, h: integer, depth: boolean }
An image on the GPU: colour (red, green, blue, alpha at 8 bits each) or depth.
pub fn texture(self: const Device, width: integer, height: integer) -> Texture
An empty colour texture, sampled between its pixels and clamped at its edges.
pub fn depth_texture(self: const Device, width: integer, height: integer) -> Texture
An empty depth texture: the depth of a target, or a shadow map.
pub fn texture_from(self: const Device, pixels: const vector<u32>, width: integer, height: integer) -> Texture
A colour texture holding pixels (0xAARRGGBB each, width to a row). Its first pixel is texture coordinate (0, 0).
pub fn put(self: const Texture, x: integer, y: integer, pixels: const vector<u32>, width: integer, height: integer)
Replace the width x height pixels at (x, y), counted from the texture's first pixel. Inside a pass, what was drawn before this call shows the pixels as they were.
pub fn put_rgb565(self: const Texture, x: integer, y: integer, pixels: const vector<i32>, width: integer, height: integer)
The same from RGB565 values (5 bits red, 6 green, 5 blue, as a small machine's frame holds them), every pixel opaque: a frame drawn on the CPU shown through the device.
pub fn nearest(self: const Texture, on: boolean)
Sample the nearest pixel (pixel art), or between pixels (how a texture starts). It holds for every draw after this call, also of a pass that named the texture before it.
pub fn mipmaps(self: const Texture)
Build smaller copies from the pixels it holds now and sample through them when it is drawn small; call again after put, or after drawing into it.
pub fn width(self: const Texture) -> integer
Its width in pixels.
pub fn height(self: const Texture) -> integer
And its height.
pub struct Target { handle: i64, table: i64, into: integer, w: integer, h: integer }
What a pass draws into other than the window. Its textures stay usable after it is gone.
pub fn colour_target(self: const Device, colour: const Texture) -> Target
A target of one colour texture.
pub fn target(self: const Device, colour: const Texture, depth: const Texture) -> Target
A target of a colour and a depth texture of one size.
pub fn depth_target(self: const Device, depth: const Texture) -> Target
A target of a depth texture alone: no colour is drawn.
pub struct Pipeline { handle: i64, table: i64, into: integer, textures: integer, instances: boolean, fields: vector<integer>, starts: vector<integer> }
A program, its inputs and its render state, built for one kind of target.
pub fn pipeline(self: const Device, program: const Program, state: const State) -> Pipeline?
Build a pipeline: program drawn with state. Null when the program has no source for this backend, declares what a block cannot hold, or does not compile — the backend says why on stderr.
pub struct Block { data: vector<single>, fields: vector<integer>, starts: vector<integer>, wrong: integer }
The values of a pipeline's uniform block. A field is named by its position in the program's block list. Setting a field as another kind than it was declared, or one that is not there, marks the block, and uniforms then refuses it.
pub fn block(self: const Pipeline) -> Block
A block for this pipeline, every field zero.
pub fn f4_at(self: Block, field: integer, index: integer, x: float, y: float, z: float, w: float)
Set element index of an f4s field; an index past its length marks the block.
pub fn mat4(self: Block, field: integer, m: const vector<float>)
Set a MAT4 field from 16 floats, column-major; fewer marks the block.
pub fn floats(self: const Block) -> vector<single>
The block's floats as the backend receives them, for a test of a layout.
pub fn begin_window(self: Device, load: integer, colour: i64)
Start a pass that draws into the window, cleared to colour (0xAARRGGBB) or kept.
pub fn begin(self: Device, target: const Target, load: integer, colour: i64)
Start a pass that draws into target.
pub fn bind(self: Device, pipeline: const Pipeline)
Draw with pipeline from here on. It forgets the block, textures and buffers the pipeline before it was given: name them again.
pub fn uniforms(self: Device, block: const Block)
Give the bound pipeline its uniform block.
pub fn sample(self: Device, slot: integer, texture: const Texture)
Give the bound pipeline the texture its slot slot samples.
pub fn vertices(self: Device, buffer: const Buffer)
The vertices the next draws read.
pub fn instances(self: Device, buffer: const Buffer, first: integer)
The values the next draw_copies reads once per copy, starting at float first of buffer.
pub fn indices(self: Device, buffer: const IndexBuffer)
The vertex numbers the next draw_indexed reads.
pub fn viewport(self: Device, x: integer, y: integer, width: integer, height: integer)
The rectangle draws map onto, origin bottom-left; a pass starts with the whole target.
pub fn scissor(self: Device, x: integer, y: integer, width: integer, height: integer)
Draw only inside this rectangle, origin bottom-left, until no_scissor or the pass ends.
pub fn no_scissor(self: Device)
Draw on the whole target again.
pub fn draw_indexed(self: Device, count: integer)
Draw the first count vertices the index buffer names, in its order.
pub fn draw_copies(self: Device, count: integer, copies: integer)
Draw the first count vertices copies times; the inputs per copy advance once a copy.
pub fn end(self: Device)
End the pass.
pub fn present(self: Device)
Show the frame, waiting for the display's next one where the machine has a frame clock.