diff --git a/src/pixi/renderers/canvas/CanvasRenderer.js b/src/pixi/renderers/canvas/CanvasRenderer.js index f966118..b9ce76e 100644 --- a/src/pixi/renderers/canvas/CanvasRenderer.js +++ b/src/pixi/renderers/canvas/CanvasRenderer.js @@ -215,11 +215,11 @@ } } - // remove frame updates.. - if(PIXI.Texture.frameUpdates.length > 0) - { - PIXI.Texture.frameUpdates.length = 0; - } + // remove frame updates.. // removeing for now... + //if(PIXI.Texture.frameUpdates.length > 0) + //{ + // PIXI.Texture.frameUpdates.length = 0; + //} }; /** diff --git a/src/pixi/renderers/canvas/CanvasRenderer.js b/src/pixi/renderers/canvas/CanvasRenderer.js index f966118..b9ce76e 100644 --- a/src/pixi/renderers/canvas/CanvasRenderer.js +++ b/src/pixi/renderers/canvas/CanvasRenderer.js @@ -215,11 +215,11 @@ } } - // remove frame updates.. - if(PIXI.Texture.frameUpdates.length > 0) - { - PIXI.Texture.frameUpdates.length = 0; - } + // remove frame updates.. // removeing for now... + //if(PIXI.Texture.frameUpdates.length > 0) + //{ + // PIXI.Texture.frameUpdates.length = 0; + //} }; /** diff --git a/src/pixi/renderers/canvas/utils/CanvasTinter.js b/src/pixi/renderers/canvas/utils/CanvasTinter.js index 8195028..172f344 100644 --- a/src/pixi/renderers/canvas/utils/CanvasTinter.js +++ b/src/pixi/renderers/canvas/utils/CanvasTinter.js @@ -78,38 +78,38 @@ { var context = canvas.getContext( "2d" ); - var frame = texture.frame; + var crop = texture.crop; - canvas.width = frame.width; - canvas.height = frame.height; + canvas.width = crop.width; + canvas.height = crop.height; context.fillStyle = "#" + ("00000" + ( color | 0).toString(16)).substr(-6); - context.fillRect(0, 0, frame.width, frame.height); + context.fillRect(0, 0, crop.width, crop.height); context.globalCompositeOperation = "multiply"; context.drawImage(texture.baseTexture.source, - frame.x, - frame.y, - frame.width, - frame.height, + crop.x, + crop.y, + crop.width, + crop.height, 0, 0, - frame.width, - frame.height); + crop.width, + crop.height); context.globalCompositeOperation = "destination-atop"; - + context.drawImage(texture.baseTexture.source, - frame.x, - frame.y, - frame.width, - frame.height, + crop.x, + crop.y, + crop.width, + crop.height, 0, 0, - frame.width, - frame.height); + crop.width, + crop.height); }; /** @@ -123,27 +123,27 @@ { var context = canvas.getContext( "2d" ); - var frame = texture.frame; + var crop = texture.crop; - canvas.width = frame.width; - canvas.height = frame.height; + canvas.width = crop.width; + canvas.height = crop.height; context.globalCompositeOperation = "copy"; context.fillStyle = "#" + ("00000" + ( color | 0).toString(16)).substr(-6); - context.fillRect(0, 0, frame.width, frame.height); + context.fillRect(0, 0, crop.width, crop.height); context.globalCompositeOperation = "destination-atop"; context.drawImage(texture.baseTexture.source, - frame.x, - frame.y, - frame.width, - frame.height, + crop.x, + crop.y, + crop.width, + crop.height, 0, 0, - frame.width, - frame.height); + crop.width, + crop.height); //context.globalCompositeOperation = "copy"; @@ -161,26 +161,26 @@ { var context = canvas.getContext( "2d" ); - var frame = texture.frame; + var crop = texture.crop; - canvas.width = frame.width; - canvas.height = frame.height; + canvas.width = crop.width; + canvas.height = crop.height; context.globalCompositeOperation = "copy"; context.drawImage(texture.baseTexture.source, - frame.x, - frame.y, - frame.width, - frame.height, + crop.x, + crop.y, + crop.width, + crop.height, 0, 0, - frame.width, - frame.height); + crop.width, + crop.height); var rgbValues = PIXI.hex2rgb(color); var r = rgbValues[0], g = rgbValues[1], b = rgbValues[2]; - var pixelData = context.getImageData(0, 0, frame.width, frame.height); + var pixelData = context.getImageData(0, 0, crop.width, crop.height); var pixels = pixelData.data; diff --git a/src/pixi/renderers/canvas/CanvasRenderer.js b/src/pixi/renderers/canvas/CanvasRenderer.js index f966118..b9ce76e 100644 --- a/src/pixi/renderers/canvas/CanvasRenderer.js +++ b/src/pixi/renderers/canvas/CanvasRenderer.js @@ -215,11 +215,11 @@ } } - // remove frame updates.. - if(PIXI.Texture.frameUpdates.length > 0) - { - PIXI.Texture.frameUpdates.length = 0; - } + // remove frame updates.. // removeing for now... + //if(PIXI.Texture.frameUpdates.length > 0) + //{ + // PIXI.Texture.frameUpdates.length = 0; + //} }; /** diff --git a/src/pixi/renderers/canvas/utils/CanvasTinter.js b/src/pixi/renderers/canvas/utils/CanvasTinter.js index 8195028..172f344 100644 --- a/src/pixi/renderers/canvas/utils/CanvasTinter.js +++ b/src/pixi/renderers/canvas/utils/CanvasTinter.js @@ -78,38 +78,38 @@ { var context = canvas.getContext( "2d" ); - var frame = texture.frame; + var crop = texture.crop; - canvas.width = frame.width; - canvas.height = frame.height; + canvas.width = crop.width; + canvas.height = crop.height; context.fillStyle = "#" + ("00000" + ( color | 0).toString(16)).substr(-6); - context.fillRect(0, 0, frame.width, frame.height); + context.fillRect(0, 0, crop.width, crop.height); context.globalCompositeOperation = "multiply"; context.drawImage(texture.baseTexture.source, - frame.x, - frame.y, - frame.width, - frame.height, + crop.x, + crop.y, + crop.width, + crop.height, 0, 0, - frame.width, - frame.height); + crop.width, + crop.height); context.globalCompositeOperation = "destination-atop"; - + context.drawImage(texture.baseTexture.source, - frame.x, - frame.y, - frame.width, - frame.height, + crop.x, + crop.y, + crop.width, + crop.height, 0, 0, - frame.width, - frame.height); + crop.width, + crop.height); }; /** @@ -123,27 +123,27 @@ { var context = canvas.getContext( "2d" ); - var frame = texture.frame; + var crop = texture.crop; - canvas.width = frame.width; - canvas.height = frame.height; + canvas.width = crop.width; + canvas.height = crop.height; context.globalCompositeOperation = "copy"; context.fillStyle = "#" + ("00000" + ( color | 0).toString(16)).substr(-6); - context.fillRect(0, 0, frame.width, frame.height); + context.fillRect(0, 0, crop.width, crop.height); context.globalCompositeOperation = "destination-atop"; context.drawImage(texture.baseTexture.source, - frame.x, - frame.y, - frame.width, - frame.height, + crop.x, + crop.y, + crop.width, + crop.height, 0, 0, - frame.width, - frame.height); + crop.width, + crop.height); //context.globalCompositeOperation = "copy"; @@ -161,26 +161,26 @@ { var context = canvas.getContext( "2d" ); - var frame = texture.frame; + var crop = texture.crop; - canvas.width = frame.width; - canvas.height = frame.height; + canvas.width = crop.width; + canvas.height = crop.height; context.globalCompositeOperation = "copy"; context.drawImage(texture.baseTexture.source, - frame.x, - frame.y, - frame.width, - frame.height, + crop.x, + crop.y, + crop.width, + crop.height, 0, 0, - frame.width, - frame.height); + crop.width, + crop.height); var rgbValues = PIXI.hex2rgb(color); var r = rgbValues[0], g = rgbValues[1], b = rgbValues[2]; - var pixelData = context.getImageData(0, 0, frame.width, frame.height); + var pixelData = context.getImageData(0, 0, crop.width, crop.height); var pixels = pixelData.data; diff --git a/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js b/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js old mode 100644 new mode 100755 index 3b12023..ac1aca3 --- a/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js +++ b/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js @@ -78,9 +78,6 @@ this.setContext(gl); this.dirty = true; - - this.textures = []; - this.blendModes = []; }; /** @@ -143,14 +140,15 @@ PIXI.WebGLSpriteBatch.prototype.render = function(sprite) { var texture = sprite.texture; - - //TODO set blend modes.. + + var blendChange = this.renderSession.blendModeManager.currentBlendMode !== sprite.blendMode; + // check texture.. - if(this.currentBatchSize >= this.size) + if(texture.baseTexture !== this.currentBaseTexture || this.currentBatchSize >= this.size || blendChange) { - //return; this.flush(); this.currentBaseTexture = texture.baseTexture; + this.renderSession.blendModeManager.setBlendMode(sprite.blendMode); } // get the uvs for the texture @@ -194,7 +192,7 @@ var index = this.currentBatchSize * 4 * this.vertSize; - var worldTransform = sprite.worldTransform; + var worldTransform = sprite.worldTransform;//.toArray(); var a = worldTransform.a;//[0]; var b = worldTransform.c;//[3]; @@ -244,11 +242,9 @@ verticies[index++] = tint; // increment the batchsize - this.textures[this.currentBatchSize] = sprite.texture.baseTexture; - this.blendModes[this.currentBatchSize] = sprite.blendMode; - this.currentBatchSize++; + }; /** @@ -261,13 +257,14 @@ { var texture = tilingSprite.tilingTexture; - + var blendChange = this.renderSession.blendModeManager.currentBlendMode !== tilingSprite.blendMode; + // check texture.. - if(this.currentBatchSize >= this.size) + if(texture.baseTexture !== this.currentBaseTexture || this.currentBatchSize >= this.size || blendChange) { - //return; this.flush(); this.currentBaseTexture = texture.baseTexture; + this.renderSession.blendModeManager.setBlendMode(tilingSprite.blendMode); } // set the textures uvs temporarily @@ -308,8 +305,8 @@ var height = tilingSprite.height; // TODO trim?? - var aX = tilingSprite.anchor.x; - var aY = tilingSprite.anchor.y; + var aX = tilingSprite.anchor.x; // - tilingSprite.texture.trim.x + var aY = tilingSprite.anchor.y; //- tilingSprite.texture.trim.y var w0 = width * (1-aX); var w1 = width * -aX; @@ -338,7 +335,7 @@ verticies[index++] = tint; // xy - verticies[index++] = (a * w0 + c * h1 + tx); + verticies[index++] = a * w0 + c * h1 + tx; verticies[index++] = d * h1 + b * w0 + ty; // uv verticies[index++] = uvs.x1; @@ -368,8 +365,6 @@ verticies[index++] = tint; // increment the batchs - this.textures[this.currentBatchSize] = texture.baseTexture; - this.blendModes[this.currentBatchSize] = tilingSprite.blendMode; this.currentBatchSize++; }; @@ -386,9 +381,10 @@ if (this.currentBatchSize===0)return; var gl = this.gl; - + this.renderSession.shaderManager.setShader(this.renderSession.shaderManager.defaultShader); + //TODO - im usre this can be done better - will look to tweak this for 1.7.. if(this.dirty) { this.dirty = false; @@ -411,6 +407,15 @@ } + // bind the current texture + gl.bindTexture(gl.TEXTURE_2D, this.currentBaseTexture._glTextures[gl.id] || PIXI.createWebGLTexture(this.currentBaseTexture, gl)); + + // check if a texture is dirty.. + if(this.currentBaseTexture._dirty[gl.id]) + { + PIXI.updateWebGLTexture(this.currentBaseTexture, gl); + } + // upload the verts to the buffer if(this.currentBatchSize > ( this.size * 0.5 ) ) { @@ -419,59 +424,19 @@ else { var view = this.vertices.subarray(0, this.currentBatchSize * 4 * this.vertSize); + gl.bufferSubData(gl.ARRAY_BUFFER, 0, view); } - var nextTexture, nextBlendMode; - var batchSize = 0; - var start = 0; - - var currentBaseTexture = null; - var currentBlendMode = this.renderSession.blendModeManager.currentBlendMode; - - for (var i = 0, j = this.currentBatchSize; i < j; i++) { - - nextTexture = this.textures[i]; - nextBlendMode = this.blendModes[i]; - - if(currentBaseTexture !== nextTexture || currentBlendMode !== nextBlendMode) - { - this.renderBatch(currentBaseTexture, batchSize, start); - - start = i; - batchSize = 0; - currentBaseTexture = nextTexture; - currentBlendMode = nextBlendMode; - - this.renderSession.blendModeManager.setBlendMode( currentBlendMode ); - } - - batchSize++; - } - - this.renderBatch(currentBaseTexture, batchSize, start); - + // var view = this.vertices.subarray(0, this.currentBatchSize * 4 * this.vertSize); + //gl.bufferSubData(gl.ARRAY_BUFFER, 0, view); + + // now draw those suckas! + gl.drawElements(gl.TRIANGLES, this.currentBatchSize * 6, gl.UNSIGNED_SHORT, 0); + // then reset the batch! this.currentBatchSize = 0; -}; -PIXI.WebGLSpriteBatch.prototype.renderBatch = function(texture, size, startIndex) -{ - if(size === 0)return; - - var gl = this.gl; - // bind the current texture - gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id] || PIXI.createWebGLTexture(texture, gl)); - - // check if a texture is dirty.. - if(texture._dirty[gl.id]) - { - PIXI.updateWebGLTexture(this.currentBaseTexture, gl); - } - - // now draw those suckas! - gl.drawElements(gl.TRIANGLES, size * 6, gl.UNSIGNED_SHORT, startIndex * 6 * 2); - // increment the draw count this.renderSession.drawCount++; }; diff --git a/src/pixi/renderers/canvas/CanvasRenderer.js b/src/pixi/renderers/canvas/CanvasRenderer.js index f966118..b9ce76e 100644 --- a/src/pixi/renderers/canvas/CanvasRenderer.js +++ b/src/pixi/renderers/canvas/CanvasRenderer.js @@ -215,11 +215,11 @@ } } - // remove frame updates.. - if(PIXI.Texture.frameUpdates.length > 0) - { - PIXI.Texture.frameUpdates.length = 0; - } + // remove frame updates.. // removeing for now... + //if(PIXI.Texture.frameUpdates.length > 0) + //{ + // PIXI.Texture.frameUpdates.length = 0; + //} }; /** diff --git a/src/pixi/renderers/canvas/utils/CanvasTinter.js b/src/pixi/renderers/canvas/utils/CanvasTinter.js index 8195028..172f344 100644 --- a/src/pixi/renderers/canvas/utils/CanvasTinter.js +++ b/src/pixi/renderers/canvas/utils/CanvasTinter.js @@ -78,38 +78,38 @@ { var context = canvas.getContext( "2d" ); - var frame = texture.frame; + var crop = texture.crop; - canvas.width = frame.width; - canvas.height = frame.height; + canvas.width = crop.width; + canvas.height = crop.height; context.fillStyle = "#" + ("00000" + ( color | 0).toString(16)).substr(-6); - context.fillRect(0, 0, frame.width, frame.height); + context.fillRect(0, 0, crop.width, crop.height); context.globalCompositeOperation = "multiply"; context.drawImage(texture.baseTexture.source, - frame.x, - frame.y, - frame.width, - frame.height, + crop.x, + crop.y, + crop.width, + crop.height, 0, 0, - frame.width, - frame.height); + crop.width, + crop.height); context.globalCompositeOperation = "destination-atop"; - + context.drawImage(texture.baseTexture.source, - frame.x, - frame.y, - frame.width, - frame.height, + crop.x, + crop.y, + crop.width, + crop.height, 0, 0, - frame.width, - frame.height); + crop.width, + crop.height); }; /** @@ -123,27 +123,27 @@ { var context = canvas.getContext( "2d" ); - var frame = texture.frame; + var crop = texture.crop; - canvas.width = frame.width; - canvas.height = frame.height; + canvas.width = crop.width; + canvas.height = crop.height; context.globalCompositeOperation = "copy"; context.fillStyle = "#" + ("00000" + ( color | 0).toString(16)).substr(-6); - context.fillRect(0, 0, frame.width, frame.height); + context.fillRect(0, 0, crop.width, crop.height); context.globalCompositeOperation = "destination-atop"; context.drawImage(texture.baseTexture.source, - frame.x, - frame.y, - frame.width, - frame.height, + crop.x, + crop.y, + crop.width, + crop.height, 0, 0, - frame.width, - frame.height); + crop.width, + crop.height); //context.globalCompositeOperation = "copy"; @@ -161,26 +161,26 @@ { var context = canvas.getContext( "2d" ); - var frame = texture.frame; + var crop = texture.crop; - canvas.width = frame.width; - canvas.height = frame.height; + canvas.width = crop.width; + canvas.height = crop.height; context.globalCompositeOperation = "copy"; context.drawImage(texture.baseTexture.source, - frame.x, - frame.y, - frame.width, - frame.height, + crop.x, + crop.y, + crop.width, + crop.height, 0, 0, - frame.width, - frame.height); + crop.width, + crop.height); var rgbValues = PIXI.hex2rgb(color); var r = rgbValues[0], g = rgbValues[1], b = rgbValues[2]; - var pixelData = context.getImageData(0, 0, frame.width, frame.height); + var pixelData = context.getImageData(0, 0, crop.width, crop.height); var pixels = pixelData.data; diff --git a/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js b/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js old mode 100644 new mode 100755 index 3b12023..ac1aca3 --- a/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js +++ b/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js @@ -78,9 +78,6 @@ this.setContext(gl); this.dirty = true; - - this.textures = []; - this.blendModes = []; }; /** @@ -143,14 +140,15 @@ PIXI.WebGLSpriteBatch.prototype.render = function(sprite) { var texture = sprite.texture; - - //TODO set blend modes.. + + var blendChange = this.renderSession.blendModeManager.currentBlendMode !== sprite.blendMode; + // check texture.. - if(this.currentBatchSize >= this.size) + if(texture.baseTexture !== this.currentBaseTexture || this.currentBatchSize >= this.size || blendChange) { - //return; this.flush(); this.currentBaseTexture = texture.baseTexture; + this.renderSession.blendModeManager.setBlendMode(sprite.blendMode); } // get the uvs for the texture @@ -194,7 +192,7 @@ var index = this.currentBatchSize * 4 * this.vertSize; - var worldTransform = sprite.worldTransform; + var worldTransform = sprite.worldTransform;//.toArray(); var a = worldTransform.a;//[0]; var b = worldTransform.c;//[3]; @@ -244,11 +242,9 @@ verticies[index++] = tint; // increment the batchsize - this.textures[this.currentBatchSize] = sprite.texture.baseTexture; - this.blendModes[this.currentBatchSize] = sprite.blendMode; - this.currentBatchSize++; + }; /** @@ -261,13 +257,14 @@ { var texture = tilingSprite.tilingTexture; - + var blendChange = this.renderSession.blendModeManager.currentBlendMode !== tilingSprite.blendMode; + // check texture.. - if(this.currentBatchSize >= this.size) + if(texture.baseTexture !== this.currentBaseTexture || this.currentBatchSize >= this.size || blendChange) { - //return; this.flush(); this.currentBaseTexture = texture.baseTexture; + this.renderSession.blendModeManager.setBlendMode(tilingSprite.blendMode); } // set the textures uvs temporarily @@ -308,8 +305,8 @@ var height = tilingSprite.height; // TODO trim?? - var aX = tilingSprite.anchor.x; - var aY = tilingSprite.anchor.y; + var aX = tilingSprite.anchor.x; // - tilingSprite.texture.trim.x + var aY = tilingSprite.anchor.y; //- tilingSprite.texture.trim.y var w0 = width * (1-aX); var w1 = width * -aX; @@ -338,7 +335,7 @@ verticies[index++] = tint; // xy - verticies[index++] = (a * w0 + c * h1 + tx); + verticies[index++] = a * w0 + c * h1 + tx; verticies[index++] = d * h1 + b * w0 + ty; // uv verticies[index++] = uvs.x1; @@ -368,8 +365,6 @@ verticies[index++] = tint; // increment the batchs - this.textures[this.currentBatchSize] = texture.baseTexture; - this.blendModes[this.currentBatchSize] = tilingSprite.blendMode; this.currentBatchSize++; }; @@ -386,9 +381,10 @@ if (this.currentBatchSize===0)return; var gl = this.gl; - + this.renderSession.shaderManager.setShader(this.renderSession.shaderManager.defaultShader); + //TODO - im usre this can be done better - will look to tweak this for 1.7.. if(this.dirty) { this.dirty = false; @@ -411,6 +407,15 @@ } + // bind the current texture + gl.bindTexture(gl.TEXTURE_2D, this.currentBaseTexture._glTextures[gl.id] || PIXI.createWebGLTexture(this.currentBaseTexture, gl)); + + // check if a texture is dirty.. + if(this.currentBaseTexture._dirty[gl.id]) + { + PIXI.updateWebGLTexture(this.currentBaseTexture, gl); + } + // upload the verts to the buffer if(this.currentBatchSize > ( this.size * 0.5 ) ) { @@ -419,59 +424,19 @@ else { var view = this.vertices.subarray(0, this.currentBatchSize * 4 * this.vertSize); + gl.bufferSubData(gl.ARRAY_BUFFER, 0, view); } - var nextTexture, nextBlendMode; - var batchSize = 0; - var start = 0; - - var currentBaseTexture = null; - var currentBlendMode = this.renderSession.blendModeManager.currentBlendMode; - - for (var i = 0, j = this.currentBatchSize; i < j; i++) { - - nextTexture = this.textures[i]; - nextBlendMode = this.blendModes[i]; - - if(currentBaseTexture !== nextTexture || currentBlendMode !== nextBlendMode) - { - this.renderBatch(currentBaseTexture, batchSize, start); - - start = i; - batchSize = 0; - currentBaseTexture = nextTexture; - currentBlendMode = nextBlendMode; - - this.renderSession.blendModeManager.setBlendMode( currentBlendMode ); - } - - batchSize++; - } - - this.renderBatch(currentBaseTexture, batchSize, start); - + // var view = this.vertices.subarray(0, this.currentBatchSize * 4 * this.vertSize); + //gl.bufferSubData(gl.ARRAY_BUFFER, 0, view); + + // now draw those suckas! + gl.drawElements(gl.TRIANGLES, this.currentBatchSize * 6, gl.UNSIGNED_SHORT, 0); + // then reset the batch! this.currentBatchSize = 0; -}; -PIXI.WebGLSpriteBatch.prototype.renderBatch = function(texture, size, startIndex) -{ - if(size === 0)return; - - var gl = this.gl; - // bind the current texture - gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id] || PIXI.createWebGLTexture(texture, gl)); - - // check if a texture is dirty.. - if(texture._dirty[gl.id]) - { - PIXI.updateWebGLTexture(this.currentBaseTexture, gl); - } - - // now draw those suckas! - gl.drawElements(gl.TRIANGLES, size * 6, gl.UNSIGNED_SHORT, startIndex * 6 * 2); - // increment the draw count this.renderSession.drawCount++; }; diff --git a/src/pixi/textures/RenderTexture.js b/src/pixi/textures/RenderTexture.js index 0b82769..82a37f5 100644 --- a/src/pixi/textures/RenderTexture.js +++ b/src/pixi/textures/RenderTexture.js @@ -196,6 +196,7 @@ //TODO -? create a new one??? dont think so! var originalWorldTransform = displayObject.worldTransform; displayObject.worldTransform = PIXI.RenderTexture.tempMatrix; + displayObject.worldAlpha = 1; // modify to flip... displayObject.worldTransform.d = -1; displayObject.worldTransform.ty = this.projection.y * -2;