Firefox Tomorrow

web api instance method

WebGLRenderingContext: getUniform() method

View on MDN ↗

Available in workers

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

Syntax

getUniform(program, location)

Parameters

Return value

The returned type depends on the uniform type:

Uniform type Returned type
WebGL 1 only
boolean [`GLBoolean`](/firefox/mdn/api/webgl_api/types/)
int [`GLint`](/firefox/mdn/api/webgl_api/types/)
float [`GLfloat`](/firefox/mdn/api/webgl_api/types/)
vec2 [`Float32Array`](/firefox/mdn/javascript/reference/global_objects/float32array/) (with 2 elements)
ivec2 [`Int32Array`](/firefox/mdn/javascript/reference/global_objects/int32array/) (with 2 elements)
bvec2 [`Array`](/firefox/mdn/javascript/reference/global_objects/array/) of [`GLBoolean`](/firefox/mdn/api/webgl_api/types/) (with 2 elements)
vec3 [`Float32Array`](/firefox/mdn/javascript/reference/global_objects/float32array/) (with 3 elements)
ivec3 [`Int32Array`](/firefox/mdn/javascript/reference/global_objects/int32array/) (with 3 elements)
bvec3 [`Array`](/firefox/mdn/javascript/reference/global_objects/array/) of [`GLBoolean`](/firefox/mdn/api/webgl_api/types/) (with 3 elements)
vec4 [`Float32Array`](/firefox/mdn/javascript/reference/global_objects/float32array/) (with 4 elements)
ivec4 [`Int32Array`](/firefox/mdn/javascript/reference/global_objects/int32array/) (with 4 elements)
bvec4 [`Array`](/firefox/mdn/javascript/reference/global_objects/array/) of [`GLBoolean`](/firefox/mdn/api/webgl_api/types/) (with 4 elements)
mat2 [`Float32Array`](/firefox/mdn/javascript/reference/global_objects/float32array/) (with 4 elements)
mat3 [`Float32Array`](/firefox/mdn/javascript/reference/global_objects/float32array/) (with 9 elements)
mat4 [`Float32Array`](/firefox/mdn/javascript/reference/global_objects/float32array/) (with 16 elements)
sampler2D [`GLint`](/firefox/mdn/api/webgl_api/types/)
samplerCube [`GLint`](/firefox/mdn/api/webgl_api/types/)
Additionally available in WebGL 2
uint [`GLuint`](/firefox/mdn/api/webgl_api/types/)
uvec2 [`Uint32Array`](/firefox/mdn/javascript/reference/global_objects/uint32array/) (with 2 elements)
uvec3 [`Uint32Array`](/firefox/mdn/javascript/reference/global_objects/uint32array/) (with 3 elements)
uvec4 [`Uint32Array`](/firefox/mdn/javascript/reference/global_objects/uint32array/) (with 4 elements)
mat2x3 [`Float32Array`](/firefox/mdn/javascript/reference/global_objects/float32array/) (with 6 elements)
mat2x4 [`Float32Array`](/firefox/mdn/javascript/reference/global_objects/float32array/) (with 8 elements)
mat3x2 [`Float32Array`](/firefox/mdn/javascript/reference/global_objects/float32array/) (with 6 elements)
mat3x4 [`Float32Array`](/firefox/mdn/javascript/reference/global_objects/float32array/) (with 12 elements)
mat4x2 [`Float32Array`](/firefox/mdn/javascript/reference/global_objects/float32array/) (with 8 elements)
mat4x3 [`Float32Array`](/firefox/mdn/javascript/reference/global_objects/float32array/) (with 12 elements)
any sampler type [`GLint`](/firefox/mdn/api/webgl_api/types/)

Examples

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

Specifications

SpecificationsStandards references are available on the canonical MDN page.

Browser compatibility

Browser compatibilityCompatibility data is available on the canonical MDN page.

See also