tangrams/tangram — pull request #29 by bcamper (2014-10-13 13:52:59+00:00)
Title: More flexible vertex layouts

This introduces a new method for constructing GL geometry buffers, allowing more control over the vertex layout, specifically the ability to mix types for attributes (the old system naively enforced Float32s for every attribute, which can be highly wasteful). A new intermediary object called ```GLVertexData``` encapsulates the buffer that will be used to make the actual GL VBO; ```GLVertexData``` maintains one central typed array buffer (an ```ArrayBuffer```), and individual views into that buffer for each attribute type (```Uint8Array``` for ```gl.UNSIGNED_BYTE```, ```Int16Array``` for ```gl.SHORT```, etc.). When a vertex is added, the typed views are used to update the correct locations in the buffer and convert a plain JS value to the correct type. ```GLVertexData``` re-allocates the typed arrays when needed, and trims them to the final necessary size when geometry construction is done.

As an example, [colors are now packed into a single 32-bit int](https://github.com/tangrams/tangram/compare/flex_vertex?expand=1#diff-9d9702aee88c2affd926c674605d3a01R197) instead of each component being a float.

To do before merge: add tests
To do (sometime): reduce vertex layout sizes further with shorts (texcoords, maybe positions), bytes (normals), etc.