diff --git a/CHANGELOG.md b/CHANGELOG.md index 48001f36a..62ff335d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - Fixed an error when the WebGL context of a destroyed game was lost (#756). - Fixed a new WebGL renderer taking the context id of a live renderer after another renderer was destroyed (#757). +- Fixed multi-texture batching binding the last batched texture to whichever texture unit was active, which could draw the wrong texture (e.g., stretched over the canvas by the debug sprite) (#231). ### Thanks diff --git a/src/gameobjects/Creature.js b/src/gameobjects/Creature.js index 40f852b46..5c961f2cd 100644 --- a/src/gameobjects/Creature.js +++ b/src/gameobjects/Creature.js @@ -492,6 +492,12 @@ Phaser.Creature.prototype._renderCreature = function (renderSession) gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.indices, gl.STATIC_DRAW); } + if (PIXI._enableMultiTextureToggle) + { + PIXI.WebGLRenderer.textureArray[0] = null; + PIXI.WebGLRenderer.textureArray[this.texture.baseTexture.textureIndex] = null; + } + gl.drawElements(gl.TRIANGLES, this.indices.length, gl.UNSIGNED_SHORT, 0); }; diff --git a/src/gameobjects/Rope.js b/src/gameobjects/Rope.js index 98bf7a297..d31bc883e 100644 --- a/src/gameobjects/Rope.js +++ b/src/gameobjects/Rope.js @@ -447,6 +447,12 @@ Phaser.Rope.prototype._renderStrip = function (renderSession) gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.indices, gl.STATIC_DRAW); } + if (PIXI._enableMultiTextureToggle) + { + PIXI.WebGLRenderer.textureArray[0] = null; + PIXI.WebGLRenderer.textureArray[this.texture.baseTexture.textureIndex] = null; + } + gl.drawElements(drawMode, this.indices.length, gl.UNSIGNED_SHORT, 0); }; diff --git a/src/pixi/renderers/webgl/utils/WebGLFilterManager.js b/src/pixi/renderers/webgl/utils/WebGLFilterManager.js index 220014be9..e2a34cfe6 100644 --- a/src/pixi/renderers/webgl/utils/WebGLFilterManager.js +++ b/src/pixi/renderers/webgl/utils/WebGLFilterManager.js @@ -93,6 +93,8 @@ PIXI.WebGLFilterManager.prototype.pushFilter = function (filterBlock) this.offsetX += filterBlock._filterArea.x; this.offsetY += filterBlock._filterArea.y; + gl.activeTexture(gl.TEXTURE0); + var texture = this.texturePool.pop(); if(!texture) { @@ -104,6 +106,7 @@ PIXI.WebGLFilterManager.prototype.pushFilter = function (filterBlock) } gl.bindTexture(gl.TEXTURE_2D, texture.texture); + PIXI.WebGLRenderer.textureArray[0] = null; var filterArea = filterBlock._filterArea;// filterBlock.target.getBounds();///filterBlock.target.filterArea; @@ -315,6 +318,7 @@ PIXI.WebGLFilterManager.prototype.popFilter = function () // set texture gl.activeTexture(gl.TEXTURE0); gl.bindTexture(gl.TEXTURE_2D, texture.texture); + PIXI.WebGLRenderer.textureArray[0] = null; // >>> modify by nextht if (this.renderSession.stencilManager) diff --git a/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js b/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js index 69aff5c75..f51aa2eb9 100644 --- a/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js +++ b/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js @@ -782,8 +782,9 @@ PIXI.WebGLSpriteBatch.prototype.renderBatch = function (texture, size, startInde return; } } - else + else if (!PIXI._enableMultiTextureToggle) { + // With multi-texture batching each texture is already bound to its own unit gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id]); }