Exhibit #0: Getting Info about Vertex Attributes
Vertex Attributes
What We Did
- You can get the number of vertex attributes that are used with
gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES)
.
- The GLSL compiler will not include attributes that are declared but not used in your program.
- You can get info about an attribute with
gl.getActiveAttrib(program, <index-of-the-attribute>)
- Index goes from 0 to
gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES)-1
- You get an object that contains the name, size (always 1), and type of the attribute.
- You can get the index of an attribute with the given name with
gl.getAttribLocation(program, <attribute-name>)
- Important: You need to check whether an attribute exist before enabling or binding
something to it.
- Hint: Use these commands to build better abstractions around vertex attributes.