This page covers useMotionGPU() for runtime context access, usePointer() for normalized pointer input, the CurrentWritable pattern for synchronous reads, and recommended integration patterns.
For advanced user-defined context, see User Context (Advanced).
useMotionGPU()
useMotionGPU() returns the MotionGPUContext — the primary API for reading runtime state and controlling rendering from within FragCanvas children.
<script lang="ts">
import { useMotionGPU } from '@motion-core/motion-gpu/svelte';
const gpu = useMotionGPU();
</script>Must be called inside a <FragCanvas> component tree. Calling it outside throws.
usePointer()
usePointer() provides adapter-managed pointer tracking (mouse, touch, pen) with shader-friendly coordinates:
state.current.uvin0..1with Y-up orientationstate.current.ndcin-1..1- optional synthesized click snapshots via
lastClick.current - optional automatic frame wakeups (
requestFrame: 'auto')
Use it to remove canvas event-listener boilerplate in runtime components.
MotionGPUContext shape
Reactive stores
Direct values
Control methods
Scheduler access
For higher-level scheduler configuration and debug snapshots, use the advanced helper exports:
The CurrentWritable / CurrentReadable pattern
Store-like subscriptions require setup/teardown to read values reactively. In useFrame callbacks (which run 60 times per second), subscribing and unsubscribing per read is wasteful.
CurrentWritable<T> and CurrentReadable<T> extend reactive store contracts with a synchronous .current getter:
API
When to use which
Integration patterns
Reading canvas size
<script lang="ts">
import { useMotionGPU } from '@motion-core/motion-gpu/svelte';
const gpu = useMotionGPU();
</script>
<p>Canvas: {$gpu.size.width}×{$gpu.size.height} @ {$gpu.dpr}x</p>Conditional rendering control
<script lang="ts">
import { useMotionGPU } from '@motion-core/motion-gpu/svelte';
const gpu = useMotionGPU();
function togglePause() {
gpu.autoRender.set(!gpu.autoRender.current);
}
</script>
<button onclick={togglePause}>
{$gpu.autoRender ? 'Pause' : 'Resume'}
</button>On-demand with external triggers
<script lang="ts">
import { useMotionGPU, useFrame, usePointer } from '@motion-core/motion-gpu/svelte';
const gpu = useMotionGPU();
const pointer = usePointer({ requestFrame: 'auto' });
$effect(() => {
gpu.renderMode.set('on-demand');
});
useFrame((state) => {
state.setUniform('uTime', state.time);
state.setUniform('uMouse', pointer.state.current.uv);
}, { autoInvalidate: false });
</script>