When to use ofShader::bindAttribute()?

Hi, I don’t understand why we need ofShader::bindAttribute().

If I for example call shader.setAttribute1f(shader.getAttributeLocation("name"), 100);, it just works even without calling shader.bindAttribute(1, "name"); beforehand.

Why do we need ofShader::bindAttribute() and when to use this?
Thank you!

bindAttribute is used for faster access so you don’t need to query for the attribute location every time and instead just set the attribute by the number instead. it’s mostly used by OF internally to bind the default attributes so the vbo always sets them to the same locations

1 Like

Thank you!

Does this look good for the documentation?

bindAttribute is used for faster access to attributes. The idea is to set attributes by location (an integer) instead of querying attribute locations multiple times by name. This method is used internally by OF in ofShader::bindDefaults() to set the default locations of the position, color, normal and texcoord attributes.


@hamoid, yeah that looks good to me