Dala.Gpu.Command (dala v0.5.0)

Copy Markdown View Source

Encodes render commands to binary format for the Rust command queue.

Binary format:

  • 1 byte: command type
  • N bytes: command-specific data

Command types:

  • 0x01: Clear (4 bytes RGBA)
  • 0x02: FillRect (16 bytes: x,y,w,h as u32 LE + 4 bytes RGBA)
  • 0x03: DrawLine (16 bytes: x1,y1,x2,y2 as i32 LE + 4 bytes RGBA)
  • 0x04: Blit (12 bytes: sprite_id as u64 LE + x,y as u32 LE)
  • 0x05: Present (0 bytes)
  • 0x06: Resize (8 bytes: width, height as u32 LE)
  • 0x07: LoadSprite (16 bytes: id as u64 LE + w,h as u32 LE + pixel data)
  • 0x08: RemoveSprite (8 bytes: id as u64 LE)

Summary

Functions

Convert a color to a 4-byte RGBA binary.

Encode a batch command containing multiple sub-commands.

Encode a blit command that draws a loaded sprite at the given position.

Encode a clear command that fills the entire surface with a solid color.

Encode a dispatch_compute command that runs a GPU compute shader.

Encode a draw_circle command.

Encode a draw_line command that draws a line between two points.

Encode a draw_round_rect command.

Encode a draw_triangle command.

Encode a fill_circle command.

Encode a fill_rect command that fills a rectangle with a solid color.

Encode a fill_round_rect command.

Encode a fill_triangle command.

Encode an image_blit command that draws a loaded image texture.

Encode a load_image command that uploads an image as a GPU texture.

Encode a load_shader command for hot-reloading shaders.

Encode a load_sprite command that uploads pixel data into the texture atlas.

Encode a present command that flushes the command queue and updates the GPU texture.

Encode a read_pixels command that reads back GPU texture data.

Encode a remove_image command that frees an image texture.

Encode a remove_sprite command that frees a sprite from the texture atlas.

Encode a reset_clip command.

Encode a resize command that changes the surface dimensions.

Encode a set_clip command.

Encode a set_uniform command for shader parameters.

Types

color()

@type color() :: atom() | {0..255, 0..255, 0..255} | {0..255, 0..255, 0..255, 0..255}

Functions

color_to_rgba(arg1)

@spec color_to_rgba(color()) :: binary()

Convert a color to a 4-byte RGBA binary.

encode_batch(commands)

@spec encode_batch([binary()]) :: binary()

Encode a batch command containing multiple sub-commands.

encode_blit(sprite_id, x, y)

@spec encode_blit(non_neg_integer(), integer(), integer()) :: binary()

Encode a blit command that draws a loaded sprite at the given position.

encode_clear(color)

@spec encode_clear(color()) :: binary()

Encode a clear command that fills the entire surface with a solid color.

encode_dispatch_compute(shader_source, params, arg)

@spec encode_dispatch_compute(
  String.t(),
  binary(),
  {non_neg_integer(), non_neg_integer(), non_neg_integer()}
) :: binary()

Encode a dispatch_compute command that runs a GPU compute shader.

encode_draw_circle(cx, cy, radius, color)

@spec encode_draw_circle(integer(), integer(), non_neg_integer(), color()) :: binary()

Encode a draw_circle command.

encode_draw_line(x1, y1, x2, y2, color)

@spec encode_draw_line(integer(), integer(), integer(), integer(), color()) ::
  binary()

Encode a draw_line command that draws a line between two points.

encode_draw_round_rect(x, y, w, h, radius, color)

@spec encode_draw_round_rect(
  non_neg_integer(),
  non_neg_integer(),
  non_neg_integer(),
  non_neg_integer(),
  non_neg_integer(),
  color()
) :: binary()

Encode a draw_round_rect command.

encode_draw_triangle(x1, y1, x2, y2, x3, y3, color)

@spec encode_draw_triangle(
  integer(),
  integer(),
  integer(),
  integer(),
  integer(),
  integer(),
  color()
) ::
  binary()

Encode a draw_triangle command.

encode_fill_circle(cx, cy, radius, color)

@spec encode_fill_circle(integer(), integer(), non_neg_integer(), color()) :: binary()

Encode a fill_circle command.

encode_fill_rect(x, y, w, h, color)

@spec encode_fill_rect(
  non_neg_integer(),
  non_neg_integer(),
  non_neg_integer(),
  non_neg_integer(),
  color()
) :: binary()

Encode a fill_rect command that fills a rectangle with a solid color.

encode_fill_round_rect(x, y, w, h, radius, color)

@spec encode_fill_round_rect(
  non_neg_integer(),
  non_neg_integer(),
  non_neg_integer(),
  non_neg_integer(),
  non_neg_integer(),
  color()
) :: binary()

Encode a fill_round_rect command.

encode_fill_triangle(x1, y1, x2, y2, x3, y3, color)

@spec encode_fill_triangle(
  integer(),
  integer(),
  integer(),
  integer(),
  integer(),
  integer(),
  color()
) ::
  binary()

Encode a fill_triangle command.

encode_image_blit(image_id, x, y, w, h)

@spec encode_image_blit(
  non_neg_integer(),
  integer(),
  integer(),
  non_neg_integer(),
  non_neg_integer()
) ::
  binary()

Encode an image_blit command that draws a loaded image texture.

encode_load_image(id, rgba_data, width, height)

@spec encode_load_image(
  non_neg_integer(),
  binary(),
  non_neg_integer(),
  non_neg_integer()
) :: binary()

Encode a load_image command that uploads an image as a GPU texture.

encode_load_shader(name, source)

@spec encode_load_shader(String.t(), String.t()) :: binary()

Encode a load_shader command for hot-reloading shaders.

encode_load_sprite(id, rgba_data, width, height)

@spec encode_load_sprite(
  non_neg_integer(),
  binary(),
  non_neg_integer(),
  non_neg_integer()
) :: binary()

Encode a load_sprite command that uploads pixel data into the texture atlas.

encode_present()

@spec encode_present() :: binary()

Encode a present command that flushes the command queue and updates the GPU texture.

encode_read_pixels(x, y, w, h)

@spec encode_read_pixels(
  non_neg_integer(),
  non_neg_integer(),
  non_neg_integer(),
  non_neg_integer()
) ::
  binary()

Encode a read_pixels command that reads back GPU texture data.

encode_remove_image(id)

@spec encode_remove_image(non_neg_integer()) :: binary()

Encode a remove_image command that frees an image texture.

encode_remove_sprite(id)

@spec encode_remove_sprite(non_neg_integer()) :: binary()

Encode a remove_sprite command that frees a sprite from the texture atlas.

encode_reset_clip()

@spec encode_reset_clip() :: binary()

Encode a reset_clip command.

encode_resize(width, height)

@spec encode_resize(non_neg_integer(), non_neg_integer()) :: binary()

Encode a resize command that changes the surface dimensions.

encode_set_clip(x, y, w, h, enabled)

@spec encode_set_clip(
  non_neg_integer(),
  non_neg_integer(),
  non_neg_integer(),
  non_neg_integer(),
  boolean()
) :: binary()

Encode a set_clip command.

encode_set_uniform(name, data)

@spec encode_set_uniform(String.t(), binary()) :: binary()

Encode a set_uniform command for shader parameters.