diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 4c96bc1..4403d8c 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -45,6 +45,8 @@ this.projectionMatrix = new math.Matrix(); + this.transform = null; + this.frame = null; // stores masking data for the render target @@ -155,6 +157,11 @@ // TODO add a dirty flag to this of a setter for the frame? this.calculateProjection( projectionFrame ); + if(this.transform) + { + this.projectionMatrix.append(this.transform); + } + gl.viewport(0,0, projectionFrame.width, projectionFrame.height); }; diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 4c96bc1..4403d8c 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -45,6 +45,8 @@ this.projectionMatrix = new math.Matrix(); + this.transform = null; + this.frame = null; // stores masking data for the render target @@ -155,6 +157,11 @@ // TODO add a dirty flag to this of a setter for the frame? this.calculateProjection( projectionFrame ); + if(this.transform) + { + this.projectionMatrix.append(this.transform); + } + gl.viewport(0,0, projectionFrame.width, projectionFrame.height); }; diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index b74b393..3bb5a2f 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -116,7 +116,7 @@ * Draw/render the given DisplayObject onto the texture. * * The displayObject and descendents are transformed during this operation. - * If `restoreWorldTransform` is true then the transformations will be restored before the + * If `updateTransform` is true then the transformations will be restored before the * method returns. Otherwise it is up to the calling code to correctly use or reset * the transformed display objects. * @@ -126,7 +126,7 @@ * @param displayObject {DisplayObject} The display object to render this texture on * @param [matrix] {Matrix} Optional matrix to apply to the display object before rendering. * @param [clear=false] {boolean} If true the texture will be cleared before the displayObject is drawn - * @param [restoreWorldTransform=true] {boolean} If true the displayObject's worldTransform/worldAlpha and all children + * @param [updateTransform=true] {boolean} If true the displayObject's worldTransform/worldAlpha and all children * transformations will be restored. Not restoring this information will be a little faster. */ this.render = null; @@ -232,49 +232,41 @@ * @param displayObject {DisplayObject} The display object to render this texture on * @param [matrix] {Matrix} Optional matrix to apply to the display object before rendering. * @param [clear=false] {boolean} If true the texture will be cleared before the displayObject is drawn - * @param [restoreWorldTransform=true] {boolean} If true the displayObject's worldTransform/worldAlpha and all children + * @param [updateTransform=true] {boolean} If true the displayObject's worldTransform/worldAlpha and all children * transformations will be restored. Not restoring this information will be a little faster. */ -RenderTexture.prototype.renderWebGL = function (displayObject, matrix, clear, restoreWorldTransform) +RenderTexture.prototype.renderWebGL = function (displayObject, matrix, clear, updateTransform) { if (!this.valid) { return; } - restoreWorldTransform = !!restoreWorldTransform; + updateTransform = !!updateTransform; var tempAlpha, tempTransform; - if (restoreWorldTransform) - { - tempAlpha = displayObject.worldAlpha; - tempTransform = displayObject.worldTransform.toArray(); - } - //TOOD replace position with matrix.. + this.textureBuffer.transform = matrix; - //Lets create a nice matrix to apply to our display object. Frame buffers come in upside down so we need to flip the matrix - var wt = displayObject.worldTransform; - - wt.identity(); - - if (matrix) - { - wt.append(matrix); - } // setWorld Alpha to ensure that the object is renderer at full opacity displayObject.worldAlpha = 1; - // Time to update all the children of the displayObject with the new matrix.. - var children = displayObject.children; - var i, j; - - for (i = 0, j = children.length; i < j; ++i) + if (updateTransform) { - children[i].updateTransform(); + // reset the matrix of the displatyObject.. + displayObject.worldTransform.identity(); + + // Time to update all the children of the displayObject with the new matrix.. + var children = displayObject.children; + var i, j; + + for (i = 0, j = children.length; i < j; ++i) + { + children[i].updateTransform(); + } } // time for the webGL fun stuff! @@ -285,18 +277,10 @@ this.textureBuffer.clear(); } + //TODO rename textureBuffer to renderTarget.. + this.renderer.renderDisplayObject(displayObject, this.textureBuffer); - if (restoreWorldTransform) - { - displayObject.worldAlpha = tempAlpha; - displayObject.worldTransform.fromArray(tempTransform); - - for (i = 0, j = children.length; i < j; ++i) - { - children[i].updateTransform(); - } - } }; diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 4c96bc1..4403d8c 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -45,6 +45,8 @@ this.projectionMatrix = new math.Matrix(); + this.transform = null; + this.frame = null; // stores masking data for the render target @@ -155,6 +157,11 @@ // TODO add a dirty flag to this of a setter for the frame? this.calculateProjection( projectionFrame ); + if(this.transform) + { + this.projectionMatrix.append(this.transform); + } + gl.viewport(0,0, projectionFrame.width, projectionFrame.height); }; diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index b74b393..3bb5a2f 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -116,7 +116,7 @@ * Draw/render the given DisplayObject onto the texture. * * The displayObject and descendents are transformed during this operation. - * If `restoreWorldTransform` is true then the transformations will be restored before the + * If `updateTransform` is true then the transformations will be restored before the * method returns. Otherwise it is up to the calling code to correctly use or reset * the transformed display objects. * @@ -126,7 +126,7 @@ * @param displayObject {DisplayObject} The display object to render this texture on * @param [matrix] {Matrix} Optional matrix to apply to the display object before rendering. * @param [clear=false] {boolean} If true the texture will be cleared before the displayObject is drawn - * @param [restoreWorldTransform=true] {boolean} If true the displayObject's worldTransform/worldAlpha and all children + * @param [updateTransform=true] {boolean} If true the displayObject's worldTransform/worldAlpha and all children * transformations will be restored. Not restoring this information will be a little faster. */ this.render = null; @@ -232,49 +232,41 @@ * @param displayObject {DisplayObject} The display object to render this texture on * @param [matrix] {Matrix} Optional matrix to apply to the display object before rendering. * @param [clear=false] {boolean} If true the texture will be cleared before the displayObject is drawn - * @param [restoreWorldTransform=true] {boolean} If true the displayObject's worldTransform/worldAlpha and all children + * @param [updateTransform=true] {boolean} If true the displayObject's worldTransform/worldAlpha and all children * transformations will be restored. Not restoring this information will be a little faster. */ -RenderTexture.prototype.renderWebGL = function (displayObject, matrix, clear, restoreWorldTransform) +RenderTexture.prototype.renderWebGL = function (displayObject, matrix, clear, updateTransform) { if (!this.valid) { return; } - restoreWorldTransform = !!restoreWorldTransform; + updateTransform = !!updateTransform; var tempAlpha, tempTransform; - if (restoreWorldTransform) - { - tempAlpha = displayObject.worldAlpha; - tempTransform = displayObject.worldTransform.toArray(); - } - //TOOD replace position with matrix.. + this.textureBuffer.transform = matrix; - //Lets create a nice matrix to apply to our display object. Frame buffers come in upside down so we need to flip the matrix - var wt = displayObject.worldTransform; - - wt.identity(); - - if (matrix) - { - wt.append(matrix); - } // setWorld Alpha to ensure that the object is renderer at full opacity displayObject.worldAlpha = 1; - // Time to update all the children of the displayObject with the new matrix.. - var children = displayObject.children; - var i, j; - - for (i = 0, j = children.length; i < j; ++i) + if (updateTransform) { - children[i].updateTransform(); + // reset the matrix of the displatyObject.. + displayObject.worldTransform.identity(); + + // Time to update all the children of the displayObject with the new matrix.. + var children = displayObject.children; + var i, j; + + for (i = 0, j = children.length; i < j; ++i) + { + children[i].updateTransform(); + } } // time for the webGL fun stuff! @@ -285,18 +277,10 @@ this.textureBuffer.clear(); } + //TODO rename textureBuffer to renderTarget.. + this.renderer.renderDisplayObject(displayObject, this.textureBuffer); - if (restoreWorldTransform) - { - displayObject.worldAlpha = tempAlpha; - displayObject.worldTransform.fromArray(tempTransform); - - for (i = 0, j = children.length; i < j; ++i) - { - children[i].updateTransform(); - } - } }; diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 27b7356..c047b51 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -67,6 +67,7 @@ return; } + //get bounds actually transforms the object for us already! var bounds = this.getLocalBounds(); var cachedRenderTarget = renderer.currentRenderTarget; @@ -82,17 +83,12 @@ // 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; @@ -101,7 +97,6 @@ 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()