Skip to content

Latest commit

 

History

History
517 lines (301 loc) · 11.5 KB

File metadata and controls

517 lines (301 loc) · 11.5 KB

gpu-io / GPULayer

Class: GPULayer

Table of contents

Properties

Methods

Constructors

Accessors

Properties

name

Readonly name: string

Name of GPULayer, used for error logging.


type

Readonly type: GPULayerType

Data type represented by GPULayer.


numComponents

Readonly numComponents: GPULayerNumComponents

Number of RGBA elements represented by each pixel in the GPULayer (1-4).


filter

Readonly filter: GPULayerFilter

Interpolation filter for GPULayer, defaults to LINEAR for 2D FLOAT/HALF_FLOAT GPULayers, otherwise defaults to NEAREST.


wrapX

Readonly wrapX: GPULayerWrap

Horizontal wrapping style for GPULayer, defaults to CLAMP_TO_EDGE.


wrapY

Readonly wrapY: GPULayerWrap

Vertical wrapping style for GPULayer, defaults to CLAMP_TO_EDGE.


numBuffers

Readonly numBuffers: number

Methods

initFromImageURL

Static initFromImageURL(composer, params): Promise<GPULayer>

Create a GPULayer from an image url.

Parameters

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.

Returns

Promise<GPULayer>


is1D

is1D(): boolean

Returns whether the GPULayer was inited as a 1D array (rather than 2D).

Returns

boolean

  • true if GPULayer is 1D, else false.

is2D

is2D(): boolean

Returns whether the GPULayer was inited as a 2D array (rather than 1D).

Returns

boolean

  • true if GPULayer is 2D, else false.

incrementBufferIndex

incrementBufferIndex(): void

Increment buffer index by 1.

Returns

void


decrementBufferIndex

decrementBufferIndex(): void

Decrement buffer index by 1.

Returns

void


getStateAtIndex

getStateAtIndex(index): GPULayerState

Get the state at a specified index as a GPULayerState object.

Parameters

Name Type
index number

Returns

GPULayerState


setFromArray

setFromArray(array): void

Parameters

Name Type
array number[] | GPULayerArray

Returns

void


resize

resize(dimensions, arrayOrImage?): void

Parameters

Name Type
dimensions number | number[]
arrayOrImage? number[] | HTMLImageElement | GPULayerArray

Returns

void


clear

clear(applyToAllBuffers?): void

Clear all data in GPULayer to GPULayer.clearValue.

Parameters

Name Type Default value Description
applyToAllBuffers boolean false Flag to apply to all buffers of GPULayer, or just the current output buffer.

Returns

void


getValues

getValues(): GPULayerArray

Returns the current values of the GPULayer as a TypedArray.

Returns

GPULayerArray

  • A TypedArray containing current state of GPULayer.

getValuesAsync

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.

Returns

Promise<GPULayerArray>

  • A TypedArray containing current state of GPULayer.

copyToWebGLBuffer

copyToWebGLBuffer(dstBuffer, dstOffset?, srcX?, srcY?, srcWidth?, srcHeight?): void

Copies the contents of the layer to a WebGLBuffer.

Parameters

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.

Returns

void


getImage

getImage(params?): HTMLImageElement

Get the current state of this GPULayer as an Image.

Parameters

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).

Returns

HTMLImageElement


savePNG

savePNG(params?): void

Save the current state of this GPULayer to png.

Parameters

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.

Returns

void


attachToThreeTexture

attachToThreeTexture(texture): void

Attach the output buffer of this GPULayer to a Threejs Texture object.

Parameters

Name Type Description
texture Texture Threejs texture object.

Returns

void


clone

clone(name?): GPULayer

Create a deep copy of GPULayer with current state copied over.

Parameters

Name Type Description
name? string Name of new GPULayer as string.

Returns

GPULayer

  • Deep copy of GPULayer.

dispose

dispose(): void

Deallocate GPULayer instance and associated WebGL properties.

Returns

void

Constructors

constructor

new GPULayer(composer, params)

Create a GPULayer.

Parameters

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.

Accessors

width

get width(): number

The width of the GPULayer array.

Returns

number


height

get height(): number

The height of the GPULayer array.

Returns

number


length

get length(): number

The length of the GPULayer array (only available to 1D GPULayers).

Returns

number


bufferIndex

get bufferIndex(): number

Get buffer index of the current state.

Returns

number


currentState

get currentState(): GPULayerState

Get the current state as a GPULayerState object.

Returns

GPULayerState


lastState

get lastState(): GPULayerState

Get the previous state as a GPULayerState object (only available for GPULayers with numBuffers > 1).

Returns

GPULayerState


clearValue

get clearValue(): number | number[]

Get the clearValue of the GPULayer.

Returns

number | number[]

set clearValue(clearValue): void

Set the clearValue of the GPULayer, which is applied during GPULayer.clear().

Parameters

Name Type
clearValue number | number[]

Returns

void