State caching

Closes #315
Closes #164

TODO:
- [X] device reset
- [X] device direct GL access
- [X] render target caching (was already there mostly)
- [X] draw state caching
- [x] mesh attribute caching
- [x] program caching

Future goals:
  * cache uniform values
  * re-use textures/blocks by tracking their bound points

cc @bvssvni @eddyb @kvark