glVertexAttribDivisor 和索引输入
伙计们, 我正在尝试在 OpenGL 实例绘图中使用 glVertexAttribDivisor。
在NV卡上可以工作,但在ATI卡上就不行。什么都没有画。
从GlExtensionViewer来看,这两个卡都支持glVertexAttribDivisor/InstancedStream。运行时没有出现错误。
我不知道这是否是由于我的错误使用造成的。
我将实例数据放在单独的顶点数组缓冲区中,然后将其映射到 gl_MultiTexCoord0~3 中。实例数据是世界矩阵。
代码在这里。
for( int i=0;i<3;i++)
{
glClientActiveTexture(kGL_TEXTURE0 + i);
glTexCoordPointer(size, type, stride, i*4*sizeof(float));
int instanceVertexAttribIndex = i + 8;
glVertexAttribDivisorARB(instanceVertexAttribIndex, 1);
}
关键问题是,如果我尝试将实例数据放在 gl_MultiTexCoord0 上,我应该给 glVertexAttribDivisorARB 提供什么正确的“索引”?
guys,
I am trying to make use of glVertexAttribDivisor in my OpenGL instanced drawing.
It works in NV card, but it doesn't work in ATI card. Nothing is drawing.
From GlExtensionViewer, it shows both of these cards supports glVertexAttribDivisor/ InstancedStream. There was no error at running.
I don't know if this is due to my wrong usage.
I put the instance data in a separate vertex array buffer, then map it into gl_MultiTexCoord0~3. The instance data is the world matrix.
Code is here.
for( int i=0;i<3;i++)
{
glClientActiveTexture(kGL_TEXTURE0 + i);
glTexCoordPointer(size, type, stride, i*4*sizeof(float));
int instanceVertexAttribIndex = i + 8;
glVertexAttribDivisorARB(instanceVertexAttribIndex, 1);
}
The key issue is what the right "index" should I give to glVertexAttribDivisorARB if I try to put the instance data on gl_MultiTexCoord0?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它适用于 NVIDIA 卡,因为 NVIDIA 没有正确实现 OpenGL 规范。
glVertexAttrbDivisorARB
仅适用于通用属性。即用户定义的着色器属性。它不能作用于除glVertexAttrib(I)Pointer
指定的属性之外的任何属性。NVIDIA 很早就实现了属性别名的行为。
gl_MultiTexCoorc[0]
的属性索引也为 8。顶点位置输入gl_Vertex
的属性索引为 0。有问题吗? OpenGL 规范不允许这样做。它特别要求如果您尝试的话,实现会失败并给出错误。当您在设置这些数组的情况下调用
glDraw*
时,您的实现应该会给出错误。遗憾的是,您陷入了 NVIDIA 陷阱:使用恰好适用于其驱动程序的非规范行为。我想您一定是从 NVIDIA 的一些论文中得到了这个想法。因此,现在您必须更改所有代码以使用用户定义的属性而不是内置属性。
哦,如果您想知道规范中的什么地方这么说,请参阅 OpenGL 3.3 兼容性配置文件,第 94 页,最底部:
It works on NVIDIA cards because NVIDIA is not implementing the OpenGL specification properly.
glVertexAttrbDivisorARB
only works on generic attributes. That is, user-defined shader attributes. It does not work on any attributes other than those specified byglVertexAttrib(I)Pointer
.NVIDIA has long implemented the behavior of attribute aliasing. That
gl_MultiTexCoorc[0]
also has the attribute index 8. Thatgl_Vertex
, the vertex position input, has the attribute index 0.The problem? The OpenGL specification does not allow this. It specifically requires implementations to fail and give an error if you try it. When you call
glDraw*
with these arrays set up, your implementation should give you an error.Sadly, you got caught in the NVIDIA trap: using non-spec behavior that just so happens to work on their drivers. I imagine you must have gotten the idea from some NVIDIA paper. So now you have to go change all your code to use user-defined attributes instead of the built-in ones.
Oh, and if you're wondering where in the specification it says this, see the OpenGL 3.3 Compatibility Profile, page 94, the very bottom: