--- title: 'WebGLRenderingContext.uniformMatrix[234]fv()' slug: Web/API/WebGLRenderingContext/uniformMatrix tags: - WebGL - WebGLAPI - WebGLRenderingContext - uniformMatrix2fv - uniformMatrix3fv - uniformMatrix4fv - 矩阵 translation_of: Web/API/WebGLRenderingContext/uniformMatrix ---
{{APIRef("WebGL")}}

WebGL API 的WebGLRenderingContext.uniformMatrix[234]fv() 方法为 uniform variables 指定了矩阵值 .

该方法的3个版本 (uniformMatrix2fv(), uniformMatrix3fv(), 和unifomMatrix4fv()) ,分别以二阶,三阶,和四阶方阵作为输入值,它们应是分别具有4,9,16个浮点数的数组.

语法

WebGLRenderingContext.uniformMatrix2fv(location, transpose, value);
WebGLRenderingContext.uniformMatrix3fv(location, transpose, value);
WebGLRenderingContext.uniformMatrix4fv(location, transpose, value);

参数

location
{{domxref("WebGLUniformLocation")}} 对象包含了要修改的 uniform attribute位置. 位置使用 {{domxref("WebGLRenderingContext.getUniformLocation", "getUniformLocation()")}}获得.
transpose
{{domxref("GLboolean")}} 指定是否转置矩阵。必须为 false.
value

 {{jsxref("Float32Array")}} 型或者是 GLfloat 序列值.假定值以列主要顺序提供.

返回值

undefined

示例

gl.uniformMatrix2fv(loc, false, [2,1, 2,2]);

说明

Specification Status Comment
{{SpecName('WebGL', "#5.14.10", "uniformMatrix")}} {{Spec2('WebGL')}} Initial definition.
{{SpecName('OpenGL ES 2.0', "glUniform.xml", "glUniform")}} {{Spec2('OpenGL ES 2.0')}} Man page of the OpenGL API.

浏览器兼容性

{{Compat("api.WebGLRenderingContext.uniformMatrix2fv")}}

另见