WebGLRenderingContext.uniform[1234][fi][v]()

The WebGLRenderingContext.uniform[1234][fi][v]() methods of the WebGL API specify values of uniform variables.

Syntax

JavaScript
void <var>gl</var>.uniform1f(<var>location</var>, <var>v0</var>);
void <var>gl</var>.uniform1fv(<var>location</var>, <var>value</var>);
void <var>gl</var>.uniform1i(<var>location</var>, <var>v0</var>);
void <var>gl</var>.uniform1iv(<var>location</var>, <var>value</var>);

void <var>gl</var>.uniform2f(<var>location</var>, <var>v0</var>, <var>v1</var>);
void <var>gl</var>.uniform2fv(<var>location</var>, <var>value</var>);
void <var>gl</var>.uniform2i(<var>location</var>, <var>v0</var>, <var>v1</var>);
void <var>gl</var>.uniform2iv(<var>location</var>, <var>value</var>);

void <var>gl</var>.uniform3f(<var>location</var>, <var>v0</var>, <var>v1</var>, <var>v2</var>);
void <var>gl</var>.uniform3fv(<var>location</var>, <var>value</var>);
void <var>gl</var>.uniform3i(<var>location</var>, <var>v0</var>, <var>v1</var>, <var>v2</var>);
void <var>gl</var>.uniform3iv(<var>location</var>, <var>value</var>);

void <var>gl</var>.uniform4f(<var>location</var>, <var>v0</var>, <var>v1</var>, <var>v2</var>, <var>v3</var>);
void <var>gl</var>.uniform4fv(<var>location</var>, <var>value</var>);
void <var>gl</var>.uniform4i(<var>location</var>, <var>v0</var>, <var>v1</var>, <var>v2</var>, <var>v3</var>);
void <var>gl</var>.uniform4iv(<var>location</var>, <var>value</var>);

Parameters

location
A WebGLUniformLocation object containing the location of the uniform attribute to modify.
value, v0, v1, v2, v3
A new value to be used for the uniform variable. Possible types:
  • A floating point Number for floating point values (methods with "f").
  • A Float32Array for floating point vector methods (methods with "fv").
  • An integer Number for integer values (methods with "i").
  • An int32Array for integer vector methods (methods with "iv").

Return value

None.

Examples

JavaScript
gl.uniform1f(u_alpha, 0.8);

Specifications

Specification Status Comment
WebGL 1.0
The definition of 'uniform' in that specification.
Recommendation Initial definition.
OpenGL ES 2.0
The definition of 'glUniform' in that specification.
Standard Man page of the OpenGL API.

Browser compatibility

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support 9 12 4.0 (2.0) 11 12 5.1
Feature Android Chrome for Android Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile
Basic support ? 25 4.0 (2.0) 1.0 ? 12 8.0

See also

License

© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/api/webglrenderingcontext/uniform

API Method Reference WebGL WebGLRenderingContext