WebGLRenderingContext: getUniform() method

Note: This feature is available in Web Workers.

The WebGLRenderingContext.getUniform() method of the WebGL API returns the value of a uniform variable at a given location.

Syntax

js
getUniform(program, location)

Parameters

program

A WebGLProgram containing the uniform attribute.

location

A WebGLUniformLocation object containing the location of the uniform attribute to get.

Return value

The returned type depends on the uniform type:

Uniform typeReturned type
WebGL 1 only
booleanGLBoolean
intGLint
floatGLfloat
vec2Float32Array (with 2 elements)
ivec2Int32Array (with 2 elements)
bvec2Array of GLBoolean (with 2 elements)
vec3Float32Array (with 3 elements)
ivec3Int32Array (with 3 elements)
bvec3Array of GLBoolean (with 3 elements)
vec4Float32Array (with 4 elements)
ivec4Int32Array (with 4 elements)
bvec4Array of GLBoolean (with 4 elements)
mat2Float32Array (with 4 elements)
mat3Float32Array (with 9 elements)
mat4Float32Array (with 16 elements)
sampler2DGLint
samplerCubeGLint
Additionally available in WebGL 2
uintGLuint
uvec2Uint32Array (with 2 elements)
uvec3Uint32Array (with 3 elements)
uvec4Uint32Array (with 4 elements)
mat2x3Float32Array (with 6 elements)
mat2x4Float32Array (with 8 elements)
mat3x2Float32Array (with 6 elements)
mat3x4Float32Array (with 12 elements)
mat4x2Float32Array (with 8 elements)
mat4x3Float32Array (with 12 elements)
any sampler typeGLint

Examples

js
const loc = gl.getUniformLocation(program, "u_foobar");
gl.getUniform(program, loc);

Specifications

See also