glVertexAttribPointer 内置顶点属性,如 gl_Vertex、gl_Normal
我必须使用 glVertexAttribPointer 将顶点属性发送到希望它们内置的着色器(gl_Vertex
、gl_Color
等)。
glVertexAttribPointer
函数需要指定每个内置属性的索引(或位置)。我可以在 NVidia 实现上执行此操作,因为每个属性的位置是固定的(请参阅 http://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/attributes.php 在“自定义属性”部分,但是我不确定 另外,当尝试获取以“gl_”开头的任何属性的位置
时,函数glGetAttribLocation
将返回-1,
我认为我错过了一些东西,这是一个微不足道的事情。问题,但是我还没有找到ATI的正确解决方案。
I have to send vertex attributes using glVertexAttribPointer to shaders expecting them as built-in (gl_Vertex
, gl_Color
, etc.).
The glVertexAttribPointer
function needs to specify the index (or location) of each built-in attribute. I can do it on NVidia implementations since the location of each attribute is fixed (see http://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/attributes.php at the section "Custom attributes), however i'm not sure about the locations in ATI implementation.
Also, the function glGetAttribLocation
will return -1 when trying to get the location of any attribute beginning starting with "gl_".
I think i'm missing something and this is a trivial problem, however I have not found the correct solution for ATI.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
内置属性数组不是使用
glVertexAttribPointer
设置的,而是使用glVertexPointer
、glColorPointer
、...。您可以通过调用glEnableClientState
使用诸如GL_VERTEX_ARRAY
、GL_COLOR_ARRAY
、... 之类的常量,而不是glEnableVertexAttribArray
。虽然在 nVidia
glVertexAttribPointer
上可能会工作,但由于它们使用内置属性对自定义属性索引进行别名,这不符合标准,我确信您不能指望在任何其他硬件供应商上出现这种情况。因此,请确保对自定义属性使用glVertexAttribPointer
,对布尔属性使用glVertexPointer/glNormalPointer/...
函数,以及匹配的启用/禁用函数。请记住,无论如何,内置属性以及提到的函数都已被弃用。因此,如果您想编写现代 OpenGL 代码,无论如何您都应该定义自己的属性。但也许您必须支持旧版着色器,或者目前不关心向前兼容性。
The builtin attribute arrays are not set with
glVertexAttribPointer
, but with functions likeglVertexPointer
,glColorPointer
, .... And you enable these by callingglEnableClientState
with constants likeGL_VERTEX_ARRAY
,GL_COLOR_ARRAY
, ..., instead ofglEnableVertexAttribArray
.Whereas on nVidia
glVertexAttribPointer
might work, due to their aliasing of custom attribute indices with builtin attributes, this is not standard conformant and I'm sure you cannot expect this on any other hardware vendor. So to be sure useglVertexAttribPointer
for custom attributes and theglVertexPointer/glNormalPointer/...
functions for bultin attributes, together with the matching enable/disable functions.Keep in mind that the builtin attributes are deprecated anyway, together with the mentioned functions. So if you want to write modern OpenGL code, you should define your own attributes anyway. But maybe you have to support legacy shaders or don't care about forward compatiblity at the moment.