aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/webglrenderingcontext/vertexattrib/index.html
blob: ab085a37f06c0d13aa79230828616e910c6d0e7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
---
title: 'WebGLRenderingContext.vertexAttrib[1234]f[v]()'
slug: Web/API/WebGLRenderingContext/vertexAttrib
translation_of: Web/API/WebGLRenderingContext/vertexAttrib
---
<div>{{APIRef("WebGL")}}</div>

<p> <strong><code>WebGLRenderingContext.vertexAttrib[1234]f[v]()</code></strong> 是 <a href="/en-US/docs/Web/API/WebGL_API">WebGL API</a> 的方法,可以为顶点attibute变量赋值。</p>

<h2 id="语法">语法</h2>

<pre class="syntaxbox">void <var>gl</var>.vertexAttrib1f(<var>index</var>, <var>v0</var>);
void <var>gl</var>.vertexAttrib2f(<var>index</var>, <var>v0</var>, <var>v1</var>);
void <var>gl</var>.vertexAttrib3f(<var>index</var>, <var>v0</var>, <var>v1</var>, <var>v2</var>);
void <var>gl</var>.vertexAttrib4f(<var>index</var>, <var>v0</var>, <var>v1</var>, <var>v2</var>, <var>v3</var>);

void <var>gl</var>.vertexAttrib1fv(<var>index</var>, <var>value</var>);
void <var>gl</var>.vertexAttrib2fv(<var>index</var>, <var>value</var>);
void <var>gl</var>.vertexAttrib3fv(<var>index</var>, <var>value</var>);
void <var>gl</var>.vertexAttrib4fv(<var>index</var>, <var>value</var>);
</pre>

<h3 id="Parameters">Parameters</h3>

<dl>
 <dt><code>index</code></dt>
 <dd> {{domxref("GLuint")}} 类型,指定了待修改顶点attribute变量的存储位置。</dd>
 <dt><code>v0, v1, v2, v3</code></dt>
 <dd>浮点数类型{{jsxref("Number")}},用于设置顶点attibute变量的各分量值。</dd>
 <dt><code>value</code></dt>
 <dd>
 <p>{{jsxref("Float32Array")}} 类型,用于设置顶点attibute变量的向量值。</p>
 </dd>
</dl>

<h3 id="返回值">返回值</h3>

<p>无。</p>

<h2 id="示例">示例</h2>

<pre class="brush: js">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);</pre>

<h2 id="规范">规范</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('WebGL', "#5.14.10", "vertexAttrib")}}</td>
   <td>{{Spec2('WebGL')}}</td>
   <td>Initial definition.</td>
  </tr>
  <tr>
   <td>{{SpecName('OpenGL ES 2.0', "glVertexAttrib.xml", "glVertexAttrib")}}</td>
   <td>{{Spec2('OpenGL ES 2.0')}}</td>
   <td>Man page of the OpenGL API.</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>

<p>{{Compat("api.WebGLRenderingContext.vertexAttrib1f")}}</p>

<h2 id="相关链接">相关链接</h2>

<ul>
 <li>{{domxref("WebGLRenderingContext.getVertexAttrib()")}}</li>
</ul>