内置顶点属性(例如gl_Vertex,gl_Normal)上的glVertexAttribPointer [英] glVertexAttribPointer on built-in vertex attributes like gl_Vertex, gl_Normal

查看:201
本文介绍了内置顶点属性(例如gl_Vertex,gl_Normal)上的glVertexAttribPointer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用glVertexAttribPointer将顶点属性发送给希望内置的着色器(gl_Vertexgl_Color等).

I have to send vertex attributes using glVertexAttribPointer to shaders expecting them as built-in (gl_Vertex, gl_Color, etc.).

glVertexAttribPointer函数需要指定每个内置属性的索引(或位置).因为每个属性的位置都是固定的,所以我可以在NVidia实现上进行操作(请参见 http://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/attributes.php 在自定义属性"部分,但是我不确定ATI实现中的位置.

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.

此外,当尝试获取以"gl_"开头的任何属性的位置时,函数glGetAttribLocation将返回-1.

Also, the function glGetAttribLocation will return -1 when trying to get the location of any attribute beginning starting with "gl_".

我认为我缺少一些东西,这是一个琐碎的问题,但是我没有找到ATI的正确解决方案.

I think i'm missing something and this is a trivial problem, however I have not found the correct solution for ATI.

推荐答案

内置属性数组不是使用glVertexAttribPointer设置的,而是使用 glEnableClientState 并使用诸如GL_VERTEX_ARRAYGL_COLOR_ARRAY,...,而不是glEnableVertexAttribArray.

The builtin attribute arrays are not set with glVertexAttribPointer, but with functions like glVertexPointer, glColorPointer, .... And you enable these by calling glEnableClientState with constants like GL_VERTEX_ARRAY, GL_COLOR_ARRAY, ..., instead of glEnableVertexAttribArray.

在nVidia glVertexAttribPointer上可能会起作用,由于它们使用内置属性来别名化自定义属性索引,因此这不是符合标准的,我敢肯定您不会在任何其他硬件供应商上期望它.因此,请确保将glVertexAttribPointer用于自定义属性,将glVertexPointer/glNormalPointer/...函数用于bultin属性,以及匹配的启用/禁用功能.

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 use glVertexAttribPointer for custom attributes and the glVertexPointer/glNormalPointer/... functions for bultin attributes, together with the matching enable/disable functions.

请记住,无论如何都不要使用内置属性以及提及的功能.因此,如果您想编写现代的OpenGL代码,则无论如何都应该定义自己的属性.但是也许您现在必须支持旧式着色器,或者暂时不关心前向兼容性.

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.

这篇关于内置顶点属性(例如gl_Vertex,gl_Normal)上的glVertexAttribPointer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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