diff --git a/src/core/display/cacheAsBitmap.js b/src/core/display/cacheAsBitmap.js deleted file mode 100644 index a52e641..0000000 --- a/src/core/display/cacheAsBitmap.js +++ /dev/null @@ -1,120 +0,0 @@ -var math = require('../math'), - RenderTexture = require('../textures/RenderTexture'), - DisplayObject = require('./DisplayObject'), - Sprite = require('../sprites/Sprite'), - - _tempMatrix = new math.Matrix(); - -DisplayObject.prototype._cacheAsBitmap = false; -DisplayObject.prototype._originalRenderWebGL = false; - -DisplayObject.prototype._originalUpdateTransform = null; -DisplayObject.prototype._cachedSprite = null; - - -Object.defineProperties(DisplayObject.prototype, { - - cacheAsBitmap: { - get: function () - { - return this._cacheAsBitmap; - }, - set: function (value) - { - if(this._cacheAsBitmap === value) - { - return; - } - - this._cacheAsBitmap = value; - - if(value) - { - this._originalRenderWebGL = this.renderWebGL; - this._originalUpdateTransform = this.updateTransform; - - this.renderWebGL = this._renderCachedWebGL; - this.updateTransform = this.displayObjectUpdateTransform; - } - else - { - if(this._cachedSprite) - { - this._destroyCachedDisplayObject(); - } - - this.renderWebGL = this._originalRenderWebGL; - this.updateTransform = this._originalUpdateTransform; - } - } - } -}); - -DisplayObject.prototype._renderCachedWebGL = function(renderer) -{ - this._initCachedDisplayObject( renderer ); - - this._cachedSprite.worldAlpha = this.worldAlpha; - - renderer.plugins.sprite.render( this._cachedSprite ); -}; - -DisplayObject.prototype._initCachedDisplayObject = function( renderer ) -{ - if(this._cachedSprite) - { - return; - } - - var bounds = this.getLocalBounds(); - - var cachedRenderTarget = renderer.currentRenderTarget; - - var renderTexture = new RenderTexture(renderer, bounds.width | 0, bounds.height | 0); - - // need to set // - var m = _tempMatrix; - - m.tx = -bounds.x; - m.ty = -bounds.y; - - // set all properties to there original so we can render to a texture - this._cacheAsBitmap = false; - this.renderWebGL = this._originalRenderWebGL; - this.updateTransform = this._originalUpdateTransform; - - renderTexture.render(this, m, true); - - // TODO this could mess up the filter stack - // TODO as this happens at runtime now this can be optimise this by removing the updateTransfom - - // now restore the state be setting the new properties - renderer.setRenderTarget(cachedRenderTarget); - - this.updateTransform = this.displayObjectUpdateTransform; - this.renderWebGL = this._renderCachedWebGL; - this._cacheAsBitmap = true; - - // create our cached sprite - this._cachedSprite = new Sprite(renderTexture); - this._cachedSprite.worldTransform = this.worldTransform; - this._cachedSprite.anchor.x = -( bounds.x / bounds.width ); - this._cachedSprite.anchor.y = -( bounds.y / bounds.height ); - -}; - -DisplayObject.prototype._destroyCachedDisplayObject = function() -{ - this._cachedSprite._texture.destroy(); - this._cachedSprite = null; -}; - -DisplayObject.prototype._renderCachedCanvas = function( renderer ) -{ - this._initCachedDisplayObject( renderer ); - - //TODO add some codes init! -}; - - -module.exports = {}; diff --git a/src/core/display/cacheAsBitmap.js b/src/core/display/cacheAsBitmap.js deleted file mode 100644 index a52e641..0000000 --- a/src/core/display/cacheAsBitmap.js +++ /dev/null @@ -1,120 +0,0 @@ -var math = require('../math'), - RenderTexture = require('../textures/RenderTexture'), - DisplayObject = require('./DisplayObject'), - Sprite = require('../sprites/Sprite'), - - _tempMatrix = new math.Matrix(); - -DisplayObject.prototype._cacheAsBitmap = false; -DisplayObject.prototype._originalRenderWebGL = false; - -DisplayObject.prototype._originalUpdateTransform = null; -DisplayObject.prototype._cachedSprite = null; - - -Object.defineProperties(DisplayObject.prototype, { - - cacheAsBitmap: { - get: function () - { - return this._cacheAsBitmap; - }, - set: function (value) - { - if(this._cacheAsBitmap === value) - { - return; - } - - this._cacheAsBitmap = value; - - if(value) - { - this._originalRenderWebGL = this.renderWebGL; - this._originalUpdateTransform = this.updateTransform; - - this.renderWebGL = this._renderCachedWebGL; - this.updateTransform = this.displayObjectUpdateTransform; - } - else - { - if(this._cachedSprite) - { - this._destroyCachedDisplayObject(); - } - - this.renderWebGL = this._originalRenderWebGL; - this.updateTransform = this._originalUpdateTransform; - } - } - } -}); - -DisplayObject.prototype._renderCachedWebGL = function(renderer) -{ - this._initCachedDisplayObject( renderer ); - - this._cachedSprite.worldAlpha = this.worldAlpha; - - renderer.plugins.sprite.render( this._cachedSprite ); -}; - -DisplayObject.prototype._initCachedDisplayObject = function( renderer ) -{ - if(this._cachedSprite) - { - return; - } - - var bounds = this.getLocalBounds(); - - var cachedRenderTarget = renderer.currentRenderTarget; - - var renderTexture = new RenderTexture(renderer, bounds.width | 0, bounds.height | 0); - - // need to set // - var m = _tempMatrix; - - m.tx = -bounds.x; - m.ty = -bounds.y; - - // set all properties to there original so we can render to a texture - this._cacheAsBitmap = false; - this.renderWebGL = this._originalRenderWebGL; - this.updateTransform = this._originalUpdateTransform; - - renderTexture.render(this, m, true); - - // TODO this could mess up the filter stack - // TODO as this happens at runtime now this can be optimise this by removing the updateTransfom - - // now restore the state be setting the new properties - renderer.setRenderTarget(cachedRenderTarget); - - this.updateTransform = this.displayObjectUpdateTransform; - this.renderWebGL = this._renderCachedWebGL; - this._cacheAsBitmap = true; - - // create our cached sprite - this._cachedSprite = new Sprite(renderTexture); - this._cachedSprite.worldTransform = this.worldTransform; - this._cachedSprite.anchor.x = -( bounds.x / bounds.width ); - this._cachedSprite.anchor.y = -( bounds.y / bounds.height ); - -}; - -DisplayObject.prototype._destroyCachedDisplayObject = function() -{ - this._cachedSprite._texture.destroy(); - this._cachedSprite = null; -}; - -DisplayObject.prototype._renderCachedCanvas = function( renderer ) -{ - this._initCachedDisplayObject( renderer ); - - //TODO add some codes init! -}; - - -module.exports = {}; diff --git a/src/core/index.js b/src/core/index.js index eb35dd2..1ded359 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -109,6 +109,5 @@ } }; -//TODO this needs to be moved! -var cacheAsBitmap = require('./display/cacheAsBitmap'); + diff --git a/src/core/display/cacheAsBitmap.js b/src/core/display/cacheAsBitmap.js deleted file mode 100644 index a52e641..0000000 --- a/src/core/display/cacheAsBitmap.js +++ /dev/null @@ -1,120 +0,0 @@ -var math = require('../math'), - RenderTexture = require('../textures/RenderTexture'), - DisplayObject = require('./DisplayObject'), - Sprite = require('../sprites/Sprite'), - - _tempMatrix = new math.Matrix(); - -DisplayObject.prototype._cacheAsBitmap = false; -DisplayObject.prototype._originalRenderWebGL = false; - -DisplayObject.prototype._originalUpdateTransform = null; -DisplayObject.prototype._cachedSprite = null; - - -Object.defineProperties(DisplayObject.prototype, { - - cacheAsBitmap: { - get: function () - { - return this._cacheAsBitmap; - }, - set: function (value) - { - if(this._cacheAsBitmap === value) - { - return; - } - - this._cacheAsBitmap = value; - - if(value) - { - this._originalRenderWebGL = this.renderWebGL; - this._originalUpdateTransform = this.updateTransform; - - this.renderWebGL = this._renderCachedWebGL; - this.updateTransform = this.displayObjectUpdateTransform; - } - else - { - if(this._cachedSprite) - { - this._destroyCachedDisplayObject(); - } - - this.renderWebGL = this._originalRenderWebGL; - this.updateTransform = this._originalUpdateTransform; - } - } - } -}); - -DisplayObject.prototype._renderCachedWebGL = function(renderer) -{ - this._initCachedDisplayObject( renderer ); - - this._cachedSprite.worldAlpha = this.worldAlpha; - - renderer.plugins.sprite.render( this._cachedSprite ); -}; - -DisplayObject.prototype._initCachedDisplayObject = function( renderer ) -{ - if(this._cachedSprite) - { - return; - } - - var bounds = this.getLocalBounds(); - - var cachedRenderTarget = renderer.currentRenderTarget; - - var renderTexture = new RenderTexture(renderer, bounds.width | 0, bounds.height | 0); - - // need to set // - var m = _tempMatrix; - - m.tx = -bounds.x; - m.ty = -bounds.y; - - // set all properties to there original so we can render to a texture - this._cacheAsBitmap = false; - this.renderWebGL = this._originalRenderWebGL; - this.updateTransform = this._originalUpdateTransform; - - renderTexture.render(this, m, true); - - // TODO this could mess up the filter stack - // TODO as this happens at runtime now this can be optimise this by removing the updateTransfom - - // now restore the state be setting the new properties - renderer.setRenderTarget(cachedRenderTarget); - - this.updateTransform = this.displayObjectUpdateTransform; - this.renderWebGL = this._renderCachedWebGL; - this._cacheAsBitmap = true; - - // create our cached sprite - this._cachedSprite = new Sprite(renderTexture); - this._cachedSprite.worldTransform = this.worldTransform; - this._cachedSprite.anchor.x = -( bounds.x / bounds.width ); - this._cachedSprite.anchor.y = -( bounds.y / bounds.height ); - -}; - -DisplayObject.prototype._destroyCachedDisplayObject = function() -{ - this._cachedSprite._texture.destroy(); - this._cachedSprite = null; -}; - -DisplayObject.prototype._renderCachedCanvas = function( renderer ) -{ - this._initCachedDisplayObject( renderer ); - - //TODO add some codes init! -}; - - -module.exports = {}; diff --git a/src/core/index.js b/src/core/index.js index eb35dd2..1ded359 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -109,6 +109,5 @@ } }; -//TODO this needs to be moved! -var cacheAsBitmap = require('./display/cacheAsBitmap'); + diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js new file mode 100644 index 0000000..27b7356 --- /dev/null +++ b/src/extras/cacheAsBitmap.js @@ -0,0 +1,121 @@ +var math = require('../core/math'), + RenderTexture = require('../core/textures/RenderTexture'), + DisplayObject = require('../core/display/DisplayObject'), + Sprite = require('../core/sprites/Sprite'), + + _tempMatrix = new math.Matrix(); + +DisplayObject.prototype._cacheAsBitmap = false; +DisplayObject.prototype._originalRenderWebGL = false; + +DisplayObject.prototype._originalUpdateTransform = null; +DisplayObject.prototype._cachedSprite = null; + + + +Object.defineProperties(DisplayObject.prototype, { + + cacheAsBitmap: { + get: function () + { + return this._cacheAsBitmap; + }, + set: function (value) + { + if(this._cacheAsBitmap === value) + { + return; + } + + this._cacheAsBitmap = value; + + if(value) + { + this._originalRenderWebGL = this.renderWebGL; + this._originalUpdateTransform = this.updateTransform; + + this.renderWebGL = this._renderCachedWebGL; + this.updateTransform = this.displayObjectUpdateTransform; + } + else + { + if(this._cachedSprite) + { + this._destroyCachedDisplayObject(); + } + + this.renderWebGL = this._originalRenderWebGL; + this.updateTransform = this._originalUpdateTransform; + } + } + } +}); + +DisplayObject.prototype._renderCachedWebGL = function(renderer) +{ + this._initCachedDisplayObject( renderer ); + + this._cachedSprite.worldAlpha = this.worldAlpha; + + renderer.plugins.sprite.render( this._cachedSprite ); +}; + +DisplayObject.prototype._initCachedDisplayObject = function( renderer ) +{ + if(this._cachedSprite) + { + return; + } + + var bounds = this.getLocalBounds(); + + var cachedRenderTarget = renderer.currentRenderTarget; + + var renderTexture = new RenderTexture(renderer, bounds.width | 0, bounds.height | 0); + + // need to set // + var m = _tempMatrix; + + m.tx = -bounds.x; + m.ty = -bounds.y; + + // set all properties to there original so we can render to a texture + this._cacheAsBitmap = false; + this.renderWebGL = this._originalRenderWebGL; + this.updateTransform = this._originalUpdateTransform; + + renderTexture.render(this, m, true); + + // TODO this could mess up the filter stack + // TODO as this happens at runtime now this can be optimise this by removing the updateTransfom + + // now restore the state be setting the new properties + renderer.setRenderTarget(cachedRenderTarget); + + this.updateTransform = this.displayObjectUpdateTransform; + this.renderWebGL = this._renderCachedWebGL; + this._cacheAsBitmap = true; + + // create our cached sprite + this._cachedSprite = new Sprite(renderTexture); + this._cachedSprite.worldTransform = this.worldTransform; + this._cachedSprite.anchor.x = -( bounds.x / bounds.width ); + this._cachedSprite.anchor.y = -( bounds.y / bounds.height ); + +}; + +DisplayObject.prototype._destroyCachedDisplayObject = function() +{ + this._cachedSprite._texture.destroy(); + this._cachedSprite = null; +}; + +DisplayObject.prototype._renderCachedCanvas = function( renderer ) +{ + this._initCachedDisplayObject( renderer ); + + //TODO add some codes init! +}; + + +module.exports = {}; diff --git a/src/core/display/cacheAsBitmap.js b/src/core/display/cacheAsBitmap.js deleted file mode 100644 index a52e641..0000000 --- a/src/core/display/cacheAsBitmap.js +++ /dev/null @@ -1,120 +0,0 @@ -var math = require('../math'), - RenderTexture = require('../textures/RenderTexture'), - DisplayObject = require('./DisplayObject'), - Sprite = require('../sprites/Sprite'), - - _tempMatrix = new math.Matrix(); - -DisplayObject.prototype._cacheAsBitmap = false; -DisplayObject.prototype._originalRenderWebGL = false; - -DisplayObject.prototype._originalUpdateTransform = null; -DisplayObject.prototype._cachedSprite = null; - - -Object.defineProperties(DisplayObject.prototype, { - - cacheAsBitmap: { - get: function () - { - return this._cacheAsBitmap; - }, - set: function (value) - { - if(this._cacheAsBitmap === value) - { - return; - } - - this._cacheAsBitmap = value; - - if(value) - { - this._originalRenderWebGL = this.renderWebGL; - this._originalUpdateTransform = this.updateTransform; - - this.renderWebGL = this._renderCachedWebGL; - this.updateTransform = this.displayObjectUpdateTransform; - } - else - { - if(this._cachedSprite) - { - this._destroyCachedDisplayObject(); - } - - this.renderWebGL = this._originalRenderWebGL; - this.updateTransform = this._originalUpdateTransform; - } - } - } -}); - -DisplayObject.prototype._renderCachedWebGL = function(renderer) -{ - this._initCachedDisplayObject( renderer ); - - this._cachedSprite.worldAlpha = this.worldAlpha; - - renderer.plugins.sprite.render( this._cachedSprite ); -}; - -DisplayObject.prototype._initCachedDisplayObject = function( renderer ) -{ - if(this._cachedSprite) - { - return; - } - - var bounds = this.getLocalBounds(); - - var cachedRenderTarget = renderer.currentRenderTarget; - - var renderTexture = new RenderTexture(renderer, bounds.width | 0, bounds.height | 0); - - // need to set // - var m = _tempMatrix; - - m.tx = -bounds.x; - m.ty = -bounds.y; - - // set all properties to there original so we can render to a texture - this._cacheAsBitmap = false; - this.renderWebGL = this._originalRenderWebGL; - this.updateTransform = this._originalUpdateTransform; - - renderTexture.render(this, m, true); - - // TODO this could mess up the filter stack - // TODO as this happens at runtime now this can be optimise this by removing the updateTransfom - - // now restore the state be setting the new properties - renderer.setRenderTarget(cachedRenderTarget); - - this.updateTransform = this.displayObjectUpdateTransform; - this.renderWebGL = this._renderCachedWebGL; - this._cacheAsBitmap = true; - - // create our cached sprite - this._cachedSprite = new Sprite(renderTexture); - this._cachedSprite.worldTransform = this.worldTransform; - this._cachedSprite.anchor.x = -( bounds.x / bounds.width ); - this._cachedSprite.anchor.y = -( bounds.y / bounds.height ); - -}; - -DisplayObject.prototype._destroyCachedDisplayObject = function() -{ - this._cachedSprite._texture.destroy(); - this._cachedSprite = null; -}; - -DisplayObject.prototype._renderCachedCanvas = function( renderer ) -{ - this._initCachedDisplayObject( renderer ); - - //TODO add some codes init! -}; - - -module.exports = {}; diff --git a/src/core/index.js b/src/core/index.js index eb35dd2..1ded359 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -109,6 +109,5 @@ } }; -//TODO this needs to be moved! -var cacheAsBitmap = require('./display/cacheAsBitmap'); + diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js new file mode 100644 index 0000000..27b7356 --- /dev/null +++ b/src/extras/cacheAsBitmap.js @@ -0,0 +1,121 @@ +var math = require('../core/math'), + RenderTexture = require('../core/textures/RenderTexture'), + DisplayObject = require('../core/display/DisplayObject'), + Sprite = require('../core/sprites/Sprite'), + + _tempMatrix = new math.Matrix(); + +DisplayObject.prototype._cacheAsBitmap = false; +DisplayObject.prototype._originalRenderWebGL = false; + +DisplayObject.prototype._originalUpdateTransform = null; +DisplayObject.prototype._cachedSprite = null; + + + +Object.defineProperties(DisplayObject.prototype, { + + cacheAsBitmap: { + get: function () + { + return this._cacheAsBitmap; + }, + set: function (value) + { + if(this._cacheAsBitmap === value) + { + return; + } + + this._cacheAsBitmap = value; + + if(value) + { + this._originalRenderWebGL = this.renderWebGL; + this._originalUpdateTransform = this.updateTransform; + + this.renderWebGL = this._renderCachedWebGL; + this.updateTransform = this.displayObjectUpdateTransform; + } + else + { + if(this._cachedSprite) + { + this._destroyCachedDisplayObject(); + } + + this.renderWebGL = this._originalRenderWebGL; + this.updateTransform = this._originalUpdateTransform; + } + } + } +}); + +DisplayObject.prototype._renderCachedWebGL = function(renderer) +{ + this._initCachedDisplayObject( renderer ); + + this._cachedSprite.worldAlpha = this.worldAlpha; + + renderer.plugins.sprite.render( this._cachedSprite ); +}; + +DisplayObject.prototype._initCachedDisplayObject = function( renderer ) +{ + if(this._cachedSprite) + { + return; + } + + var bounds = this.getLocalBounds(); + + var cachedRenderTarget = renderer.currentRenderTarget; + + var renderTexture = new RenderTexture(renderer, bounds.width | 0, bounds.height | 0); + + // need to set // + var m = _tempMatrix; + + m.tx = -bounds.x; + m.ty = -bounds.y; + + // set all properties to there original so we can render to a texture + this._cacheAsBitmap = false; + this.renderWebGL = this._originalRenderWebGL; + this.updateTransform = this._originalUpdateTransform; + + renderTexture.render(this, m, true); + + // TODO this could mess up the filter stack + // TODO as this happens at runtime now this can be optimise this by removing the updateTransfom + + // now restore the state be setting the new properties + renderer.setRenderTarget(cachedRenderTarget); + + this.updateTransform = this.displayObjectUpdateTransform; + this.renderWebGL = this._renderCachedWebGL; + this._cacheAsBitmap = true; + + // create our cached sprite + this._cachedSprite = new Sprite(renderTexture); + this._cachedSprite.worldTransform = this.worldTransform; + this._cachedSprite.anchor.x = -( bounds.x / bounds.width ); + this._cachedSprite.anchor.y = -( bounds.y / bounds.height ); + +}; + +DisplayObject.prototype._destroyCachedDisplayObject = function() +{ + this._cachedSprite._texture.destroy(); + this._cachedSprite = null; +}; + +DisplayObject.prototype._renderCachedCanvas = function( renderer ) +{ + this._initCachedDisplayObject( renderer ); + + //TODO add some codes init! +}; + + +module.exports = {}; diff --git a/src/extras/index.js b/src/extras/index.js index f80b7ba..3732290 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -15,3 +15,6 @@ StripShader: require('./StripShader'), TilingSprite: require('./TilingSprite') }; + +// activate the cachAsBitmap +var cacheAsBitmap = require('./cacheAsBitmap');