glVertexAttrib(与glVertexAttribPointer相比)有什么用? [英] What is glVertexAttrib (versus glVertexAttribPointer) used for?

查看:231
本文介绍了glVertexAttrib(与glVertexAttribPointer相比)有什么用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道glVertexAttribPointer将基于指向的数组设置顶点属性的值.但是,glVertexAttrib是做什么用的?看起来它只是为vertex属性设置了一个(可能是向量)值,所以当您有多个顶点时会发生什么?所有顶点最终都看到相同的属性值吗?

I understand that glVertexAttribPointer will set the values for a vertex attribute based on the pointed-to array. What is glVertexAttrib for, though? It looks like it just sets a single (possibly vector) value for the vertex attribute, so what happens when you have multiple vertices? Do all of the vertices end up seeing the same value for the attribute?

推荐答案

这主要用于旧的立即模式(glBegin/glEnd),在此模式下您不使用顶点数组(已弃用(在OpenGL ES中已删除) 2.0和桌面OpenGL 3+内核.

This was mainly used with the old immediate mode (glBegin/glEnd), where you don't use vertex arrays, which is deprecated (and removed in OpenGL ES 2.0 and desktop OpenGL 3+ core).

但是此函数仍可用于数组(这就是为什么它在现代版本中仍然存在).您的假设是正确的,即此调用之后的所有顶点对此属性都具有相同的值(当然,仅当您不启用此属性的数组时).或者更确切地说,每个未启用其对应数组的着色器属性都从单个状态值获取其值,并且可以使用glVertexAttrib更改此值.

But this function still has its use with arrays (that's why it's still there in the modern versions). You are right in your assumption that all vertices following this call have the same value for this attribute (only if you don't enable this attribute's array, of course). Or more exactly every used shader attribute that doesn't have its corresponding array enabled sources its value from a single state value and this value can be changed with glVertexAttrib.

如果您有一个通用着色器,例如颜色属性和位置属性,并且您有一个颜色恒定的对象.因此,通过使用glVertexAttrib,您不必为每个顶点提交颜色,也不必使用将颜色更改为统一颜色的特殊着色器.

This is usefull if you have a general shader with e.g. a color attribute and a position attribute and you have an object with a constant color. So by using glVertexAttrib you neither have to submit a color for each vertex, nor do you have to use a special shader with the color changed to a uniform.

这篇关于glVertexAttrib(与glVertexAttribPointer相比)有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