Assets

:= []

Assets module - host-owned textures and other resources.

Textures are opaque, host-owned GPU resources. Load or generate them during initialization, keep them in the model, then draw or update them through the operations in this module. Releasing the final Roc reference unloads the native texture automatically.

load_texture! : Str => Try(Texture, [TextureLoadFailed, ResourceLimit, ..])

Load an image file into GPU texture memory. The returned value owns the resource and may be safely shared between sprites, uniforms, and models.

generate_color_texture! : GenerateColorTexture => Try(Texture, [TextureGenerationFailed, ResourceLimit, ..])

Generate a solid-color GPU texture. The temporary CPU image is released inside the host; only the host-owned texture crosses back.

generate_checked_texture! : GenerateCheckedTexture => Try(Texture, [TextureGenerationFailed, ResourceLimit, ..])

Generate a checkerboard GPU texture without retaining a CPU image.

update_texture! : Texture, List(Color) => Try({  }, [PixelCountMismatch, ..])

Replace every pixel. The row-major RGBA list must exactly match the texture dimensions and is borrowed only for this host call.

Texture

Assets.Texture :: # (opaque)

Opaque, host-owned mutable GPU texture with immutable dimensions.

load! : Str => Try(Texture, [TextureLoadFailed, ResourceLimit, ..])

Load an image file into GPU texture memory.

generate_color! : GenerateColorTexture => Try(Texture, [TextureGenerationFailed, ResourceLimit, ..])

Generate a solid-color GPU texture.

generate_checked! : GenerateCheckedTexture => Try(Texture, [TextureGenerationFailed, ResourceLimit, ..])

Generate a checkerboard GPU texture.

view : Texture -> TextureView

Read-only sampling view sharing this texture's host-owned ARC resource.

width : Texture -> F32

Width in pixels.

size : Texture -> Vec2

Texture dimensions in pixels.

rect : Texture -> Rect

Rectangle covering the complete texture in pixel coordinates.

update! : Texture, List(Color) => Try({  }, [PixelCountMismatch, ..])

Replace every pixel in row-major RGBA order.

set_filter! : Texture, TextureFilter => {  }

Change how this texture is sampled when scaled.

set_wrap! : Texture, TextureWrap => {  }

Change how out-of-range texture coordinates are wrapped.

TextureView

Assets.TextureView :: # (opaque)

Read-only sampled texture view. It owns the same ARC reference as its source but deliberately has no pixel-update capability.

width : TextureView -> F32

Width in pixels.

height : TextureView -> F32

Height in pixels.

size : TextureView -> Vec2

Texture dimensions in pixels.

rect : TextureView -> Rect

Rectangle covering the complete texture in pixel coordinates.

set_filter! : TextureView, TextureFilter => {  }

Change how this view is sampled when scaled.

set_wrap! : TextureView, TextureWrap => {  }

Change how out-of-range texture coordinates are wrapped.

TextureFilter

:= [Point, Bilinear, Trilinear, Anisotropic4x, Anisotropic8x, Anisotropic16x]

Texture sampling filter used when an image is scaled.

TextureWrap

:= [Repeat, Clamp, MirrorRepeat, MirrorClamp]

Texture-coordinate behavior outside the normal 0-to-1 range.