Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion scripting/api-reference/gpu/gpu-canvas.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ Height in pixels.

### `format`

Native pixel format of the canvas backing texture ('bgra8unorm' on D3D, 'rgba8unorm' elsewhere).
Pixel format of the canvas backing texture, always 'rgba8unorm'. A
deferred canvas reports this before its texture is allocated.
MSAA resolve requires source and target to have identical formats — always
derive GPUTexture and pipeline formats from this value:
```lua
Expand Down
21 changes: 4 additions & 17 deletions scripting/api-reference/gpu/shader.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,9 @@
title: Shader
---

An opaque compiled shader module. Create via `context:loadShader`.


## Constructors

### `new`

{/* new: (wgslAssetName: string) -> Shader */}
<div class="signature">
```lua
new(wgslAssetName: string) -> Shader
```
</div>

Load a pre-compiled WGSL shader embedded in the Rive file.
The name must match a shader asset added in the editor (e.g. "myEffect.wgsl").
Raw WGSL source strings are not accepted at runtime.
An opaque compiled shader module. Get one with `context:shader(name)`,
where `name` is the shader asset's name as added in the editor (e.g.
"myEffect" — no ".wgsl" extension). Raw WGSL source strings are not
accepted at runtime.


40 changes: 6 additions & 34 deletions scripting/api-reference/interfaces/context.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -298,46 +298,18 @@ Query GPU capabilities. Returns a table of supported features
and limits for the current backend.


### `preferredCanvasFormat`
### `shader`

{/* function preferredCanvasFormat(self): TextureFormat */}
{/* function shader(self, name: string): Shader? */}
<div class="signature">
```lua
preferredCanvasFormat() -> TextureFormat
shader(name: string) -> Shader?
```
</div>

Returns the native canvas texture format for the current platform.

This is the format that `context:gpuCanvas(...)` backing textures use,
and therefore what `canvas.format` will report. Equivalent to WebGPU's
`navigator.gpu.getPreferredCanvasFormat()`.

- Metal (macOS/iOS): `'rgba8unorm'` (off-screen canvas, not a CAMetalLayer surface)
- D3D11/D3D12 (Windows): `'bgra8unorm'`
- Vulkan, OpenGL, WebGPU: `'rgba8unorm'` (safe default; actual surface format
may vary — use `canvas.format` for the authoritative value once a
canvas exists)

Use this at init time to create [GPUTexture](/scripting/api-reference/gpu/gpu-texture) and [GPUPipeline](/scripting/api-reference/gpu/gpu-pipeline)
with a matching format before any canvas is drawn:
```lua
local fmt = context:preferredCanvasFormat()
self.pipeline = GPUPipeline.new({ colorTargets = {{ format = fmt }}, ... })
```


### `loadShader`

{/* function loadShader(self, name: string): Shader? */}
<div class="signature">
```lua
loadShader(name: string) -> Shader?
```
</div>

Load a compiled shader by asset name. Returns a Shader ready for use
in GPUPipeline.new(), or nil if the named shader is not found.
Get a compiled shader by asset name (the name as added in the editor,
with no ".wgsl" extension). Returns a Shader ready for use in
GPUPipeline.new(), or nil if the named shader is not found.


### `decodeImage`
Expand Down