gpu-io
January 12, 2023 · View on GitHub
gpu-io
gpu-io
Table of contents
Classes
Variables
- HALF_FLOAT
- FLOAT
- UNSIGNED_BYTE
- BYTE
- UNSIGNED_SHORT
- SHORT
- UNSIGNED_INT
- INT
- BOOL
- UINT
- NEAREST
- LINEAR
- CLAMP_TO_EDGE
- REPEAT
- RGB
- RGBA
- GLSL3
- GLSL1
- WEBGL2
- WEBGL1
- EXPERIMENTAL_WEBGL
- EXPERIMENTAL_WEBGL2
- PRECISION_LOW_P
- PRECISION_MEDIUM_P
- PRECISION_HIGH_P
- BOUNDARY_TOP
- BOUNDARY_BOTTOM
- BOUNDARY_LEFT
- BOUNDARY_RIGHT
Type Aliases
- GPULayerArray
- GPULayerType
- GPULayerNumComponents
- GPULayerFilter
- GPULayerWrap
- GPULayerState
- ImageFormat
- ImageType
- GLSLVersion
- GLSLPrecision
- UniformType
- UniformValue
- UniformParams
- CompileTimeConstants
- ErrorCallback
- BoundaryEdge
GPUProgram Helper Functions
- copyProgram
- addLayersProgram
- addValueProgram
- multiplyValueProgram
- setValueProgram
- setColorProgram
- zeroProgram
- renderRGBProgram
- renderAmplitudeProgram
- renderSignedAmplitudeProgram
Other Functions
- isWebGL2
- isWebGL2Supported
- isHighpSupportedInVertexShader
- isHighpSupportedInFragmentShader
- getVertexShaderMediumpPrecision
- getFragmentShaderMediumpPrecision
Variables
HALF_FLOAT
• Const HALF_FLOAT: "HALF_FLOAT"
Half float data type.
FLOAT
• Const FLOAT: "FLOAT"
Float data type.
UNSIGNED_BYTE
• Const UNSIGNED_BYTE: "UNSIGNED_BYTE"
Unsigned byte data type.
BYTE
• Const BYTE: "BYTE"
Byte data type.
UNSIGNED_SHORT
• Const UNSIGNED_SHORT: "UNSIGNED_SHORT"
Unsigned short data type.
SHORT
• Const SHORT: "SHORT"
Short data type.
UNSIGNED_INT
• Const UNSIGNED_INT: "UNSIGNED_INT"
Unsigned int data type.
INT
• Const INT: "INT"
Int data type.
BOOL
• Const BOOL: "BOOL"
Boolean data type (GPUProgram uniforms only).
UINT
• Const UINT: "UINT"
Unsigned int data type (GPUProgram uniforms only).
NEAREST
• Const NEAREST: "NEAREST"
Nearest texture filtering.
LINEAR
• Const LINEAR: "LINEAR"
Linear texture filtering.
CLAMP_TO_EDGE
• Const CLAMP_TO_EDGE: "CLAMP_TO_EDGE"
Clamp to edge wrapping (no wrapping).
REPEAT
• Const REPEAT: "REPEAT"
Repeat/periodic wrapping.
RGB
• Const RGB: "RGB"
RGB image format.
RGBA
• Const RGBA: "RGBA"
RGBA image format.
GLSL3
• Const GLSL3: "300 es"
GLSL version 300 (WebGL2 only).
GLSL1
• Const GLSL1: "100"
GLSL version 100 (WebGL1 and WebGL2).
WEBGL2
• Const WEBGL2: "webgl2"
WebGL2 context ID.
WEBGL1
• Const WEBGL1: "webgl"
WebGL1 context ID.
EXPERIMENTAL_WEBGL
• Const EXPERIMENTAL_WEBGL: "experimental-webgl"
Experimental WebGL context ID.
EXPERIMENTAL_WEBGL2
• Const EXPERIMENTAL_WEBGL2: "experimental-webgl2"
Experimental WebGL context ID.
PRECISION_LOW_P
• Const PRECISION_LOW_P: "lowp"
GLSL lowp precision declaration.
PRECISION_MEDIUM_P
• Const PRECISION_MEDIUM_P: "mediump"
GLSL mediump precision declaration.
PRECISION_HIGH_P
• Const PRECISION_HIGH_P: "highp"
GLSL highp precision declaration.
BOUNDARY_TOP
• Const BOUNDARY_TOP: "BOUNDARY_TOP"
BOUNDARY_BOTTOM
• Const BOUNDARY_BOTTOM: "BOUNDARY_BOTTOM"
BOUNDARY_LEFT
• Const BOUNDARY_LEFT: "BOUNDARY_LEFT"
BOUNDARY_RIGHT
• Const BOUNDARY_RIGHT: "BOUNDARY_RIGHT"
Type Aliases
GPULayerArray
Ƭ GPULayerArray: Float32Array | Uint8Array | Int8Array | Uint16Array | Int16Array | Uint32Array | Int32Array
GPULayer array types.
GPULayerType
Ƭ GPULayerType: typeof HALF_FLOAT | typeof FLOAT | typeof UNSIGNED_BYTE | typeof BYTE | typeof UNSIGNED_SHORT | typeof SHORT | typeof UNSIGNED_INT | typeof INT
GPULayer data types.
GPULayerNumComponents
Ƭ GPULayerNumComponents: 1 | 2 | 3 | 4
GPULayer numComponents options.
GPULayerFilter
Ƭ GPULayerFilter: typeof LINEAR | typeof NEAREST
GPULayer filter/interpolation types.
GPULayerWrap
Ƭ GPULayerWrap: typeof REPEAT | typeof CLAMP_TO_EDGE
GPULayer wrap types.
GPULayerState
Ƭ GPULayerState: Object
The WebGLTexture corresponding to a GPULayer buffer (e.g. currentState or lastState). This data structure also includes a reference back to the GPULayer that it originated from.
Type declaration
| Name | Type |
|---|---|
texture | WebGLTexture |
layer | GPULayer |
ImageFormat
Ƭ ImageFormat: typeof RGB | typeof RGBA
Image formats for GPULayer.initFromImage().
ImageType
Ƭ ImageType: typeof UNSIGNED_BYTE | typeof FLOAT | typeof HALF_FLOAT
Image types for GPULayer.initFromImage().
GLSLVersion
Ƭ GLSLVersion: typeof GLSL1 | typeof GLSL3
GLSL available versions.
GLSLPrecision
Ƭ GLSLPrecision: typeof PRECISION_LOW_P | typeof PRECISION_MEDIUM_P | typeof PRECISION_HIGH_P
GLSL available precision declarations.
UniformType
Ƭ UniformType: typeof FLOAT | typeof INT | typeof UINT | typeof BOOL
GPUProgram uniform types.
UniformValue
Ƭ UniformValue: boolean | boolean[] | number | number[]
GPUProgram uniform values.
UniformParams
Ƭ UniformParams: Object
GPUProgram uniform parameters.
Type declaration
| Name | Type |
|---|---|
name | string |
value | UniformValue |
type | UniformType |
CompileTimeConstants
Ƭ CompileTimeConstants: Object
Object containing compile time #define constants for GPUProgram fragment shader.
Index signature
▪ [key: string]: string
ErrorCallback
Ƭ ErrorCallback: (message: string) => void
Type declaration
▸ (message): void
Parameters
| Name | Type |
|---|---|
message | string |
Returns
void
BoundaryEdge
Ƭ BoundaryEdge: typeof BOUNDARY_TOP | typeof BOUNDARY_BOTTOM | typeof BOUNDARY_LEFT | typeof BOUNDARY_RIGHT
GPUProgram Helper Functions
copyProgram
▸ copyProgram(composer, params): GPUProgram
Init GPUProgram to copy contents of one GPULayer to another GPULayer.
Parameters
| Name | Type | Description |
|---|---|---|
composer | GPUComposer | The current GPUComposer. |
params | Object | Program parameters. |
params.type | GPULayerType | The type of the input/output. |
params.name? | string | Optionally pass in a GPUProgram name, used for error logging. |
params.precision? | GLSLPrecision | Optionally specify the precision of the input/output. |
Returns
addLayersProgram
▸ addLayersProgram(composer, params): GPUProgram
Init GPUProgram to add several GPULayers together.
Parameters
| Name | Type | Description |
|---|---|---|
composer | GPUComposer | The current GPUComposer. |
params | Object | Program parameters. |
params.type | GPULayerType | The type of the inputs/output. |
params.components? | string | Component(s) of inputs to add, defaults to 'xyzw. |
params.name? | string | Optionally pass in a GPUProgram name, used for error logging. |
params.numInputs? | number | The number of inputs to add together, defaults to 2. |
params.precision? | GLSLPrecision | Optionally specify the precision of the inputs/output. |
Returns
addValueProgram
▸ addValueProgram(composer, params): GPUProgram
Init GPUProgram to add uniform "u_value" to a GPULayer.
Parameters
| Name | Type | Description |
|---|---|---|
composer | GPUComposer | The current GPUComposer. |
params | Object | Program parameters. |
params.type | GPULayerType | The type of the input/output (we assume "u_value" has the same type). |
params.value | number | number[] | Initial value to add, if value has length 1 it will be applied to all components of GPULayer. Change this later using uniform "u_value". |
params.name? | string | Optionally pass in a GPUProgram name, used for error logging. |
params.precision? | GLSLPrecision | Optionally specify the precision of the input/output/"u_value". |
Returns
multiplyValueProgram
▸ multiplyValueProgram(composer, params): GPUProgram
Init GPUProgram to multiply uniform "u_value" to a GPULayer.
Parameters
| Name | Type | Description |
|---|---|---|
composer | GPUComposer | The current GPUComposer. |
params | Object | Program parameters. |
params.type | GPULayerType | The type of the input/output (we assume "u_value" has the same type). |
params.value | number | number[] | Initial value to multiply, if value has length 1 it will be applied to all components of GPULayer. Change this later using uniform "u_value". |
params.name? | string | Optionally pass in a GPUProgram name, used for error logging. |
params.precision? | GLSLPrecision | Optionally specify the precision of the input/output/"u_value". |
Returns
setValueProgram
▸ setValueProgram(composer, params): GPUProgram
Init GPUProgram to set all elements in a GPULayer to uniform "u_value".
Parameters
| Name | Type | Description |
|---|---|---|
composer | GPUComposer | The current GPUComposer. |
params | Object | Program parameters. |
params.type | GPULayerType | The type of the output (we assume "u_value" has same type). |
params.value | number | number[] | Initial value to set, if value has length 1 it will be applied to all components of GPULayer. Change this later using uniform "u_value". |
params.name? | string | Optionally pass in a GPUProgram name, used for error logging. |
params.precision? | GLSLPrecision | Optionally specify the precision of the output/"u_value". |
Returns
setColorProgram
▸ setColorProgram(composer, params): GPUProgram
Init GPUProgram to set all elements in a GPULayer to uniform "u_value".
Parameters
| Name | Type | Description |
|---|---|---|
composer | GPUComposer | The current GPUComposer. |
params | Object | Program parameters. |
params.type | GPULayerType | The type of the output. |
params.color? | number[] | Initial color as RGB in range [0, 1], defaults to [0, 0, 0]. Change this later using uniform "u_color". |
params.opacity? | number | Initial opacity in range [0, 1], defaults to 1. Change this later using uniform "u_opacity". |
params.name? | string | Optionally pass in a GPUProgram name, used for error logging. |
params.precision? | GLSLPrecision | Optionally specify the precision of the output/uniforms. |
Returns
zeroProgram
▸ zeroProgram(composer, params): GPUProgram
Init GPUProgram to zero output GPULayer.
Parameters
| Name | Type | Description |
|---|---|---|
composer | GPUComposer | The current GPUComposer. |
params | Object | Program parameters. |
params.name? | string | Optionally pass in a GPUProgram name, used for error logging. |
Returns
renderRGBProgram
▸ renderRGBProgram(composer, params): GPUProgram
Init GPUProgram to render 3 component GPULayer as RGB.
Parameters
| Name | Type | Description |
|---|---|---|
composer | GPUComposer | The current GPUComposer. |
params | Object | Program parameters. |
params.type | GPULayerType | The type of the input. |
params.name? | string | Optionally pass in a GPUProgram name, used for error logging. |
params.scale? | number | Scaling factor, defaults to 1. Change this later using uniform "u_scale". |
params.opacity? | number | Opacity, defaults to 1. Change this later using uniform "u_opacity". |
params.precision? | GLSLPrecision | Optionally specify the precision of the input. |
Returns
renderAmplitudeProgram
▸ renderAmplitudeProgram(composer, params): GPUProgram
Init GPUProgram to render RGBA amplitude of an input GPULayer's components, defaults to grayscale rendering and works for scalar and vector fields.
Parameters
| Name | Type | Description |
|---|---|---|
composer | GPUComposer | The current GPUComposer. |
params | Object | Program parameters. |
params.type | GPULayerType | The type of the input. |
params.components? | string | Component(s) of input GPULayer to render, defaults to 'xyzw'. |
params.name? | string | Optionally pass in a GPUProgram name, used for error logging. |
params.scale? | number | Scaling factor, defaults to 1. Change this later using uniform "u_scale". |
params.opacity? | number | Opacity, defaults to 1. Change this later using uniform "u_opacity". |
params.colorMax? | number[] | RGB color for amplitude === scale, scaled to [0,1] range, defaults to white. Change this later using uniform "u_colorMax". |
params.colorMin? | number[] | RGB color for amplitude === 0, scaled to [0,1] range, defaults to black. Change this later using uniform "u_colorMin". |
params.precision? | GLSLPrecision | Optionally specify the precision of the input. |
Returns
renderSignedAmplitudeProgram
▸ renderSignedAmplitudeProgram(composer, params): GPUProgram
Init GPUProgram to render signed amplitude of an input GPULayer to linearly interpolated colors.
Parameters
| Name | Type | Description |
|---|---|---|
composer | GPUComposer | The current GPUComposer. |
params | Object | Program parameters. |
params.type | GPULayerType | The type of the input. |
params.component? | "x" | "y" | "z" | "w" | Component of input GPULayer to render, defaults to "x". |
params.name? | string | Optionally pass in a GPUProgram name, used for error logging. |
params.scale? | number | Scaling factor, defaults to 1. Change this later using uniform "u_scale". |
params.bias? | number | Bias for center point of color range, defaults to 0. Change this later using uniform "u_bias". |
params.opacity? | number | Opacity, defaults to 1. Change this later using uniform "u_opacity". |
params.colorMax? | number[] | RGB color for amplitude === bias + scale, scaled to [0,1] range, defaults to red. Change this later using uniform "u_colorMax". |
params.colorMin? | number[] | RGB color for amplitude === bias + scale, scaled to [0,1] range, defaults to blue. Change this later using uniform "u_colorMin". |
params.colorCenter? | number[] | RGB color for amplitude === bias, scaled to [0,1] range, defaults to white. Change this later using uniform "u_colorCenter". |
params.precision? | GLSLPrecision | Optionally specify the precision of the input. |
Returns
Other Functions
isWebGL2
▸ isWebGL2(gl): boolean
Returns whether a WebGL context is WebGL2. This code is pulled from https://github.com/mrdoob/three.js/blob/master/src/renderers/webgl/WebGLCapabilities.js
Parameters
| Name | Type | Description |
|---|---|---|
gl | WebGLRenderingContext | WebGL2RenderingContext | WebGL context to test. |
Returns
boolean
- true if WebGL2 context, else false.
isWebGL2Supported
▸ isWebGL2Supported(): boolean
Returns whether WebGL2 is supported by the current browser.
Returns
boolean
- true if WebGL2 is supported, else false.
isHighpSupportedInVertexShader
▸ isHighpSupportedInVertexShader(): boolean
Detects whether highp precision is supported in vertex shaders in the current browser.
Returns
boolean
- true is highp is supported in vertex shaders, else false.
isHighpSupportedInFragmentShader
▸ isHighpSupportedInFragmentShader(): boolean
Detects whether highp precision is supported in fragment shaders in the current browser.
Returns
boolean
- true is highp is supported in fragment shaders, else false.
getVertexShaderMediumpPrecision
▸ getVertexShaderMediumpPrecision(): "highp" | "mediump"
Returns the actual precision of mediump inside vertex shader. From https://webglfundamentals.org/webgl/lessons/webgl-precision-issues.html
Returns
"highp" | "mediump"
- Vertex shader mediump precision.
getFragmentShaderMediumpPrecision
▸ getFragmentShaderMediumpPrecision(): "highp" | "mediump"
Returns the actual precision of mediump inside fragment shader. From https://webglfundamentals.org/webgl/lessons/webgl-precision-issues.html
Returns
"highp" | "mediump"
- Fragment shader supported mediump precision.