# `Dala.Gpu.Command`
[🔗](https://github.com/manhvu/dala/blob/main/lib/dala/gpu/command.ex#L1)

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)

# `color`

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

# `color_to_rgba`

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

Convert a color to a 4-byte RGBA binary.

# `encode_batch`

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

Encode a batch command containing multiple sub-commands.

# `encode_blit`

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

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

# `encode_clear`

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

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

# `encode_dispatch_compute`

```elixir
@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`

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

Encode a draw_circle command.

# `encode_draw_line`

```elixir
@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`

```elixir
@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`

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

Encode a draw_triangle command.

# `encode_fill_circle`

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

Encode a fill_circle command.

# `encode_fill_rect`

```elixir
@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`

```elixir
@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`

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

Encode a fill_triangle command.

# `encode_image_blit`

```elixir
@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`

```elixir
@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`

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

Encode a load_shader command for hot-reloading shaders.

# `encode_load_sprite`

```elixir
@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`

```elixir
@spec encode_present() :: binary()
```

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

# `encode_read_pixels`

```elixir
@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`

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

Encode a remove_image command that frees an image texture.

# `encode_remove_sprite`

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

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

# `encode_reset_clip`

```elixir
@spec encode_reset_clip() :: binary()
```

Encode a reset_clip command.

# `encode_resize`

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

Encode a resize command that changes the surface dimensions.

# `encode_set_clip`

```elixir
@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`

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

Encode a set_uniform command for shader parameters.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
