diff --git a/gulp/util/jsdoc.conf.json b/gulp/util/jsdoc.conf.json index 7449cb6..adb649a 100644 --- a/gulp/util/jsdoc.conf.json +++ b/gulp/util/jsdoc.conf.json @@ -4,8 +4,7 @@ }, "source": { "include": [ - "./src/index.js", - "./src/core/display/DisplayObject.js" + "./src/" ], "exclude": [ ], diff --git a/gulp/util/jsdoc.conf.json b/gulp/util/jsdoc.conf.json index 7449cb6..adb649a 100644 --- a/gulp/util/jsdoc.conf.json +++ b/gulp/util/jsdoc.conf.json @@ -4,8 +4,7 @@ }, "source": { "include": [ - "./src/index.js", - "./src/core/display/DisplayObject.js" + "./src/" ], "exclude": [ ], diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 9ebe8e4..3ff6d22 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -74,7 +74,29 @@ bounds.width = bounds.width | 0; bounds.height = bounds.height | 0; - this.capFilterArea( bounds ); + + + + + if(this.renderer.currentRenderTarget.transform) + { + //TODO this will break if the renderTexture transform is anything other than a translation. + //Will need to take the full matrix transform into acount.. + var transform = this.renderer.currentRenderTarget.transform; + + bounds.x += transform.tx; + bounds.y += transform.ty; + + this.capFilterArea( bounds ); + + bounds.x -= transform.tx; + bounds.y -= transform.ty; + } + else + { + this.capFilterArea( bounds ); + } + this.currentFrame = bounds; diff --git a/gulp/util/jsdoc.conf.json b/gulp/util/jsdoc.conf.json index 7449cb6..adb649a 100644 --- a/gulp/util/jsdoc.conf.json +++ b/gulp/util/jsdoc.conf.json @@ -4,8 +4,7 @@ }, "source": { "include": [ - "./src/index.js", - "./src/core/display/DisplayObject.js" + "./src/" ], "exclude": [ ], diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 9ebe8e4..3ff6d22 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -74,7 +74,29 @@ bounds.width = bounds.width | 0; bounds.height = bounds.height | 0; - this.capFilterArea( bounds ); + + + + + if(this.renderer.currentRenderTarget.transform) + { + //TODO this will break if the renderTexture transform is anything other than a translation. + //Will need to take the full matrix transform into acount.. + var transform = this.renderer.currentRenderTarget.transform; + + bounds.x += transform.tx; + bounds.y += transform.ty; + + this.capFilterArea( bounds ); + + bounds.x -= transform.tx; + bounds.y -= transform.ty; + } + else + { + this.capFilterArea( bounds ); + } + this.currentFrame = bounds; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index cf75bc4..32a7bf2 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -347,31 +347,65 @@ // Ignore null sources if (this.texture.valid) { - var resolution = this.texture.baseTexture.resolution / renderer.resolution; + var texture = this._texture, + wt = this.worldTransform, + dx, + dy, + width, + height; + + var resolution = texture.baseTexture.resolution / renderer.resolution; renderer.context.globalAlpha = this.worldAlpha; // If smoothingEnabled is supported and we need to change the smoothing property for this texture - if (renderer.smoothProperty && renderer.currentScaleMode !== this.texture.baseTexture.scaleMode) + if (renderer.smoothProperty && renderer.currentScaleMode !== texture.baseTexture.scaleMode) { - renderer.currentScaleMode = this.texture.baseTexture.scaleMode; + renderer.currentScaleMode = texture.baseTexture.scaleMode; renderer.context[renderer.smoothProperty] = (renderer.currentScaleMode === CONST.SCALE_MODES.LINEAR); } // If the texture is trimmed we offset by the trim x/y, otherwise we use the frame dimensions - var dx = (this.texture.trim) ? this.texture.trim.x - this.anchor.x * this.texture.trim.width : this.anchor.x * -this.texture._frame.width; - var dy = (this.texture.trim) ? this.texture.trim.y - this.anchor.y * this.texture.trim.height : this.anchor.y * -this.texture._frame.height; + + if(texture.rotate) + { + + // cheeky rotation! + var a = wt.a; + var b = wt.b; + + wt.a = -wt.c; + wt.b = -wt.d; + wt.c = a; + wt.d = b; + + width = texture.crop.height; + height = texture.crop.width; + + dx = (texture.trim) ? texture.trim.y - this.anchor.y * texture.trim.height : this.anchor.y * -texture._frame.height; + dy = (texture.trim) ? texture.trim.x - this.anchor.x * texture.trim.width : this.anchor.x * -texture._frame.width; + } + else + { + width = texture.crop.width; + height = texture.crop.height; + + dx = (texture.trim) ? texture.trim.x - this.anchor.x * texture.trim.width : this.anchor.x * -texture._frame.width; + dy = (texture.trim) ? texture.trim.y - this.anchor.y * texture.trim.height : this.anchor.y * -texture._frame.height; + } + + // Allow for pixel rounding if (renderer.roundPixels) { renderer.context.setTransform( - this.worldTransform.a, - this.worldTransform.b, - this.worldTransform.c, - this.worldTransform.d, - (this.worldTransform.tx * renderer.resolution) | 0, - (this.worldTransform.ty * renderer.resolution) | 0 + wt.a, + wt.b, + wt.c, + wt.d, + (wt.tx * renderer.resolution) | 0, + (wt.ty * renderer.resolution) | 0 ); dx = dx | 0; @@ -379,14 +413,17 @@ } else { + renderer.context.setTransform( - this.worldTransform.a, - this.worldTransform.b, - this.worldTransform.c, - this.worldTransform.d, - this.worldTransform.tx * renderer.resolution, - this.worldTransform.ty * renderer.resolution + wt.a, + wt.b, + wt.c, + wt.d, + wt.tx * renderer.resolution, + wt.ty * renderer.resolution ); + + } if (this.tint !== 0xFFFFFF) @@ -403,26 +440,26 @@ this.tintedTexture, 0, 0, - this.texture.crop.width, - this.texture.crop.height, + width, + height, dx / resolution, dy / resolution, - this.texture.crop.width / resolution, - this.texture.crop.height / resolution + width / resolution, + width / resolution ); } else { renderer.context.drawImage( - this.texture.baseTexture.source, - this.texture.crop.x, - this.texture.crop.y, - this.texture.crop.width, - this.texture.crop.height, + texture.baseTexture.source, + texture.crop.x, + texture.crop.y, + width, + height, dx / resolution, dy / resolution, - this.texture.crop.width / resolution, - this.texture.crop.height / resolution + width / resolution, + height / resolution ); } } diff --git a/gulp/util/jsdoc.conf.json b/gulp/util/jsdoc.conf.json index 7449cb6..adb649a 100644 --- a/gulp/util/jsdoc.conf.json +++ b/gulp/util/jsdoc.conf.json @@ -4,8 +4,7 @@ }, "source": { "include": [ - "./src/index.js", - "./src/core/display/DisplayObject.js" + "./src/" ], "exclude": [ ], diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 9ebe8e4..3ff6d22 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -74,7 +74,29 @@ bounds.width = bounds.width | 0; bounds.height = bounds.height | 0; - this.capFilterArea( bounds ); + + + + + if(this.renderer.currentRenderTarget.transform) + { + //TODO this will break if the renderTexture transform is anything other than a translation. + //Will need to take the full matrix transform into acount.. + var transform = this.renderer.currentRenderTarget.transform; + + bounds.x += transform.tx; + bounds.y += transform.ty; + + this.capFilterArea( bounds ); + + bounds.x -= transform.tx; + bounds.y -= transform.ty; + } + else + { + this.capFilterArea( bounds ); + } + this.currentFrame = bounds; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index cf75bc4..32a7bf2 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -347,31 +347,65 @@ // Ignore null sources if (this.texture.valid) { - var resolution = this.texture.baseTexture.resolution / renderer.resolution; + var texture = this._texture, + wt = this.worldTransform, + dx, + dy, + width, + height; + + var resolution = texture.baseTexture.resolution / renderer.resolution; renderer.context.globalAlpha = this.worldAlpha; // If smoothingEnabled is supported and we need to change the smoothing property for this texture - if (renderer.smoothProperty && renderer.currentScaleMode !== this.texture.baseTexture.scaleMode) + if (renderer.smoothProperty && renderer.currentScaleMode !== texture.baseTexture.scaleMode) { - renderer.currentScaleMode = this.texture.baseTexture.scaleMode; + renderer.currentScaleMode = texture.baseTexture.scaleMode; renderer.context[renderer.smoothProperty] = (renderer.currentScaleMode === CONST.SCALE_MODES.LINEAR); } // If the texture is trimmed we offset by the trim x/y, otherwise we use the frame dimensions - var dx = (this.texture.trim) ? this.texture.trim.x - this.anchor.x * this.texture.trim.width : this.anchor.x * -this.texture._frame.width; - var dy = (this.texture.trim) ? this.texture.trim.y - this.anchor.y * this.texture.trim.height : this.anchor.y * -this.texture._frame.height; + + if(texture.rotate) + { + + // cheeky rotation! + var a = wt.a; + var b = wt.b; + + wt.a = -wt.c; + wt.b = -wt.d; + wt.c = a; + wt.d = b; + + width = texture.crop.height; + height = texture.crop.width; + + dx = (texture.trim) ? texture.trim.y - this.anchor.y * texture.trim.height : this.anchor.y * -texture._frame.height; + dy = (texture.trim) ? texture.trim.x - this.anchor.x * texture.trim.width : this.anchor.x * -texture._frame.width; + } + else + { + width = texture.crop.width; + height = texture.crop.height; + + dx = (texture.trim) ? texture.trim.x - this.anchor.x * texture.trim.width : this.anchor.x * -texture._frame.width; + dy = (texture.trim) ? texture.trim.y - this.anchor.y * texture.trim.height : this.anchor.y * -texture._frame.height; + } + + // Allow for pixel rounding if (renderer.roundPixels) { renderer.context.setTransform( - this.worldTransform.a, - this.worldTransform.b, - this.worldTransform.c, - this.worldTransform.d, - (this.worldTransform.tx * renderer.resolution) | 0, - (this.worldTransform.ty * renderer.resolution) | 0 + wt.a, + wt.b, + wt.c, + wt.d, + (wt.tx * renderer.resolution) | 0, + (wt.ty * renderer.resolution) | 0 ); dx = dx | 0; @@ -379,14 +413,17 @@ } else { + renderer.context.setTransform( - this.worldTransform.a, - this.worldTransform.b, - this.worldTransform.c, - this.worldTransform.d, - this.worldTransform.tx * renderer.resolution, - this.worldTransform.ty * renderer.resolution + wt.a, + wt.b, + wt.c, + wt.d, + wt.tx * renderer.resolution, + wt.ty * renderer.resolution ); + + } if (this.tint !== 0xFFFFFF) @@ -403,26 +440,26 @@ this.tintedTexture, 0, 0, - this.texture.crop.width, - this.texture.crop.height, + width, + height, dx / resolution, dy / resolution, - this.texture.crop.width / resolution, - this.texture.crop.height / resolution + width / resolution, + width / resolution ); } else { renderer.context.drawImage( - this.texture.baseTexture.source, - this.texture.crop.x, - this.texture.crop.y, - this.texture.crop.width, - this.texture.crop.height, + texture.baseTexture.source, + texture.crop.x, + texture.crop.y, + width, + height, dx / resolution, dy / resolution, - this.texture.crop.width / resolution, - this.texture.crop.height / resolution + width / resolution, + height / resolution ); } } diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 6a571c8..8958dfc 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,6 +1,7 @@ var BaseTexture = require('./BaseTexture'), Texture = require('./Texture'), RenderTarget = require('../renderers/webgl/utils/RenderTarget'), + FilterManager = require('../renderers/webgl/managers/FilterManager'), CanvasBuffer = require('../renderers/canvas/utils/CanvasBuffer'), math = require('../math'), CONST = require('../const'), @@ -146,6 +147,10 @@ this.textureBuffer = new RenderTarget(gl, this.width, this.height, null, this.resolution);//, this.baseTexture.scaleMode); this.baseTexture._glTextures[gl.id] = this.textureBuffer.texture; + //TODO refactor filter manager.. as really its no longer a manager if we use it here.. + this.filterManager = new FilterManager(this.renderer); + this.filterManager.onContextChange(); + this.filterManager.resize(width, height); this.render = this.renderWebGL; } else @@ -205,6 +210,11 @@ } this.textureBuffer.resize(this.width * this.resolution, this.height * this.resolution); + + if(this.filterManager) + { + this.filterManager.resize(this.width, this.height); + } }; /** @@ -243,19 +253,23 @@ return; } + //TODO this should be true by default updateTransform = !!updateTransform; this.textureBuffer.transform = matrix; // setWorld Alpha to ensure that the object is renderer at full opacity - displayObject.worldAlpha = 1; + displayObject.worldAlpha = displayObject.alpha; if (updateTransform) { + // reset the matrix of the displatyObject.. displayObject.worldTransform.identity(); + displayObject.currentBounds = null; + // Time to update all the children of the displayObject with the new matrix.. var children = displayObject.children; var i, j; @@ -273,9 +287,12 @@ } //TODO rename textureBuffer to renderTarget.. + var temp = this.renderer.filterManager; + this.renderer.filterManager = this.filterManager; this.renderer.renderDisplayObject(displayObject, this.textureBuffer); + this.renderer.filterManager = temp; }; @@ -354,6 +371,12 @@ this.textureBuffer.destroy(); + // destroy the filtermanager.. + if(this.filterManager) + { + this.filterManager.destroy(); + } + this.renderer = null; }; diff --git a/gulp/util/jsdoc.conf.json b/gulp/util/jsdoc.conf.json index 7449cb6..adb649a 100644 --- a/gulp/util/jsdoc.conf.json +++ b/gulp/util/jsdoc.conf.json @@ -4,8 +4,7 @@ }, "source": { "include": [ - "./src/index.js", - "./src/core/display/DisplayObject.js" + "./src/" ], "exclude": [ ], diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 9ebe8e4..3ff6d22 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -74,7 +74,29 @@ bounds.width = bounds.width | 0; bounds.height = bounds.height | 0; - this.capFilterArea( bounds ); + + + + + if(this.renderer.currentRenderTarget.transform) + { + //TODO this will break if the renderTexture transform is anything other than a translation. + //Will need to take the full matrix transform into acount.. + var transform = this.renderer.currentRenderTarget.transform; + + bounds.x += transform.tx; + bounds.y += transform.ty; + + this.capFilterArea( bounds ); + + bounds.x -= transform.tx; + bounds.y -= transform.ty; + } + else + { + this.capFilterArea( bounds ); + } + this.currentFrame = bounds; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index cf75bc4..32a7bf2 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -347,31 +347,65 @@ // Ignore null sources if (this.texture.valid) { - var resolution = this.texture.baseTexture.resolution / renderer.resolution; + var texture = this._texture, + wt = this.worldTransform, + dx, + dy, + width, + height; + + var resolution = texture.baseTexture.resolution / renderer.resolution; renderer.context.globalAlpha = this.worldAlpha; // If smoothingEnabled is supported and we need to change the smoothing property for this texture - if (renderer.smoothProperty && renderer.currentScaleMode !== this.texture.baseTexture.scaleMode) + if (renderer.smoothProperty && renderer.currentScaleMode !== texture.baseTexture.scaleMode) { - renderer.currentScaleMode = this.texture.baseTexture.scaleMode; + renderer.currentScaleMode = texture.baseTexture.scaleMode; renderer.context[renderer.smoothProperty] = (renderer.currentScaleMode === CONST.SCALE_MODES.LINEAR); } // If the texture is trimmed we offset by the trim x/y, otherwise we use the frame dimensions - var dx = (this.texture.trim) ? this.texture.trim.x - this.anchor.x * this.texture.trim.width : this.anchor.x * -this.texture._frame.width; - var dy = (this.texture.trim) ? this.texture.trim.y - this.anchor.y * this.texture.trim.height : this.anchor.y * -this.texture._frame.height; + + if(texture.rotate) + { + + // cheeky rotation! + var a = wt.a; + var b = wt.b; + + wt.a = -wt.c; + wt.b = -wt.d; + wt.c = a; + wt.d = b; + + width = texture.crop.height; + height = texture.crop.width; + + dx = (texture.trim) ? texture.trim.y - this.anchor.y * texture.trim.height : this.anchor.y * -texture._frame.height; + dy = (texture.trim) ? texture.trim.x - this.anchor.x * texture.trim.width : this.anchor.x * -texture._frame.width; + } + else + { + width = texture.crop.width; + height = texture.crop.height; + + dx = (texture.trim) ? texture.trim.x - this.anchor.x * texture.trim.width : this.anchor.x * -texture._frame.width; + dy = (texture.trim) ? texture.trim.y - this.anchor.y * texture.trim.height : this.anchor.y * -texture._frame.height; + } + + // Allow for pixel rounding if (renderer.roundPixels) { renderer.context.setTransform( - this.worldTransform.a, - this.worldTransform.b, - this.worldTransform.c, - this.worldTransform.d, - (this.worldTransform.tx * renderer.resolution) | 0, - (this.worldTransform.ty * renderer.resolution) | 0 + wt.a, + wt.b, + wt.c, + wt.d, + (wt.tx * renderer.resolution) | 0, + (wt.ty * renderer.resolution) | 0 ); dx = dx | 0; @@ -379,14 +413,17 @@ } else { + renderer.context.setTransform( - this.worldTransform.a, - this.worldTransform.b, - this.worldTransform.c, - this.worldTransform.d, - this.worldTransform.tx * renderer.resolution, - this.worldTransform.ty * renderer.resolution + wt.a, + wt.b, + wt.c, + wt.d, + wt.tx * renderer.resolution, + wt.ty * renderer.resolution ); + + } if (this.tint !== 0xFFFFFF) @@ -403,26 +440,26 @@ this.tintedTexture, 0, 0, - this.texture.crop.width, - this.texture.crop.height, + width, + height, dx / resolution, dy / resolution, - this.texture.crop.width / resolution, - this.texture.crop.height / resolution + width / resolution, + width / resolution ); } else { renderer.context.drawImage( - this.texture.baseTexture.source, - this.texture.crop.x, - this.texture.crop.y, - this.texture.crop.width, - this.texture.crop.height, + texture.baseTexture.source, + texture.crop.x, + texture.crop.y, + width, + height, dx / resolution, dy / resolution, - this.texture.crop.width / resolution, - this.texture.crop.height / resolution + width / resolution, + height / resolution ); } } diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 6a571c8..8958dfc 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,6 +1,7 @@ var BaseTexture = require('./BaseTexture'), Texture = require('./Texture'), RenderTarget = require('../renderers/webgl/utils/RenderTarget'), + FilterManager = require('../renderers/webgl/managers/FilterManager'), CanvasBuffer = require('../renderers/canvas/utils/CanvasBuffer'), math = require('../math'), CONST = require('../const'), @@ -146,6 +147,10 @@ this.textureBuffer = new RenderTarget(gl, this.width, this.height, null, this.resolution);//, this.baseTexture.scaleMode); this.baseTexture._glTextures[gl.id] = this.textureBuffer.texture; + //TODO refactor filter manager.. as really its no longer a manager if we use it here.. + this.filterManager = new FilterManager(this.renderer); + this.filterManager.onContextChange(); + this.filterManager.resize(width, height); this.render = this.renderWebGL; } else @@ -205,6 +210,11 @@ } this.textureBuffer.resize(this.width * this.resolution, this.height * this.resolution); + + if(this.filterManager) + { + this.filterManager.resize(this.width, this.height); + } }; /** @@ -243,19 +253,23 @@ return; } + //TODO this should be true by default updateTransform = !!updateTransform; this.textureBuffer.transform = matrix; // setWorld Alpha to ensure that the object is renderer at full opacity - displayObject.worldAlpha = 1; + displayObject.worldAlpha = displayObject.alpha; if (updateTransform) { + // reset the matrix of the displatyObject.. displayObject.worldTransform.identity(); + displayObject.currentBounds = null; + // Time to update all the children of the displayObject with the new matrix.. var children = displayObject.children; var i, j; @@ -273,9 +287,12 @@ } //TODO rename textureBuffer to renderTarget.. + var temp = this.renderer.filterManager; + this.renderer.filterManager = this.filterManager; this.renderer.renderDisplayObject(displayObject, this.textureBuffer); + this.renderer.filterManager = temp; }; @@ -354,6 +371,12 @@ this.textureBuffer.destroy(); + // destroy the filtermanager.. + if(this.filterManager) + { + this.filterManager.destroy(); + } + this.renderer = null; }; diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 1185599..eb039c0 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -85,10 +85,11 @@ // first we flush anything left in the renderer (otherwise it would get rendered to the cached texture) renderer.currentRenderer.flush(); - + //this.filters= []; // next we find the dimensions of the untransformed object // this function also calls updatetransform on all its children as part of the measuring. This means we don't need to update the transform again in this function - var bounds = this.getLocalBounds(); + // TODO pass an object to clone too? saves having to create a new one each time! + var bounds = this.getLocalBounds().clone(); // for now we cache the current renderTarget that the webGL renderer is currently using. // this could be more elegent.. diff --git a/gulp/util/jsdoc.conf.json b/gulp/util/jsdoc.conf.json index 7449cb6..adb649a 100644 --- a/gulp/util/jsdoc.conf.json +++ b/gulp/util/jsdoc.conf.json @@ -4,8 +4,7 @@ }, "source": { "include": [ - "./src/index.js", - "./src/core/display/DisplayObject.js" + "./src/" ], "exclude": [ ], diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 9ebe8e4..3ff6d22 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -74,7 +74,29 @@ bounds.width = bounds.width | 0; bounds.height = bounds.height | 0; - this.capFilterArea( bounds ); + + + + + if(this.renderer.currentRenderTarget.transform) + { + //TODO this will break if the renderTexture transform is anything other than a translation. + //Will need to take the full matrix transform into acount.. + var transform = this.renderer.currentRenderTarget.transform; + + bounds.x += transform.tx; + bounds.y += transform.ty; + + this.capFilterArea( bounds ); + + bounds.x -= transform.tx; + bounds.y -= transform.ty; + } + else + { + this.capFilterArea( bounds ); + } + this.currentFrame = bounds; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index cf75bc4..32a7bf2 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -347,31 +347,65 @@ // Ignore null sources if (this.texture.valid) { - var resolution = this.texture.baseTexture.resolution / renderer.resolution; + var texture = this._texture, + wt = this.worldTransform, + dx, + dy, + width, + height; + + var resolution = texture.baseTexture.resolution / renderer.resolution; renderer.context.globalAlpha = this.worldAlpha; // If smoothingEnabled is supported and we need to change the smoothing property for this texture - if (renderer.smoothProperty && renderer.currentScaleMode !== this.texture.baseTexture.scaleMode) + if (renderer.smoothProperty && renderer.currentScaleMode !== texture.baseTexture.scaleMode) { - renderer.currentScaleMode = this.texture.baseTexture.scaleMode; + renderer.currentScaleMode = texture.baseTexture.scaleMode; renderer.context[renderer.smoothProperty] = (renderer.currentScaleMode === CONST.SCALE_MODES.LINEAR); } // If the texture is trimmed we offset by the trim x/y, otherwise we use the frame dimensions - var dx = (this.texture.trim) ? this.texture.trim.x - this.anchor.x * this.texture.trim.width : this.anchor.x * -this.texture._frame.width; - var dy = (this.texture.trim) ? this.texture.trim.y - this.anchor.y * this.texture.trim.height : this.anchor.y * -this.texture._frame.height; + + if(texture.rotate) + { + + // cheeky rotation! + var a = wt.a; + var b = wt.b; + + wt.a = -wt.c; + wt.b = -wt.d; + wt.c = a; + wt.d = b; + + width = texture.crop.height; + height = texture.crop.width; + + dx = (texture.trim) ? texture.trim.y - this.anchor.y * texture.trim.height : this.anchor.y * -texture._frame.height; + dy = (texture.trim) ? texture.trim.x - this.anchor.x * texture.trim.width : this.anchor.x * -texture._frame.width; + } + else + { + width = texture.crop.width; + height = texture.crop.height; + + dx = (texture.trim) ? texture.trim.x - this.anchor.x * texture.trim.width : this.anchor.x * -texture._frame.width; + dy = (texture.trim) ? texture.trim.y - this.anchor.y * texture.trim.height : this.anchor.y * -texture._frame.height; + } + + // Allow for pixel rounding if (renderer.roundPixels) { renderer.context.setTransform( - this.worldTransform.a, - this.worldTransform.b, - this.worldTransform.c, - this.worldTransform.d, - (this.worldTransform.tx * renderer.resolution) | 0, - (this.worldTransform.ty * renderer.resolution) | 0 + wt.a, + wt.b, + wt.c, + wt.d, + (wt.tx * renderer.resolution) | 0, + (wt.ty * renderer.resolution) | 0 ); dx = dx | 0; @@ -379,14 +413,17 @@ } else { + renderer.context.setTransform( - this.worldTransform.a, - this.worldTransform.b, - this.worldTransform.c, - this.worldTransform.d, - this.worldTransform.tx * renderer.resolution, - this.worldTransform.ty * renderer.resolution + wt.a, + wt.b, + wt.c, + wt.d, + wt.tx * renderer.resolution, + wt.ty * renderer.resolution ); + + } if (this.tint !== 0xFFFFFF) @@ -403,26 +440,26 @@ this.tintedTexture, 0, 0, - this.texture.crop.width, - this.texture.crop.height, + width, + height, dx / resolution, dy / resolution, - this.texture.crop.width / resolution, - this.texture.crop.height / resolution + width / resolution, + width / resolution ); } else { renderer.context.drawImage( - this.texture.baseTexture.source, - this.texture.crop.x, - this.texture.crop.y, - this.texture.crop.width, - this.texture.crop.height, + texture.baseTexture.source, + texture.crop.x, + texture.crop.y, + width, + height, dx / resolution, dy / resolution, - this.texture.crop.width / resolution, - this.texture.crop.height / resolution + width / resolution, + height / resolution ); } } diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 6a571c8..8958dfc 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,6 +1,7 @@ var BaseTexture = require('./BaseTexture'), Texture = require('./Texture'), RenderTarget = require('../renderers/webgl/utils/RenderTarget'), + FilterManager = require('../renderers/webgl/managers/FilterManager'), CanvasBuffer = require('../renderers/canvas/utils/CanvasBuffer'), math = require('../math'), CONST = require('../const'), @@ -146,6 +147,10 @@ this.textureBuffer = new RenderTarget(gl, this.width, this.height, null, this.resolution);//, this.baseTexture.scaleMode); this.baseTexture._glTextures[gl.id] = this.textureBuffer.texture; + //TODO refactor filter manager.. as really its no longer a manager if we use it here.. + this.filterManager = new FilterManager(this.renderer); + this.filterManager.onContextChange(); + this.filterManager.resize(width, height); this.render = this.renderWebGL; } else @@ -205,6 +210,11 @@ } this.textureBuffer.resize(this.width * this.resolution, this.height * this.resolution); + + if(this.filterManager) + { + this.filterManager.resize(this.width, this.height); + } }; /** @@ -243,19 +253,23 @@ return; } + //TODO this should be true by default updateTransform = !!updateTransform; this.textureBuffer.transform = matrix; // setWorld Alpha to ensure that the object is renderer at full opacity - displayObject.worldAlpha = 1; + displayObject.worldAlpha = displayObject.alpha; if (updateTransform) { + // reset the matrix of the displatyObject.. displayObject.worldTransform.identity(); + displayObject.currentBounds = null; + // Time to update all the children of the displayObject with the new matrix.. var children = displayObject.children; var i, j; @@ -273,9 +287,12 @@ } //TODO rename textureBuffer to renderTarget.. + var temp = this.renderer.filterManager; + this.renderer.filterManager = this.filterManager; this.renderer.renderDisplayObject(displayObject, this.textureBuffer); + this.renderer.filterManager = temp; }; @@ -354,6 +371,12 @@ this.textureBuffer.destroy(); + // destroy the filtermanager.. + if(this.filterManager) + { + this.filterManager.destroy(); + } + this.renderer = null; }; diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 1185599..eb039c0 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -85,10 +85,11 @@ // first we flush anything left in the renderer (otherwise it would get rendered to the cached texture) renderer.currentRenderer.flush(); - + //this.filters= []; // next we find the dimensions of the untransformed object // this function also calls updatetransform on all its children as part of the measuring. This means we don't need to update the transform again in this function - var bounds = this.getLocalBounds(); + // TODO pass an object to clone too? saves having to create a new one each time! + var bounds = this.getLocalBounds().clone(); // for now we cache the current renderTarget that the webGL renderer is currently using. // this could be more elegent.. diff --git a/src/loaders/index.js b/src/loaders/index.js index 5063bab..7781074 100644 --- a/src/loaders/index.js +++ b/src/loaders/index.js @@ -9,8 +9,8 @@ * @namespace PIXI */ module.exports = { - // Loader: require('resource-loader'), - Loader: require('./Loader'), + // Loader: require('resource-loader'), + Loader: require('./loader'), // parsers bitmapFontParser: require('./bitmapFontParser'), diff --git a/gulp/util/jsdoc.conf.json b/gulp/util/jsdoc.conf.json index 7449cb6..adb649a 100644 --- a/gulp/util/jsdoc.conf.json +++ b/gulp/util/jsdoc.conf.json @@ -4,8 +4,7 @@ }, "source": { "include": [ - "./src/index.js", - "./src/core/display/DisplayObject.js" + "./src/" ], "exclude": [ ], diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 9ebe8e4..3ff6d22 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -74,7 +74,29 @@ bounds.width = bounds.width | 0; bounds.height = bounds.height | 0; - this.capFilterArea( bounds ); + + + + + if(this.renderer.currentRenderTarget.transform) + { + //TODO this will break if the renderTexture transform is anything other than a translation. + //Will need to take the full matrix transform into acount.. + var transform = this.renderer.currentRenderTarget.transform; + + bounds.x += transform.tx; + bounds.y += transform.ty; + + this.capFilterArea( bounds ); + + bounds.x -= transform.tx; + bounds.y -= transform.ty; + } + else + { + this.capFilterArea( bounds ); + } + this.currentFrame = bounds; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index cf75bc4..32a7bf2 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -347,31 +347,65 @@ // Ignore null sources if (this.texture.valid) { - var resolution = this.texture.baseTexture.resolution / renderer.resolution; + var texture = this._texture, + wt = this.worldTransform, + dx, + dy, + width, + height; + + var resolution = texture.baseTexture.resolution / renderer.resolution; renderer.context.globalAlpha = this.worldAlpha; // If smoothingEnabled is supported and we need to change the smoothing property for this texture - if (renderer.smoothProperty && renderer.currentScaleMode !== this.texture.baseTexture.scaleMode) + if (renderer.smoothProperty && renderer.currentScaleMode !== texture.baseTexture.scaleMode) { - renderer.currentScaleMode = this.texture.baseTexture.scaleMode; + renderer.currentScaleMode = texture.baseTexture.scaleMode; renderer.context[renderer.smoothProperty] = (renderer.currentScaleMode === CONST.SCALE_MODES.LINEAR); } // If the texture is trimmed we offset by the trim x/y, otherwise we use the frame dimensions - var dx = (this.texture.trim) ? this.texture.trim.x - this.anchor.x * this.texture.trim.width : this.anchor.x * -this.texture._frame.width; - var dy = (this.texture.trim) ? this.texture.trim.y - this.anchor.y * this.texture.trim.height : this.anchor.y * -this.texture._frame.height; + + if(texture.rotate) + { + + // cheeky rotation! + var a = wt.a; + var b = wt.b; + + wt.a = -wt.c; + wt.b = -wt.d; + wt.c = a; + wt.d = b; + + width = texture.crop.height; + height = texture.crop.width; + + dx = (texture.trim) ? texture.trim.y - this.anchor.y * texture.trim.height : this.anchor.y * -texture._frame.height; + dy = (texture.trim) ? texture.trim.x - this.anchor.x * texture.trim.width : this.anchor.x * -texture._frame.width; + } + else + { + width = texture.crop.width; + height = texture.crop.height; + + dx = (texture.trim) ? texture.trim.x - this.anchor.x * texture.trim.width : this.anchor.x * -texture._frame.width; + dy = (texture.trim) ? texture.trim.y - this.anchor.y * texture.trim.height : this.anchor.y * -texture._frame.height; + } + + // Allow for pixel rounding if (renderer.roundPixels) { renderer.context.setTransform( - this.worldTransform.a, - this.worldTransform.b, - this.worldTransform.c, - this.worldTransform.d, - (this.worldTransform.tx * renderer.resolution) | 0, - (this.worldTransform.ty * renderer.resolution) | 0 + wt.a, + wt.b, + wt.c, + wt.d, + (wt.tx * renderer.resolution) | 0, + (wt.ty * renderer.resolution) | 0 ); dx = dx | 0; @@ -379,14 +413,17 @@ } else { + renderer.context.setTransform( - this.worldTransform.a, - this.worldTransform.b, - this.worldTransform.c, - this.worldTransform.d, - this.worldTransform.tx * renderer.resolution, - this.worldTransform.ty * renderer.resolution + wt.a, + wt.b, + wt.c, + wt.d, + wt.tx * renderer.resolution, + wt.ty * renderer.resolution ); + + } if (this.tint !== 0xFFFFFF) @@ -403,26 +440,26 @@ this.tintedTexture, 0, 0, - this.texture.crop.width, - this.texture.crop.height, + width, + height, dx / resolution, dy / resolution, - this.texture.crop.width / resolution, - this.texture.crop.height / resolution + width / resolution, + width / resolution ); } else { renderer.context.drawImage( - this.texture.baseTexture.source, - this.texture.crop.x, - this.texture.crop.y, - this.texture.crop.width, - this.texture.crop.height, + texture.baseTexture.source, + texture.crop.x, + texture.crop.y, + width, + height, dx / resolution, dy / resolution, - this.texture.crop.width / resolution, - this.texture.crop.height / resolution + width / resolution, + height / resolution ); } } diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index 6a571c8..8958dfc 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,6 +1,7 @@ var BaseTexture = require('./BaseTexture'), Texture = require('./Texture'), RenderTarget = require('../renderers/webgl/utils/RenderTarget'), + FilterManager = require('../renderers/webgl/managers/FilterManager'), CanvasBuffer = require('../renderers/canvas/utils/CanvasBuffer'), math = require('../math'), CONST = require('../const'), @@ -146,6 +147,10 @@ this.textureBuffer = new RenderTarget(gl, this.width, this.height, null, this.resolution);//, this.baseTexture.scaleMode); this.baseTexture._glTextures[gl.id] = this.textureBuffer.texture; + //TODO refactor filter manager.. as really its no longer a manager if we use it here.. + this.filterManager = new FilterManager(this.renderer); + this.filterManager.onContextChange(); + this.filterManager.resize(width, height); this.render = this.renderWebGL; } else @@ -205,6 +210,11 @@ } this.textureBuffer.resize(this.width * this.resolution, this.height * this.resolution); + + if(this.filterManager) + { + this.filterManager.resize(this.width, this.height); + } }; /** @@ -243,19 +253,23 @@ return; } + //TODO this should be true by default updateTransform = !!updateTransform; this.textureBuffer.transform = matrix; // setWorld Alpha to ensure that the object is renderer at full opacity - displayObject.worldAlpha = 1; + displayObject.worldAlpha = displayObject.alpha; if (updateTransform) { + // reset the matrix of the displatyObject.. displayObject.worldTransform.identity(); + displayObject.currentBounds = null; + // Time to update all the children of the displayObject with the new matrix.. var children = displayObject.children; var i, j; @@ -273,9 +287,12 @@ } //TODO rename textureBuffer to renderTarget.. + var temp = this.renderer.filterManager; + this.renderer.filterManager = this.filterManager; this.renderer.renderDisplayObject(displayObject, this.textureBuffer); + this.renderer.filterManager = temp; }; @@ -354,6 +371,12 @@ this.textureBuffer.destroy(); + // destroy the filtermanager.. + if(this.filterManager) + { + this.filterManager.destroy(); + } + this.renderer = null; }; diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 1185599..eb039c0 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -85,10 +85,11 @@ // first we flush anything left in the renderer (otherwise it would get rendered to the cached texture) renderer.currentRenderer.flush(); - + //this.filters= []; // next we find the dimensions of the untransformed object // this function also calls updatetransform on all its children as part of the measuring. This means we don't need to update the transform again in this function - var bounds = this.getLocalBounds(); + // TODO pass an object to clone too? saves having to create a new one each time! + var bounds = this.getLocalBounds().clone(); // for now we cache the current renderTarget that the webGL renderer is currently using. // this could be more elegent.. diff --git a/src/loaders/index.js b/src/loaders/index.js index 5063bab..7781074 100644 --- a/src/loaders/index.js +++ b/src/loaders/index.js @@ -9,8 +9,8 @@ * @namespace PIXI */ module.exports = { - // Loader: require('resource-loader'), - Loader: require('./Loader'), + // Loader: require('resource-loader'), + Loader: require('./loader'), // parsers bitmapFontParser: require('./bitmapFontParser'), diff --git a/src/text/Text.js b/src/text/Text.js index 6b43047..08a8c04 100644 --- a/src/text/Text.js +++ b/src/text/Text.js @@ -384,7 +384,7 @@ context.font = fontStyle; - var width = Math.ceil(context.measureText('|Mq').width); + var width = Math.ceil(context.measureText('|M�q').width); var baseline = Math.ceil(context.measureText('M').width); var height = 2 * baseline; @@ -459,8 +459,6 @@ } properties.descent = i - baseline; - //TODO might need a tweak. kind of a temp fix! - properties.descent += 6; properties.fontSize = properties.ascent + properties.descent; Text.fontPropertiesCache[fontStyle] = properties;