WebGLRenderingContext.vertexAttrib[1234]f[v]()
是 WebGL API 的方法,可以为顶点attibute变量赋值。
语法
void gl.vertexAttrib1f(index, v0); void gl.vertexAttrib2f(index, v0, v1); void gl.vertexAttrib3f(index, v0, v1, v2); void gl.vertexAttrib4f(index, v0, v1, v2, v3); void gl.vertexAttrib1fv(index, value); void gl.vertexAttrib2fv(index, value); void gl.vertexAttrib3fv(index, value); void gl.vertexAttrib4fv(index, value);
Parameters
index
-
GLuint
类型,指定了待修改顶点attribute变量的存储位置。 v0, v1, v2, v3
- 浮点数类型
Number
,用于设置顶点attibute变量的各分量值。 value
-
Float32Array
类型,用于设置顶点attibute变量的向量值。
返回值
无。
示例
const a_foobar = gl.getAttribLocation(shaderProgram, 'foobar');
//either set each component individually:
gl.vertexAttrib3f(a_foobar, 10.0, 5.0, 2.0);
//or provide a Float32Array:
const floatArray = new Float32Array([10.0, 5.0, 2.0]);
gl.vertexAttrib3fv(a_foobar, floatArray);
规范
Specification | Status | Comment |
---|---|---|
WebGL 1.0 vertexAttrib |
Recommendation | Initial definition. |
OpenGL ES 2.0 glVertexAttrib |
Standard | Man page of the OpenGL API. |
浏览器兼容性
BCD tables only load in the browser
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.