PDA

View Full Version : Do I have to call glDisableVertexAttribArray?



padawan
04-16-2011, 12:18 AM
I found a page somewhere that was saying that I have to call glDisableVertexAttribArray when I call glEnableVertexAttribArray. However I couldn't find that much about that, not even in the specification (I'm talking about OpenGL 3.3). So I'm not sure of how things are supposed to work.
In general it makes kind of sense, since I couldn't find a meaning for this method.

Actually, making the question a bit more generic: why do I have to enable and disable vertex attribute arrays in the first place?

Alfonse Reinheart
04-16-2011, 12:36 AM
why do I have to enable and disable vertex attribute arrays in the first place?

In order to tell OpenGL which attribute arrays are valid and which are not.

Remember: OpenGL is a state machine. When you call glVertexAttribPointer, that basically sets fields in a struct. And state always has a value. There's no way to call glVertexAttribPointer and say, "This attribute doesn't matter anymore; don't use it."

That's what the enable/disable calls are for. To tell OpenGL whether or not it should use the state for that attribute.

padawan
04-16-2011, 01:07 AM
I have been waiting online for an answer. I knew it would come soon :). Thanks a lot Alfonse.
OopenGL documentation is a bit difficult sometimes, but this forum is awesome.

now, back on topic.



why do I have to enable and disable vertex attribute arrays in the first place?

In order to tell OpenGL which attribute arrays are valid and which are not.

Remember: OpenGL is a state machine. When you call glVertexAttribPointer, that basically sets fields in a struct. And state always has a value. There's no way to call glVertexAttribPointer and say, "This attribute doesn't matter anymore; don't use it."

That's what the enable/disable calls are for. To tell OpenGL whether or not it should use the state for that attribute.
But don't I say that with glBindAttribLocation? With that I tell a program where to find the attribute I prepared with glVertexAttribPointer, and the various operations before that used to prepare the buffer,
If I bind an attribute array to a variable, which will be used by a program, I automatically tell the program that it can use that attribute array.

I must be missing something.

Alfonse Reinheart
04-16-2011, 01:19 AM
But don't I say that with glBindAttribLocation?

That tells OpenGL which attributes your shader uses. What the shader uses and what attributes you provide with arrays do not have to agree. If your attribute arrays don't provide an attribute (ie: it is disabled), then the value comes from a default value (set with glVertexAttrib* calls).

padawan
04-16-2011, 01:22 AM
Got it. So that also means that I don't necessarily have to call glDisableVertexAttribArray, unless I want the default value to be used. Correct?