Class: GridParticleSimProgram

GridParticleSimProgram(gl)

GridParticleSimProgram is a GLSL program that simulates particle movement.

Constructor

new GridParticleSimProgram(gl)

Constructs a new program. Initializes, compiles and links this GLSL program with the source code for its vertex and fragment shaders.

This method creates WebGL shaders for the program's shader sources and attaches them to a new GLSL program. This method then compiles the shaders and then links the program if compilation is successful. Use the bind method to make the program current during rendering.

Parameters:
Name Type Description
gl WebGLRenderingContext The current WebGL context.
Source:
Throws:
If the shaders cannot be compiled, or linking of the compiled shaders into a program fails.
Type
ArgumentError

Extends

Members

(static, readonly) key :string

A string that uniquely identifies this program.
Type:
  • string
Source:

(readonly) bboxLocation :WebGLUniformLocation

The WebGL location for this program's 'bbox' uniform.
Type:
  • WebGLUniformLocation
Source:

(readonly) dropRateLocation :WebGLUniformLocation

The WebGL location for this program's 'dropRate' uniform.
Type:
  • WebGLUniformLocation
Source:

(readonly) dropRateMultiplierLocation :WebGLUniformLocation

The WebGL location for this program's 'dropRateMultiplier' uniform.
Type:
  • WebGLUniformLocation
Source:

(readonly) gridDimensionsLocation :WebGLUniformLocation

The WebGL location for this program's 'gridDimensions' uniform.
Type:
  • WebGLUniformLocation
Source:

(readonly) gridMinMaxLocation :WebGLUniformLocation

The WebGL location for this program's 'gridMinMax' uniform.
Type:
  • WebGLUniformLocation
Source:

(readonly) gridSamplerLocation :WebGLUniformLocation

The WebGL location for this program's 'gridSampler' uniform.
Type:
  • WebGLUniformLocation
Source:

(readonly) particleSamplerLocation :WebGLUniformLocation

The WebGL location for this program's 'particleSampler' uniform.
Type:
  • WebGLUniformLocation
Source:

(readonly) programId :WebGLProgram

Indicates the WebGL program object associated with this GPU program.
Type:
  • WebGLProgram
Inherited From:
Source:

(readonly) randSeedLocation :WebGLUniformLocation

The WebGL location for this program's 'randSeed' uniform.
Type:
  • WebGLUniformLocation
Source:

(readonly) speedFactorLocation :WebGLUniformLocation

The WebGL location for this program's 'speedFactor' uniform.
Type:
  • WebGLUniformLocation
Source:

(readonly) vertexPointLocation :Number

The WebGL location for this program's 'vertexPosition' attribute.
Type:
  • Number
Source:

Methods

attributeLocation(gl, attributeName) → {Number}

Returns the GLSL attribute location of a specified attribute name.
Parameters:
Name Type Description
gl WebGLRenderingContext The current WebGL context.
attributeName String The name of the attribute whose location is determined.
Inherited From:
Source:
Throws:
If the specified attribute name is null, empty or undefined.
Type
ArgumentError
Returns:
The WebGL attribute location of the specified attribute, or -1 if the attribute is not found.
Type
Number

dispose(gl)

Releases this GPU program's WebGL program and associated shaders. Upon return this GPU program's WebGL program ID is 0 as is that of the associated shaders.
Parameters:
Name Type Description
gl WebGLRenderingContext The current WebGL context.
Inherited From:
Source:
Links a specified GLSL program. This method is not meant to be called by applications. It is called internally as needed.
Parameters:
Name Type Description
gl WebGLRenderingContext The current WebGL context.
program WebGLProgram The WebGL program.
Inherited From:
Source:
Returns:
true if linking was successful, otherwise false.
Type
Boolean

loadBbox(gl, bbox)

Loads the specified bbox as the value of this program's 'bboxLocation' uniform variable.
Parameters:
Name Type Description
gl WebGLRenderingContext The current WebGL context.
bbox Float32Array A normalised bounding box. (0, 0) is in the top left corner and (1, 1) is in the bottom right corner.
Source:
Throws:
If the specified bbox is missing.
Type
ArgumentError

loadDropRate(gl, dropRate)

Loads the specified dropRate as the value of this program's 'dropRateLocation' uniform variable.
Parameters:
Name Type Description
gl WebGLRenderingContext The current WebGL context.
dropRate Number Controls how often the particles move to a random place.
Source:
Throws:
If the specified dropRate value is missing.
Type
ArgumentError

loadDropRateMultiplier(gl, dropRateMultiplier)

