Skip to content

GLCanvas<U>

ts
type GLCanvas<U> = {
  gl: WebGL2RenderingContext;
  render: () => void;
  onCanvasReady: (callback: () => void) => void;
  canvas: HTMLCanvasElement | OffscreenCanvas;
  setSize: (size: { width: number; height: number }) => void;
  play: () => void;
  pause: () => void;
  dpr: number;
  uniforms: U & Record<string, unknown>;
  onUpdated: (callback: UpdatedCallback<U>) => void;
  onBeforeRender: (callback: () => void) => void;
  onAfterRender: (callback: () => void) => void;
  resizeObserver: ReturnType<typeof onResize> | null;
};

The object returned by the glCanvas function.

Type Parameters

U

U extends Uniforms = Record<string, any>

Properties

PropertyTypeDescription
glWebGL2RenderingContextThe WebGL2 rendering context.
render() => voidExecutes a single render of the entire pipeline.
onCanvasReady(callback: () => void) => voidRegister a callback to execute after the first resizing of the canvas.
canvasHTMLCanvasElement | OffscreenCanvasThe HTMLCanvasElement or OffscreenCanvas being used.
setSize(size: { width: number; height: number; }) => voidResizes the canvas and all render targets in the postprocessing chain.
play() => voidResumes the internal animation loop (if a 'time' uniform is detected).
pause() => voidPauses the internal animation loop.
dprnumberThe Device Pixel Ratio being used.
uniformsU & Record<string, unknown>Reactive proxy of the main render pass's uniforms.
onUpdated(callback: UpdatedCallback<U>) => voidRegisters a callback called whenever a uniform of the main render pass is updated.
onBeforeRender(callback: () => void) => voidRegisters a callback called just before the main render pass is rendered.
onAfterRender(callback: () => void) => voidRegisters a callback called after the last post-processing effect is rendered.
resizeObserver| ReturnType<typeof onResize> | nullThe resize observer managing the canvas resizing.

Released under the MIT License.