Skip to content

Commit b7a6120

Browse files
committed
Fixed framebuffer / FilterTexture issue when using multi texture batching
1 parent e99ab87 commit b7a6120

3 files changed

Lines changed: 11 additions & 39 deletions

File tree

src/pixi/display/DisplayObject.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,8 @@ PIXI.DisplayObject.prototype = {
530530
if (!this._cachedSprite)
531531
{
532532
var textureUnit = 0;
533-
533+
if (this.texture && this.texture.baseTexture && PIXI._enableMultiTextureToggle)
534+
textureUnit = this.texture.baseTexture.textureIndex;
534535
var renderTexture = new PIXI.RenderTexture(bounds.width, bounds.height, null, null, null, textureUnit);
535536
this._cachedSprite = new PIXI.Sprite(renderTexture);
536537
this._cachedSprite.worldTransform = this.worldTransform;

src/pixi/renderers/webgl/utils/FilterTexture.js

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
function _CreateEmptyTexture(gl, width, height, scaleMode) {
66
var texture = gl.createTexture();
7-
gl.activeTexture(gl.TEXTURE0);
87
gl.bindTexture(gl.TEXTURE_2D, texture);
98
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
109
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
@@ -21,12 +20,13 @@ var _fbErrors = {
2120
36061: 'Framebuffer unsupported'
2221
};
2322

24-
function _CreateFramebuffer(gl, width, height, scaleMode) {
23+
function _CreateFramebuffer(gl, width, height, scaleMode, textureUnit) {
2524
var framebuffer = gl.createFramebuffer();
2625
var depthStencilBuffer = gl.createRenderbuffer();
2726
var colorBuffer = null;
2827
var fbStatus = 0;
2928

29+
gl.activeTexture(gl.TEXTURE0 + textureUnit);
3030
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
3131
gl.bindRenderbuffer(gl.RENDERBUFFER, depthStencilBuffer);
3232
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, this.renderBuffer);
@@ -55,7 +55,7 @@ function _CreateFramebuffer(gl, width, height, scaleMode) {
5555
* @param height {Number} the vertical range of the filter
5656
* @param scaleMode {Number} See {{#crossLink "PIXI/scaleModes:property"}}PIXI.scaleModes{{/crossLink}} for possible values
5757
*/
58-
PIXI.FilterTexture = function(gl, width, height, scaleMode)
58+
PIXI.FilterTexture = function(gl, width, height, scaleMode, textureUnit)
5959
{
6060
/**
6161
* @property gl
@@ -69,43 +69,15 @@ PIXI.FilterTexture = function(gl, width, height, scaleMode)
6969
* @property frameBuffer
7070
* @type Any
7171
*/
72-
this.frameBuffer = _CreateFramebuffer(gl, width, height, scaleMode || PIXI.scaleModes.DEFAULT);
72+
this.frameBuffer = _CreateFramebuffer(gl, width, height, scaleMode || PIXI.scaleModes.DEFAULT, textureUnit);
73+
/**
74+
* @property texture
75+
* @type Any
76+
*/
7377
this.texture = this.frameBuffer.targetTexture;
7478
this.width = width;
7579
this.height = height;
7680
this.renderBuffer = this.frameBuffer.renderBuffer;
77-
/* this.frameBuffer = gl.createFramebuffer();
78-
79-
/ **
80-
* @property texture
81-
* @type Any
82-
* /
83-
//this.texture = gl.createTexture();
84-
85-
/ **
86-
* @property scaleMode
87-
* @type Number
88-
* /
89-
scaleMode = scaleMode || PIXI.scaleModes.DEFAULT;
90-
91-
this.destTexture = gl.createTexture();
92-
gl.activeTexture(gl.TEXTURE0);
93-
94-
gl.bindTexture(gl.TEXTURE_2D, this.destTexture);
95-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST);
96-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST);
97-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
98-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
99-
100-
gl.bindFramebuffer(gl.FRAMEBUFFER, this.frameBuffer );
101-
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.destTexture, 0);
102-
103-
// required for masking a mask??
104-
this.renderBuffer = gl.createRenderbuffer();
105-
gl.bindRenderbuffer(gl.RENDERBUFFER, this.renderBuffer);
106-
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, this.renderBuffer);
107-
108-
this.resize(width, height);*/
10981
};
11082

11183
PIXI.FilterTexture.prototype.constructor = PIXI.FilterTexture;

src/pixi/textures/RenderTexture.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,10 @@ PIXI.RenderTexture = function(width, height, renderer, scaleMode, resolution, te
108108
if (this.renderer.type === PIXI.WEBGL_RENDERER)
109109
{
110110
var gl = this.renderer.gl;
111-
// gl.activeTexture(gl.TEXTURE0 + textureUnit);
112111
this.baseTexture.textureIndex = textureUnit;
113112
this.baseTexture._dirty[gl.id] = false;
114113

115-
this.textureBuffer = new PIXI.FilterTexture(gl, this.width, this.height, this.baseTexture.scaleMode);
114+
this.textureBuffer = new PIXI.FilterTexture(gl, this.width, this.height, this.baseTexture.scaleMode, textureUnit);
116115
this.baseTexture._glTextures[gl.id] = this.textureBuffer.texture;
117116

118117
this.render = this.renderWebGL;

0 commit comments

Comments
 (0)