is glEnableVertexAttribArray redundant?

Started by
9 comments, last by 21st Century Moose 10 years ago

If you just enable all attrib arrays, each one for which you don't make a glVertexAttribPointer call will take the default attrib pointer state.

The most important thing here is that the initial value for the pointer param is 0.

The second most important thing is that when you make a glVertexAttribPointer call, the driver takes a bunch of state and params, including the params to your glvertexAttribPointer call and the currently bound GL_ARRAY_BUFFER, and, saves them out as state for that attrib array. So in other words, this and not anywhere else is the point at which your currently bound buffer takes effect.

If you've no GL_ARRAY_BUFFER bound your draw call will end up dereferencing a NULL pointer.

But the GL_ARRAY_BUFFER binding isn't established until you call glVertexAttribPointer so if you never call glVertexAttribPointer then you'll never have a GL_ARRAY_BUFFER binding for that attrib array.

So you'll always dereference a NULL pointer.

And you'll crash.

Go ahead, check out the OpenGL.org forums and you'll see a healthy enough supply of cries for help from people who get a crash inside a draw call and it turns out they've an array enabled but no glVertexAttribPointer set for it.

At this point one is just getting cutesy and trying to fight against the API rather than work with it and use it the way it was designed to be used. That's not a clever thing to do.

(IIRC it's also illegal to have a GL_ARRAY_BUFFER of 0 when using VAOs too, so even if you have a really really robust driver - which you can't rely on your customers also having - best case is you'll get a bunch of GL errors).

Seriously - it's insane, don't do it.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This topic is closed to new replies.

Advertisement