diff --git a/examples/example 18 - Batch/index.html b/examples/example 18 - Batch/index.html index 7757801..23a7555 100644 --- a/examples/example 18 - Batch/index.html +++ b/examples/example 18 - Batch/index.html @@ -25,6 +25,8 @@ + + + + + + + + + + + + diff --git a/examples/example 18 - Batch/index.html b/examples/example 18 - Batch/index.html index 7757801..23a7555 100644 --- a/examples/example 18 - Batch/index.html +++ b/examples/example 18 - Batch/index.html @@ -25,6 +25,8 @@ + + + + + + + + + + + + diff --git a/examples/example 19 - CacheAsBitmap/logo_small.png b/examples/example 19 - CacheAsBitmap/logo_small.png new file mode 100644 index 0000000..3a63544 --- /dev/null +++ b/examples/example 19 - CacheAsBitmap/logo_small.png Binary files differ diff --git a/examples/example 18 - Batch/index.html b/examples/example 18 - Batch/index.html index 7757801..23a7555 100644 --- a/examples/example 18 - Batch/index.html +++ b/examples/example 18 - Batch/index.html @@ -25,6 +25,8 @@ + + + + + + + + + + + + diff --git a/examples/example 19 - CacheAsBitmap/logo_small.png b/examples/example 19 - CacheAsBitmap/logo_small.png new file mode 100644 index 0000000..3a63544 --- /dev/null +++ b/examples/example 19 - CacheAsBitmap/logo_small.png Binary files differ diff --git a/examples/example 19 - CacheAsBitmap/tinyMaggot.png b/examples/example 19 - CacheAsBitmap/tinyMaggot.png new file mode 100644 index 0000000..c0b1c00 --- /dev/null +++ b/examples/example 19 - CacheAsBitmap/tinyMaggot.png Binary files differ diff --git a/examples/example 18 - Batch/index.html b/examples/example 18 - Batch/index.html index 7757801..23a7555 100644 --- a/examples/example 18 - Batch/index.html +++ b/examples/example 18 - Batch/index.html @@ -25,6 +25,8 @@ + + + + + + + + + + + + diff --git a/examples/example 19 - CacheAsBitmap/logo_small.png b/examples/example 19 - CacheAsBitmap/logo_small.png new file mode 100644 index 0000000..3a63544 --- /dev/null +++ b/examples/example 19 - CacheAsBitmap/logo_small.png Binary files differ diff --git a/examples/example 19 - CacheAsBitmap/tinyMaggot.png b/examples/example 19 - CacheAsBitmap/tinyMaggot.png new file mode 100644 index 0000000..c0b1c00 --- /dev/null +++ b/examples/example 19 - CacheAsBitmap/tinyMaggot.png Binary files differ diff --git a/src/pixi/InteractionManager.js b/src/pixi/InteractionManager.js index efddfdd..718b377 100644 --- a/src/pixi/InteractionManager.js +++ b/src/pixi/InteractionManager.js @@ -83,7 +83,7 @@ // if(child.visible) { // push all interactive bits - if(child.interactive) + if(child._interactive) { iParent.interactiveChildren = true; //child.__iParent = iParent; diff --git a/examples/example 18 - Batch/index.html b/examples/example 18 - Batch/index.html index 7757801..23a7555 100644 --- a/examples/example 18 - Batch/index.html +++ b/examples/example 18 - Batch/index.html @@ -25,6 +25,8 @@ + + + + + + + + + + + + diff --git a/examples/example 19 - CacheAsBitmap/logo_small.png b/examples/example 19 - CacheAsBitmap/logo_small.png new file mode 100644 index 0000000..3a63544 --- /dev/null +++ b/examples/example 19 - CacheAsBitmap/logo_small.png Binary files differ diff --git a/examples/example 19 - CacheAsBitmap/tinyMaggot.png b/examples/example 19 - CacheAsBitmap/tinyMaggot.png new file mode 100644 index 0000000..c0b1c00 --- /dev/null +++ b/examples/example 19 - CacheAsBitmap/tinyMaggot.png Binary files differ diff --git a/src/pixi/InteractionManager.js b/src/pixi/InteractionManager.js index efddfdd..718b377 100644 --- a/src/pixi/InteractionManager.js +++ b/src/pixi/InteractionManager.js @@ -83,7 +83,7 @@ // if(child.visible) { // 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 20808d2..66a948f 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -181,6 +181,7 @@ this._currentBounds = null; this._mask = null; + this._cacheAsBitmap = false; /* * MOUSE Callbacks */ @@ -366,6 +367,27 @@ } }); +Object.defineProperty(PIXI.DisplayObject.prototype, 'cacheAsBitmap', { + get: function() { + return this._cacheAsBitmap; + }, + set: function(value) { + + if(this._cacheAsBitmap === value)return; + + if(value) + { + this._generateCachedSprite(); + } + else + { + this._destroyCachedSprite(); + } + + this._cacheAsBitmap = value; + } +}); + /* * Updates the object transform for rendering * @@ -385,6 +407,7 @@ var localTransform = this.localTransform; var parentTransform = this.parent.worldTransform; var worldTransform = this.worldTransform; + //console.log(localTransform) localTransform[0] = this._cr * this.scale.x; localTransform[1] = -this._sr * this.scale.y; @@ -426,17 +449,7 @@ PIXI.DisplayObject.prototype.getLocalBounds = function() { - var matrixCache = this.worldTransform; - - this.worldTransform = PIXI.identityMatrix; - - this.updateTransform(); - - var bounds = this.getBounds(); - - this.worldTransform = matrixCache; - - return bounds; + return PIXI.EmptyRectangle; }; PIXI.DisplayObject.prototype.setStageReference = function(stage) @@ -445,6 +458,67 @@ 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) +{ + if(this.dirty) + { + this._generateCachedSprite(); + this.dirty = false; + } + + 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(renderer) +{ + var bounds = this.getLocalBounds(); + // console.log(bounds.width); + // console.log(bounds ) + // console.log("generate sprite " + this._cachedSprite) + if(!this._cachedSprite) + { + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0, 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); + // document.body.appendChild(renderTexture.baseTexture.source) + // this._cachedSprite.buffer.context.restore(); +}; + +PIXI.DisplayObject.prototype._destroyCachedSprite = function() +{ + 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/examples/example 18 - Batch/index.html b/examples/example 18 - Batch/index.html index 7757801..23a7555 100644 --- a/examples/example 18 - Batch/index.html +++ b/examples/example 18 - Batch/index.html @@ -25,6 +25,8 @@ + + + + + + + + + + + + diff --git a/examples/example 19 - CacheAsBitmap/logo_small.png b/examples/example 19 - CacheAsBitmap/logo_small.png new file mode 100644 index 0000000..3a63544 --- /dev/null +++ b/examples/example 19 - CacheAsBitmap/logo_small.png Binary files differ diff --git a/examples/example 19 - CacheAsBitmap/tinyMaggot.png b/examples/example 19 - CacheAsBitmap/tinyMaggot.png new file mode 100644 index 0000000..c0b1c00 --- /dev/null +++ b/examples/example 19 - CacheAsBitmap/tinyMaggot.png Binary files differ diff --git a/src/pixi/InteractionManager.js b/src/pixi/InteractionManager.js index efddfdd..718b377 100644 --- a/src/pixi/InteractionManager.js +++ b/src/pixi/InteractionManager.js @@ -83,7 +83,7 @@ // if(child.visible) { // 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 20808d2..66a948f 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -181,6 +181,7 @@ this._currentBounds = null; this._mask = null; + this._cacheAsBitmap = false; /* * MOUSE Callbacks */ @@ -366,6 +367,27 @@ } }); +Object.defineProperty(PIXI.DisplayObject.prototype, 'cacheAsBitmap', { + get: function() { + return this._cacheAsBitmap; + }, + set: function(value) { + + if(this._cacheAsBitmap === value)return; + + if(value) + { + this._generateCachedSprite(); + } + else + { + this._destroyCachedSprite(); + } + + this._cacheAsBitmap = value; + } +}); + /* * Updates the object transform for rendering * @@ -385,6 +407,7 @@ var localTransform = this.localTransform; var parentTransform = this.parent.worldTransform; var worldTransform = this.worldTransform; + //console.log(localTransform) localTransform[0] = this._cr * this.scale.x; localTransform[1] = -this._sr * this.scale.y; @@ -426,17 +449,7 @@ PIXI.DisplayObject.prototype.getLocalBounds = function() { - var matrixCache = this.worldTransform; - - this.worldTransform = PIXI.identityMatrix; - - this.updateTransform(); - - var bounds = this.getBounds(); - - this.worldTransform = matrixCache; - - return bounds; + return PIXI.EmptyRectangle; }; PIXI.DisplayObject.prototype.setStageReference = function(stage) @@ -445,6 +458,67 @@ 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) +{ + if(this.dirty) + { + this._generateCachedSprite(); + this.dirty = false; + } + + 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(renderer) +{ + var bounds = this.getLocalBounds(); + // console.log(bounds.width); + // console.log(bounds ) + // console.log("generate sprite " + this._cachedSprite) + if(!this._cachedSprite) + { + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0, 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); + // document.body.appendChild(renderTexture.baseTexture.source) + // this._cachedSprite.buffer.context.restore(); +}; + +PIXI.DisplayObject.prototype._destroyCachedSprite = function() +{ + 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 435de83..fb22bf0 100644 --- a/src/pixi/display/DisplayObjectContainer.js +++ b/src/pixi/display/DisplayObjectContainer.js @@ -187,6 +187,8 @@ PIXI.DisplayObject.prototype.updateTransform.call( this ); + if(this._cacheAsBitmap)return; + for(var i=0,j=this.children.length; i + + + + + + + + + + + + diff --git a/examples/example 19 - CacheAsBitmap/logo_small.png b/examples/example 19 - CacheAsBitmap/logo_small.png new file mode 100644 index 0000000..3a63544 --- /dev/null +++ b/examples/example 19 - CacheAsBitmap/logo_small.png Binary files differ diff --git a/examples/example 19 - CacheAsBitmap/tinyMaggot.png b/examples/example 19 - CacheAsBitmap/tinyMaggot.png new file mode 100644 index 0000000..c0b1c00 --- /dev/null +++ b/examples/example 19 - CacheAsBitmap/tinyMaggot.png Binary files differ diff --git a/src/pixi/InteractionManager.js b/src/pixi/InteractionManager.js index efddfdd..718b377 100644 --- a/src/pixi/InteractionManager.js +++ b/src/pixi/InteractionManager.js @@ -83,7 +83,7 @@ // if(child.visible) { // 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 20808d2..66a948f 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -181,6 +181,7 @@ this._currentBounds = null; this._mask = null; + this._cacheAsBitmap = false; /* * MOUSE Callbacks */ @@ -366,6 +367,27 @@ } }); +Object.defineProperty(PIXI.DisplayObject.prototype, 'cacheAsBitmap', { + get: function() { + return this._cacheAsBitmap; + }, + set: function(value) { + + if(this._cacheAsBitmap === value)return; + + if(value) + { + this._generateCachedSprite(); + } + else + { + this._destroyCachedSprite(); + } + + this._cacheAsBitmap = value; + } +}); + /* * Updates the object transform for rendering * @@ -385,6 +407,7 @@ var localTransform = this.localTransform; var parentTransform = this.parent.worldTransform; var worldTransform = this.worldTransform; + //console.log(localTransform) localTransform[0] = this._cr * this.scale.x; localTransform[1] = -this._sr * this.scale.y; @@ -426,17 +449,7 @@ PIXI.DisplayObject.prototype.getLocalBounds = function() { - var matrixCache = this.worldTransform; - - this.worldTransform = PIXI.identityMatrix; - - this.updateTransform(); - - var bounds = this.getBounds(); - - this.worldTransform = matrixCache; - - return bounds; + return PIXI.EmptyRectangle; }; PIXI.DisplayObject.prototype.setStageReference = function(stage) @@ -445,6 +458,67 @@ 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) +{ + if(this.dirty) + { + this._generateCachedSprite(); + this.dirty = false; + } + + 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(renderer) +{ + var bounds = this.getLocalBounds(); + // console.log(bounds.width); + // console.log(bounds ) + // console.log("generate sprite " + this._cachedSprite) + if(!this._cachedSprite) + { + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0, 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); + // document.body.appendChild(renderTexture.baseTexture.source) + // this._cachedSprite.buffer.context.restore(); +}; + +PIXI.DisplayObject.prototype._destroyCachedSprite = function() +{ + 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 435de83..fb22bf0 100644 --- a/src/pixi/display/DisplayObjectContainer.js +++ b/src/pixi/display/DisplayObjectContainer.js @@ -187,6 +187,8 @@ PIXI.DisplayObject.prototype.updateTransform.call( this ); + if(this._cacheAsBitmap)return; + for(var i=0,j=this.children.length; i + + + + + + + + + + + + diff --git a/examples/example 19 - CacheAsBitmap/logo_small.png b/examples/example 19 - CacheAsBitmap/logo_small.png new file mode 100644 index 0000000..3a63544 --- /dev/null +++ b/examples/example 19 - CacheAsBitmap/logo_small.png Binary files differ diff --git a/examples/example 19 - CacheAsBitmap/tinyMaggot.png b/examples/example 19 - CacheAsBitmap/tinyMaggot.png new file mode 100644 index 0000000..c0b1c00 --- /dev/null +++ b/examples/example 19 - CacheAsBitmap/tinyMaggot.png Binary files differ diff --git a/src/pixi/InteractionManager.js b/src/pixi/InteractionManager.js index efddfdd..718b377 100644 --- a/src/pixi/InteractionManager.js +++ b/src/pixi/InteractionManager.js @@ -83,7 +83,7 @@ // if(child.visible) { // 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 20808d2..66a948f 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -181,6 +181,7 @@ this._currentBounds = null; this._mask = null; + this._cacheAsBitmap = false; /* * MOUSE Callbacks */ @@ -366,6 +367,27 @@ } }); +Object.defineProperty(PIXI.DisplayObject.prototype, 'cacheAsBitmap', { + get: function() { + return this._cacheAsBitmap; + }, + set: function(value) { + + if(this._cacheAsBitmap === value)return; + + if(value) + { + this._generateCachedSprite(); + } + else + { + this._destroyCachedSprite(); + } + + this._cacheAsBitmap = value; + } +}); + /* * Updates the object transform for rendering * @@ -385,6 +407,7 @@ var localTransform = this.localTransform; var parentTransform = this.parent.worldTransform; var worldTransform = this.worldTransform; + //console.log(localTransform) localTransform[0] = this._cr * this.scale.x; localTransform[1] = -this._sr * this.scale.y; @@ -426,17 +449,7 @@ PIXI.DisplayObject.prototype.getLocalBounds = function() { - var matrixCache = this.worldTransform; - - this.worldTransform = PIXI.identityMatrix; - - this.updateTransform(); - - var bounds = this.getBounds(); - - this.worldTransform = matrixCache; - - return bounds; + return PIXI.EmptyRectangle; }; PIXI.DisplayObject.prototype.setStageReference = function(stage) @@ -445,6 +458,67 @@ 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) +{ + if(this.dirty) + { + this._generateCachedSprite(); + this.dirty = false; + } + + 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(renderer) +{ + var bounds = this.getLocalBounds(); + // console.log(bounds.width); + // console.log(bounds ) + // console.log("generate sprite " + this._cachedSprite) + if(!this._cachedSprite) + { + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0, 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); + // document.body.appendChild(renderTexture.baseTexture.source) + // this._cachedSprite.buffer.context.restore(); +}; + +PIXI.DisplayObject.prototype._destroyCachedSprite = function() +{ + 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 435de83..fb22bf0 100644 --- a/src/pixi/display/DisplayObjectContainer.js +++ b/src/pixi/display/DisplayObjectContainer.js @@ -187,6 +187,8 @@ PIXI.DisplayObject.prototype.updateTransform.call( this ); + if(this._cacheAsBitmap)return; + for(var i=0,j=this.children.length; i + + + + + + + + + + + + diff --git a/examples/example 19 - CacheAsBitmap/logo_small.png b/examples/example 19 - CacheAsBitmap/logo_small.png new file mode 100644 index 0000000..3a63544 --- /dev/null +++ b/examples/example 19 - CacheAsBitmap/logo_small.png Binary files differ diff --git a/examples/example 19 - CacheAsBitmap/tinyMaggot.png b/examples/example 19 - CacheAsBitmap/tinyMaggot.png new file mode 100644 index 0000000..c0b1c00 --- /dev/null +++ b/examples/example 19 - CacheAsBitmap/tinyMaggot.png Binary files differ diff --git a/src/pixi/InteractionManager.js b/src/pixi/InteractionManager.js index efddfdd..718b377 100644 --- a/src/pixi/InteractionManager.js +++ b/src/pixi/InteractionManager.js @@ -83,7 +83,7 @@ // if(child.visible) { // 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 20808d2..66a948f 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -181,6 +181,7 @@ this._currentBounds = null; this._mask = null; + this._cacheAsBitmap = false; /* * MOUSE Callbacks */ @@ -366,6 +367,27 @@ } }); +Object.defineProperty(PIXI.DisplayObject.prototype, 'cacheAsBitmap', { + get: function() { + return this._cacheAsBitmap; + }, + set: function(value) { + + if(this._cacheAsBitmap === value)return; + + if(value) + { + this._generateCachedSprite(); + } + else + { + this._destroyCachedSprite(); + } + + this._cacheAsBitmap = value; + } +}); + /* * Updates the object transform for rendering * @@ -385,6 +407,7 @@ var localTransform = this.localTransform; var parentTransform = this.parent.worldTransform; var worldTransform = this.worldTransform; + //console.log(localTransform) localTransform[0] = this._cr * this.scale.x; localTransform[1] = -this._sr * this.scale.y; @@ -426,17 +449,7 @@ PIXI.DisplayObject.prototype.getLocalBounds = function() { - var matrixCache = this.worldTransform; - - this.worldTransform = PIXI.identityMatrix; - - this.updateTransform(); - - var bounds = this.getBounds(); - - this.worldTransform = matrixCache; - - return bounds; + return PIXI.EmptyRectangle; }; PIXI.DisplayObject.prototype.setStageReference = function(stage) @@ -445,6 +458,67 @@ 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) +{ + if(this.dirty) + { + this._generateCachedSprite(); + this.dirty = false; + } + + 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(renderer) +{ + var bounds = this.getLocalBounds(); + // console.log(bounds.width); + // console.log(bounds ) + // console.log("generate sprite " + this._cachedSprite) + if(!this._cachedSprite) + { + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0, 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); + // document.body.appendChild(renderTexture.baseTexture.source) + // this._cachedSprite.buffer.context.restore(); +}; + +PIXI.DisplayObject.prototype._destroyCachedSprite = function() +{ + 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 435de83..fb22bf0 100644 --- a/src/pixi/display/DisplayObjectContainer.js +++ b/src/pixi/display/DisplayObjectContainer.js @@ -187,6 +187,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; } @@ -108,8 +110,6 @@ var verticies = this.vertices; - var width = sprite.texture.frame.width; - var height = sprite.texture.frame.height; // TODO trim?? var aX = sprite.anchor.x; @@ -117,24 +117,22 @@ var w0, w1, h0, h1; - if (sprite.texture.trimmed) + if (texture.trimmed) { // if the sprite is trimmed then we need to add the extra space before transforming the sprite coords.. - var trim = sprite.texture.trim; + w1 = texture.trim.x - aX * texture.trim.realWidth; + w0 = w1 + texture.frame.width; - w1 = trim.x - aX * trim.realWidth; - w0 = w1 + width; - - h1 = trim.y - aY * trim.realHeight; - h0 = h1 + height; + h1 = texture.trim.y - aY * texture.trim.realHeight; + h0 = h1 + texture.frame.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/examples/example 18 - Batch/index.html b/examples/example 18 - Batch/index.html index 7757801..23a7555 100644 --- a/examples/example 18 - Batch/index.html +++ b/examples/example 18 - Batch/index.html @@ -25,6 +25,8 @@ + + + + + + + + + + + + diff --git a/examples/example 19 - CacheAsBitmap/logo_small.png b/examples/example 19 - CacheAsBitmap/logo_small.png new file mode 100644 index 0000000..3a63544 --- /dev/null +++ b/examples/example 19 - CacheAsBitmap/logo_small.png Binary files differ diff --git a/examples/example 19 - CacheAsBitmap/tinyMaggot.png b/examples/example 19 - CacheAsBitmap/tinyMaggot.png new file mode 100644 index 0000000..c0b1c00 --- /dev/null +++ b/examples/example 19 - CacheAsBitmap/tinyMaggot.png Binary files differ diff --git a/src/pixi/InteractionManager.js b/src/pixi/InteractionManager.js index efddfdd..718b377 100644 --- a/src/pixi/InteractionManager.js +++ b/src/pixi/InteractionManager.js @@ -83,7 +83,7 @@ // if(child.visible) { // 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 20808d2..66a948f 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -181,6 +181,7 @@ this._currentBounds = null; this._mask = null; + this._cacheAsBitmap = false; /* * MOUSE Callbacks */ @@ -366,6 +367,27 @@ } }); +Object.defineProperty(PIXI.DisplayObject.prototype, 'cacheAsBitmap', { + get: function() { + return this._cacheAsBitmap; + }, + set: function(value) { + + if(this._cacheAsBitmap === value)return; + + if(value) + { + this._generateCachedSprite(); + } + else + { + this._destroyCachedSprite(); + } + + this._cacheAsBitmap = value; + } +}); + /* * Updates the object transform for rendering * @@ -385,6 +407,7 @@ var localTransform = this.localTransform; var parentTransform = this.parent.worldTransform; var worldTransform = this.worldTransform; + //console.log(localTransform) localTransform[0] = this._cr * this.scale.x; localTransform[1] = -this._sr * this.scale.y; @@ -426,17 +449,7 @@ PIXI.DisplayObject.prototype.getLocalBounds = function() { - var matrixCache = this.worldTransform; - - this.worldTransform = PIXI.identityMatrix; - - this.updateTransform(); - - var bounds = this.getBounds(); - - this.worldTransform = matrixCache; - - return bounds; + return PIXI.EmptyRectangle; }; PIXI.DisplayObject.prototype.setStageReference = function(stage) @@ -445,6 +458,67 @@ 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) +{ + if(this.dirty) + { + this._generateCachedSprite(); + this.dirty = false; + } + + 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(renderer) +{ + var bounds = this.getLocalBounds(); + // console.log(bounds.width); + // console.log(bounds ) + // console.log("generate sprite " + this._cachedSprite) + if(!this._cachedSprite) + { + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0, 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); + // document.body.appendChild(renderTexture.baseTexture.source) + // this._cachedSprite.buffer.context.restore(); +}; + +PIXI.DisplayObject.prototype._destroyCachedSprite = function() +{ + 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 435de83..fb22bf0 100644 --- a/src/pixi/display/DisplayObjectContainer.js +++ b/src/pixi/display/DisplayObjectContainer.js @@ -187,6 +187,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; } @@ -108,8 +110,6 @@ var verticies = this.vertices; - var width = sprite.texture.frame.width; - var height = sprite.texture.frame.height; // TODO trim?? var aX = sprite.anchor.x; @@ -117,24 +117,22 @@ var w0, w1, h0, h1; - if (sprite.texture.trimmed) + if (texture.trimmed) { // if the sprite is trimmed then we need to add the extra space before transforming the sprite coords.. - var trim = sprite.texture.trim; + w1 = texture.trim.x - aX * texture.trim.realWidth; + w0 = w1 + texture.frame.width; - w1 = trim.x - aX * trim.realWidth; - w0 = w1 + width; - - h1 = trim.y - aY * trim.realHeight; - h0 = h1 + height; + h1 = texture.trim.y - aY * texture.trim.realHeight; + h0 = h1 + texture.frame.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 df76c70..5fea248 100644 --- a/src/pixi/textures/BaseTexture.js +++ b/src/pixi/textures/BaseTexture.js @@ -63,6 +63,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 instanceof Image || this.source instanceof HTMLImageElement) @@ -104,11 +110,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/examples/example 18 - Batch/index.html b/examples/example 18 - Batch/index.html index 7757801..23a7555 100644 --- a/examples/example 18 - Batch/index.html +++ b/examples/example 18 - Batch/index.html @@ -25,6 +25,8 @@ + + + + + + + + + + + + diff --git a/examples/example 19 - CacheAsBitmap/logo_small.png b/examples/example 19 - CacheAsBitmap/logo_small.png new file mode 100644 index 0000000..3a63544 --- /dev/null +++ b/examples/example 19 - CacheAsBitmap/logo_small.png Binary files differ diff --git a/examples/example 19 - CacheAsBitmap/tinyMaggot.png b/examples/example 19 - CacheAsBitmap/tinyMaggot.png new file mode 100644 index 0000000..c0b1c00 --- /dev/null +++ b/examples/example 19 - CacheAsBitmap/tinyMaggot.png Binary files differ diff --git a/src/pixi/InteractionManager.js b/src/pixi/InteractionManager.js index efddfdd..718b377 100644 --- a/src/pixi/InteractionManager.js +++ b/src/pixi/InteractionManager.js @@ -83,7 +83,7 @@ // if(child.visible) { // 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 20808d2..66a948f 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -181,6 +181,7 @@ this._currentBounds = null; this._mask = null; + this._cacheAsBitmap = false; /* * MOUSE Callbacks */ @@ -366,6 +367,27 @@ } }); +Object.defineProperty(PIXI.DisplayObject.prototype, 'cacheAsBitmap', { + get: function() { + return this._cacheAsBitmap; + }, + set: function(value) { + + if(this._cacheAsBitmap === value)return; + + if(value) + { + this._generateCachedSprite(); + } + else + { + this._destroyCachedSprite(); + } + + this._cacheAsBitmap = value; + } +}); + /* * Updates the object transform for rendering * @@ -385,6 +407,7 @@ var localTransform = this.localTransform; var parentTransform = this.parent.worldTransform; var worldTransform = this.worldTransform; + //console.log(localTransform) localTransform[0] = this._cr * this.scale.x; localTransform[1] = -this._sr * this.scale.y; @@ -426,17 +449,7 @@ PIXI.DisplayObject.prototype.getLocalBounds = function() { - var matrixCache = this.worldTransform; - - this.worldTransform = PIXI.identityMatrix; - - this.updateTransform(); - - var bounds = this.getBounds(); - - this.worldTransform = matrixCache; - - return bounds; + return PIXI.EmptyRectangle; }; PIXI.DisplayObject.prototype.setStageReference = function(stage) @@ -445,6 +458,67 @@ 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) +{ + if(this.dirty) + { + this._generateCachedSprite(); + this.dirty = false; + } + + 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(renderer) +{ + var bounds = this.getLocalBounds(); + // console.log(bounds.width); + // console.log(bounds ) + // console.log("generate sprite " + this._cachedSprite) + if(!this._cachedSprite) + { + var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0, 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); + // document.body.appendChild(renderTexture.baseTexture.source) + // this._cachedSprite.buffer.context.restore(); +}; + +PIXI.DisplayObject.prototype._destroyCachedSprite = function() +{ + 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 435de83..fb22bf0 100644 --- a/src/pixi/display/DisplayObjectContainer.js +++ b/src/pixi/display/DisplayObjectContainer.js @@ -187,6 +187,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; } @@ -108,8 +110,6 @@ var verticies = this.vertices; - var width = sprite.texture.frame.width; - var height = sprite.texture.frame.height; // TODO trim?? var aX = sprite.anchor.x; @@ -117,24 +117,22 @@ var w0, w1, h0, h1; - if (sprite.texture.trimmed) + if (texture.trimmed) { // if the sprite is trimmed then we need to add the extra space before transforming the sprite coords.. - var trim = sprite.texture.trim; + w1 = texture.trim.x - aX * texture.trim.realWidth; + w0 = w1 + texture.frame.width; - w1 = trim.x - aX * trim.realWidth; - w0 = w1 + width; - - h1 = trim.y - aY * trim.realHeight; - h0 = h1 + height; + h1 = texture.trim.y - aY * texture.trim.realHeight; + h0 = h1 + texture.frame.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 df76c70..5fea248 100644 --- a/src/pixi/textures/BaseTexture.js +++ b/src/pixi/textures/BaseTexture.js @@ -63,6 +63,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 instanceof Image || this.source instanceof HTMLImageElement) @@ -104,11 +110,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 8c6eeff..4276ca3 100644 --- a/src/pixi/textures/RenderTexture.js +++ b/src/pixi/textures/RenderTexture.js @@ -124,7 +124,7 @@ //TODO -? create a new one??? dont think so! var originalWorldTransform = displayObject.worldTransform; - displayObject.worldTransform = PIXI.mat3.create();//this.identityMatrix; + displayObject.worldTransform = PIXI.identityMatrix;//this.identityMatrix; // modify to flip... displayObject.worldTransform[4] = -1; displayObject.worldTransform[5] = this.projection.y * -2; @@ -163,7 +163,8 @@ //console.log("!!") var children = displayObject.children; - displayObject.worldTransform = PIXI.mat3.create(); + var originalWorldTransform = displayObject.worldTransform; + displayObject.worldTransform = PIXI.identityMatrix; if(position) { @@ -184,4 +185,6 @@ context.setTransform(1,0,0,1,0,0); + displayObject.worldTransform = originalWorldTransform; + };