Loads the specified dropRateMultiplier as the value of this program's 'dropRateMultiplierLocation' uniform variable.
Parameters:
Name Type Description
gl WebGLRenderingContext The current WebGL context.
dropRateMultiplier Number Controls the drop rate of a particle relative to individual particle speed.
Source:
Throws:
If the specified dropRateMultiplier value is missing.
Type
ArgumentError

loadGridDimensions(gl, width, height)

Loads the specified width and height as the value of this program's 'gridDimensions' uniform variable.
Parameters:
Name Type Description
gl WebGLRenderingContext The current WebGL context.
width Number The width of the grid.
height Number The height of the grid.
Source:
Throws:
If the specified width or height are missing.
Type
ArgumentError

loadGridMinMax(gl, uMin, vMin, uMax, vMax)

Loads the min and max u and v vectors of the grid as the value of this program's 'gridMinMaxLocation' uniform variable.
Parameters:
Name Type Description
gl WebGLRenderingContext The current WebGL context.
uMin Number The minimum u value of the grid data.
vMin Number The minimum v value of the grid data.
uMax Number The maximum u value of the grid data.
vMax Number The maximum v value of the grid data.
Source:
Throws:
If the specified u and v values are missing.
Type
ArgumentError

loadGridSampler(gl, unit)

Loads the specified number as the value of this program's 'gridSamplerLocation' uniform variable.
Parameters:
Name Type Description
gl WebGLRenderingContext The current WebGL context.
unit Number The texture unit.
Source:

loadParticleSamper(gl, unit)

Loads the specified number as the value of this program's 'particleSamplerLocation' uniform variable.
Parameters:
Name Type Description
gl WebGLRenderingContext The current WebGL context.
unit Number The texture unit.
Source:

loadRandSeed(gl, seed)

Loads a random value as the value of this program's 'randSeedLocation' uniform variable.
Parameters:
Name Type Description
gl WebGLRenderingContext The current WebGL context.
seed Number A random value between [0, 1).
Source:
Throws:
If the specified value is missing.
Type
ArgumentError

loadSpeedFactor(gl, speedFactor)

Loads the specified speedFactor as the value of this program's 'speedFactorLocation' uniform variable.
Parameters:
Name Type Description
gl WebGLRenderingContext The current WebGL context.
speedFactor Number Controls how fast the particles move.
Source:
Throws:
If the specified speedFactor value is missing.
Type
ArgumentError

loadUniformColor(gl, color, location)

Loads a specified color as the value of a GLSL vec4 uniform variable with the specified location.

This function multiplies the red, green and blue components by the alpha component prior to loading the color in the GLSL uniform variable, but does not modify the specified color.

Parameters:
Name Type Description
gl WebGLRenderingContext The current WebGL context.
color Color The color to load.
location WebGLUniformLocation The location of the uniform variable in the currently bound GLSL program.
Inherited From:
Source:
Throws:
If the specified color is null or undefined.
Type
ArgumentError

loadUniformColorComponents(gl, red, green, blue, alpha, location)

Loads the specified RGBA color components as the value of a GLSL vec4 uniform variable with the specified location.

This function multiplies the red, green and blue components by the alpha component prior to loading the color in the GLSL uniform variable.

Parameters:
Name Type Description
gl WebGLRenderingContext The current WebGL context.
red Number The red component, a number between 0 and 1.
green Number The green component, a number between 0 and 1.
blue Number The blue component, a number between 0 and 1.
alpha Number The alpha component, a number between 0 and 1.
location WebGLUniformLocation The location of the uniform variable in the currently bound GLSL program.
Inherited From:
Source:

loadUniformMatrix(gl, matrix, location)

Loads a specified matrix as the value of a GLSL 4x4 matrix uniform variable with the specified location.

This functions converts the matrix into column-major order prior to loading its components into the GLSL uniform variable, but does not modify the specified matrix.

Parameters:
Name Type Description
gl WebGLRenderingContext The current WebGL context.
matrix Matrix The matrix to load.
location WebGLUniformLocation The location of the uniform variable in the currently bound GLSL program.
Inherited From:
Source:
Throws:
If the specified matrix is null or undefined.
Type
ArgumentError

uniformLocation(gl, uniformName) → {WebGLUniformLocation}

Returns the GLSL uniform location of a specified uniform name.
Parameters:
Name Type Description
gl WebGLRenderingContext The current WebGL context.
uniformName String The name of the uniform variable whose location is determined.
Inherited From:
Source:
Throws:
If the specified uniform name is null, empty or undefined.
Type
ArgumentError
Returns:
The WebGL uniform location of the specified uniform variable, or -1 if the uniform is not found.
Type
WebGLUniformLocation