diff --git a/src/core/display/Container.js b/src/core/display/Container.js index 5f12eda..797c7c1 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -288,7 +288,7 @@ * @param renderer {CanvasRenderer|WebGLRenderer} The renderer used to generate the texture. * @return {Texture} a texture of the graphics object */ -Container.prototype.generateTexture = function (resolution, scaleMode, renderer) +Container.prototype.generateTexture = function (renderer, resolution, scaleMode) { var bounds = this.getLocalBounds(); @@ -426,6 +426,12 @@ return; } + if(this.cacheAsBitmap) + { + this._renderCached( renderer ); + return; + } + var i, j; // do a quick check to see if this element has a mask or a filter. @@ -486,6 +492,8 @@ // this is where content itself gets renderd.. }; + + /** * Renders the object using the Canvas renderer * diff --git a/src/core/display/Container.js b/src/core/display/Container.js index 5f12eda..797c7c1 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -288,7 +288,7 @@ * @param renderer {CanvasRenderer|WebGLRenderer} The renderer used to generate the texture. * @return {Texture} a texture of the graphics object */ -Container.prototype.generateTexture = function (resolution, scaleMode, renderer) +Container.prototype.generateTexture = function (renderer, resolution, scaleMode) { var bounds = this.getLocalBounds(); @@ -426,6 +426,12 @@ return; } + if(this.cacheAsBitmap) + { + this._renderCached( renderer ); + return; + } + var i, j; // do a quick check to see if this element has a mask or a filter. @@ -486,6 +492,8 @@ // this is where content itself gets renderd.. }; + + /** * Renders the object using the Canvas renderer * diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index fe2c0b0..aa05a5f 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,7 @@ var math = require('../math'), - utils = require('../utils'); + utils = require('../utils'), + RenderTexture = require('../textures/RenderTexture'), + _tempMatrix = new math.Matrix(); /** * The base class for all objects that are rendered on the screen. @@ -142,9 +144,8 @@ * @member {boolean} * @private */ - this._cacheIsDirty = false; - - // this.cacheAsBitmap = false; + this._cacheAsBitmap = false; + this._cachedObject = null; } // constructor @@ -258,6 +259,30 @@ { this._filters = value && value.slice(); } + }, + + cacheAsBitmap: { + get: function () + { + return this._cacheAsBitmap; + }, + set: function (value) + { + if(this._cacheAsBitmap === value) + { + return; + } + + this._cacheAsBitmap = value; + + if(!value) + { + if(this._cachedObject) + { + this._destroyCachedDisplayObject(); + } + } + } } }); @@ -413,3 +438,73 @@ { // OVERWRITE; }; + +DisplayObject.prototype.generateTexture = function (renderer, resolution, scaleMode) +{ + var bounds = this.getLocalBounds(); + + var renderTexture = new RenderTexture(renderer, bounds.width | 0, bounds.height | 0, renderer, scaleMode, resolution); + + _tempMatrix.tx = -bounds.x; + _tempMatrix.ty = -bounds.y; + + renderTexture.render(this, _tempMatrix); + + return renderTexture; +}; + +DisplayObject.prototype._generateCachedDisplayObject = function( renderer ) +{ + if(this._cachedObject) + { + return; + } + + var bounds = this.getLocalBounds(); + + var cachedRenderTarget = renderer.currentRenderTarget; + + var renderTexture = new RenderTexture(renderer, bounds.width | 0, bounds.height | 0);//, renderSession.renderer); + + // need to set // + var m = new math.Matrix(); + + m.tx = -bounds.x; + m.ty = -bounds.y; + + this.cacheAsBitmap = false; + + renderTexture.render(this, m, true); + + renderer.setRenderTarget(cachedRenderTarget); + + this.cacheAsBitmap = true; + + this._cachedObject = { + worldTransform:this.worldTransform, + anchor:new math.Point(-( bounds.x / bounds.width ), -( bounds.y / bounds.height )), + _texture:renderTexture, + blendMode:0, + worldAlpha:1, + tint:0xFFFFFF + }; +}; + +DisplayObject.prototype._destroyCachedDisplayObject = function( renderer ) +{ + this._cachedObject._texture.destroy(); + this._cachedObject = null; +}; + +DisplayObject.prototype._renderCached = function( renderer ) +{ + this._generateCachedDisplayObject( renderer ); + + this._cachedObject.worldAlpha = this.worldAlpha; + // this._cachedObject.tint = this.tint; + + renderer.plugins.sprite.render( this._cachedObject ); +}; + + + diff --git a/src/core/display/Container.js b/src/core/display/Container.js index 5f12eda..797c7c1 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -288,7 +288,7 @@ * @param renderer {CanvasRenderer|WebGLRenderer} The renderer used to generate the texture. * @return {Texture} a texture of the graphics object */ -Container.prototype.generateTexture = function (resolution, scaleMode, renderer) +Container.prototype.generateTexture = function (renderer, resolution, scaleMode) { var bounds = this.getLocalBounds(); @@ -426,6 +426,12 @@ return; } + if(this.cacheAsBitmap) + { + this._renderCached( renderer ); + return; + } + var i, j; // do a quick check to see if this element has a mask or a filter. @@ -486,6 +492,8 @@ // this is where content itself gets renderd.. }; + + /** * Renders the object using the Canvas renderer * diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index fe2c0b0..aa05a5f 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,7 @@ var math = require('../math'), - utils = require('../utils'); + utils = require('../utils'), + RenderTexture = require('../textures/RenderTexture'), + _tempMatrix = new math.Matrix(); /** * The base class for all objects that are rendered on the screen. @@ -142,9 +144,8 @@ * @member {boolean} * @private */ - this._cacheIsDirty = false; - - // this.cacheAsBitmap = false; + this._cacheAsBitmap = false; + this._cachedObject = null; } // constructor @@ -258,6 +259,30 @@ { this._filters = value && value.slice(); } + }, + + cacheAsBitmap: { + get: function () + { + return this._cacheAsBitmap; + }, + set: function (value) + { + if(this._cacheAsBitmap === value) + { + return; + } + + this._cacheAsBitmap = value; + + if(!value) + { + if(this._cachedObject) + { + this._destroyCachedDisplayObject(); + } + } + } } }); @@ -413,3 +438,73 @@ { // OVERWRITE; }; + +DisplayObject.prototype.generateTexture = function (renderer, resolution, scaleMode) +{ + var bounds = this.getLocalBounds(); + + var renderTexture = new RenderTexture(renderer, bounds.width | 0, bounds.height | 0, renderer, scaleMode, resolution); + + _tempMatrix.tx = -bounds.x; + _tempMatrix.ty = -bounds.y; + + renderTexture.render(this, _tempMatrix); + + return renderTexture; +}; + +DisplayObject.prototype._generateCachedDisplayObject = function( renderer ) +{ + if(this._cachedObject) + { + return; + } + + var bounds = this.getLocalBounds(); + + var cachedRenderTarget = renderer.currentRenderTarget; + + var renderTexture = new RenderTexture(renderer, bounds.width | 0, bounds.height | 0);//, renderSession.renderer); + + // need to set // + var m = new math.Matrix(); + + m.tx = -bounds.x; + m.ty = -bounds.y; + + this.cacheAsBitmap = false; + + renderTexture.render(this, m, true); + + renderer.setRenderTarget(cachedRenderTarget); + + this.cacheAsBitmap = true; + + this._cachedObject = { + worldTransform:this.worldTransform, + anchor:new math.Point(-( bounds.x / bounds.width ), -( bounds.y / bounds.height )), + _texture:renderTexture, + blendMode:0, + worldAlpha:1, + tint:0xFFFFFF + }; +}; + +DisplayObject.prototype._destroyCachedDisplayObject = function( renderer ) +{ + this._cachedObject._texture.destroy(); + this._cachedObject = null; +}; + +DisplayObject.prototype._renderCached = function( renderer ) +{ + this._generateCachedDisplayObject( renderer ); + + this._cachedObject.worldAlpha = this.worldAlpha; + // this._cachedObject.tint = this.tint; + + renderer.plugins.sprite.render( this._cachedObject ); +}; + + + diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 8d7b26b..0c73030 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -372,6 +372,15 @@ }; +RenderTexture.prototype.destroy = function () +{ + Texture.prototype.destroy.call(this, true); + + this.textureBuffer.destroy(); + + this.renderer = null; +}; + /** * Will return a HTML Image of the texture * diff --git a/src/core/display/Container.js b/src/core/display/Container.js index 5f12eda..797c7c1 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -288,7 +288,7 @@ * @param renderer {CanvasRenderer|WebGLRenderer} The renderer used to generate the texture. * @return {Texture} a texture of the graphics object */ -Container.prototype.generateTexture = function (resolution, scaleMode, renderer) +Container.prototype.generateTexture = function (renderer, resolution, scaleMode) { var bounds = this.getLocalBounds(); @@ -426,6 +426,12 @@ return; } + if(this.cacheAsBitmap) + { + this._renderCached( renderer ); + return; + } + var i, j; // do a quick check to see if this element has a mask or a filter. @@ -486,6 +492,8 @@ // this is where content itself gets renderd.. }; + + /** * Renders the object using the Canvas renderer * diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index fe2c0b0..aa05a5f 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,7 @@ var math = require('../math'), - utils = require('../utils'); + utils = require('../utils'), + RenderTexture = require('../textures/RenderTexture'), + _tempMatrix = new math.Matrix(); /** * The base class for all objects that are rendered on the screen. @@ -142,9 +144,8 @@ * @member {boolean} * @private */ - this._cacheIsDirty = false; - - // this.cacheAsBitmap = false; + this._cacheAsBitmap = false; + this._cachedObject = null; } // constructor @@ -258,6 +259,30 @@ { this._filters = value && value.slice(); } + }, + + cacheAsBitmap: { + get: function () + { + return this._cacheAsBitmap; + }, + set: function (value) + { + if(this._cacheAsBitmap === value) + { + return; + } + + this._cacheAsBitmap = value; + + if(!value) + { + if(this._cachedObject) + { + this._destroyCachedDisplayObject(); + } + } + } } }); @@ -413,3 +438,73 @@ { // OVERWRITE; }; + +DisplayObject.prototype.generateTexture = function (renderer, resolution, scaleMode) +{ + var bounds = this.getLocalBounds(); + + var renderTexture = new RenderTexture(renderer, bounds.width | 0, bounds.height | 0, renderer, scaleMode, resolution); + + _tempMatrix.tx = -bounds.x; + _tempMatrix.ty = -bounds.y; + + renderTexture.render(this, _tempMatrix); + + return renderTexture; +}; + +DisplayObject.prototype._generateCachedDisplayObject = function( renderer ) +{ + if(this._cachedObject) + { + return; + } + + var bounds = this.getLocalBounds(); + + var cachedRenderTarget = renderer.currentRenderTarget; + + var renderTexture = new RenderTexture(renderer, bounds.width | 0, bounds.height | 0);//, renderSession.renderer); + + // need to set // + var m = new math.Matrix(); + + m.tx = -bounds.x; + m.ty = -bounds.y; + + this.cacheAsBitmap = false; + + renderTexture.render(this, m, true); + + renderer.setRenderTarget(cachedRenderTarget); + + this.cacheAsBitmap = true; + + this._cachedObject = { + worldTransform:this.worldTransform, + anchor:new math.Point(-( bounds.x / bounds.width ), -( bounds.y / bounds.height )), + _texture:renderTexture, + blendMode:0, + worldAlpha:1, + tint:0xFFFFFF + }; +}; + +DisplayObject.prototype._destroyCachedDisplayObject = function( renderer ) +{ + this._cachedObject._texture.destroy(); + this._cachedObject = null; +}; + +DisplayObject.prototype._renderCached = function( renderer ) +{ + this._generateCachedDisplayObject( renderer ); + + this._cachedObject.worldAlpha = this.worldAlpha; + // this._cachedObject.tint = this.tint; + + renderer.plugins.sprite.render( this._cachedObject ); +}; + + + diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 8d7b26b..0c73030 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -372,6 +372,15 @@ }; +RenderTexture.prototype.destroy = function () +{ + Texture.prototype.destroy.call(this, true); + + this.textureBuffer.destroy(); + + this.renderer = null; +}; + /** * Will return a HTML Image of the texture * diff --git a/src/interaction/InteractionManager.js b/src/interaction/InteractionManager.js index 5c86cc1..ef88035 100644 --- a/src/interaction/InteractionManager.js +++ b/src/interaction/InteractionManager.js @@ -30,13 +30,6 @@ this.eventData.data = this.mouse; /** - * An object that stores current touches (InteractionData) by id reference - * - * @member {object} - */ - this.touches = {}; - - /** * Tiny little interactiveData pool ! * * @member {Array}