GoodBoyDigital/pixi.js — pull request #357 by mattdesl (2013-10-15 19:13:05+00:00)
Title: WebGL Context Loss Support

There are a lot of bugs with context loss. For debugging, you can simulate context loss like so (in Chrome);
```javascript
var loseCtx = this.gl.getExtension("WEBGL_lose_context");
loseCtx.loseContext();

... after some time ...
loseCtx.restoreContext();
```

I also did a bit of code tidy in WebGLRenderer. Here is a run-down of the issues that were fixed:

- Context was not getting restored with the correct options (antialiasing, etc)
- Context was not getting restored with correct GL states (blending, depth test, etc)
- WebGLBatch was not re-settings its buffers after initialization.
- WebGLRenderGroup was not activating the default shader before rendering.
So if another shader was previously bound (i.e. line strip) this would cause errors on context restore.
- WebGLRenderer.handleContextRestored was trying to call a method that didn't exist
- PIXI.gl wasn't getting set on context restore.
- destroyTexture was using gl.createTexture() before deleting it; thus rendering the method useless. fixed now
- Changed a invalid script tag in Example 7 (unrelated to Context Loss, but a simple fix...)
- backgroundColor in WebGLRenderGroup was not used
- "batch" in WebGLRenderer was not used, removed
- "batchs" array in WebGLRenderer was not used, removed

There are still some outstanding bugs:
- TilingSprite, RenderTexture, Graphics, Stirp, and other extras don't seem to be handling context loss at all. Instead of me making a change, I feel like these should be overhauled to have a unified underlying base class, kind of like what we've got started with CustomRenderer.
- `PIXI._restoreBatchs`, `PIXI._returnBatch` and `PIXI._getBatch` seem like they duplicate functionality that should be in WebGLRenderGroup. This should really be changed. Also, static globals should be removed to better support multiple canvases and contexts, and make a cleaner API.
- Context loss is not fully supported with certain examples, namely look at the Bitmap Text example with a simulated context loss. I suspect it has something to do with bitmap loading?

Also, if batch features ever become part of the public API, we should use the naming "batches" instead of "batchs".