glGetAttribLocation returns -1 when retrieving existing shader attribute

前端 未结 1 1735
孤独总比滥情好
孤独总比滥情好 2020-12-15 05:01

I\'m trying to pass in attributes to my vertex shader but for some reason it keeps giving me a -1 on the 3rd attribute location I\'m asking openGl to retrieve via glGetAttri

相关标签:
1条回答
  • 2020-12-15 05:54

    You should stop using glGetAttribLocation. Assign each attribute a location, either with glBindAttribLocation before linking the program or with explicit attribute locations, if that's available to you.

    That way, if the compiler optimizes an attribute away (which is what's happening here; your fragment shader probably doesn't use one of the interpolated values), you won't care. You'll set up your arrays as normal, using a standard convention for attribute indices. Plus, you won't have to keep asking what an attribute location is every time you want to render with a different program; you know what location it is because you assigned it.

    If you can't/won't, then there's nothing you can do. The compiler will optimize away attributes if you're not actually using them. The only thing you can do is detect that it returns -1 and not set up the array for that attribute.

    0 讨论(0)
提交回复
热议问题