diff --git a/bin/pixi.dev.js b/bin/pixi.dev.js index 4dc8dd9..47d0e28 100644 --- a/bin/pixi.dev.js +++ b/bin/pixi.dev.js @@ -4,7 +4,7 @@ * Copyright (c) 2012-2014, Mat Groves * http://goodboydigital.com/ * - * Compiled: 2014-02-15 + * Compiled: 2014-02-17 * * pixi.js is licensed under the MIT License. * http://www.opensource.org/licenses/mit-license.php @@ -742,6 +742,8 @@ */ this._mask = null; + this._cacheAsBitmap = false; + this._cacheIsDirty = false; /* * MOUSE Callbacks */ @@ -927,6 +929,28 @@ } }); +Object.defineProperty(PIXI.DisplayObject.prototype, 'cacheAsBitmap', { + get: function() { + return this._cacheAsBitmap; + }, + set: function(value) { + + if(this._cacheAsBitmap === value)return; + + if(value) + { + //this._cacheIsDirty = true; + this._generateCachedSprite(); + } + else + { + this._destroyCachedSprite(); + } + + this._cacheAsBitmap = value; + } +}); + /* * Updates the object transform for rendering * @@ -947,6 +971,7 @@ // var localTransform = this.localTransform//.toArray(); var parentTransform = this.parent.worldTransform;//.toArray(); var worldTransform = this.worldTransform;//.toArray(); + var px = this.pivot.x; var py = this.pivot.y; @@ -990,11 +1015,10 @@ */ PIXI.DisplayObject.prototype.getLocalBounds = function() { - //var matrixCache = this.worldTransform; - return this.getBounds(PIXI.identityMatrix);///PIXI.EmptyRectangle(); }; + /** * Sets the object's stage reference, the stage this object is connected to * @@ -1007,6 +1031,59 @@ if(this._interactive)this.stage.dirty = true; }; +PIXI.DisplayObject.prototype.generateTexture = function(renderer) +{ + var bounds = this.getLocalBounds(); + + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0, renderer); + renderTexture.render(this); + + return renderTexture; +}; + +PIXI.DisplayObject.prototype._renderCachedSprite = function(renderSession) +{ + // console.log(this._cacheIsDirty) + /* if(this._cacheIsDirty) + { + //this._generateCachedSprite(renderSession) + //this._cacheIsDirty = false;a + }*/ + + if(renderSession.gl) + { + PIXI.Sprite.prototype._renderWebGL.call(this._cachedSprite, renderSession); + } + else + { + PIXI.Sprite.prototype._renderCanvas.call(this._cachedSprite, renderSession); + } +}; + +PIXI.DisplayObject.prototype._generateCachedSprite = function()//renderSession) +{ + this._cacheAsBitmap = false; + var bounds = this.getLocalBounds(); + + if(!this._cachedSprite) + { + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0);//, renderSession.renderer); + + this._cachedSprite = new PIXI.Sprite(renderTexture); + this._cachedSprite.worldTransform = this.worldTransform; + } + else + { + this._cachedSprite.texture.resize(bounds.width | 0, bounds.height | 0); + } + + + this._cachedSprite.texture.render(this); + + + this._cacheAsBitmap = true; +}; + /** * Renders the object using the WebGL renderer * @@ -1014,6 +1091,18 @@ * @param renderSession {RenderSession} * @private */ +PIXI.DisplayObject.prototype._destroyCachedSprite = function() +{ + if(!this._cachedSprite)return; + + this._cachedSprite.texture.destroy(true); + // console.log("DESTROY") + // let the gc collect the unused sprite + // TODO could be object pooled! + this._cachedSprite = null; +}; + + PIXI.DisplayObject.prototype._renderWebGL = function(renderSession) { // OVERWRITE; @@ -1272,6 +1361,8 @@ PIXI.DisplayObject.prototype.updateTransform.call( this ); + if(this._cacheAsBitmap)return; + for(var i=0,j=this.children.length; i= this.size) + if(texture.baseTexture !== this.currentBaseTexture || this.currentBatchSize >= this.size) { this.flush(); - this.currentBaseTexture = sprite.texture.baseTexture; + this.currentBaseTexture = texture.baseTexture; } @@ -6507,8 +6624,6 @@ var verticies = this.vertices; - var width = sprite.texture.frame.width; - var height = sprite.texture.frame.height; // TODO trim?? var aX = sprite.anchor.x; @@ -6526,14 +6641,15 @@ h1 = trim.y - aY * trim.height; h0 = h1 + height; + } else { - w0 = (width ) * (1-aX); - w1 = (width ) * -aX; + w0 = (texture.frame.width ) * (1-aX); + w1 = (texture.frame.width ) * -aX; - h0 = height * (1-aY); - h1 = height * -aY; + h0 = texture.frame.height * (1-aY); + h1 = texture.frame.height * -aY; } var index = this.currentBatchSize * 4 * this.vertSize; @@ -7236,7 +7352,7 @@ this.defaultShader = renderSession.shaderManager.defaultShader; var projection = this.renderSession.projection; - + // console.log(this.width) this.width = projection.x * 2; this.height = -projection.y * 2; this.buffer = buffer; @@ -7362,6 +7478,7 @@ var inputTexture = texture; var outputTexture = this.texturePool.pop(); if(!outputTexture)outputTexture = new PIXI.FilterTexture(this.gl, this.width, this.height); + outputTexture.resize(this.width, this.height); // need to clear this FBO as it may have some left over elements from a previous filter. gl.bindFramebuffer(gl.FRAMEBUFFER, outputTexture.frameBuffer ); @@ -7412,7 +7529,7 @@ // time to render the filters texture to the previous scene if(this.filterStack.length === 0) { - gl.colorMask(true, true, true, this.transparent); + gl.colorMask(true, true, true, true);//this.transparent); } else { @@ -7469,7 +7586,12 @@ gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.uvArray); + //console.log(this.vertexArray) + //console.log(this.uvArray) + //console.log(sizeX + " : " + sizeY) + gl.viewport(0, 0, sizeX, sizeY); + // bind the buffer gl.bindFramebuffer(gl.FRAMEBUFFER, buffer ); @@ -7533,6 +7655,7 @@ filter.uniforms.dimensions.value[3] = this.vertexArray[5];//filterArea.height; } + // console.log(this.uvArray ) shader.syncUniforms(); gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); @@ -7638,6 +7761,7 @@ gl.deleteBuffer(this.colorBuffer); gl.deleteBuffer(this.indexBuffer); }; + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -11606,6 +11730,12 @@ */ this.source = source; + //TODO will be used for futer pixi 1.5... + this.id = PIXI.BaseTextureCacheIdGenerator++; + + // used for webGL + this._glTextures = []; + if(!source)return; if(this.source.complete || this.source.getContext) @@ -11635,11 +11765,7 @@ this.imageUrl = null; this._powerOf2 = false; - //TODO will be used for futer pixi 1.5... - this.id = PIXI.BaseTextureCacheIdGenerator++; - - // used for webGL - this._glTextures = []; + }; @@ -12175,6 +12301,8 @@ { var children = displayObject.children; + var originalWorldTransform = displayObject.worldTransform; + displayObject.worldTransform = PIXI.RenderTexture.tempMatrix; if(position) @@ -12195,9 +12323,13 @@ this.renderer.renderDisplayObject(displayObject, context); context.setTransform(1,0,0,1,0,0); + + displayObject.worldTransform = originalWorldTransform; }; PIXI.RenderTexture.tempMatrix = new PIXI.Matrix(); + + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ diff --git a/bin/pixi.dev.js b/bin/pixi.dev.js index 4dc8dd9..47d0e28 100644 --- a/bin/pixi.dev.js +++ b/bin/pixi.dev.js @@ -4,7 +4,7 @@ * Copyright (c) 2012-2014, Mat Groves * http://goodboydigital.com/ * - * Compiled: 2014-02-15 + * Compiled: 2014-02-17 * * pixi.js is licensed under the MIT License. * http://www.opensource.org/licenses/mit-license.php @@ -742,6 +742,8 @@ */ this._mask = null; + this._cacheAsBitmap = false; + this._cacheIsDirty = false; /* * MOUSE Callbacks */ @@ -927,6 +929,28 @@ } }); +Object.defineProperty(PIXI.DisplayObject.prototype, 'cacheAsBitmap', { + get: function() { + return this._cacheAsBitmap; + }, + set: function(value) { + + if(this._cacheAsBitmap === value)return; + + if(value) + { + //this._cacheIsDirty = true; + this._generateCachedSprite(); + } + else + { + this._destroyCachedSprite(); + } + + this._cacheAsBitmap = value; + } +}); + /* * Updates the object transform for rendering * @@ -947,6 +971,7 @@ // var localTransform = this.localTransform//.toArray(); var parentTransform = this.parent.worldTransform;//.toArray(); var worldTransform = this.worldTransform;//.toArray(); + var px = this.pivot.x; var py = this.pivot.y; @@ -990,11 +1015,10 @@ */ PIXI.DisplayObject.prototype.getLocalBounds = function() { - //var matrixCache = this.worldTransform; - return this.getBounds(PIXI.identityMatrix);///PIXI.EmptyRectangle(); }; + /** * Sets the object's stage reference, the stage this object is connected to * @@ -1007,6 +1031,59 @@ if(this._interactive)this.stage.dirty = true; }; +PIXI.DisplayObject.prototype.generateTexture = function(renderer) +{ + var bounds = this.getLocalBounds(); + + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0, renderer); + renderTexture.render(this); + + return renderTexture; +}; + +PIXI.DisplayObject.prototype._renderCachedSprite = function(renderSession) +{ + // console.log(this._cacheIsDirty) + /* if(this._cacheIsDirty) + { + //this._generateCachedSprite(renderSession) + //this._cacheIsDirty = false;a + }*/ + + if(renderSession.gl) + { + PIXI.Sprite.prototype._renderWebGL.call(this._cachedSprite, renderSession); + } + else + { + PIXI.Sprite.prototype._renderCanvas.call(this._cachedSprite, renderSession); + } +}; + +PIXI.DisplayObject.prototype._generateCachedSprite = function()//renderSession) +{ + this._cacheAsBitmap = false; + var bounds = this.getLocalBounds(); + + if(!this._cachedSprite) + { + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0);//, renderSession.renderer); + + this._cachedSprite = new PIXI.Sprite(renderTexture); + this._cachedSprite.worldTransform = this.worldTransform; + } + else + { + this._cachedSprite.texture.resize(bounds.width | 0, bounds.height | 0); + } + + + this._cachedSprite.texture.render(this); + + + this._cacheAsBitmap = true; +}; + /** * Renders the object using the WebGL renderer * @@ -1014,6 +1091,18 @@ * @param renderSession {RenderSession} * @private */ +PIXI.DisplayObject.prototype._destroyCachedSprite = function() +{ + if(!this._cachedSprite)return; + + this._cachedSprite.texture.destroy(true); + // console.log("DESTROY") + // let the gc collect the unused sprite + // TODO could be object pooled! + this._cachedSprite = null; +}; + + PIXI.DisplayObject.prototype._renderWebGL = function(renderSession) { // OVERWRITE; @@ -1272,6 +1361,8 @@ PIXI.DisplayObject.prototype.updateTransform.call( this ); + if(this._cacheAsBitmap)return; + for(var i=0,j=this.children.length; i= this.size) + if(texture.baseTexture !== this.currentBaseTexture || this.currentBatchSize >= this.size) { this.flush(); - this.currentBaseTexture = sprite.texture.baseTexture; + this.currentBaseTexture = texture.baseTexture; } @@ -6507,8 +6624,6 @@ var verticies = this.vertices; - var width = sprite.texture.frame.width; - var height = sprite.texture.frame.height; // TODO trim?? var aX = sprite.anchor.x; @@ -6526,14 +6641,15 @@ h1 = trim.y - aY * trim.height; h0 = h1 + height; + } else { - w0 = (width ) * (1-aX); - w1 = (width ) * -aX; + w0 = (texture.frame.width ) * (1-aX); + w1 = (texture.frame.width ) * -aX; - h0 = height * (1-aY); - h1 = height * -aY; + h0 = texture.frame.height * (1-aY); + h1 = texture.frame.height * -aY; } var index = this.currentBatchSize * 4 * this.vertSize; @@ -7236,7 +7352,7 @@ this.defaultShader = renderSession.shaderManager.defaultShader; var projection = this.renderSession.projection; - + // console.log(this.width) this.width = projection.x * 2; this.height = -projection.y * 2; this.buffer = buffer; @@ -7362,6 +7478,7 @@ var inputTexture = texture; var outputTexture = this.texturePool.pop(); if(!outputTexture)outputTexture = new PIXI.FilterTexture(this.gl, this.width, this.height); + outputTexture.resize(this.width, this.height); // need to clear this FBO as it may have some left over elements from a previous filter. gl.bindFramebuffer(gl.FRAMEBUFFER, outputTexture.frameBuffer ); @@ -7412,7 +7529,7 @@ // time to render the filters texture to the previous scene if(this.filterStack.length === 0) { - gl.colorMask(true, true, true, this.transparent); + gl.colorMask(true, true, true, true);//this.transparent); } else { @@ -7469,7 +7586,12 @@ gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.uvArray); + //console.log(this.vertexArray) + //console.log(this.uvArray) + //console.log(sizeX + " : " + sizeY) + gl.viewport(0, 0, sizeX, sizeY); + // bind the buffer gl.bindFramebuffer(gl.FRAMEBUFFER, buffer ); @@ -7533,6 +7655,7 @@ filter.uniforms.dimensions.value[3] = this.vertexArray[5];//filterArea.height; } + // console.log(this.uvArray ) shader.syncUniforms(); gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); @@ -7638,6 +7761,7 @@ gl.deleteBuffer(this.colorBuffer); gl.deleteBuffer(this.indexBuffer); }; + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -11606,6 +11730,12 @@ */ this.source = source; + //TODO will be used for futer pixi 1.5... + this.id = PIXI.BaseTextureCacheIdGenerator++; + + // used for webGL + this._glTextures = []; + if(!source)return; if(this.source.complete || this.source.getContext) @@ -11635,11 +11765,7 @@ this.imageUrl = null; this._powerOf2 = false; - //TODO will be used for futer pixi 1.5... - this.id = PIXI.BaseTextureCacheIdGenerator++; - - // used for webGL - this._glTextures = []; + }; @@ -12175,6 +12301,8 @@ { var children = displayObject.children; + var originalWorldTransform = displayObject.worldTransform; + displayObject.worldTransform = PIXI.RenderTexture.tempMatrix; if(position) @@ -12195,9 +12323,13 @@ this.renderer.renderDisplayObject(displayObject, context); context.setTransform(1,0,0,1,0,0); + + displayObject.worldTransform = originalWorldTransform; }; PIXI.RenderTexture.tempMatrix = new PIXI.Matrix(); + + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ diff --git a/src/pixi/InteractionManager.js b/src/pixi/InteractionManager.js index b80f144..8153beb 100644 --- a/src/pixi/InteractionManager.js +++ b/src/pixi/InteractionManager.js @@ -124,7 +124,7 @@ var child = children[i]; // push all interactive bits - if(child.interactive) + if(child._interactive) { iParent.interactiveChildren = true; //child.__iParent = iParent; diff --git a/bin/pixi.dev.js b/bin/pixi.dev.js index 4dc8dd9..47d0e28 100644 --- a/bin/pixi.dev.js +++ b/bin/pixi.dev.js @@ -4,7 +4,7 @@ * Copyright (c) 2012-2014, Mat Groves * http://goodboydigital.com/ * - * Compiled: 2014-02-15 + * Compiled: 2014-02-17 * * pixi.js is licensed under the MIT License. * http://www.opensource.org/licenses/mit-license.php @@ -742,6 +742,8 @@ */ this._mask = null; + this._cacheAsBitmap = false; + this._cacheIsDirty = false; /* * MOUSE Callbacks */ @@ -927,6 +929,28 @@ } }); +Object.defineProperty(PIXI.DisplayObject.prototype, 'cacheAsBitmap', { + get: function() { + return this._cacheAsBitmap; + }, + set: function(value) { + + if(this._cacheAsBitmap === value)return; + + if(value) + { + //this._cacheIsDirty = true; + this._generateCachedSprite(); + } + else + { + this._destroyCachedSprite(); + } + + this._cacheAsBitmap = value; + } +}); + /* * Updates the object transform for rendering * @@ -947,6 +971,7 @@ // var localTransform = this.localTransform//.toArray(); var parentTransform = this.parent.worldTransform;//.toArray(); var worldTransform = this.worldTransform;//.toArray(); + var px = this.pivot.x; var py = this.pivot.y; @@ -990,11 +1015,10 @@ */ PIXI.DisplayObject.prototype.getLocalBounds = function() { - //var matrixCache = this.worldTransform; - return this.getBounds(PIXI.identityMatrix);///PIXI.EmptyRectangle(); }; + /** * Sets the object's stage reference, the stage this object is connected to * @@ -1007,6 +1031,59 @@ if(this._interactive)this.stage.dirty = true; }; +PIXI.DisplayObject.prototype.generateTexture = function(renderer) +{ + var bounds = this.getLocalBounds(); + + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0, renderer); + renderTexture.render(this); + + return renderTexture; +}; + +PIXI.DisplayObject.prototype._renderCachedSprite = function(renderSession) +{ + // console.log(this._cacheIsDirty) + /* if(this._cacheIsDirty) + { + //this._generateCachedSprite(renderSession) + //this._cacheIsDirty = false;a + }*/ + + if(renderSession.gl) + { + PIXI.Sprite.prototype._renderWebGL.call(this._cachedSprite, renderSession); + } + else + { + PIXI.Sprite.prototype._renderCanvas.call(this._cachedSprite, renderSession); + } +}; + +PIXI.DisplayObject.prototype._generateCachedSprite = function()//renderSession) +{ + this._cacheAsBitmap = false; + var bounds = this.getLocalBounds(); + + if(!this._cachedSprite) + { + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0);//, renderSession.renderer); + + this._cachedSprite = new PIXI.Sprite(renderTexture); + this._cachedSprite.worldTransform = this.worldTransform; + } + else + { + this._cachedSprite.texture.resize(bounds.width | 0, bounds.height | 0); + } + + + this._cachedSprite.texture.render(this); + + + this._cacheAsBitmap = true; +}; + /** * Renders the object using the WebGL renderer * @@ -1014,6 +1091,18 @@ * @param renderSession {RenderSession} * @private */ +PIXI.DisplayObject.prototype._destroyCachedSprite = function() +{ + if(!this._cachedSprite)return; + + this._cachedSprite.texture.destroy(true); + // console.log("DESTROY") + // let the gc collect the unused sprite + // TODO could be object pooled! + this._cachedSprite = null; +}; + + PIXI.DisplayObject.prototype._renderWebGL = function(renderSession) { // OVERWRITE; @@ -1272,6 +1361,8 @@ PIXI.DisplayObject.prototype.updateTransform.call( this ); + if(this._cacheAsBitmap)return; + for(var i=0,j=this.children.length; i= this.size) + if(texture.baseTexture !== this.currentBaseTexture || this.currentBatchSize >= this.size) { this.flush(); - this.currentBaseTexture = sprite.texture.baseTexture; + this.currentBaseTexture = texture.baseTexture; } @@ -6507,8 +6624,6 @@ var verticies = this.vertices; - var width = sprite.texture.frame.width; - var height = sprite.texture.frame.height; // TODO trim?? var aX = sprite.anchor.x; @@ -6526,14 +6641,15 @@ h1 = trim.y - aY * trim.height; h0 = h1 + height; + } else { - w0 = (width ) * (1-aX); - w1 = (width ) * -aX; + w0 = (texture.frame.width ) * (1-aX); + w1 = (texture.frame.width ) * -aX; - h0 = height * (1-aY); - h1 = height * -aY; + h0 = texture.frame.height * (1-aY); + h1 = texture.frame.height * -aY; } var index = this.currentBatchSize * 4 * this.vertSize; @@ -7236,7 +7352,7 @@ this.defaultShader = renderSession.shaderManager.defaultShader; var projection = this.renderSession.projection; - + // console.log(this.width) this.width = projection.x * 2; this.height = -projection.y * 2; this.buffer = buffer; @@ -7362,6 +7478,7 @@ var inputTexture = texture; var outputTexture = this.texturePool.pop(); if(!outputTexture)outputTexture = new PIXI.FilterTexture(this.gl, this.width, this.height); + outputTexture.resize(this.width, this.height); // need to clear this FBO as it may have some left over elements from a previous filter. gl.bindFramebuffer(gl.FRAMEBUFFER, outputTexture.frameBuffer ); @@ -7412,7 +7529,7 @@ // time to render the filters texture to the previous scene if(this.filterStack.length === 0) { - gl.colorMask(true, true, true, this.transparent); + gl.colorMask(true, true, true, true);//this.transparent); } else { @@ -7469,7 +7586,12 @@ gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.uvArray); + //console.log(this.vertexArray) + //console.log(this.uvArray) + //console.log(sizeX + " : " + sizeY) + gl.viewport(0, 0, sizeX, sizeY); + // bind the buffer gl.bindFramebuffer(gl.FRAMEBUFFER, buffer ); @@ -7533,6 +7655,7 @@ filter.uniforms.dimensions.value[3] = this.vertexArray[5];//filterArea.height; } + // console.log(this.uvArray ) shader.syncUniforms(); gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); @@ -7638,6 +7761,7 @@ gl.deleteBuffer(this.colorBuffer); gl.deleteBuffer(this.indexBuffer); }; + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -11606,6 +11730,12 @@ */ this.source = source; + //TODO will be used for futer pixi 1.5... + this.id = PIXI.BaseTextureCacheIdGenerator++; + + // used for webGL + this._glTextures = []; + if(!source)return; if(this.source.complete || this.source.getContext) @@ -11635,11 +11765,7 @@ this.imageUrl = null; this._powerOf2 = false; - //TODO will be used for futer pixi 1.5... - this.id = PIXI.BaseTextureCacheIdGenerator++; - - // used for webGL - this._glTextures = []; + }; @@ -12175,6 +12301,8 @@ { var children = displayObject.children; + var originalWorldTransform = displayObject.worldTransform; + displayObject.worldTransform = PIXI.RenderTexture.tempMatrix; if(position) @@ -12195,9 +12323,13 @@ this.renderer.renderDisplayObject(displayObject, context); context.setTransform(1,0,0,1,0,0); + + displayObject.worldTransform = originalWorldTransform; }; PIXI.RenderTexture.tempMatrix = new PIXI.Matrix(); + + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ diff --git a/src/pixi/InteractionManager.js b/src/pixi/InteractionManager.js index b80f144..8153beb 100644 --- a/src/pixi/InteractionManager.js +++ b/src/pixi/InteractionManager.js @@ -124,7 +124,7 @@ var child = children[i]; // push all interactive bits - if(child.interactive) + if(child._interactive) { iParent.interactiveChildren = true; //child.__iParent = iParent; diff --git a/src/pixi/display/DisplayObject.js b/src/pixi/display/DisplayObject.js index 6d8739e..2491904 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -194,6 +194,8 @@ */ this._mask = null; + this._cacheAsBitmap = false; + this._cacheIsDirty = false; /* * MOUSE Callbacks */ @@ -379,6 +381,28 @@ } }); +Object.defineProperty(PIXI.DisplayObject.prototype, 'cacheAsBitmap', { + get: function() { + return this._cacheAsBitmap; + }, + set: function(value) { + + if(this._cacheAsBitmap === value)return; + + if(value) + { + //this._cacheIsDirty = true; + this._generateCachedSprite(); + } + else + { + this._destroyCachedSprite(); + } + + this._cacheAsBitmap = value; + } +}); + /* * Updates the object transform for rendering * @@ -399,6 +423,7 @@ // var localTransform = this.localTransform//.toArray(); var parentTransform = this.parent.worldTransform;//.toArray(); var worldTransform = this.worldTransform;//.toArray(); + var px = this.pivot.x; var py = this.pivot.y; @@ -442,11 +467,10 @@ */ PIXI.DisplayObject.prototype.getLocalBounds = function() { - //var matrixCache = this.worldTransform; - return this.getBounds(PIXI.identityMatrix);///PIXI.EmptyRectangle(); }; + /** * Sets the object's stage reference, the stage this object is connected to * @@ -459,6 +483,59 @@ if(this._interactive)this.stage.dirty = true; }; +PIXI.DisplayObject.prototype.generateTexture = function(renderer) +{ + var bounds = this.getLocalBounds(); + + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0, renderer); + renderTexture.render(this); + + return renderTexture; +}; + +PIXI.DisplayObject.prototype._renderCachedSprite = function(renderSession) +{ + // console.log(this._cacheIsDirty) + /* if(this._cacheIsDirty) + { + //this._generateCachedSprite(renderSession) + //this._cacheIsDirty = false;a + }*/ + + if(renderSession.gl) + { + PIXI.Sprite.prototype._renderWebGL.call(this._cachedSprite, renderSession); + } + else + { + PIXI.Sprite.prototype._renderCanvas.call(this._cachedSprite, renderSession); + } +}; + +PIXI.DisplayObject.prototype._generateCachedSprite = function()//renderSession) +{ + this._cacheAsBitmap = false; + var bounds = this.getLocalBounds(); + + if(!this._cachedSprite) + { + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0);//, renderSession.renderer); + + this._cachedSprite = new PIXI.Sprite(renderTexture); + this._cachedSprite.worldTransform = this.worldTransform; + } + else + { + this._cachedSprite.texture.resize(bounds.width | 0, bounds.height | 0); + } + + + this._cachedSprite.texture.render(this); + + + this._cacheAsBitmap = true; +}; + /** * Renders the object using the WebGL renderer * @@ -466,6 +543,18 @@ * @param renderSession {RenderSession} * @private */ +PIXI.DisplayObject.prototype._destroyCachedSprite = function() +{ + if(!this._cachedSprite)return; + + this._cachedSprite.texture.destroy(true); + // console.log("DESTROY") + // let the gc collect the unused sprite + // TODO could be object pooled! + this._cachedSprite = null; +}; + + PIXI.DisplayObject.prototype._renderWebGL = function(renderSession) { // OVERWRITE; diff --git a/bin/pixi.dev.js b/bin/pixi.dev.js index 4dc8dd9..47d0e28 100644 --- a/bin/pixi.dev.js +++ b/bin/pixi.dev.js @@ -4,7 +4,7 @@ * Copyright (c) 2012-2014, Mat Groves * http://goodboydigital.com/ * - * Compiled: 2014-02-15 + * Compiled: 2014-02-17 * * pixi.js is licensed under the MIT License. * http://www.opensource.org/licenses/mit-license.php @@ -742,6 +742,8 @@ */ this._mask = null; + this._cacheAsBitmap = false; + this._cacheIsDirty = false; /* * MOUSE Callbacks */ @@ -927,6 +929,28 @@ } }); +Object.defineProperty(PIXI.DisplayObject.prototype, 'cacheAsBitmap', { + get: function() { + return this._cacheAsBitmap; + }, + set: function(value) { + + if(this._cacheAsBitmap === value)return; + + if(value) + { + //this._cacheIsDirty = true; + this._generateCachedSprite(); + } + else + { + this._destroyCachedSprite(); + } + + this._cacheAsBitmap = value; + } +}); + /* * Updates the object transform for rendering * @@ -947,6 +971,7 @@ // var localTransform = this.localTransform//.toArray(); var parentTransform = this.parent.worldTransform;//.toArray(); var worldTransform = this.worldTransform;//.toArray(); + var px = this.pivot.x; var py = this.pivot.y; @@ -990,11 +1015,10 @@ */ PIXI.DisplayObject.prototype.getLocalBounds = function() { - //var matrixCache = this.worldTransform; - return this.getBounds(PIXI.identityMatrix);///PIXI.EmptyRectangle(); }; + /** * Sets the object's stage reference, the stage this object is connected to * @@ -1007,6 +1031,59 @@ if(this._interactive)this.stage.dirty = true; }; +PIXI.DisplayObject.prototype.generateTexture = function(renderer) +{ + var bounds = this.getLocalBounds(); + + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0, renderer); + renderTexture.render(this); + + return renderTexture; +}; + +PIXI.DisplayObject.prototype._renderCachedSprite = function(renderSession) +{ + // console.log(this._cacheIsDirty) + /* if(this._cacheIsDirty) + { + //this._generateCachedSprite(renderSession) + //this._cacheIsDirty = false;a + }*/ + + if(renderSession.gl) + { + PIXI.Sprite.prototype._renderWebGL.call(this._cachedSprite, renderSession); + } + else + { + PIXI.Sprite.prototype._renderCanvas.call(this._cachedSprite, renderSession); + } +}; + +PIXI.DisplayObject.prototype._generateCachedSprite = function()//renderSession) +{ + this._cacheAsBitmap = false; + var bounds = this.getLocalBounds(); + + if(!this._cachedSprite) + { + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0);//, renderSession.renderer); + + this._cachedSprite = new PIXI.Sprite(renderTexture); + this._cachedSprite.worldTransform = this.worldTransform; + } + else + { + this._cachedSprite.texture.resize(bounds.width | 0, bounds.height | 0); + } + + + this._cachedSprite.texture.render(this); + + + this._cacheAsBitmap = true; +}; + /** * Renders the object using the WebGL renderer * @@ -1014,6 +1091,18 @@ * @param renderSession {RenderSession} * @private */ +PIXI.DisplayObject.prototype._destroyCachedSprite = function() +{ + if(!this._cachedSprite)return; + + this._cachedSprite.texture.destroy(true); + // console.log("DESTROY") + // let the gc collect the unused sprite + // TODO could be object pooled! + this._cachedSprite = null; +}; + + PIXI.DisplayObject.prototype._renderWebGL = function(renderSession) { // OVERWRITE; @@ -1272,6 +1361,8 @@ PIXI.DisplayObject.prototype.updateTransform.call( this ); + if(this._cacheAsBitmap)return; + for(var i=0,j=this.children.length; i= this.size) + if(texture.baseTexture !== this.currentBaseTexture || this.currentBatchSize >= this.size) { this.flush(); - this.currentBaseTexture = sprite.texture.baseTexture; + this.currentBaseTexture = texture.baseTexture; } @@ -6507,8 +6624,6 @@ var verticies = this.vertices; - var width = sprite.texture.frame.width; - var height = sprite.texture.frame.height; // TODO trim?? var aX = sprite.anchor.x; @@ -6526,14 +6641,15 @@ h1 = trim.y - aY * trim.height; h0 = h1 + height; + } else { - w0 = (width ) * (1-aX); - w1 = (width ) * -aX; + w0 = (texture.frame.width ) * (1-aX); + w1 = (texture.frame.width ) * -aX; - h0 = height * (1-aY); - h1 = height * -aY; + h0 = texture.frame.height * (1-aY); + h1 = texture.frame.height * -aY; } var index = this.currentBatchSize * 4 * this.vertSize; @@ -7236,7 +7352,7 @@ this.defaultShader = renderSession.shaderManager.defaultShader; var projection = this.renderSession.projection; - + // console.log(this.width) this.width = projection.x * 2; this.height = -projection.y * 2; this.buffer = buffer; @@ -7362,6 +7478,7 @@ var inputTexture = texture; var outputTexture = this.texturePool.pop(); if(!outputTexture)outputTexture = new PIXI.FilterTexture(this.gl, this.width, this.height); + outputTexture.resize(this.width, this.height); // need to clear this FBO as it may have some left over elements from a previous filter. gl.bindFramebuffer(gl.FRAMEBUFFER, outputTexture.frameBuffer ); @@ -7412,7 +7529,7 @@ // time to render the filters texture to the previous scene if(this.filterStack.length === 0) { - gl.colorMask(true, true, true, this.transparent); + gl.colorMask(true, true, true, true);//this.transparent); } else { @@ -7469,7 +7586,12 @@ gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.uvArray); + //console.log(this.vertexArray) + //console.log(this.uvArray) + //console.log(sizeX + " : " + sizeY) + gl.viewport(0, 0, sizeX, sizeY); + // bind the buffer gl.bindFramebuffer(gl.FRAMEBUFFER, buffer ); @@ -7533,6 +7655,7 @@ filter.uniforms.dimensions.value[3] = this.vertexArray[5];//filterArea.height; } + // console.log(this.uvArray ) shader.syncUniforms(); gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); @@ -7638,6 +7761,7 @@ gl.deleteBuffer(this.colorBuffer); gl.deleteBuffer(this.indexBuffer); }; + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -11606,6 +11730,12 @@ */ this.source = source; + //TODO will be used for futer pixi 1.5... + this.id = PIXI.BaseTextureCacheIdGenerator++; + + // used for webGL + this._glTextures = []; + if(!source)return; if(this.source.complete || this.source.getContext) @@ -11635,11 +11765,7 @@ this.imageUrl = null; this._powerOf2 = false; - //TODO will be used for futer pixi 1.5... - this.id = PIXI.BaseTextureCacheIdGenerator++; - - // used for webGL - this._glTextures = []; + }; @@ -12175,6 +12301,8 @@ { var children = displayObject.children; + var originalWorldTransform = displayObject.worldTransform; + displayObject.worldTransform = PIXI.RenderTexture.tempMatrix; if(position) @@ -12195,9 +12323,13 @@ this.renderer.renderDisplayObject(displayObject, context); context.setTransform(1,0,0,1,0,0); + + displayObject.worldTransform = originalWorldTransform; }; PIXI.RenderTexture.tempMatrix = new PIXI.Matrix(); + + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ diff --git a/src/pixi/InteractionManager.js b/src/pixi/InteractionManager.js index b80f144..8153beb 100644 --- a/src/pixi/InteractionManager.js +++ b/src/pixi/InteractionManager.js @@ -124,7 +124,7 @@ var child = children[i]; // push all interactive bits - if(child.interactive) + if(child._interactive) { iParent.interactiveChildren = true; //child.__iParent = iParent; diff --git a/src/pixi/display/DisplayObject.js b/src/pixi/display/DisplayObject.js index 6d8739e..2491904 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -194,6 +194,8 @@ */ this._mask = null; + this._cacheAsBitmap = false; + this._cacheIsDirty = false; /* * MOUSE Callbacks */ @@ -379,6 +381,28 @@ } }); +Object.defineProperty(PIXI.DisplayObject.prototype, 'cacheAsBitmap', { + get: function() { + return this._cacheAsBitmap; + }, + set: function(value) { + + if(this._cacheAsBitmap === value)return; + + if(value) + { + //this._cacheIsDirty = true; + this._generateCachedSprite(); + } + else + { + this._destroyCachedSprite(); + } + + this._cacheAsBitmap = value; + } +}); + /* * Updates the object transform for rendering * @@ -399,6 +423,7 @@ // var localTransform = this.localTransform//.toArray(); var parentTransform = this.parent.worldTransform;//.toArray(); var worldTransform = this.worldTransform;//.toArray(); + var px = this.pivot.x; var py = this.pivot.y; @@ -442,11 +467,10 @@ */ PIXI.DisplayObject.prototype.getLocalBounds = function() { - //var matrixCache = this.worldTransform; - return this.getBounds(PIXI.identityMatrix);///PIXI.EmptyRectangle(); }; + /** * Sets the object's stage reference, the stage this object is connected to * @@ -459,6 +483,59 @@ if(this._interactive)this.stage.dirty = true; }; +PIXI.DisplayObject.prototype.generateTexture = function(renderer) +{ + var bounds = this.getLocalBounds(); + + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0, renderer); + renderTexture.render(this); + + return renderTexture; +}; + +PIXI.DisplayObject.prototype._renderCachedSprite = function(renderSession) +{ + // console.log(this._cacheIsDirty) + /* if(this._cacheIsDirty) + { + //this._generateCachedSprite(renderSession) + //this._cacheIsDirty = false;a + }*/ + + if(renderSession.gl) + { + PIXI.Sprite.prototype._renderWebGL.call(this._cachedSprite, renderSession); + } + else + { + PIXI.Sprite.prototype._renderCanvas.call(this._cachedSprite, renderSession); + } +}; + +PIXI.DisplayObject.prototype._generateCachedSprite = function()//renderSession) +{ + this._cacheAsBitmap = false; + var bounds = this.getLocalBounds(); + + if(!this._cachedSprite) + { + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0);//, renderSession.renderer); + + this._cachedSprite = new PIXI.Sprite(renderTexture); + this._cachedSprite.worldTransform = this.worldTransform; + } + else + { + this._cachedSprite.texture.resize(bounds.width | 0, bounds.height | 0); + } + + + this._cachedSprite.texture.render(this); + + + this._cacheAsBitmap = true; +}; + /** * Renders the object using the WebGL renderer * @@ -466,6 +543,18 @@ * @param renderSession {RenderSession} * @private */ +PIXI.DisplayObject.prototype._destroyCachedSprite = function() +{ + if(!this._cachedSprite)return; + + this._cachedSprite.texture.destroy(true); + // console.log("DESTROY") + // let the gc collect the unused sprite + // TODO could be object pooled! + this._cachedSprite = null; +}; + + PIXI.DisplayObject.prototype._renderWebGL = function(renderSession) { // OVERWRITE; diff --git a/src/pixi/display/DisplayObjectContainer.js b/src/pixi/display/DisplayObjectContainer.js index d8ad9e9..92ae06e 100644 --- a/src/pixi/display/DisplayObjectContainer.js +++ b/src/pixi/display/DisplayObjectContainer.js @@ -205,6 +205,8 @@ PIXI.DisplayObject.prototype.updateTransform.call( this ); + if(this._cacheAsBitmap)return; + for(var i=0,j=this.children.length; i= this.size) + if(texture.baseTexture !== this.currentBaseTexture || this.currentBatchSize >= this.size) { this.flush(); - this.currentBaseTexture = sprite.texture.baseTexture; + this.currentBaseTexture = texture.baseTexture; } @@ -6507,8 +6624,6 @@ var verticies = this.vertices; - var width = sprite.texture.frame.width; - var height = sprite.texture.frame.height; // TODO trim?? var aX = sprite.anchor.x; @@ -6526,14 +6641,15 @@ h1 = trim.y - aY * trim.height; h0 = h1 + height; + } else { - w0 = (width ) * (1-aX); - w1 = (width ) * -aX; + w0 = (texture.frame.width ) * (1-aX); + w1 = (texture.frame.width ) * -aX; - h0 = height * (1-aY); - h1 = height * -aY; + h0 = texture.frame.height * (1-aY); + h1 = texture.frame.height * -aY; } var index = this.currentBatchSize * 4 * this.vertSize; @@ -7236,7 +7352,7 @@ this.defaultShader = renderSession.shaderManager.defaultShader; var projection = this.renderSession.projection; - + // console.log(this.width) this.width = projection.x * 2; this.height = -projection.y * 2; this.buffer = buffer; @@ -7362,6 +7478,7 @@ var inputTexture = texture; var outputTexture = this.texturePool.pop(); if(!outputTexture)outputTexture = new PIXI.FilterTexture(this.gl, this.width, this.height); + outputTexture.resize(this.width, this.height); // need to clear this FBO as it may have some left over elements from a previous filter. gl.bindFramebuffer(gl.FRAMEBUFFER, outputTexture.frameBuffer ); @@ -7412,7 +7529,7 @@ // time to render the filters texture to the previous scene if(this.filterStack.length === 0) { - gl.colorMask(true, true, true, this.transparent); + gl.colorMask(true, true, true, true);//this.transparent); } else { @@ -7469,7 +7586,12 @@ gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.uvArray); + //console.log(this.vertexArray) + //console.log(this.uvArray) + //console.log(sizeX + " : " + sizeY) + gl.viewport(0, 0, sizeX, sizeY); + // bind the buffer gl.bindFramebuffer(gl.FRAMEBUFFER, buffer ); @@ -7533,6 +7655,7 @@ filter.uniforms.dimensions.value[3] = this.vertexArray[5];//filterArea.height; } + // console.log(this.uvArray ) shader.syncUniforms(); gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); @@ -7638,6 +7761,7 @@ gl.deleteBuffer(this.colorBuffer); gl.deleteBuffer(this.indexBuffer); }; + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -11606,6 +11730,12 @@ */ this.source = source; + //TODO will be used for futer pixi 1.5... + this.id = PIXI.BaseTextureCacheIdGenerator++; + + // used for webGL + this._glTextures = []; + if(!source)return; if(this.source.complete || this.source.getContext) @@ -11635,11 +11765,7 @@ this.imageUrl = null; this._powerOf2 = false; - //TODO will be used for futer pixi 1.5... - this.id = PIXI.BaseTextureCacheIdGenerator++; - - // used for webGL - this._glTextures = []; + }; @@ -12175,6 +12301,8 @@ { var children = displayObject.children; + var originalWorldTransform = displayObject.worldTransform; + displayObject.worldTransform = PIXI.RenderTexture.tempMatrix; if(position) @@ -12195,9 +12323,13 @@ this.renderer.renderDisplayObject(displayObject, context); context.setTransform(1,0,0,1,0,0); + + displayObject.worldTransform = originalWorldTransform; }; PIXI.RenderTexture.tempMatrix = new PIXI.Matrix(); + + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ diff --git a/src/pixi/InteractionManager.js b/src/pixi/InteractionManager.js index b80f144..8153beb 100644 --- a/src/pixi/InteractionManager.js +++ b/src/pixi/InteractionManager.js @@ -124,7 +124,7 @@ var child = children[i]; // push all interactive bits - if(child.interactive) + if(child._interactive) { iParent.interactiveChildren = true; //child.__iParent = iParent; diff --git a/src/pixi/display/DisplayObject.js b/src/pixi/display/DisplayObject.js index 6d8739e..2491904 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -194,6 +194,8 @@ */ this._mask = null; + this._cacheAsBitmap = false; + this._cacheIsDirty = false; /* * MOUSE Callbacks */ @@ -379,6 +381,28 @@ } }); +Object.defineProperty(PIXI.DisplayObject.prototype, 'cacheAsBitmap', { + get: function() { + return this._cacheAsBitmap; + }, + set: function(value) { + + if(this._cacheAsBitmap === value)return; + + if(value) + { + //this._cacheIsDirty = true; + this._generateCachedSprite(); + } + else + { + this._destroyCachedSprite(); + } + + this._cacheAsBitmap = value; + } +}); + /* * Updates the object transform for rendering * @@ -399,6 +423,7 @@ // var localTransform = this.localTransform//.toArray(); var parentTransform = this.parent.worldTransform;//.toArray(); var worldTransform = this.worldTransform;//.toArray(); + var px = this.pivot.x; var py = this.pivot.y; @@ -442,11 +467,10 @@ */ PIXI.DisplayObject.prototype.getLocalBounds = function() { - //var matrixCache = this.worldTransform; - return this.getBounds(PIXI.identityMatrix);///PIXI.EmptyRectangle(); }; + /** * Sets the object's stage reference, the stage this object is connected to * @@ -459,6 +483,59 @@ if(this._interactive)this.stage.dirty = true; }; +PIXI.DisplayObject.prototype.generateTexture = function(renderer) +{ + var bounds = this.getLocalBounds(); + + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0, renderer); + renderTexture.render(this); + + return renderTexture; +}; + +PIXI.DisplayObject.prototype._renderCachedSprite = function(renderSession) +{ + // console.log(this._cacheIsDirty) + /* if(this._cacheIsDirty) + { + //this._generateCachedSprite(renderSession) + //this._cacheIsDirty = false;a + }*/ + + if(renderSession.gl) + { + PIXI.Sprite.prototype._renderWebGL.call(this._cachedSprite, renderSession); + } + else + { + PIXI.Sprite.prototype._renderCanvas.call(this._cachedSprite, renderSession); + } +}; + +PIXI.DisplayObject.prototype._generateCachedSprite = function()//renderSession) +{ + this._cacheAsBitmap = false; + var bounds = this.getLocalBounds(); + + if(!this._cachedSprite) + { + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0);//, renderSession.renderer); + + this._cachedSprite = new PIXI.Sprite(renderTexture); + this._cachedSprite.worldTransform = this.worldTransform; + } + else + { + this._cachedSprite.texture.resize(bounds.width | 0, bounds.height | 0); + } + + + this._cachedSprite.texture.render(this); + + + this._cacheAsBitmap = true; +}; + /** * Renders the object using the WebGL renderer * @@ -466,6 +543,18 @@ * @param renderSession {RenderSession} * @private */ +PIXI.DisplayObject.prototype._destroyCachedSprite = function() +{ + if(!this._cachedSprite)return; + + this._cachedSprite.texture.destroy(true); + // console.log("DESTROY") + // let the gc collect the unused sprite + // TODO could be object pooled! + this._cachedSprite = null; +}; + + PIXI.DisplayObject.prototype._renderWebGL = function(renderSession) { // OVERWRITE; diff --git a/src/pixi/display/DisplayObjectContainer.js b/src/pixi/display/DisplayObjectContainer.js index d8ad9e9..92ae06e 100644 --- a/src/pixi/display/DisplayObjectContainer.js +++ b/src/pixi/display/DisplayObjectContainer.js @@ -205,6 +205,8 @@ PIXI.DisplayObject.prototype.updateTransform.call( this ); + if(this._cacheAsBitmap)return; + for(var i=0,j=this.children.length; i= this.size) + if(texture.baseTexture !== this.currentBaseTexture || this.currentBatchSize >= this.size) { this.flush(); - this.currentBaseTexture = sprite.texture.baseTexture; + this.currentBaseTexture = texture.baseTexture; } @@ -6507,8 +6624,6 @@ var verticies = this.vertices; - var width = sprite.texture.frame.width; - var height = sprite.texture.frame.height; // TODO trim?? var aX = sprite.anchor.x; @@ -6526,14 +6641,15 @@ h1 = trim.y - aY * trim.height; h0 = h1 + height; + } else { - w0 = (width ) * (1-aX); - w1 = (width ) * -aX; + w0 = (texture.frame.width ) * (1-aX); + w1 = (texture.frame.width ) * -aX; - h0 = height * (1-aY); - h1 = height * -aY; + h0 = texture.frame.height * (1-aY); + h1 = texture.frame.height * -aY; } var index = this.currentBatchSize * 4 * this.vertSize; @@ -7236,7 +7352,7 @@ this.defaultShader = renderSession.shaderManager.defaultShader; var projection = this.renderSession.projection; - + // console.log(this.width) this.width = projection.x * 2; this.height = -projection.y * 2; this.buffer = buffer; @@ -7362,6 +7478,7 @@ var inputTexture = texture; var outputTexture = this.texturePool.pop(); if(!outputTexture)outputTexture = new PIXI.FilterTexture(this.gl, this.width, this.height); + outputTexture.resize(this.width, this.height); // need to clear this FBO as it may have some left over elements from a previous filter. gl.bindFramebuffer(gl.FRAMEBUFFER, outputTexture.frameBuffer ); @@ -7412,7 +7529,7 @@ // time to render the filters texture to the previous scene if(this.filterStack.length === 0) { - gl.colorMask(true, true, true, this.transparent); + gl.colorMask(true, true, true, true);//this.transparent); } else { @@ -7469,7 +7586,12 @@ gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.uvArray); + //console.log(this.vertexArray) + //console.log(this.uvArray) + //console.log(sizeX + " : " + sizeY) + gl.viewport(0, 0, sizeX, sizeY); + // bind the buffer gl.bindFramebuffer(gl.FRAMEBUFFER, buffer ); @@ -7533,6 +7655,7 @@ filter.uniforms.dimensions.value[3] = this.vertexArray[5];//filterArea.height; } + // console.log(this.uvArray ) shader.syncUniforms(); gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); @@ -7638,6 +7761,7 @@ gl.deleteBuffer(this.colorBuffer); gl.deleteBuffer(this.indexBuffer); }; + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -11606,6 +11730,12 @@ */ this.source = source; + //TODO will be used for futer pixi 1.5... + this.id = PIXI.BaseTextureCacheIdGenerator++; + + // used for webGL + this._glTextures = []; + if(!source)return; if(this.source.complete || this.source.getContext) @@ -11635,11 +11765,7 @@ this.imageUrl = null; this._powerOf2 = false; - //TODO will be used for futer pixi 1.5... - this.id = PIXI.BaseTextureCacheIdGenerator++; - - // used for webGL - this._glTextures = []; + }; @@ -12175,6 +12301,8 @@ { var children = displayObject.children; + var originalWorldTransform = displayObject.worldTransform; + displayObject.worldTransform = PIXI.RenderTexture.tempMatrix; if(position) @@ -12195,9 +12323,13 @@ this.renderer.renderDisplayObject(displayObject, context); context.setTransform(1,0,0,1,0,0); + + displayObject.worldTransform = originalWorldTransform; }; PIXI.RenderTexture.tempMatrix = new PIXI.Matrix(); + + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ diff --git a/src/pixi/InteractionManager.js b/src/pixi/InteractionManager.js index b80f144..8153beb 100644 --- a/src/pixi/InteractionManager.js +++ b/src/pixi/InteractionManager.js @@ -124,7 +124,7 @@ var child = children[i]; // push all interactive bits - if(child.interactive) + if(child._interactive) { iParent.interactiveChildren = true; //child.__iParent = iParent; diff --git a/src/pixi/display/DisplayObject.js b/src/pixi/display/DisplayObject.js index 6d8739e..2491904 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -194,6 +194,8 @@ */ this._mask = null; + this._cacheAsBitmap = false; + this._cacheIsDirty = false; /* * MOUSE Callbacks */ @@ -379,6 +381,28 @@ } }); +Object.defineProperty(PIXI.DisplayObject.prototype, 'cacheAsBitmap', { + get: function() { + return this._cacheAsBitmap; + }, + set: function(value) { + + if(this._cacheAsBitmap === value)return; + + if(value) + { + //this._cacheIsDirty = true; + this._generateCachedSprite(); + } + else + { + this._destroyCachedSprite(); + } + + this._cacheAsBitmap = value; + } +}); + /* * Updates the object transform for rendering * @@ -399,6 +423,7 @@ // var localTransform = this.localTransform//.toArray(); var parentTransform = this.parent.worldTransform;//.toArray(); var worldTransform = this.worldTransform;//.toArray(); + var px = this.pivot.x; var py = this.pivot.y; @@ -442,11 +467,10 @@ */ PIXI.DisplayObject.prototype.getLocalBounds = function() { - //var matrixCache = this.worldTransform; - return this.getBounds(PIXI.identityMatrix);///PIXI.EmptyRectangle(); }; + /** * Sets the object's stage reference, the stage this object is connected to * @@ -459,6 +483,59 @@ if(this._interactive)this.stage.dirty = true; }; +PIXI.DisplayObject.prototype.generateTexture = function(renderer) +{ + var bounds = this.getLocalBounds(); + + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0, renderer); + renderTexture.render(this); + + return renderTexture; +}; + +PIXI.DisplayObject.prototype._renderCachedSprite = function(renderSession) +{ + // console.log(this._cacheIsDirty) + /* if(this._cacheIsDirty) + { + //this._generateCachedSprite(renderSession) + //this._cacheIsDirty = false;a + }*/ + + if(renderSession.gl) + { + PIXI.Sprite.prototype._renderWebGL.call(this._cachedSprite, renderSession); + } + else + { + PIXI.Sprite.prototype._renderCanvas.call(this._cachedSprite, renderSession); + } +}; + +PIXI.DisplayObject.prototype._generateCachedSprite = function()//renderSession) +{ + this._cacheAsBitmap = false; + var bounds = this.getLocalBounds(); + + if(!this._cachedSprite) + { + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0);//, renderSession.renderer); + + this._cachedSprite = new PIXI.Sprite(renderTexture); + this._cachedSprite.worldTransform = this.worldTransform; + } + else + { + this._cachedSprite.texture.resize(bounds.width | 0, bounds.height | 0); + } + + + this._cachedSprite.texture.render(this); + + + this._cacheAsBitmap = true; +}; + /** * Renders the object using the WebGL renderer * @@ -466,6 +543,18 @@ * @param renderSession {RenderSession} * @private */ +PIXI.DisplayObject.prototype._destroyCachedSprite = function() +{ + if(!this._cachedSprite)return; + + this._cachedSprite.texture.destroy(true); + // console.log("DESTROY") + // let the gc collect the unused sprite + // TODO could be object pooled! + this._cachedSprite = null; +}; + + PIXI.DisplayObject.prototype._renderWebGL = function(renderSession) { // OVERWRITE; diff --git a/src/pixi/display/DisplayObjectContainer.js b/src/pixi/display/DisplayObjectContainer.js index d8ad9e9..92ae06e 100644 --- a/src/pixi/display/DisplayObjectContainer.js +++ b/src/pixi/display/DisplayObjectContainer.js @@ -205,6 +205,8 @@ PIXI.DisplayObject.prototype.updateTransform.call( this ); + if(this._cacheAsBitmap)return; + for(var i=0,j=this.children.length; i= this.size) + if(texture.baseTexture !== this.currentBaseTexture || this.currentBatchSize >= this.size) { this.flush(); - this.currentBaseTexture = sprite.texture.baseTexture; + this.currentBaseTexture = texture.baseTexture; } @@ -6507,8 +6624,6 @@ var verticies = this.vertices; - var width = sprite.texture.frame.width; - var height = sprite.texture.frame.height; // TODO trim?? var aX = sprite.anchor.x; @@ -6526,14 +6641,15 @@ h1 = trim.y - aY * trim.height; h0 = h1 + height; + } else { - w0 = (width ) * (1-aX); - w1 = (width ) * -aX; + w0 = (texture.frame.width ) * (1-aX); + w1 = (texture.frame.width ) * -aX; - h0 = height * (1-aY); - h1 = height * -aY; + h0 = texture.frame.height * (1-aY); + h1 = texture.frame.height * -aY; } var index = this.currentBatchSize * 4 * this.vertSize; @@ -7236,7 +7352,7 @@ this.defaultShader = renderSession.shaderManager.defaultShader; var projection = this.renderSession.projection; - + // console.log(this.width) this.width = projection.x * 2; this.height = -projection.y * 2; this.buffer = buffer; @@ -7362,6 +7478,7 @@ var inputTexture = texture; var outputTexture = this.texturePool.pop(); if(!outputTexture)outputTexture = new PIXI.FilterTexture(this.gl, this.width, this.height); + outputTexture.resize(this.width, this.height); // need to clear this FBO as it may have some left over elements from a previous filter. gl.bindFramebuffer(gl.FRAMEBUFFER, outputTexture.frameBuffer ); @@ -7412,7 +7529,7 @@ // time to render the filters texture to the previous scene if(this.filterStack.length === 0) { - gl.colorMask(true, true, true, this.transparent); + gl.colorMask(true, true, true, true);//this.transparent); } else { @@ -7469,7 +7586,12 @@ gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.uvArray); + //console.log(this.vertexArray) + //console.log(this.uvArray) + //console.log(sizeX + " : " + sizeY) + gl.viewport(0, 0, sizeX, sizeY); + // bind the buffer gl.bindFramebuffer(gl.FRAMEBUFFER, buffer ); @@ -7533,6 +7655,7 @@ filter.uniforms.dimensions.value[3] = this.vertexArray[5];//filterArea.height; } + // console.log(this.uvArray ) shader.syncUniforms(); gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); @@ -7638,6 +7761,7 @@ gl.deleteBuffer(this.colorBuffer); gl.deleteBuffer(this.indexBuffer); }; + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -11606,6 +11730,12 @@ */ this.source = source; + //TODO will be used for futer pixi 1.5... + this.id = PIXI.BaseTextureCacheIdGenerator++; + + // used for webGL + this._glTextures = []; + if(!source)return; if(this.source.complete || this.source.getContext) @@ -11635,11 +11765,7 @@ this.imageUrl = null; this._powerOf2 = false; - //TODO will be used for futer pixi 1.5... - this.id = PIXI.BaseTextureCacheIdGenerator++; - - // used for webGL - this._glTextures = []; + }; @@ -12175,6 +12301,8 @@ { var children = displayObject.children; + var originalWorldTransform = displayObject.worldTransform; + displayObject.worldTransform = PIXI.RenderTexture.tempMatrix; if(position) @@ -12195,9 +12323,13 @@ this.renderer.renderDisplayObject(displayObject, context); context.setTransform(1,0,0,1,0,0); + + displayObject.worldTransform = originalWorldTransform; }; PIXI.RenderTexture.tempMatrix = new PIXI.Matrix(); + + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ diff --git a/src/pixi/InteractionManager.js b/src/pixi/InteractionManager.js index b80f144..8153beb 100644 --- a/src/pixi/InteractionManager.js +++ b/src/pixi/InteractionManager.js @@ -124,7 +124,7 @@ var child = children[i]; // push all interactive bits - if(child.interactive) + if(child._interactive) { iParent.interactiveChildren = true; //child.__iParent = iParent; diff --git a/src/pixi/display/DisplayObject.js b/src/pixi/display/DisplayObject.js index 6d8739e..2491904 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -194,6 +194,8 @@ */ this._mask = null; + this._cacheAsBitmap = false; + this._cacheIsDirty = false; /* * MOUSE Callbacks */ @@ -379,6 +381,28 @@ } }); +Object.defineProperty(PIXI.DisplayObject.prototype, 'cacheAsBitmap', { + get: function() { + return this._cacheAsBitmap; + }, + set: function(value) { + + if(this._cacheAsBitmap === value)return; + + if(value) + { + //this._cacheIsDirty = true; + this._generateCachedSprite(); + } + else + { + this._destroyCachedSprite(); + } + + this._cacheAsBitmap = value; + } +}); + /* * Updates the object transform for rendering * @@ -399,6 +423,7 @@ // var localTransform = this.localTransform//.toArray(); var parentTransform = this.parent.worldTransform;//.toArray(); var worldTransform = this.worldTransform;//.toArray(); + var px = this.pivot.x; var py = this.pivot.y; @@ -442,11 +467,10 @@ */ PIXI.DisplayObject.prototype.getLocalBounds = function() { - //var matrixCache = this.worldTransform; - return this.getBounds(PIXI.identityMatrix);///PIXI.EmptyRectangle(); }; + /** * Sets the object's stage reference, the stage this object is connected to * @@ -459,6 +483,59 @@ if(this._interactive)this.stage.dirty = true; }; +PIXI.DisplayObject.prototype.generateTexture = function(renderer) +{ + var bounds = this.getLocalBounds(); + + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0, renderer); + renderTexture.render(this); + + return renderTexture; +}; + +PIXI.DisplayObject.prototype._renderCachedSprite = function(renderSession) +{ + // console.log(this._cacheIsDirty) + /* if(this._cacheIsDirty) + { + //this._generateCachedSprite(renderSession) + //this._cacheIsDirty = false;a + }*/ + + if(renderSession.gl) + { + PIXI.Sprite.prototype._renderWebGL.call(this._cachedSprite, renderSession); + } + else + { + PIXI.Sprite.prototype._renderCanvas.call(this._cachedSprite, renderSession); + } +}; + +PIXI.DisplayObject.prototype._generateCachedSprite = function()//renderSession) +{ + this._cacheAsBitmap = false; + var bounds = this.getLocalBounds(); + + if(!this._cachedSprite) + { + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0);//, renderSession.renderer); + + this._cachedSprite = new PIXI.Sprite(renderTexture); + this._cachedSprite.worldTransform = this.worldTransform; + } + else + { + this._cachedSprite.texture.resize(bounds.width | 0, bounds.height | 0); + } + + + this._cachedSprite.texture.render(this); + + + this._cacheAsBitmap = true; +}; + /** * Renders the object using the WebGL renderer * @@ -466,6 +543,18 @@ * @param renderSession {RenderSession} * @private */ +PIXI.DisplayObject.prototype._destroyCachedSprite = function() +{ + if(!this._cachedSprite)return; + + this._cachedSprite.texture.destroy(true); + // console.log("DESTROY") + // let the gc collect the unused sprite + // TODO could be object pooled! + this._cachedSprite = null; +}; + + PIXI.DisplayObject.prototype._renderWebGL = function(renderSession) { // OVERWRITE; diff --git a/src/pixi/display/DisplayObjectContainer.js b/src/pixi/display/DisplayObjectContainer.js index d8ad9e9..92ae06e 100644 --- a/src/pixi/display/DisplayObjectContainer.js +++ b/src/pixi/display/DisplayObjectContainer.js @@ -205,6 +205,8 @@ PIXI.DisplayObject.prototype.updateTransform.call( this ); + if(this._cacheAsBitmap)return; + for(var i=0,j=this.children.length; i= this.size) + if(texture.baseTexture !== this.currentBaseTexture || this.currentBatchSize >= this.size) { this.flush(); - this.currentBaseTexture = sprite.texture.baseTexture; + this.currentBaseTexture = texture.baseTexture; } @@ -6507,8 +6624,6 @@ var verticies = this.vertices; - var width = sprite.texture.frame.width; - var height = sprite.texture.frame.height; // TODO trim?? var aX = sprite.anchor.x; @@ -6526,14 +6641,15 @@ h1 = trim.y - aY * trim.height; h0 = h1 + height; + } else { - w0 = (width ) * (1-aX); - w1 = (width ) * -aX; + w0 = (texture.frame.width ) * (1-aX); + w1 = (texture.frame.width ) * -aX; - h0 = height * (1-aY); - h1 = height * -aY; + h0 = texture.frame.height * (1-aY); + h1 = texture.frame.height * -aY; } var index = this.currentBatchSize * 4 * this.vertSize; @@ -7236,7 +7352,7 @@ this.defaultShader = renderSession.shaderManager.defaultShader; var projection = this.renderSession.projection; - + // console.log(this.width) this.width = projection.x * 2; this.height = -projection.y * 2; this.buffer = buffer; @@ -7362,6 +7478,7 @@ var inputTexture = texture; var outputTexture = this.texturePool.pop(); if(!outputTexture)outputTexture = new PIXI.FilterTexture(this.gl, this.width, this.height); + outputTexture.resize(this.width, this.height); // need to clear this FBO as it may have some left over elements from a previous filter. gl.bindFramebuffer(gl.FRAMEBUFFER, outputTexture.frameBuffer ); @@ -7412,7 +7529,7 @@ // time to render the filters texture to the previous scene if(this.filterStack.length === 0) { - gl.colorMask(true, true, true, this.transparent); + gl.colorMask(true, true, true, true);//this.transparent); } else { @@ -7469,7 +7586,12 @@ gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.uvArray); + //console.log(this.vertexArray) + //console.log(this.uvArray) + //console.log(sizeX + " : " + sizeY) + gl.viewport(0, 0, sizeX, sizeY); + // bind the buffer gl.bindFramebuffer(gl.FRAMEBUFFER, buffer ); @@ -7533,6 +7655,7 @@ filter.uniforms.dimensions.value[3] = this.vertexArray[5];//filterArea.height; } + // console.log(this.uvArray ) shader.syncUniforms(); gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); @@ -7638,6 +7761,7 @@ gl.deleteBuffer(this.colorBuffer); gl.deleteBuffer(this.indexBuffer); }; + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -11606,6 +11730,12 @@ */ this.source = source; + //TODO will be used for futer pixi 1.5... + this.id = PIXI.BaseTextureCacheIdGenerator++; + + // used for webGL + this._glTextures = []; + if(!source)return; if(this.source.complete || this.source.getContext) @@ -11635,11 +11765,7 @@ this.imageUrl = null; this._powerOf2 = false; - //TODO will be used for futer pixi 1.5... - this.id = PIXI.BaseTextureCacheIdGenerator++; - - // used for webGL - this._glTextures = []; + }; @@ -12175,6 +12301,8 @@ { var children = displayObject.children; + var originalWorldTransform = displayObject.worldTransform; + displayObject.worldTransform = PIXI.RenderTexture.tempMatrix; if(position) @@ -12195,9 +12323,13 @@ this.renderer.renderDisplayObject(displayObject, context); context.setTransform(1,0,0,1,0,0); + + displayObject.worldTransform = originalWorldTransform; }; PIXI.RenderTexture.tempMatrix = new PIXI.Matrix(); + + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ diff --git a/src/pixi/InteractionManager.js b/src/pixi/InteractionManager.js index b80f144..8153beb 100644 --- a/src/pixi/InteractionManager.js +++ b/src/pixi/InteractionManager.js @@ -124,7 +124,7 @@ var child = children[i]; // push all interactive bits - if(child.interactive) + if(child._interactive) { iParent.interactiveChildren = true; //child.__iParent = iParent; diff --git a/src/pixi/display/DisplayObject.js b/src/pixi/display/DisplayObject.js index 6d8739e..2491904 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -194,6 +194,8 @@ */ this._mask = null; + this._cacheAsBitmap = false; + this._cacheIsDirty = false; /* * MOUSE Callbacks */ @@ -379,6 +381,28 @@ } }); +Object.defineProperty(PIXI.DisplayObject.prototype, 'cacheAsBitmap', { + get: function() { + return this._cacheAsBitmap; + }, + set: function(value) { + + if(this._cacheAsBitmap === value)return; + + if(value) + { + //this._cacheIsDirty = true; + this._generateCachedSprite(); + } + else + { + this._destroyCachedSprite(); + } + + this._cacheAsBitmap = value; + } +}); + /* * Updates the object transform for rendering * @@ -399,6 +423,7 @@ // var localTransform = this.localTransform//.toArray(); var parentTransform = this.parent.worldTransform;//.toArray(); var worldTransform = this.worldTransform;//.toArray(); + var px = this.pivot.x; var py = this.pivot.y; @@ -442,11 +467,10 @@ */ PIXI.DisplayObject.prototype.getLocalBounds = function() { - //var matrixCache = this.worldTransform; - return this.getBounds(PIXI.identityMatrix);///PIXI.EmptyRectangle(); }; + /** * Sets the object's stage reference, the stage this object is connected to * @@ -459,6 +483,59 @@ if(this._interactive)this.stage.dirty = true; }; +PIXI.DisplayObject.prototype.generateTexture = function(renderer) +{ + var bounds = this.getLocalBounds(); + + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0, renderer); + renderTexture.render(this); + + return renderTexture; +}; + +PIXI.DisplayObject.prototype._renderCachedSprite = function(renderSession) +{ + // console.log(this._cacheIsDirty) + /* if(this._cacheIsDirty) + { + //this._generateCachedSprite(renderSession) + //this._cacheIsDirty = false;a + }*/ + + if(renderSession.gl) + { + PIXI.Sprite.prototype._renderWebGL.call(this._cachedSprite, renderSession); + } + else + { + PIXI.Sprite.prototype._renderCanvas.call(this._cachedSprite, renderSession); + } +}; + +PIXI.DisplayObject.prototype._generateCachedSprite = function()//renderSession) +{ + this._cacheAsBitmap = false; + var bounds = this.getLocalBounds(); + + if(!this._cachedSprite) + { + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0);//, renderSession.renderer); + + this._cachedSprite = new PIXI.Sprite(renderTexture); + this._cachedSprite.worldTransform = this.worldTransform; + } + else + { + this._cachedSprite.texture.resize(bounds.width | 0, bounds.height | 0); + } + + + this._cachedSprite.texture.render(this); + + + this._cacheAsBitmap = true; +}; + /** * Renders the object using the WebGL renderer * @@ -466,6 +543,18 @@ * @param renderSession {RenderSession} * @private */ +PIXI.DisplayObject.prototype._destroyCachedSprite = function() +{ + if(!this._cachedSprite)return; + + this._cachedSprite.texture.destroy(true); + // console.log("DESTROY") + // let the gc collect the unused sprite + // TODO could be object pooled! + this._cachedSprite = null; +}; + + PIXI.DisplayObject.prototype._renderWebGL = function(renderSession) { // OVERWRITE; diff --git a/src/pixi/display/DisplayObjectContainer.js b/src/pixi/display/DisplayObjectContainer.js index d8ad9e9..92ae06e 100644 --- a/src/pixi/display/DisplayObjectContainer.js +++ b/src/pixi/display/DisplayObjectContainer.js @@ -205,6 +205,8 @@ PIXI.DisplayObject.prototype.updateTransform.call( this ); + if(this._cacheAsBitmap)return; + for(var i=0,j=this.children.length; i= this.size) + if(texture.baseTexture !== this.currentBaseTexture || this.currentBatchSize >= this.size) { this.flush(); - this.currentBaseTexture = sprite.texture.baseTexture; + this.currentBaseTexture = texture.baseTexture; } @@ -162,8 +164,6 @@ var verticies = this.vertices; - var width = sprite.texture.frame.width; - var height = sprite.texture.frame.height; // TODO trim?? var aX = sprite.anchor.x; @@ -181,14 +181,15 @@ h1 = trim.y - aY * trim.height; h0 = h1 + height; + } else { - w0 = (width ) * (1-aX); - w1 = (width ) * -aX; + w0 = (texture.frame.width ) * (1-aX); + w1 = (texture.frame.width ) * -aX; - h0 = height * (1-aY); - h1 = height * -aY; + h0 = texture.frame.height * (1-aY); + h1 = texture.frame.height * -aY; } var index = this.currentBatchSize * 4 * this.vertSize; diff --git a/bin/pixi.dev.js b/bin/pixi.dev.js index 4dc8dd9..47d0e28 100644 --- a/bin/pixi.dev.js +++ b/bin/pixi.dev.js @@ -4,7 +4,7 @@ * Copyright (c) 2012-2014, Mat Groves * http://goodboydigital.com/ * - * Compiled: 2014-02-15 + * Compiled: 2014-02-17 * * pixi.js is licensed under the MIT License. * http://www.opensource.org/licenses/mit-license.php @@ -742,6 +742,8 @@ */ this._mask = null; + this._cacheAsBitmap = false; + this._cacheIsDirty = false; /* * MOUSE Callbacks */ @@ -927,6 +929,28 @@ } }); +Object.defineProperty(PIXI.DisplayObject.prototype, 'cacheAsBitmap', { + get: function() { + return this._cacheAsBitmap; + }, + set: function(value) { + + if(this._cacheAsBitmap === value)return; + + if(value) + { + //this._cacheIsDirty = true; + this._generateCachedSprite(); + } + else + { + this._destroyCachedSprite(); + } + + this._cacheAsBitmap = value; + } +}); + /* * Updates the object transform for rendering * @@ -947,6 +971,7 @@ // var localTransform = this.localTransform//.toArray(); var parentTransform = this.parent.worldTransform;//.toArray(); var worldTransform = this.worldTransform;//.toArray(); + var px = this.pivot.x; var py = this.pivot.y; @@ -990,11 +1015,10 @@ */ PIXI.DisplayObject.prototype.getLocalBounds = function() { - //var matrixCache = this.worldTransform; - return this.getBounds(PIXI.identityMatrix);///PIXI.EmptyRectangle(); }; + /** * Sets the object's stage reference, the stage this object is connected to * @@ -1007,6 +1031,59 @@ if(this._interactive)this.stage.dirty = true; }; +PIXI.DisplayObject.prototype.generateTexture = function(renderer) +{ + var bounds = this.getLocalBounds(); + + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0, renderer); + renderTexture.render(this); + + return renderTexture; +}; + +PIXI.DisplayObject.prototype._renderCachedSprite = function(renderSession) +{ + // console.log(this._cacheIsDirty) + /* if(this._cacheIsDirty) + { + //this._generateCachedSprite(renderSession) + //this._cacheIsDirty = false;a + }*/ + + if(renderSession.gl) + { + PIXI.Sprite.prototype._renderWebGL.call(this._cachedSprite, renderSession); + } + else + { + PIXI.Sprite.prototype._renderCanvas.call(this._cachedSprite, renderSession); + } +}; + +PIXI.DisplayObject.prototype._generateCachedSprite = function()//renderSession) +{ + this._cacheAsBitmap = false; + var bounds = this.getLocalBounds(); + + if(!this._cachedSprite) + { + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0);//, renderSession.renderer); + + this._cachedSprite = new PIXI.Sprite(renderTexture); + this._cachedSprite.worldTransform = this.worldTransform; + } + else + { + this._cachedSprite.texture.resize(bounds.width | 0, bounds.height | 0); + } + + + this._cachedSprite.texture.render(this); + + + this._cacheAsBitmap = true; +}; + /** * Renders the object using the WebGL renderer * @@ -1014,6 +1091,18 @@ * @param renderSession {RenderSession} * @private */ +PIXI.DisplayObject.prototype._destroyCachedSprite = function() +{ + if(!this._cachedSprite)return; + + this._cachedSprite.texture.destroy(true); + // console.log("DESTROY") + // let the gc collect the unused sprite + // TODO could be object pooled! + this._cachedSprite = null; +}; + + PIXI.DisplayObject.prototype._renderWebGL = function(renderSession) { // OVERWRITE; @@ -1272,6 +1361,8 @@ PIXI.DisplayObject.prototype.updateTransform.call( this ); + if(this._cacheAsBitmap)return; + for(var i=0,j=this.children.length; i= this.size) + if(texture.baseTexture !== this.currentBaseTexture || this.currentBatchSize >= this.size) { this.flush(); - this.currentBaseTexture = sprite.texture.baseTexture; + this.currentBaseTexture = texture.baseTexture; } @@ -6507,8 +6624,6 @@ var verticies = this.vertices; - var width = sprite.texture.frame.width; - var height = sprite.texture.frame.height; // TODO trim?? var aX = sprite.anchor.x; @@ -6526,14 +6641,15 @@ h1 = trim.y - aY * trim.height; h0 = h1 + height; + } else { - w0 = (width ) * (1-aX); - w1 = (width ) * -aX; + w0 = (texture.frame.width ) * (1-aX); + w1 = (texture.frame.width ) * -aX; - h0 = height * (1-aY); - h1 = height * -aY; + h0 = texture.frame.height * (1-aY); + h1 = texture.frame.height * -aY; } var index = this.currentBatchSize * 4 * this.vertSize; @@ -7236,7 +7352,7 @@ this.defaultShader = renderSession.shaderManager.defaultShader; var projection = this.renderSession.projection; - + // console.log(this.width) this.width = projection.x * 2; this.height = -projection.y * 2; this.buffer = buffer; @@ -7362,6 +7478,7 @@ var inputTexture = texture; var outputTexture = this.texturePool.pop(); if(!outputTexture)outputTexture = new PIXI.FilterTexture(this.gl, this.width, this.height); + outputTexture.resize(this.width, this.height); // need to clear this FBO as it may have some left over elements from a previous filter. gl.bindFramebuffer(gl.FRAMEBUFFER, outputTexture.frameBuffer ); @@ -7412,7 +7529,7 @@ // time to render the filters texture to the previous scene if(this.filterStack.length === 0) { - gl.colorMask(true, true, true, this.transparent); + gl.colorMask(true, true, true, true);//this.transparent); } else { @@ -7469,7 +7586,12 @@ gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.uvArray); + //console.log(this.vertexArray) + //console.log(this.uvArray) + //console.log(sizeX + " : " + sizeY) + gl.viewport(0, 0, sizeX, sizeY); + // bind the buffer gl.bindFramebuffer(gl.FRAMEBUFFER, buffer ); @@ -7533,6 +7655,7 @@ filter.uniforms.dimensions.value[3] = this.vertexArray[5];//filterArea.height; } + // console.log(this.uvArray ) shader.syncUniforms(); gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); @@ -7638,6 +7761,7 @@ gl.deleteBuffer(this.colorBuffer); gl.deleteBuffer(this.indexBuffer); }; + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -11606,6 +11730,12 @@ */ this.source = source; + //TODO will be used for futer pixi 1.5... + this.id = PIXI.BaseTextureCacheIdGenerator++; + + // used for webGL + this._glTextures = []; + if(!source)return; if(this.source.complete || this.source.getContext) @@ -11635,11 +11765,7 @@ this.imageUrl = null; this._powerOf2 = false; - //TODO will be used for futer pixi 1.5... - this.id = PIXI.BaseTextureCacheIdGenerator++; - - // used for webGL - this._glTextures = []; + }; @@ -12175,6 +12301,8 @@ { var children = displayObject.children; + var originalWorldTransform = displayObject.worldTransform; + displayObject.worldTransform = PIXI.RenderTexture.tempMatrix; if(position) @@ -12195,9 +12323,13 @@ this.renderer.renderDisplayObject(displayObject, context); context.setTransform(1,0,0,1,0,0); + + displayObject.worldTransform = originalWorldTransform; }; PIXI.RenderTexture.tempMatrix = new PIXI.Matrix(); + + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ diff --git a/src/pixi/InteractionManager.js b/src/pixi/InteractionManager.js index b80f144..8153beb 100644 --- a/src/pixi/InteractionManager.js +++ b/src/pixi/InteractionManager.js @@ -124,7 +124,7 @@ var child = children[i]; // push all interactive bits - if(child.interactive) + if(child._interactive) { iParent.interactiveChildren = true; //child.__iParent = iParent; diff --git a/src/pixi/display/DisplayObject.js b/src/pixi/display/DisplayObject.js index 6d8739e..2491904 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -194,6 +194,8 @@ */ this._mask = null; + this._cacheAsBitmap = false; + this._cacheIsDirty = false; /* * MOUSE Callbacks */ @@ -379,6 +381,28 @@ } }); +Object.defineProperty(PIXI.DisplayObject.prototype, 'cacheAsBitmap', { + get: function() { + return this._cacheAsBitmap; + }, + set: function(value) { + + if(this._cacheAsBitmap === value)return; + + if(value) + { + //this._cacheIsDirty = true; + this._generateCachedSprite(); + } + else + { + this._destroyCachedSprite(); + } + + this._cacheAsBitmap = value; + } +}); + /* * Updates the object transform for rendering * @@ -399,6 +423,7 @@ // var localTransform = this.localTransform//.toArray(); var parentTransform = this.parent.worldTransform;//.toArray(); var worldTransform = this.worldTransform;//.toArray(); + var px = this.pivot.x; var py = this.pivot.y; @@ -442,11 +467,10 @@ */ PIXI.DisplayObject.prototype.getLocalBounds = function() { - //var matrixCache = this.worldTransform; - return this.getBounds(PIXI.identityMatrix);///PIXI.EmptyRectangle(); }; + /** * Sets the object's stage reference, the stage this object is connected to * @@ -459,6 +483,59 @@ if(this._interactive)this.stage.dirty = true; }; +PIXI.DisplayObject.prototype.generateTexture = function(renderer) +{ + var bounds = this.getLocalBounds(); + + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0, renderer); + renderTexture.render(this); + + return renderTexture; +}; + +PIXI.DisplayObject.prototype._renderCachedSprite = function(renderSession) +{ + // console.log(this._cacheIsDirty) + /* if(this._cacheIsDirty) + { + //this._generateCachedSprite(renderSession) + //this._cacheIsDirty = false;a + }*/ + + if(renderSession.gl) + { + PIXI.Sprite.prototype._renderWebGL.call(this._cachedSprite, renderSession); + } + else + { + PIXI.Sprite.prototype._renderCanvas.call(this._cachedSprite, renderSession); + } +}; + +PIXI.DisplayObject.prototype._generateCachedSprite = function()//renderSession) +{ + this._cacheAsBitmap = false; + var bounds = this.getLocalBounds(); + + if(!this._cachedSprite) + { + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0);//, renderSession.renderer); + + this._cachedSprite = new PIXI.Sprite(renderTexture); + this._cachedSprite.worldTransform = this.worldTransform; + } + else + { + this._cachedSprite.texture.resize(bounds.width | 0, bounds.height | 0); + } + + + this._cachedSprite.texture.render(this); + + + this._cacheAsBitmap = true; +}; + /** * Renders the object using the WebGL renderer * @@ -466,6 +543,18 @@ * @param renderSession {RenderSession} * @private */ +PIXI.DisplayObject.prototype._destroyCachedSprite = function() +{ + if(!this._cachedSprite)return; + + this._cachedSprite.texture.destroy(true); + // console.log("DESTROY") + // let the gc collect the unused sprite + // TODO could be object pooled! + this._cachedSprite = null; +}; + + PIXI.DisplayObject.prototype._renderWebGL = function(renderSession) { // OVERWRITE; diff --git a/src/pixi/display/DisplayObjectContainer.js b/src/pixi/display/DisplayObjectContainer.js index d8ad9e9..92ae06e 100644 --- a/src/pixi/display/DisplayObjectContainer.js +++ b/src/pixi/display/DisplayObjectContainer.js @@ -205,6 +205,8 @@ PIXI.DisplayObject.prototype.updateTransform.call( this ); + if(this._cacheAsBitmap)return; + for(var i=0,j=this.children.length; i= this.size) + if(texture.baseTexture !== this.currentBaseTexture || this.currentBatchSize >= this.size) { this.flush(); - this.currentBaseTexture = sprite.texture.baseTexture; + this.currentBaseTexture = texture.baseTexture; } @@ -162,8 +164,6 @@ var verticies = this.vertices; - var width = sprite.texture.frame.width; - var height = sprite.texture.frame.height; // TODO trim?? var aX = sprite.anchor.x; @@ -181,14 +181,15 @@ h1 = trim.y - aY * trim.height; h0 = h1 + height; + } else { - w0 = (width ) * (1-aX); - w1 = (width ) * -aX; + w0 = (texture.frame.width ) * (1-aX); + w1 = (texture.frame.width ) * -aX; - h0 = height * (1-aY); - h1 = height * -aY; + h0 = texture.frame.height * (1-aY); + h1 = texture.frame.height * -aY; } var index = this.currentBatchSize * 4 * this.vertSize; diff --git a/src/pixi/textures/BaseTexture.js b/src/pixi/textures/BaseTexture.js index fd65bfd..ad62d5e 100644 --- a/src/pixi/textures/BaseTexture.js +++ b/src/pixi/textures/BaseTexture.js @@ -64,6 +64,12 @@ */ this.source = source; + //TODO will be used for futer pixi 1.5... + this.id = PIXI.BaseTextureCacheIdGenerator++; + + // used for webGL + this._glTextures = []; + if(!source)return; if(this.source.complete || this.source.getContext) @@ -93,11 +99,7 @@ this.imageUrl = null; this._powerOf2 = false; - //TODO will be used for futer pixi 1.5... - this.id = PIXI.BaseTextureCacheIdGenerator++; - - // used for webGL - this._glTextures = []; + }; diff --git a/bin/pixi.dev.js b/bin/pixi.dev.js index 4dc8dd9..47d0e28 100644 --- a/bin/pixi.dev.js +++ b/bin/pixi.dev.js @@ -4,7 +4,7 @@ * Copyright (c) 2012-2014, Mat Groves * http://goodboydigital.com/ * - * Compiled: 2014-02-15 + * Compiled: 2014-02-17 * * pixi.js is licensed under the MIT License. * http://www.opensource.org/licenses/mit-license.php @@ -742,6 +742,8 @@ */ this._mask = null; + this._cacheAsBitmap = false; + this._cacheIsDirty = false; /* * MOUSE Callbacks */ @@ -927,6 +929,28 @@ } }); +Object.defineProperty(PIXI.DisplayObject.prototype, 'cacheAsBitmap', { + get: function() { + return this._cacheAsBitmap; + }, + set: function(value) { + + if(this._cacheAsBitmap === value)return; + + if(value) + { + //this._cacheIsDirty = true; + this._generateCachedSprite(); + } + else + { + this._destroyCachedSprite(); + } + + this._cacheAsBitmap = value; + } +}); + /* * Updates the object transform for rendering * @@ -947,6 +971,7 @@ // var localTransform = this.localTransform//.toArray(); var parentTransform = this.parent.worldTransform;//.toArray(); var worldTransform = this.worldTransform;//.toArray(); + var px = this.pivot.x; var py = this.pivot.y; @@ -990,11 +1015,10 @@ */ PIXI.DisplayObject.prototype.getLocalBounds = function() { - //var matrixCache = this.worldTransform; - return this.getBounds(PIXI.identityMatrix);///PIXI.EmptyRectangle(); }; + /** * Sets the object's stage reference, the stage this object is connected to * @@ -1007,6 +1031,59 @@ if(this._interactive)this.stage.dirty = true; }; +PIXI.DisplayObject.prototype.generateTexture = function(renderer) +{ + var bounds = this.getLocalBounds(); + + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0, renderer); + renderTexture.render(this); + + return renderTexture; +}; + +PIXI.DisplayObject.prototype._renderCachedSprite = function(renderSession) +{ + // console.log(this._cacheIsDirty) + /* if(this._cacheIsDirty) + { + //this._generateCachedSprite(renderSession) + //this._cacheIsDirty = false;a + }*/ + + if(renderSession.gl) + { + PIXI.Sprite.prototype._renderWebGL.call(this._cachedSprite, renderSession); + } + else + { + PIXI.Sprite.prototype._renderCanvas.call(this._cachedSprite, renderSession); + } +}; + +PIXI.DisplayObject.prototype._generateCachedSprite = function()//renderSession) +{ + this._cacheAsBitmap = false; + var bounds = this.getLocalBounds(); + + if(!this._cachedSprite) + { + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0);//, renderSession.renderer); + + this._cachedSprite = new PIXI.Sprite(renderTexture); + this._cachedSprite.worldTransform = this.worldTransform; + } + else + { + this._cachedSprite.texture.resize(bounds.width | 0, bounds.height | 0); + } + + + this._cachedSprite.texture.render(this); + + + this._cacheAsBitmap = true; +}; + /** * Renders the object using the WebGL renderer * @@ -1014,6 +1091,18 @@ * @param renderSession {RenderSession} * @private */ +PIXI.DisplayObject.prototype._destroyCachedSprite = function() +{ + if(!this._cachedSprite)return; + + this._cachedSprite.texture.destroy(true); + // console.log("DESTROY") + // let the gc collect the unused sprite + // TODO could be object pooled! + this._cachedSprite = null; +}; + + PIXI.DisplayObject.prototype._renderWebGL = function(renderSession) { // OVERWRITE; @@ -1272,6 +1361,8 @@ PIXI.DisplayObject.prototype.updateTransform.call( this ); + if(this._cacheAsBitmap)return; + for(var i=0,j=this.children.length; i= this.size) + if(texture.baseTexture !== this.currentBaseTexture || this.currentBatchSize >= this.size) { this.flush(); - this.currentBaseTexture = sprite.texture.baseTexture; + this.currentBaseTexture = texture.baseTexture; } @@ -6507,8 +6624,6 @@ var verticies = this.vertices; - var width = sprite.texture.frame.width; - var height = sprite.texture.frame.height; // TODO trim?? var aX = sprite.anchor.x; @@ -6526,14 +6641,15 @@ h1 = trim.y - aY * trim.height; h0 = h1 + height; + } else { - w0 = (width ) * (1-aX); - w1 = (width ) * -aX; + w0 = (texture.frame.width ) * (1-aX); + w1 = (texture.frame.width ) * -aX; - h0 = height * (1-aY); - h1 = height * -aY; + h0 = texture.frame.height * (1-aY); + h1 = texture.frame.height * -aY; } var index = this.currentBatchSize * 4 * this.vertSize; @@ -7236,7 +7352,7 @@ this.defaultShader = renderSession.shaderManager.defaultShader; var projection = this.renderSession.projection; - + // console.log(this.width) this.width = projection.x * 2; this.height = -projection.y * 2; this.buffer = buffer; @@ -7362,6 +7478,7 @@ var inputTexture = texture; var outputTexture = this.texturePool.pop(); if(!outputTexture)outputTexture = new PIXI.FilterTexture(this.gl, this.width, this.height); + outputTexture.resize(this.width, this.height); // need to clear this FBO as it may have some left over elements from a previous filter. gl.bindFramebuffer(gl.FRAMEBUFFER, outputTexture.frameBuffer ); @@ -7412,7 +7529,7 @@ // time to render the filters texture to the previous scene if(this.filterStack.length === 0) { - gl.colorMask(true, true, true, this.transparent); + gl.colorMask(true, true, true, true);//this.transparent); } else { @@ -7469,7 +7586,12 @@ gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.uvArray); + //console.log(this.vertexArray) + //console.log(this.uvArray) + //console.log(sizeX + " : " + sizeY) + gl.viewport(0, 0, sizeX, sizeY); + // bind the buffer gl.bindFramebuffer(gl.FRAMEBUFFER, buffer ); @@ -7533,6 +7655,7 @@ filter.uniforms.dimensions.value[3] = this.vertexArray[5];//filterArea.height; } + // console.log(this.uvArray ) shader.syncUniforms(); gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); @@ -7638,6 +7761,7 @@ gl.deleteBuffer(this.colorBuffer); gl.deleteBuffer(this.indexBuffer); }; + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -11606,6 +11730,12 @@ */ this.source = source; + //TODO will be used for futer pixi 1.5... + this.id = PIXI.BaseTextureCacheIdGenerator++; + + // used for webGL + this._glTextures = []; + if(!source)return; if(this.source.complete || this.source.getContext) @@ -11635,11 +11765,7 @@ this.imageUrl = null; this._powerOf2 = false; - //TODO will be used for futer pixi 1.5... - this.id = PIXI.BaseTextureCacheIdGenerator++; - - // used for webGL - this._glTextures = []; + }; @@ -12175,6 +12301,8 @@ { var children = displayObject.children; + var originalWorldTransform = displayObject.worldTransform; + displayObject.worldTransform = PIXI.RenderTexture.tempMatrix; if(position) @@ -12195,9 +12323,13 @@ this.renderer.renderDisplayObject(displayObject, context); context.setTransform(1,0,0,1,0,0); + + displayObject.worldTransform = originalWorldTransform; }; PIXI.RenderTexture.tempMatrix = new PIXI.Matrix(); + + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ diff --git a/src/pixi/InteractionManager.js b/src/pixi/InteractionManager.js index b80f144..8153beb 100644 --- a/src/pixi/InteractionManager.js +++ b/src/pixi/InteractionManager.js @@ -124,7 +124,7 @@ var child = children[i]; // push all interactive bits - if(child.interactive) + if(child._interactive) { iParent.interactiveChildren = true; //child.__iParent = iParent; diff --git a/src/pixi/display/DisplayObject.js b/src/pixi/display/DisplayObject.js index 6d8739e..2491904 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -194,6 +194,8 @@ */ this._mask = null; + this._cacheAsBitmap = false; + this._cacheIsDirty = false; /* * MOUSE Callbacks */ @@ -379,6 +381,28 @@ } }); +Object.defineProperty(PIXI.DisplayObject.prototype, 'cacheAsBitmap', { + get: function() { + return this._cacheAsBitmap; + }, + set: function(value) { + + if(this._cacheAsBitmap === value)return; + + if(value) + { + //this._cacheIsDirty = true; + this._generateCachedSprite(); + } + else + { + this._destroyCachedSprite(); + } + + this._cacheAsBitmap = value; + } +}); + /* * Updates the object transform for rendering * @@ -399,6 +423,7 @@ // var localTransform = this.localTransform//.toArray(); var parentTransform = this.parent.worldTransform;//.toArray(); var worldTransform = this.worldTransform;//.toArray(); + var px = this.pivot.x; var py = this.pivot.y; @@ -442,11 +467,10 @@ */ PIXI.DisplayObject.prototype.getLocalBounds = function() { - //var matrixCache = this.worldTransform; - return this.getBounds(PIXI.identityMatrix);///PIXI.EmptyRectangle(); }; + /** * Sets the object's stage reference, the stage this object is connected to * @@ -459,6 +483,59 @@ if(this._interactive)this.stage.dirty = true; }; +PIXI.DisplayObject.prototype.generateTexture = function(renderer) +{ + var bounds = this.getLocalBounds(); + + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0, renderer); + renderTexture.render(this); + + return renderTexture; +}; + +PIXI.DisplayObject.prototype._renderCachedSprite = function(renderSession) +{ + // console.log(this._cacheIsDirty) + /* if(this._cacheIsDirty) + { + //this._generateCachedSprite(renderSession) + //this._cacheIsDirty = false;a + }*/ + + if(renderSession.gl) + { + PIXI.Sprite.prototype._renderWebGL.call(this._cachedSprite, renderSession); + } + else + { + PIXI.Sprite.prototype._renderCanvas.call(this._cachedSprite, renderSession); + } +}; + +PIXI.DisplayObject.prototype._generateCachedSprite = function()//renderSession) +{ + this._cacheAsBitmap = false; + var bounds = this.getLocalBounds(); + + if(!this._cachedSprite) + { + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0);//, renderSession.renderer); + + this._cachedSprite = new PIXI.Sprite(renderTexture); + this._cachedSprite.worldTransform = this.worldTransform; + } + else + { + this._cachedSprite.texture.resize(bounds.width | 0, bounds.height | 0); + } + + + this._cachedSprite.texture.render(this); + + + this._cacheAsBitmap = true; +}; + /** * Renders the object using the WebGL renderer * @@ -466,6 +543,18 @@ * @param renderSession {RenderSession} * @private */ +PIXI.DisplayObject.prototype._destroyCachedSprite = function() +{ + if(!this._cachedSprite)return; + + this._cachedSprite.texture.destroy(true); + // console.log("DESTROY") + // let the gc collect the unused sprite + // TODO could be object pooled! + this._cachedSprite = null; +}; + + PIXI.DisplayObject.prototype._renderWebGL = function(renderSession) { // OVERWRITE; diff --git a/src/pixi/display/DisplayObjectContainer.js b/src/pixi/display/DisplayObjectContainer.js index d8ad9e9..92ae06e 100644 --- a/src/pixi/display/DisplayObjectContainer.js +++ b/src/pixi/display/DisplayObjectContainer.js @@ -205,6 +205,8 @@ PIXI.DisplayObject.prototype.updateTransform.call( this ); + if(this._cacheAsBitmap)return; + for(var i=0,j=this.children.length; i= this.size) + if(texture.baseTexture !== this.currentBaseTexture || this.currentBatchSize >= this.size) { this.flush(); - this.currentBaseTexture = sprite.texture.baseTexture; + this.currentBaseTexture = texture.baseTexture; } @@ -162,8 +164,6 @@ var verticies = this.vertices; - var width = sprite.texture.frame.width; - var height = sprite.texture.frame.height; // TODO trim?? var aX = sprite.anchor.x; @@ -181,14 +181,15 @@ h1 = trim.y - aY * trim.height; h0 = h1 + height; + } else { - w0 = (width ) * (1-aX); - w1 = (width ) * -aX; + w0 = (texture.frame.width ) * (1-aX); + w1 = (texture.frame.width ) * -aX; - h0 = height * (1-aY); - h1 = height * -aY; + h0 = texture.frame.height * (1-aY); + h1 = texture.frame.height * -aY; } var index = this.currentBatchSize * 4 * this.vertSize; diff --git a/src/pixi/textures/BaseTexture.js b/src/pixi/textures/BaseTexture.js index fd65bfd..ad62d5e 100644 --- a/src/pixi/textures/BaseTexture.js +++ b/src/pixi/textures/BaseTexture.js @@ -64,6 +64,12 @@ */ this.source = source; + //TODO will be used for futer pixi 1.5... + this.id = PIXI.BaseTextureCacheIdGenerator++; + + // used for webGL + this._glTextures = []; + if(!source)return; if(this.source.complete || this.source.getContext) @@ -93,11 +99,7 @@ this.imageUrl = null; this._powerOf2 = false; - //TODO will be used for futer pixi 1.5... - this.id = PIXI.BaseTextureCacheIdGenerator++; - - // used for webGL - this._glTextures = []; + }; diff --git a/src/pixi/textures/RenderTexture.js b/src/pixi/textures/RenderTexture.js index 556933d..cd73f65 100644 --- a/src/pixi/textures/RenderTexture.js +++ b/src/pixi/textures/RenderTexture.js @@ -187,6 +187,8 @@ { var children = displayObject.children; + var originalWorldTransform = displayObject.worldTransform; + displayObject.worldTransform = PIXI.RenderTexture.tempMatrix; if(position) @@ -207,6 +209,9 @@ this.renderer.renderDisplayObject(displayObject, context); context.setTransform(1,0,0,1,0,0); + + displayObject.worldTransform = originalWorldTransform; }; -PIXI.RenderTexture.tempMatrix = new PIXI.Matrix(); \ No newline at end of file +PIXI.RenderTexture.tempMatrix = new PIXI.Matrix(); +