GO-Ve01
ServicesDevelopersBooksDictionaryPapersWikidataEncyclopediaSearchBabelCareersDeck

WebGLRenderingContext: getUniform() method

WebGL

WebGL

The **`WebGLRenderingContext.getUniform()`** method of the [WebGL API](/docs/Web/API/WebGL_API) returns the value of a uniform
variable at a given location.

## Syntax

```js-nolint
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:

<table class="standard-table">
<thead>
<tr>
<th scope="col">Uniform type</th>
<th scope="col">Returned type</th>
</tr>
</thead>
<tbody>
<tr>
<th colspan="2">WebGL 1 only</th>
</tr>
<tr>
<td><code>boolean</code></td>
<td>GLBoolean</td>
</tr>
<tr>
<td><code>int</code></td>
<td>GLint</td>
</tr>
<tr>
<td><code>float</code></td>
<td>GLfloat</td>
</tr>
<tr>
<td><code>vec2</code></td>
<td>Float32Array (with 2 elements)</td>
</tr>
<tr>
<td><code>ivec2</code></td>
<td>Int32Array (with 2 elements)</td>
</tr>
<tr>
<td><code>bvec2</code></td>
<td>
Array of
GLBoolean (with 2
elements)
</td>
</tr>
<tr>
<td><code>vec3</code></td>
<td>Float32Array (with 3 elements)</td>
</tr>
<tr>
<td><code>ivec3</code></td>
<td>Int32Array (with 3 elements)</td>
</tr>
<tr>
<td><code>bvec3</code></td>
<td>
Array of
GLBoolean (with 3
elements)
</td>
</tr>
<tr>
<td><code>vec4</code></td>
<td>Float32Array (with 4 elements)</td>
</tr>
<tr>
<td><code>ivec4</code></td>
<td>Int32Array (with 4 elements)</td>
</tr>
<tr>
<td><code>bvec4</code></td>
<td>
Array of
GLBoolean (with 4
elements)
</td>
</tr>
<tr>
<td><code>mat2</code></td>
<td>Float32Array (with 4 elements)</td>
</tr>
<tr>
<td><code>mat3</code></td>
<td>Float32Array (with 9 elements)</td>
</tr>
<tr>
<td><code>mat4</code></td>
<td>Float32Array (with 16 elements)</td>
</tr>
<tr>
<td><code>sampler2D</code></td>
<td>GLint</td>
</tr>
<tr>
<td><code>samplerCube</code></td>
<td>GLint</td>
</tr>
<tr>
<th colspan="2">Additionally available in WebGL 2</th>
</tr>
<tr>
<td><code>uint</code></td>
<td>GLuint</td>
</tr>
<tr>
<td><code>uvec2</code></td>
<td>Uint32Array (with 2 elements)</td>
</tr>
<tr>
<td><code>uvec3</code></td>
<td>Uint32Array (with 3 elements)</td>
</tr>
<tr>
<td><code>uvec4</code></td>
<td>Uint32Array (with 4 elements)</td>
</tr>
<tr>
<td><code>mat2x3</code></td>
<td>Float32Array (with 6 elements)</td>
</tr>
<tr>
<td><code>mat2x4</code></td>
<td>Float32Array (with 8 elements)</td>
</tr>
<tr>
<td><code>mat3x2</code></td>
<td>Float32Array (with 6 elements)</td>
</tr>
<tr>
<td><code>mat3x4</code></td>
<td>Float32Array (with 12 elements)</td>
</tr>
<tr>
<td><code>mat4x2</code></td>
<td>Float32Array (with 8 elements)</td>
</tr>
<tr>
<td><code>mat4x3</code></td>
<td>Float32Array (with 12 elements)</td>
</tr>
<tr>
<td>any sampler type</td>
<td>GLint</td>
</tr>
</tbody>
</table>

## Examples

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

## Specifications

## Browser compatibility

## See also

- WebGLUniformLocation
- WebGLRenderingContext.getActiveUniform()

source: MDN Web Docs mirror · page

Cite this

"WebGLRenderingContext: getUniform() method". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/getUniform

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·