diff --git a/CHANGELOG.md b/CHANGELOG.md index 69941ed7b..4da5f33ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ ## Unreleased +### API Changes + +- `PIXI.WebGLGraphics.graphicsDataPool` is now an array of pools indexed by WebGL context id. + +### Bug Fixes + +- Fixed WebGL errors when a Graphics object reused pooled WebGL data from another game. + ### New Features - The game config now has an `antialiasGL` option for the WebGL context's `antialias` attribute, separate from texture smoothing. diff --git a/src/pixi/renderers/webgl/WebGLRenderer.js b/src/pixi/renderers/webgl/WebGLRenderer.js index 3c84a8bb5..fbcacb48a 100644 --- a/src/pixi/renderers/webgl/WebGLRenderer.js +++ b/src/pixi/renderers/webgl/WebGLRenderer.js @@ -255,6 +255,8 @@ PIXI.WebGLRenderer.prototype.initContext = function () PIXI.instances[this.glContextId] = this; + PIXI.WebGLGraphics.graphicsDataPool[this.glContextId] = []; + // set up the default pixi settings.. gl.disable(gl.DEPTH_TEST); gl.disable(gl.CULL_FACE); @@ -618,6 +620,8 @@ PIXI.WebGLRenderer.prototype.destroy = function () { PIXI.glContexts[this.glContextId] = null; + PIXI.WebGLGraphics.graphicsDataPool[this.glContextId] = null; + this.projection = null; this.offset = null; diff --git a/src/pixi/renderers/webgl/utils/WebGLGraphics.js b/src/pixi/renderers/webgl/utils/WebGLGraphics.js index a4b43ab1e..c4166e068 100644 --- a/src/pixi/renderers/webgl/utils/WebGLGraphics.js +++ b/src/pixi/renderers/webgl/utils/WebGLGraphics.js @@ -126,7 +126,7 @@ PIXI.WebGLGraphics.updateGraphics = function (graphics, gl) { var graphicsData = webGL.data[i]; graphicsData.reset(); - PIXI.WebGLGraphics.graphicsDataPool.push(graphicsData); + PIXI.WebGLGraphics.graphicsDataPool[gl.id].push(graphicsData); } // clear the array and reset the index.. @@ -234,7 +234,7 @@ PIXI.WebGLGraphics.switchMode = function (webGL, type) if(!webGL.data.length) { - webGLData = PIXI.WebGLGraphics.graphicsDataPool.pop() || new PIXI.WebGLGraphicsData(webGL.gl); + webGLData = PIXI.WebGLGraphics.graphicsDataPool[webGL.gl.id].pop() || new PIXI.WebGLGraphicsData(webGL.gl); webGLData.mode = type; webGL.data.push(webGLData); } @@ -244,7 +244,7 @@ PIXI.WebGLGraphics.switchMode = function (webGL, type) if(webGLData.mode !== type || type === 1) { - webGLData = PIXI.WebGLGraphics.graphicsDataPool.pop() || new PIXI.WebGLGraphicsData(webGL.gl); + webGLData = PIXI.WebGLGraphics.graphicsDataPool[webGL.gl.id].pop() || new PIXI.WebGLGraphicsData(webGL.gl); webGLData.mode = type; webGL.data.push(webGLData); } @@ -856,6 +856,11 @@ PIXI.WebGLGraphics.buildPoly = function (graphicsData, webGLData) return true; }; +/** + * Pools of unused WebGLGraphicsData, one per WebGL context id. + * + * @type {Array} + */ PIXI.WebGLGraphics.graphicsDataPool = []; /**