<p>gl.vertexAttribPointer is used when different vertices should have different values, and gl.vertexAttrib is used when all vertices should have the same values, and you don't want to use a special shader with a uniform.</p>

CC BY-SA 3.0
2017-10-22T20:22:43.393Z
2017-10-22T20:22:43.393Z
Daniel Kareh
<p>I'm re-learning WebGL, and I stumbled upon <a href="https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/vertexAttribPointer" rel="noreferrer" title="gl.vertexAttribPointer">gl.vertexAttribPointer</a> and <a href="https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/vertexAttrib" rel="noreferrer" title="gl.vertexAttrib">gl.vertexAttrib</a>. To my knowledge, gl.vertexAttribPointer tells the GPU how the data in the currently binded buffer relates to the vertex attributes. But, I'm confused on what gl.vertexAttrib does. It seems like it also sends data to the GPU, but without the use of a buffer. Can anybody explain it's role to me?</p>

CC BY-SA 3.0
2017-10-21T05:17:51.297Z
See [What is glVertexAttrib (vs. glVertexAttribPointer) used for?](https://stackoverflow.com/questions/7718976/what-is-glvertexattrib-versus-glvertexattribpointer-used-for#7719060). Essentially, they're the same thing, but `glVertexAttrib` is for the older immediate mode.
user1118321
CC BY-SA 3.0
2017-10-22T20:21:24.750Z
Thanks for the response! I think I understand the difference now. One sets a constant value, and the other links the values to a buffer.
Daniel Kareh
<shader><webgl><vertex-buffer-object>
Role of gl.vertexAttrib
Daniel Kareh
# Role of gl.vertexAttrib

(Asked by: username_0 on 2017-10-20)

I'm re-learning WebGL, and I stumbled upon [gl.vertexAttribPointer](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/vertexAttribPointer "gl.vertexAttribPointer") and [gl.vertexAttrib](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/vertexAttrib "gl.vertexAttrib"). To my knowledge, gl.vertexAttribPointer tells the GPU how the data in the currently binded buffer relates to the vertex attributes. But, I'm confused on what gl.vertexAttrib does. It seems like it also sends data to the GPU, but without the use of a buffer. Can anybody explain it's role to me?

**Tags:** shader, webgl, vertex-buffer-object

> **Comments:**
> **username_1**: See [What is glVertexAttrib (vs. glVertexAttribPointer) used for?](https://stackoverflow.com/questions/7718976/what-is-glvertexattrib-versus-glvertexattribpointer-used-for#7719060). Essentially, they're the same thing, but `glVertexAttrib` is for the older immediate mode.  
> **username_0**: Thanks for the response! I think I understand the difference now. One sets a constant value, and the other links the values to a buffer.  

---

## 1 answers

### Answer by username_0 on 2017-10-22. Score: 2 | Accepted answer

gl.vertexAttribPointer is used when different vertices should have different values, and gl.vertexAttrib is used when all vertices should have the same values, and you don't want to use a special shader with a uniform.


---

