Basic API
Set gl config
gl('count', 6) // or
gl({ count: 6 })
Set buffer object
// set uniform
gl.uniform('iTime', performance.now() / 1000) // or
gl.uniform({ iTime: performance.now() / 1000 })
// set attribute
gl.attribute('a_position', [-1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1]) // or
gl.attribute({ a_position: [-1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1] })
Set mount and clean callback
// run when mount phase
gl('mount', () => {})
// run when clean phase
gl('clean', () => {})
more
Set frame callback
// Schedule an update
gl.frame((dt) => {})
// Start an update loop
gl.frame((dt) => true)
more
Render shorthands
gl.frame(() => {
gl.clear() // ...... to call gl.clear(gl.COLOR_BUFFER_BIT)
gl.viewport() // ... to call gl.viewport(0, 0, width, height)
gl.drawArrays() // . to call gl.drawArrays(gl.TRIANGLES, 0, count)
// or
gl.drawElements() // to call gl.drawElements(gl.TRIANGLES, count, gl.UNSIGNED_SHORT, 0)
})
uniform type | uniform key | description | availability |
---|
uniform vec3 | iResolution | viewport resolution (in pixels) | ✔ |
uniform float | iTime | shader playback time (in seconds) | ✔ |
uniform float | iTimeDelta | render time (in seconds) | ✔ |
uniform float | iFrameRate | shader frame rate | ❌ |
uniform int | iFrame | shader playback frame | ❌ |
uniform float | iChannelTime[4] | channel playback time (in seconds) | ✔ |
uniform vec3 | iChannelResolution[4] | channel resolution (in pixels) | ❌ |
uniform vec4 | iMouse | mouse pixel coords. xy: current (if MLB down), zw: click | ✔ |
uniform samplerXX | iChannel0..3 | input channel. XX = 2D/Cube | ❌ |
uniform vec4 | iDate | (year, month, day, time in seconds) | ❌ |
uniform float | iSampleRate | sound sample rate (i.e., 44100) | ❌ |