tangrams/fontstash-es — pull request #2 by karimnaaji (2014-12-17 17:36:07+00:00)
Title: Reduce draw calls

Modified the rendering back-end in order to reduce draw calls. Before, each text had one static VBO in order to have a matrix stack to transform the vertices. Having all texts vertices in the same VBO leads to share the same matrix transformations. In the new method, all texts vertices are stored inside one single static VBO and the transforms are indexed inside a 32*64 texture (1024 potential ids since each id uses 8 bytes). OpenGL ES 2.0 doesn't provide natively floating point textures (maximum stored data is 1byte per channel) and has no instance rendering. We need to store the fractional part of the translations in order to have more accuracy, less accuracy on rotations doesn't lead to visible artifact. We could have used streamed VBOs and update them each time the transform changes, but it means that each glyph vertices would have had the transforms as attributes, which gives a lot of redundancy.

Average time in ms for a frame on iPhone 5s, where each text was rotated and translated each frame:

| Text id number | 100 | 250 | 500 | 750 | 1000
| ------------- | ------------- | ------------- | ------------- | ------------- | ------------- |
| New method (texture transforms) | 0.54 | 0.6 | 0.685 | 0.8 | 0.87 |
| Old method (matrix stack) | 8.7 | 11.45 | 26.6 | 26.6 | 33.2 |