WebGLRenderingContext: getActiveUniform() method

Note: This feature is available in Web Workers.

The WebGLRenderingContext.getActiveUniform() method of the WebGL API returns a WebGLActiveInfo object containing size, type, and name of a uniform attribute. It is generally used when querying unknown uniforms either for debugging or generic library creation.

Syntax

js
getActiveUniform(program, index)

Parameters

program

A WebGLProgram specifying the WebGL shader program from which to obtain the uniform variable's information.

index

A GLuint specifying the index of the uniform attribute to get. This value is an index 0 to N - 1 as returned by gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS).

Return value

A WebGLActiveInfo object describing the uniform.

The type attribute of the return value will be one of the following:

When gl.linkProgram is called, WebGL creates a list of active uniforms. These are possible values of the name attribute of return values of getActiveUniform. WebGL generates one or more entries in the list depending on the declared type of the uniform in the shader:

The size attribute of the return value corresponds to the length of the array for uniforms declared as arrays. Otherwise, it is 1 (this includes interface blocks instanced with arrays).

Exceptions

Examples

js
const numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
for (let i = 0; i < numUniforms; ++i) {
  const info = gl.getActiveUniform(program, i);
  console.log("name:", info.name, "type:", info.type, "size:", info.size);
}

Specifications

See also