From 34cb845ac8c1b02c12b25b7b0809f9006bcb758b Mon Sep 17 00:00:00 2001 From: Felipe Alfonso Date: Mon, 12 Sep 2016 23:17:25 -0300 Subject: [PATCH] Wip fixing filter issue with multitexture --- src/pixi/display/DisplayObject.js | 4 +++- src/pixi/renderers/webgl/shaders/PixiFastShader.js | 2 +- src/pixi/renderers/webgl/utils/FilterTexture.js | 2 ++ src/pixi/textures/RenderTexture.js | 6 +++++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/pixi/display/DisplayObject.js b/src/pixi/display/DisplayObject.js index fa121f75c..dae90838e 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -529,7 +529,9 @@ PIXI.DisplayObject.prototype = { if (!this._cachedSprite) { - var renderTexture = new PIXI.RenderTexture(bounds.width, bounds.height); + var textureUnit = 0; + + var renderTexture = new PIXI.RenderTexture(bounds.width, bounds.height, null, null, null, textureUnit); this._cachedSprite = new PIXI.Sprite(renderTexture); this._cachedSprite.worldTransform = this.worldTransform; } diff --git a/src/pixi/renderers/webgl/shaders/PixiFastShader.js b/src/pixi/renderers/webgl/shaders/PixiFastShader.js index 191406bce..17946003e 100644 --- a/src/pixi/renderers/webgl/shaders/PixiFastShader.js +++ b/src/pixi/renderers/webgl/shaders/PixiFastShader.js @@ -67,7 +67,7 @@ PIXI.PixiFastShader = function (gl) { 'varying float vTextureIndex;', 'uniform sampler2D uSampler;', 'void main(void) {', - ' gl_FragColor = texture2D(uSampler, vTextureCoord) * vColor;' + ' gl_FragColor = texture2D(uSampler, vTextureCoord) * vColor;', '}' ]; } diff --git a/src/pixi/renderers/webgl/utils/FilterTexture.js b/src/pixi/renderers/webgl/utils/FilterTexture.js index 0340289c9..884cc9550 100644 --- a/src/pixi/renderers/webgl/utils/FilterTexture.js +++ b/src/pixi/renderers/webgl/utils/FilterTexture.js @@ -38,6 +38,8 @@ PIXI.FilterTexture = function(gl, width, height, scaleMode) */ scaleMode = scaleMode || PIXI.scaleModes.DEFAULT; + gl.activeTexture(gl.TEXTURE0); + gl.bindTexture(gl.TEXTURE_2D, this.texture); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); diff --git a/src/pixi/textures/RenderTexture.js b/src/pixi/textures/RenderTexture.js index cf5e7d9eb..e81ea69fe 100644 --- a/src/pixi/textures/RenderTexture.js +++ b/src/pixi/textures/RenderTexture.js @@ -32,8 +32,9 @@ * @param scaleMode {Number} See {{#crossLink "PIXI/scaleModes:property"}}PIXI.scaleModes{{/crossLink}} for possible values * @param resolution {Number} The resolution of the texture being generated */ -PIXI.RenderTexture = function(width, height, renderer, scaleMode, resolution) +PIXI.RenderTexture = function(width, height, renderer, scaleMode, resolution, textureUnit) { + textureUnit = typeof textureUnit == 'number' ? textureUnit : 0; /** * The with of the render texture * @@ -107,6 +108,8 @@ PIXI.RenderTexture = function(width, height, renderer, scaleMode, resolution) if (this.renderer.type === PIXI.WEBGL_RENDERER) { var gl = this.renderer.gl; + // gl.activeTexture(gl.TEXTURE0 + textureUnit); + this.baseTexture.textureIndex = textureUnit; this.baseTexture._dirty[gl.id] = false; this.textureBuffer = new PIXI.FilterTexture(gl, this.width, this.height, this.baseTexture.scaleMode); @@ -245,6 +248,7 @@ PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, matrix, clear this.renderer.spriteBatch.dirty = true; + gl.bindFramebuffer(gl.FRAMEBUFFER, null); }; /**