diff --git a/src/pixi/primitives/Graphics.js b/src/pixi/primitives/Graphics.js index b4bae09..7a51d9a 100644 --- a/src/pixi/primitives/Graphics.js +++ b/src/pixi/primitives/Graphics.js @@ -94,14 +94,6 @@ this.isMask = false; /** - * The bounds of the graphic shape - * - * @property bounds - * @type Rectangle - */ - this.bounds = new PIXI.Rectangle(0, 0, 0, 0); - - /** * The bounds' padding used for bounds calculation. * * @property boundsPadding @@ -118,6 +110,15 @@ */ this.dirty = true; + /** + * Used to detect if the cached sprite object needs to be updated. + * + * @property cachedSpriteDirty + * @type Boolean + * @private + */ + this.cachedSpriteDirty = false; + }; // constructor @@ -599,8 +600,6 @@ this.clearDirty = true; this.graphicsData = []; - this.bounds = null; //new PIXI.Rectangle(); - return this; }; @@ -647,13 +646,15 @@ if(this._cacheAsBitmap) { - if(this.dirty) + if(this.dirty || this.cachedSpriteDirty) { this._generateCachedSprite(); + // we will also need to update the texture on the gpu too! - PIXI.updateWebGLTexture(this._cachedSprite.texture.baseTexture, renderSession.gl); - - this.dirty = false; + this.updateCachedSpriteTexture(); + + this.cachedSpriteDirty = false; + this.dirty = false; } this._cachedSprite.alpha = this.alpha; @@ -714,40 +715,85 @@ // if the sprite is not visible or the alpha is 0 then no need to render this element if(this.visible === false || this.alpha === 0 || this.isMask === true)return; - var context = renderSession.context; - var transform = this.worldTransform; - - if(this.blendMode !== renderSession.currentBlendMode) + if(this._cacheAsBitmap) { - renderSession.currentBlendMode = this.blendMode; - context.globalCompositeOperation = PIXI.blendModesCanvas[renderSession.currentBlendMode]; - } + if(this.dirty || this.cachedSpriteDirty) + { + this._generateCachedSprite(); + + // we will also need to update the texture + this.updateCachedSpriteTexture(); - if(this._mask) + this.cachedSpriteDirty = false; + this.dirty = false; + } + + this._cachedSprite.alpha = this.alpha; + PIXI.Sprite.prototype._renderCanvas.call(this._cachedSprite, renderSession); + + return; + } + else { - renderSession.maskManager.pushMask(this._mask, renderSession); + var context = renderSession.context; + var transform = this.worldTransform; + + if(this.blendMode !== renderSession.currentBlendMode) + { + renderSession.currentBlendMode = this.blendMode; + context.globalCompositeOperation = PIXI.blendModesCanvas[renderSession.currentBlendMode]; + } + + if(this._mask) + { + renderSession.maskManager.pushMask(this._mask, renderSession); + } + + var resolution = renderSession.resolution; + context.setTransform(transform.a * resolution, + transform.b * resolution, + transform.c * resolution, + transform.d * resolution, + transform.tx * resolution, + transform.ty * resolution); + + PIXI.CanvasGraphics.renderGraphics(this, context); + + // simple render children! + for(var i=0, j=this.children.length; i maxY ? y3 : maxY; maxY = y4 > maxY ? y4 : maxY; - var bounds = this._bounds; - bounds.x = minX; bounds.width = maxX - minX; @@ -842,7 +893,7 @@ shape = data.shape; - if(type === PIXI.Graphics.RECT) + if(type === PIXI.Graphics.RECT || type === PIXI.Graphics.RRECT) { x = shape.x - lineWidth/2; y = shape.y - lineWidth/2; @@ -901,7 +952,13 @@ } var padding = this.boundsPadding; - this.bounds = new PIXI.Rectangle(minX - padding, minY - padding, (maxX - minX) + padding * 2, (maxY - minY) + padding * 2); + var bounds = this._bounds; + + bounds.x = minX - padding; + bounds.width = (maxX - minX) + padding * 2; + + bounds.y = minY - padding; + bounds.height = (maxY - minY) + padding * 2; }; /**