Optimize GL emulation layer.

This pull request adds several optimizations to the Emscripten built-in GL emulation layer. Currently running try builds on bots to check that it doesn't regress anything.

See the individual commit messages for detailed explanations on each optimization.