gpu-io / GPULayer
- initFromImageURL
- is1D
- is2D
- incrementBufferIndex
- decrementBufferIndex
- getStateAtIndex
- setFromArray
- resize
- clear
- getValues
- getValuesAsync
- copyToWebGLBuffer
- getImage
- savePNG
- attachToThreeTexture
- clone
- dispose
• Readonly name: string
Name of GPULayer, used for error logging.
• Readonly type: GPULayerType
Data type represented by GPULayer.
• Readonly numComponents: GPULayerNumComponents
Number of RGBA elements represented by each pixel in the GPULayer (1-4).
• Readonly filter: GPULayerFilter
Interpolation filter for GPULayer, defaults to LINEAR for 2D FLOAT/HALF_FLOAT GPULayers, otherwise defaults to NEAREST.
• Readonly wrapX: GPULayerWrap
Horizontal wrapping style for GPULayer, defaults to CLAMP_TO_EDGE.
• Readonly wrapY: GPULayerWrap
Vertical wrapping style for GPULayer, defaults to CLAMP_TO_EDGE.
• Readonly numBuffers: number
▸ Static initFromImageURL(composer, params): Promise<GPULayer>
Create a GPULayer from an image url.
| Name | Type | Description |
|---|---|---|
composer |
GPUComposer |
The current GPUComposer instance. |
params |
Object |
GPULayer parameters. |
params.name |
string |
Name of GPULayer, used for error logging. |
params.url |
string |
URL of the image source. |
params.type? |
ImageType |
Data type represented by GPULayer. |
params.format? |
ImageFormat |
Image format, either RGB or RGBA. |
params.filter? |
GPULayerFilter |
Interpolation filter for GPULayer, defaults to LINEAR for FLOAT/HALF_FLOAT Images, otherwise defaults to NEAREST. |
params.wrapX? |
GPULayerWrap |
Horizontal wrapping style for GPULayer, defaults to CLAMP_TO_EDGE. |
params.wrapY? |
GPULayerWrap |
Vertical wrapping style for GPULayer, defaults to CLAMP_TO_EDGE. |
params.clearValue? |
number | number[] |
Value to write to GPULayer when GPULayer.clear() is called. |
Promise<GPULayer>
▸ is1D(): boolean
Returns whether the GPULayer was inited as a 1D array (rather than 2D).
boolean
- true if GPULayer is 1D, else false.
▸ is2D(): boolean
Returns whether the GPULayer was inited as a 2D array (rather than 1D).
boolean
- true if GPULayer is 2D, else false.
▸ incrementBufferIndex(): void
Increment buffer index by 1.
void
▸ decrementBufferIndex(): void
Decrement buffer index by 1.
void
▸ getStateAtIndex(index): GPULayerState
Get the state at a specified index as a GPULayerState object.
| Name | Type |
|---|---|
index |
number |
▸ setFromArray(array): void
| Name | Type |
|---|---|
array |
number[] | GPULayerArray |
void
▸ resize(dimensions, arrayOrImage?): void
| Name | Type |
|---|---|
dimensions |
number | number[] |
arrayOrImage? |
number[] | HTMLImageElement | GPULayerArray |
void
▸ clear(applyToAllBuffers?): void
Clear all data in GPULayer to GPULayer.clearValue.
| Name | Type | Default value | Description |
|---|---|---|---|
applyToAllBuffers |
boolean |
false |
Flag to apply to all buffers of GPULayer, or just the current output buffer. |
void
▸ getValues(): GPULayerArray
Returns the current values of the GPULayer as a TypedArray.
- A TypedArray containing current state of GPULayer.
▸ getValuesAsync(): Promise<GPULayerArray>
Non-blocking function to return the current values of the GPULayer as a TypedArray. This only works for WebGL2 contexts, will fall back to getValues() if WebGL1 context.
Promise<GPULayerArray>
- A TypedArray containing current state of GPULayer.
▸ copyToWebGLBuffer(dstBuffer, dstOffset?, srcX?, srcY?, srcWidth?, srcHeight?): void
Copies the contents of the layer to a WebGLBuffer.
| Name | Type | Default value | Description |
|---|---|---|---|
dstBuffer |
WebGLBuffer |
undefined |
The WebGLBuffer to copy the contents of the layer to. |
dstOffset |
number |
0 |
The offset in bytes to start copying to. |
srcX? |
number |
0 |
The x coordinate of the source rectangle. |
srcY? |
number |
0 |
The y coordinate of the source rectangle. |
srcWidth? |
number |
undefined |
The width of the source rectangle. |
srcHeight? |
number |
undefined |
The height of the source rectangle. |
void
▸ getImage(params?): HTMLImageElement
Get the current state of this GPULayer as an Image.
| Name | Type | Description |
|---|---|---|
params? |
Object |
Image parameters. |
params.multiplier? |
number |
Multiplier to apply to data (defaults to 255 for FLOAT and HALF_FLOAT types, else 1). |
HTMLImageElement
▸ savePNG(params?): void
Save the current state of this GPULayer to png.
| Name | Type | Description |
|---|---|---|
params |
Object |
PNG parameters. |
params.filename? |
string |
PNG filename (no extension, defaults to the name of the GPULayer). |
params.dpi? |
number |
PNG dpi (defaults to 72dpi). |
params.multiplier? |
number |
Multiplier to apply to data before saving PNG (defaults to 255 for FLOAT and HALF_FLOAT types, else 1). |
params.callback? |
(blob: Blob, filename: string) => void |
Optional callback when Blob is ready, default behavior saves the PNG using file-saver. |
void
▸ attachToThreeTexture(texture): void
Attach the output buffer of this GPULayer to a Threejs Texture object.
| Name | Type | Description |
|---|---|---|
texture |
Texture |
Threejs texture object. |
void
▸ clone(name?): GPULayer
Create a deep copy of GPULayer with current state copied over.
| Name | Type | Description |
|---|---|---|
name? |
string |
Name of new GPULayer as string. |
- Deep copy of GPULayer.
▸ dispose(): void
Deallocate GPULayer instance and associated WebGL properties.
void
• new GPULayer(composer, params)
Create a GPULayer.
| Name | Type | Description |
|---|---|---|
composer |
GPUComposer |
The current GPUComposer instance. |
params |
Object |
GPULayer parameters. |
params.name |
string |
Name of GPULayer, used for error logging. |
params.type |
GPULayerType |
Data type represented by GPULayer. |
params.numComponents |
GPULayerNumComponents |
Number of RGBA elements represented by each pixel in the GPULayer (1-4). |
params.dimensions |
number | number[] |
Dimensions of 1D or 2D GPULayer. |
params.array? |
number[] | GPULayerArray |
Array to initialize GPULayer. |
params.filter? |
GPULayerFilter |
Interpolation filter for GPULayer, defaults to LINEAR for 2D FLOAT/HALF_FLOAT GPULayers, otherwise defaults to NEAREST. |
params.wrapX? |
GPULayerWrap |
Horizontal wrapping style for GPULayer, defaults to CLAMP_TO_EDGE. |
params.wrapY? |
GPULayerWrap |
Vertical wrapping style for GPULayer, defaults to CLAMP_TO_EDGE. |
params.numBuffers? |
number |
How may buffers to allocate, defaults to 1. If you intend to use the current state of this GPULayer as an input to generate a new state, you will need at least 2 buffers. |
params.clearValue? |
number | number[] |
Value to write to GPULayer when GPULayer.clear() is called. |
• get width(): number
The width of the GPULayer array.
number
• get height(): number
The height of the GPULayer array.
number
• get length(): number
The length of the GPULayer array (only available to 1D GPULayers).
number
• get bufferIndex(): number
Get buffer index of the current state.
number
• get currentState(): GPULayerState
Get the current state as a GPULayerState object.
• get lastState(): GPULayerState
Get the previous state as a GPULayerState object (only available for GPULayers with numBuffers > 1).
• get clearValue(): number | number[]
Get the clearValue of the GPULayer.
number | number[]
• set clearValue(clearValue): void
Set the clearValue of the GPULayer, which is applied during GPULayer.clear().
| Name | Type |
|---|---|
clearValue |
number | number[] |
void