diff --git a/packages/canvas/canvas-graphics/src/CanvasGraphicsRenderer.js b/packages/canvas/canvas-graphics/src/CanvasGraphicsRenderer.js index cabe8e2..b7df597 100644 --- a/packages/canvas/canvas-graphics/src/CanvasGraphicsRenderer.js +++ b/packages/canvas/canvas-graphics/src/CanvasGraphicsRenderer.js @@ -52,7 +52,7 @@ ); // update tint if graphics was dirty - if (graphics.canvasTintDirty !== graphics.dirty + if (graphics.canvasTintDirty !== graphics.geometry.dirty || graphics._prevTint !== graphics.tint) { this.updateGraphicsTint(graphics); @@ -293,7 +293,7 @@ updateGraphicsTint(graphics) { graphics._prevTint = graphics.tint; - graphics.canvasTintDirty = graphics.dirty; + graphics.canvasTintDirty = graphics.geometry.dirty; const tintR = ((graphics.tint >> 16) & 0xFF) / 255; const tintG = ((graphics.tint >> 8) & 0xFF) / 255; diff --git a/packages/canvas/canvas-graphics/src/CanvasGraphicsRenderer.js b/packages/canvas/canvas-graphics/src/CanvasGraphicsRenderer.js index cabe8e2..b7df597 100644 --- a/packages/canvas/canvas-graphics/src/CanvasGraphicsRenderer.js +++ b/packages/canvas/canvas-graphics/src/CanvasGraphicsRenderer.js @@ -52,7 +52,7 @@ ); // update tint if graphics was dirty - if (graphics.canvasTintDirty !== graphics.dirty + if (graphics.canvasTintDirty !== graphics.geometry.dirty || graphics._prevTint !== graphics.tint) { this.updateGraphicsTint(graphics); @@ -293,7 +293,7 @@ updateGraphicsTint(graphics) { graphics._prevTint = graphics.tint; - graphics.canvasTintDirty = graphics.dirty; + graphics.canvasTintDirty = graphics.geometry.dirty; const tintR = ((graphics.tint >> 16) & 0xFF) / 255; const tintG = ((graphics.tint >> 8) & 0xFF) / 255; diff --git a/packages/graphics/src/GraphicsGeometry.js b/packages/graphics/src/GraphicsGeometry.js index b02d285..6751354 100644 --- a/packages/graphics/src/GraphicsGeometry.js +++ b/packages/graphics/src/GraphicsGeometry.js @@ -111,8 +111,7 @@ this.graphicsData = []; /** - * Used to detect if the graphics object has changed. If this is set to true then the graphics - * object will be recalculated. + * Used to detect if the graphics object has changed. * * @member {number} * @protected @@ -136,7 +135,7 @@ this.cacheDirty = -1; /** - * Used to detect if we clear the graphics WebGL data. + * Used to detect if we cleared the graphicsData. * * @member {number} * @default 0 @@ -162,7 +161,7 @@ this.batches = []; /** - * Index of the current last shape in the stack of calls. + * Index of the last batched shape in the stack of calls. * * @member {number} * @protected @@ -218,6 +217,44 @@ } /** + * Call if you changed graphicsData manually. + * Empties all batch buffers. + */ + invalidate() + { + this.boundsDirty = -1; + this.dirty++; + this.batchDirty++; + this.shapeIndex = 0; + + this.points.length = 0; + this.colors.length = 0; + this.uvs.length = 0; + this.indices.length = 0; + this.textureIds.length = 0; + + for (let i = 0; i < this.drawCalls.length; i++) + { + this.drawCalls[i].textures.length = 0; + DRAW_CALL_POOL.push(this.drawCalls[i]); + } + + this.drawCalls.length = 0; + + for (let i = 0; i < this.batches.length; i++) + { + const batch = this.batches[i]; + + batch.start = 0; + batch.attribStart = 0; + batch.style = null; + BATCH_POOL.push(batch); + } + + this.batches.length = 0; + } + + /** * Clears the graphics that were drawn to this Graphics object, and resets fill and line style settings. * * @return {PIXI.GraphicsGeometry} This GraphicsGeometry object. Good for chaining method calls @@ -226,38 +263,9 @@ { if (this.graphicsData.length > 0) { - this.boundsDirty = -1; - this.dirty++; + this.invalidate(); this.clearDirty++; - this.batchDirty++; this.graphicsData.length = 0; - this.shapeIndex = 0; - - this.points.length = 0; - this.colors.length = 0; - this.uvs.length = 0; - this.indices.length = 0; - this.textureIds.length = 0; - - for (let i = 0; i < this.drawCalls.length; i++) - { - this.drawCalls[i].textures.length = 0; - DRAW_CALL_POOL.push(this.drawCalls[i]); - } - - this.drawCalls.length = 0; - - for (let i = 0; i < this.batches.length; i++) - { - const batch = this.batches[i]; - - batch.start = 0; - batch.attribStart = 0; - batch.style = null; - BATCH_POOL.push(batch); - } - - this.batches.length = 0; } return this; @@ -398,7 +406,6 @@ /** * Generates intermediate batch data. Either gets converted to drawCalls * or used to convert to batch objects directly by the Graphics object. - * @protected */ updateBatches() {