GenServer that holds the state for a GPU surface.
Each surface corresponds to a Rust-side GPU renderer with a CPU-side
framebuffer, a command queue, and a GPU texture. The GenServer owns the
NIF reference and ensures clean teardown via terminate/2.
Commands are fire-and-forget (cast) for performance. Pixel access is synchronous (call) since it returns data.
Summary
Functions
Execute a batch of pre-encoded commands.
Blit a loaded sprite at the given position.
Returns a specification to start this module under a supervisor.
Clear the surface with a solid color.
Dispatch a GPU compute shader.
Draw a circle outline.
Draw a loaded image onto the framebuffer.
Draw a line between two points.
Draw a rounded rectangle outline.
Draw a triangle outline.
Fill a circle.
Fill a rectangle with a solid color.
Fill a rounded rectangle.
Fill a triangle.
Get surface info as a map.
Read the current pixel data as an RGBA8888 binary.
Load an image into the GPU texture pool.
Load or hot-reload a shader.
Load a sprite into the texture atlas for later blitting.
Present the surface — flush the command queue and update the GPU texture.
Remove an image from the GPU texture pool.
Remove a sprite from the texture atlas.
Reset the clipping region.
Resize the surface.
Set the clipping rectangle.
Set the pixel data directly. Binary must be exactly width height 4 bytes.
Set a uniform value.
Start a linked surface GenServer.
Stop the surface GenServer and free GPU resources.
Check compute support.
Modify pixels via a callback. The callback receives the current RGBA8888 binary and must return the new RGBA8888 binary of the same size.
Types
@type t() :: %Dala.Gpu.Surface{ height: non_neg_integer(), ref: reference(), width: non_neg_integer() }
Functions
Execute a batch of pre-encoded commands.
@spec blit(pid(), non_neg_integer(), integer(), integer()) :: :ok
Blit a loaded sprite at the given position.
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec clear(pid(), Dala.Gpu.Command.color()) :: :ok
Clear the surface with a solid color.
@spec dispatch_compute( pid(), String.t(), binary(), {non_neg_integer(), non_neg_integer(), non_neg_integer()} ) :: :ok | {:error, term()}
Dispatch a GPU compute shader.
@spec draw_circle( pid(), integer(), integer(), non_neg_integer(), Dala.Gpu.Command.color() ) :: :ok
Draw a circle outline.
@spec draw_image( pid(), non_neg_integer(), integer(), integer(), non_neg_integer(), non_neg_integer() ) :: :ok
Draw a loaded image onto the framebuffer.
@spec draw_line( pid(), integer(), integer(), integer(), integer(), Dala.Gpu.Command.color() ) :: :ok
Draw a line between two points.
@spec draw_round_rect( pid(), non_neg_integer(), non_neg_integer(), non_neg_integer(), non_neg_integer(), non_neg_integer(), Dala.Gpu.Command.color() ) :: :ok
Draw a rounded rectangle outline.
@spec draw_triangle( pid(), integer(), integer(), integer(), integer(), integer(), integer(), Dala.Gpu.Command.color() ) :: :ok
Draw a triangle outline.
@spec fill_circle( pid(), integer(), integer(), non_neg_integer(), Dala.Gpu.Command.color() ) :: :ok
Fill a circle.
@spec fill_rect( pid(), non_neg_integer(), non_neg_integer(), non_neg_integer(), non_neg_integer(), Dala.Gpu.Command.color() ) :: :ok
Fill a rectangle with a solid color.
@spec fill_round_rect( pid(), non_neg_integer(), non_neg_integer(), non_neg_integer(), non_neg_integer(), non_neg_integer(), Dala.Gpu.Command.color() ) :: :ok
Fill a rounded rectangle.
@spec fill_triangle( pid(), integer(), integer(), integer(), integer(), integer(), integer(), Dala.Gpu.Command.color() ) :: :ok
Fill a triangle.
@spec get_info(pid()) :: %{width: non_neg_integer(), height: non_neg_integer()}
Get surface info as a map.
Read the current pixel data as an RGBA8888 binary.
@spec load_image( pid(), non_neg_integer(), binary(), non_neg_integer(), non_neg_integer() ) :: :ok
Load an image into the GPU texture pool.
Load or hot-reload a shader.
@spec load_sprite( pid(), non_neg_integer(), binary(), non_neg_integer(), non_neg_integer() ) :: :ok
Load a sprite into the texture atlas for later blitting.
@spec present(pid()) :: :ok
Present the surface — flush the command queue and update the GPU texture.
@spec remove_image(pid(), non_neg_integer()) :: :ok
Remove an image from the GPU texture pool.
@spec remove_sprite(pid(), non_neg_integer()) :: :ok
Remove a sprite from the texture atlas.
@spec reset_clip(pid()) :: :ok
Reset the clipping region.
@spec resize(pid(), non_neg_integer(), non_neg_integer()) :: :ok
Resize the surface.
@spec set_clip( pid(), non_neg_integer(), non_neg_integer(), non_neg_integer(), non_neg_integer(), boolean() ) :: :ok
Set the clipping rectangle.
Set the pixel data directly. Binary must be exactly width height 4 bytes.
Set a uniform value.
@spec start_link(keyword()) :: GenServer.on_start()
Start a linked surface GenServer.
@spec stop(pid()) :: :ok
Stop the surface GenServer and free GPU resources.
Check compute support.
Modify pixels via a callback. The callback receives the current RGBA8888 binary and must return the new RGBA8888 binary of the same size.