API Docs for: 0.5.1
Show:

ShaderProgram Class

Creates a new ShaderProgram from the given source, and an optional map of attribute locations as pairs.

Note: Chrome version 31 was giving me issues with attribute locations -- you may want to omit this to let the browser pick the locations for you.

Constructor

ShaderProgram

(
  • context
  • vertSource
  • fragSource
  • attributeLocations
)

Parameters:

  • context WebGLContext

    the context to manage this object

  • vertSource String

    the vertex shader source

  • fragSource String

    the fragment shader source

  • attributeLocations Object

    the attribute locations

Methods

bind

()

Called to bind this shader. Note that there is no "unbind" since technically such a thing is not possible in the programmable pipeline.

You must bind a shader before settings its uniforms.

create

()

This is called during the ShaderProgram constructor, and may need to be called again after context loss and restore.

destroy

()

Destroys this shader and its resources. You should not try to use this after destroying it.

getAttributeInfo

(
  • name
)
Object

Returns the cached attribute info (size, type, location). If the attribute is not found in the cache, it is assumed to not exist, and this method returns null.

This may return null even if the attribute is defined in GLSL: if it is inactive (i.e. not used in the program or disabled) then it may be optimized out.

Parameters:

  • name String

    the attribute name as defined in GLSL

Returns:

Object:

an object containing location, size and type

getAttributeLocation

(
  • name
)
GLint

Returns the cached uniform location object. If the uniform is not found, this method returns null.

Parameters:

  • name String

    the uniform name as defined in GLSL

Returns:

GLint:

the location object

getUniform

(
  • name
)
Any

Returns the uniform value by name.

Parameters:

  • name String

    the uniform name as defined in GLSL

Returns:

Any:

The value of the WebGL uniform

getUniformAt

(
  • location
)
Any

Returns the uniform value at the specified WebGLUniformLocation.

Parameters:

  • location WebGLUniformLocation

    the location object

Returns:

Any:

The value of the WebGL uniform

getUniformInfo

(
  • name
)
Object

Returns the cached uniform info (size, type, location). If the uniform is not found in the cache, it is assumed to not exist, and this method returns null.

This may return null even if the uniform is defined in GLSL: if it is inactive (i.e. not used in the program) then it may be optimized out.

Parameters:

  • name String

    the uniform name as defined in GLSL

Returns:

Object:

an object containing location, size, and type

getUniformLocation

(
  • name
)
WebGLUniformLocation

Returns the cached uniform location object, assuming it exists and is active. Note that uniforms may be inactive if the GLSL compiler deemed them unused.

Parameters:

  • name String

    the uniform name as defined in GLSL

Returns:

WebGLUniformLocation:

the location object

hasAttribute

(
  • name
)
Boolean

Returns true if the attribute is active and found in this compiled program.

Parameters:

  • name String

    the attribute name

Returns:

Boolean:

true if the attribute is found and active

hasUniform

(
  • name
)
Boolean

Returns true if the uniform is active and found in this compiled program. Note that uniforms may be inactive if the GLSL compiler deemed them unused.

Parameters:

  • name String

    the uniform name

Returns:

Boolean:

true if the uniform is found and active

setUniformf

(
  • name
  • x
  • y
  • z
  • w
)

A convenience method to set uniformf from the given arguments. We determine which GL call to make based on the number of arguments passed. For example, setUniformf("var", 0, 1) maps to gl.uniform2f.

Parameters:

  • name String

    the name of the uniform

  • x GLfloat

    the x component for floats

  • y GLfloat

    the y component for vec2

  • z GLfloat

    the z component for vec3

  • w GLfloat

    the w component for vec4

setUniformfv

(
  • name
  • arrayBuffer
  • count
)

A convenience method to set uniformNfv from the given ArrayBuffer. We determine which GL call to make based on the length of the array buffer (for 1-4 component vectors stored in a Float32Array). To use this method to upload data to uniform arrays, you need to specify the 'count' parameter; i.e. the data type you are using for that array. If specified, this will dictate whether to call uniform1fv, uniform2fv, etc.

Parameters:

  • name String

    the name of the uniform

  • arrayBuffer ArrayBuffer

    the array buffer

  • count Number

    optional, the explicit data type count, e.g. 2 for vec2

setUniformi

(
  • name
  • x
  • y
  • z
  • w
)

A convenience method to set uniformi from the given arguments. We determine which GL call to make based on the number of arguments passed. For example, setUniformi("var", 0, 1) maps to gl.uniform2i.

Parameters:

  • name String

    the name of the uniform

  • x GLint

    the x component for ints

  • y GLint

    the y component for ivec2

  • z GLint

    the z component for ivec3

  • w GLint

    the w component for ivec4

setUniformiv

(
  • name
  • arrayBuffer
  • count
)

A convenience method to set uniformNiv from the given ArrayBuffer. We determine which GL call to make based on the length of the array buffer (for 1-4 component vectors stored in a int array). To use this method to upload data to uniform arrays, you need to specify the 'count' parameter; i.e. the data type you are using for that array. If specified, this will dictate whether to call uniform1fv, uniform2fv, etc.

Parameters:

  • name String

    the name of the uniform

  • arrayBuffer ArrayBuffer

    the array buffer

  • count Number

    optional, the explicit data type count, e.g. 2 for ivec2