In usual OpenGL fashion, there are multiple possible causes of failure, all of which return GL_INVALID_OPERATION as the error code. I’m actually not sure if there even are any other GL error codes, honestly. $deity knows I’ve never seen one.
… what? First, if you don’t actually know OpenGL, then making suggestions for it is probably not an appropriate thing for you to do.
Second, you cannot possibly have ever run into the problem you suggest, because passing -1 to glVertexAttribPointer results in GL_INVALID_VALUE, not OPERATION. So you cannot both have never seen any other error and have run into the problem you’re complaining about.
And if this is just ridiculous hyperbole, stop using hyperbole when making a serious suggestion. It makes your “suggestion” sound less like a suggestion and more like grousing.
So yeah, you see an awful lot of glGetAttribLocation when you’re new to GL.
Then fix that. Users should not be taught to use glGetAttribLocation
. They should be taught to tell OpenGL what attribute locations they want and thereby establish an attribute convention.
For example, my tutorials (linked in my sig) are for new users, but they never once call glGetAttribLocation
. And even before explicit_attrib_location, I just used glBindAttribLocation
before linking in those tutorials. That is how it should be done, that is how people actually do it, and therefore, that is how people should be taught to do it.
Tutorials and learning materials that suggest using glGetAttribLocation
are wrong and should be corrected.
Also, GLES doesn’t have explicit attribute location support at all, does it?
No, but it does have glBindAttribLocation. Why are you getting something that you’ve already told the program to set up? And if you didn’t set it up, then that is what you should be fixing.
I suppose now that I think on it, just adding a new GL error code would be just as good as adding a new magic return value, would be easier, and is far far less likely to break any existing code. I amend my suggestion to just doing that instead.
I want to make sure I understand your suggestion. You’re saying that if you call glGetAttribLocation
for an attribute that is either inactive or doesn’t exist, this should throw a GL Error.
Even though this is not an error. Even though errors are used to indicate erroneous conditions or uses of a function, yet it is perfectly valid to ask for attribute locations that were optimized out. And even those all of those tutorials and whatnot that you cite will not be affected by this in the slightest, because virtually all of them ignore error checking entirely.
So who exactly is this feature for, anyway?
glProgramHasAttribLocation() maybe ?
Inactive attributes don’t have a location. What you probably intended is, “glProgramIsAttribInactive”, which would return false for attributes that aren’t on the inactive list. You would use it like this:
GLint loc = glGetAttribLocation(...);
if(loc == -1)
{
if(glProgramIsAttribInactive(...))
//Inactive attribute.
else
//Name mismatch.
}
glShaderGetAttribType() ?
… what?
If you are going to ask for something, it would be a good idea to at least make a cursory inspection of the API to make sure that it doesn’t already exist.
And before you ask, there’s no reason to ask for information for an inactive attribute. So it’s find that it only works for active ones.