glGetAttribLocation返回较大且不可用的值 [英] glGetAttribLocation returns large and unusable value
问题描述
看来我的glGetAttribLocation
返回的值是4294967295
,但我不确定为什么.我见过很多人用它返回-1
,但是我遇到的问题却很少.问题在于它返回的值大于GL_MAX_VERTEX_ATTRIBS
,这意味着我不能使用glEnableVertexAttribArray
将法线发送到着色器.谁知道此函数将返回这么高的值吗?
It seems my glGetAttribLocation
is returning a value of 4294967295
and I'm not sure why. I've seen a lot of people with it returning -1
but not so many with my problem. The problem is that it returns a value greater than GL_MAX_VERTEX_ATTRIBS
meaning I can't use glEnableVertexAttribArray
to send my normals to the shader. Would anyone know what this function would return such a high value?
推荐答案
值4294967295是可以由 unsigned 32位数字表示的最大值.如果将其转换为十六进制,则为0xFFFFFFFF.
The value 4294967295 is the largest value that can be represented by an unsigned 32-bit number. If you convert it to hex, it's 0xFFFFFFFF.
glGetAttribLocation()
返回类型为GLint
的值,该值是带符号的32位值.如果您将获得的0xFFFFFFFF值解释为有符号值,则实际上为-1. [*]
glGetAttribLocation()
returns a value of type GLint
, which is a signed 32-bit value. If you interpret the 0xFFFFFFFF value you got as signed value, it is in fact -1. [*]
所以您确实获得了-1的返回值,这意味着未找到该属性.造成这种情况的常见原因是:
So you did get a return value of -1, which means that the attribute was not found. The common reasons for this are:
- 具有给定名称的属性不会出现在着色器代码中.
- 具有给定名称的属性已被优化,因为未使用该属性.
- 您传入的程序无效.
- 您传入的程序未成功链接.
获得此返回值的意外通常是由原因2引起的.
The surprises for getting this return value are often caused by reason 2.
[*]至少在以2的补码形式表示带符号值的机器上确实如此,这在当今几乎所有情况下都是如此.
[*] At least that's true on machines that represent signed values in a 2's complement form, which is the case for almost anything these days.
这篇关于glGetAttribLocation返回较大且不可用的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!