Skip to content

Attribute and VAO locations

David Komer edited this page Jul 25, 2018 · 6 revisions

Attribute locations can be set manually (e.g. globally or per-renderer) or automatically (e.g. derived per-shader).

In GLTF it's done manually, because this allows uploading data as a separate step from the shader, as well as re-using attribute data across different shaders that would have otherwise given different indexes.

If using other shaders with Gltf, attributes must also be set manually otherwise they will conflict with gltf (haven't thoroughly tested this - but it makes sense...)

This is very simple to do, just append the new variable names to renderer.attributes.globalLocations before creating the shader, and call renderer.attributes.getLocationInRenderer() to get the locations. Since renderer.attributes.globalLocations is a Set it's safe to just blindly add the same attribute name for various different shaders without fear of a conflict.

For setups that are using an automatic flow, just call renderer.attributes.getLocationInShader() which will need the program as an argument (so that it can get the location).

See the example code, particularly DualGltf and Basic Box examples (non-gltf), for demos.

Clone this wiki locally