Partial implementation of restore gl context. Plus some debug code.