@react-vertex/buffer-hooks v1.2.0
@react-vertex/buffer-hooks
Documentation and Examples
React hooks for working with WebGL buffers. Efficiently manage static, stream, and dynamic buffers for use in WebGL programs.
Install via npm:
npm install @react-vertex/buffer-hooks
Importing:
import {
useStaticBuffer,
useStreamBuffer,
useDynamicBuffer,
} from '@react-vertex/buffer-hooks'
useStaticBuffer(gl, data, [isIndex], [format])
=> WebGLBuffer
React hook to create a static WebGL buffer. For cases where the contents of the buffer are likely to be used often and not change often. See docs on WebGL buffers for more.
Arguments:
gl
: A WebGL context.
data
: An array. If you pass a regular array, use format
to convert to a typed array.
isIndex (optional)
: Boolean indicating if you want to create an index buffer or not. Defaults to false.
format (optional)
: A string format e.g. 'F32'. See formats list below.
Returns:
buffer
: A WebGLBuffer instance.
useStreamBuffer(gl, data, [isIndex], [format])
=> WebGLBuffer
React hook to create a WebGL stream buffer. For cases where the contents of the buffer are likely to not be used often. See docs on WebGL buffers for more.
Arguments:
gl
: A WebGL context.
data
: An array. If you pass a regular array, use format
to convert to a typed array.
isIndex (optional)
: Boolean indicating if you want to create an index buffer or not. Defaults to false.
format (optional)
: A string format e.g. 'F32'. See formats list below.
Returns:
buffer
: A WebGLBuffer instance.
useDynamicBuffer(gl, data, [isIndex], [format])
=> WebGLBuffer
React hook to create a dynamic WebGL buffer. For cases where the contents of the buffer are likely to be used often and change often. See docs on WebGL buffers for more.
Arguments:
gl
: A WebGL context.
data
: An array. If you pass a regular array, use format
to convert to a typed array.
isIndex (optional)
: Boolean indicating if you want to create an index buffer or not. Defaults to false.
format (optional)
: A string format e.g. 'F32'. See formats list below.
Returns:
buffer
: A WebGLBuffer instance.
Valid Formats
Format | Type | Range |
---|---|---|
'U8' | Uint8Array | -128 to 127 |
'U16' | Uint16Array | -32,768 to 32,767 |
'U32' | Uint32Array | -2,147,483,648 to 2,147,483,647 |
'I8' | Int8Array | -128 to 127 |
'I16' | Int16Array | -32,768 to 32,767 |
'I32' | Int32Array | -2,147,483,648 to 2,147,483,647 |
'F32' | Float32Array | 1.2x10^-38 to 3.4x10^38 |