Bug 881227 refactor gl code

Hi @ednapiranha -- I have tried to make it very clear this time and deleted stuff that shouldn't be in the repo.

r? or not (sounds like a website targeting devs only)