Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

D.8 WebGL Shader Intrinsics

The WASM backend also provides a minimal WebGL path for fullscreen fragment shader demos driven by udewy strings and integer uniforms:

IntrinsicArgsDescription
__webgl_init__(shader_ptr shader_len width height)4Compile a fragment shader string and initialize a fullscreen WebGL canvas
__webgl_uniform1i__(name_ptr name_len value)3Set an int uniform on the active shader program
__webgl_uniform2i__(name_ptr name_len x y)4Set an ivec2 uniform on the active shader program
__webgl_uniform1iv__(name_ptr name_len values_ptr count)4Set an int[count] uniform array from udewy memory
__webgl_uniform2iv__(name_ptr name_len values_ptr count)4Set an ivec2[count] uniform array from udewy memory
__webgl_render__()0Draw the active fullscreen shader

Usage:

  1. Store your fragment shader source as a normal udewy string
  2. Use __load__(shader - 8) to recover its byte length
  3. Call __webgl_init__(shader shader_len width height) once
  4. Update uniforms each frame with __webgl_uniform1i__, __webgl_uniform2i__, __webgl_uniform1iv__, or __webgl_uniform2iv__
  5. Call __webgl_render__() to draw

The runtime provides a built-in passthrough vertex shader with an a_position attribute, so user programs only need to supply fragment shader code.