1.2.0 • Published 5 years ago

@react-vertex/buffer-hooks v1.2.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

@react-vertex/buffer-hooks

license bundlephobia npm version

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

Typed Arrays on MDN

FormatTypeRange
'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'Float32Array1.2x10^-38 to 3.4x10^38
1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago