diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 122c690..c7641f6 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -128,18 +128,25 @@ * @member {boolean} * @private */ - this.dirty = true; + this.dirty = 0; /** - * Used to detect if the WebGL graphics object has changed. If this is set to true then the - * graphics object will be recalculated. - * - * @member {boolean} - * @private + * Used to detect if we need to do a fast rect check using the id compare method + * @type {Number} */ - this.glDirty = false; + this.fastRectDirty = -1; - this.boundsDirty = true; + /** + * Used to detect if we clear the graphics webGL data + * @type {Number} + */ + this.clearDirty = 0; + + /** + * Used to detect if we we need to recalculate local bounds + * @type {Number} + */ + this.boundsDirty = -1; /** * Used to detect if the cached sprite object needs to be updated. @@ -192,8 +199,7 @@ clone.blendMode = this.blendMode; clone.isMask = this.isMask; clone.boundsPadding = this.boundsPadding; - clone.dirty = true; - clone.glDirty = true; + clone.dirty = 0; clone.cachedSpriteDirty = this.cachedSpriteDirty; // copy graphics data @@ -271,7 +277,7 @@ Graphics.prototype.lineTo = function (x, y) { this.currentPath.shape.points.push(x, y); - this.dirty = true; + this.dirty++; return this; }; @@ -326,7 +332,7 @@ ya + ( ((cpY + ( (toY - cpY) * j )) - ya) * j ) ); } - this.dirty = this.boundsDirty = true; + this.dirty++; return this; }; @@ -365,7 +371,7 @@ bezierCurveTo(fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, points); - this.dirty = this.boundsDirty = true; + this.dirty++; return this; }; @@ -433,7 +439,7 @@ this.arc(cx + x1, cy + y1, radius, startAngle, endAngle, b1 * a2 > b2 * a1); } - this.dirty = this.boundsDirty = true; + this.dirty++; return this; }; @@ -513,7 +519,7 @@ ( (cTheta * -s) + (sTheta * c) ) * radius + cy); } - this.dirty = this.boundsDirty = true; + this.dirty++; return this; }; @@ -670,8 +676,8 @@ this.lineWidth = 0; this.filling = false; - this.dirty = true; - this.clearDirty = true; + this.dirty++; + this.clearDirty++; this.graphicsData = []; return this; @@ -694,15 +700,9 @@ Graphics.prototype._renderWebGL = function (renderer) { // if the sprite is not visible or the alpha is 0 then no need to render this element - - if (this.glDirty) + if(this.dirty !== this.fastRectDirty) { - this.dirty = true; - this.glDirty = false; - } - - if(this.dirty) - { + this.fastRectDirty = this.dirty; this._fastRect = this.isFastRect(); } @@ -782,13 +782,13 @@ return; } - if (this.boundsDirty) + if (this.boundsDirty !== this.dirty) { + this.boundsDirty = this.dirty; this.updateLocalBounds(); - this.glDirty = true; + this.dirty++; this.cachedSpriteDirty = true; - this.boundsDirty = false; } var lb = this._localBounds; @@ -957,7 +957,7 @@ this.currentPath = data; } - this.dirty = this.boundsDirty = true; + this.dirty++; return data; }; diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 122c690..c7641f6 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -128,18 +128,25 @@ * @member {boolean} * @private */ - this.dirty = true; + this.dirty = 0; /** - * Used to detect if the WebGL graphics object has changed. If this is set to true then the - * graphics object will be recalculated. - * - * @member {boolean} - * @private + * Used to detect if we need to do a fast rect check using the id compare method + * @type {Number} */ - this.glDirty = false; + this.fastRectDirty = -1; - this.boundsDirty = true; + /** + * Used to detect if we clear the graphics webGL data + * @type {Number} + */ + this.clearDirty = 0; + + /** + * Used to detect if we we need to recalculate local bounds + * @type {Number} + */ + this.boundsDirty = -1; /** * Used to detect if the cached sprite object needs to be updated. @@ -192,8 +199,7 @@ clone.blendMode = this.blendMode; clone.isMask = this.isMask; clone.boundsPadding = this.boundsPadding; - clone.dirty = true; - clone.glDirty = true; + clone.dirty = 0; clone.cachedSpriteDirty = this.cachedSpriteDirty; // copy graphics data @@ -271,7 +277,7 @@ Graphics.prototype.lineTo = function (x, y) { this.currentPath.shape.points.push(x, y); - this.dirty = true; + this.dirty++; return this; }; @@ -326,7 +332,7 @@ ya + ( ((cpY + ( (toY - cpY) * j )) - ya) * j ) ); } - this.dirty = this.boundsDirty = true; + this.dirty++; return this; }; @@ -365,7 +371,7 @@ bezierCurveTo(fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, points); - this.dirty = this.boundsDirty = true; + this.dirty++; return this; }; @@ -433,7 +439,7 @@ this.arc(cx + x1, cy + y1, radius, startAngle, endAngle, b1 * a2 > b2 * a1); } - this.dirty = this.boundsDirty = true; + this.dirty++; return this; }; @@ -513,7 +519,7 @@ ( (cTheta * -s) + (sTheta * c) ) * radius + cy); } - this.dirty = this.boundsDirty = true; + this.dirty++; return this; }; @@ -670,8 +676,8 @@ this.lineWidth = 0; this.filling = false; - this.dirty = true; - this.clearDirty = true; + this.dirty++; + this.clearDirty++; this.graphicsData = []; return this; @@ -694,15 +700,9 @@ Graphics.prototype._renderWebGL = function (renderer) { // if the sprite is not visible or the alpha is 0 then no need to render this element - - if (this.glDirty) + if(this.dirty !== this.fastRectDirty) { - this.dirty = true; - this.glDirty = false; - } - - if(this.dirty) - { + this.fastRectDirty = this.dirty; this._fastRect = this.isFastRect(); } @@ -782,13 +782,13 @@ return; } - if (this.boundsDirty) + if (this.boundsDirty !== this.dirty) { + this.boundsDirty = this.dirty; this.updateLocalBounds(); - this.glDirty = true; + this.dirty++; this.cachedSpriteDirty = true; - this.boundsDirty = false; } var lb = this._localBounds; @@ -957,7 +957,7 @@ this.currentPath = data; } - this.dirty = this.boundsDirty = true; + this.dirty++; return data; }; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index da99308..ccf1117 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -81,12 +81,17 @@ var webGLData; - if (graphics.dirty || !graphics._webGL[this.CONTEXT_UID]) + var webGL = graphics._webGL[this.CONTEXT_UID]; + + if (!webGL || graphics.dirty !== webGL.dirty ) { + this.updateGraphics(graphics); + + webGL = graphics._webGL[this.CONTEXT_UID]; } - var webGL = graphics._webGL[this.CONTEXT_UID]; + // This could be speeded up for sure! var shader = this.primitiveShader; @@ -125,19 +130,19 @@ // if the graphics object does not exist in the webGL context time to create it! if (!webGL) { - webGL = graphics._webGL[this.CONTEXT_UID] = {lastIndex:0, data:[], gl:gl}; + webGL = graphics._webGL[this.CONTEXT_UID] = {lastIndex:0, data:[], gl:gl, clearDirty:-1, dirty:-1}; } // flag the graphics as not dirty as we are about to update it... - graphics.dirty = false; + webGL.dirty = graphics.dirty; var i; // if the user cleared the graphics object we will need to clear every object - if (graphics.clearDirty) + if (graphics.clearDirty !== webGL.clearDirty) { - graphics.clearDirty = false; + webGL.clearDirty = graphics.clearDirty; // loop through and return all the webGLDatas to the object pool so than can be reused later on for (i = 0; i < webGL.data.length; i++) diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 122c690..c7641f6 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -128,18 +128,25 @@ * @member {boolean} * @private */ - this.dirty = true; + this.dirty = 0; /** - * Used to detect if the WebGL graphics object has changed. If this is set to true then the - * graphics object will be recalculated. - * - * @member {boolean} - * @private + * Used to detect if we need to do a fast rect check using the id compare method + * @type {Number} */ - this.glDirty = false; + this.fastRectDirty = -1; - this.boundsDirty = true; + /** + * Used to detect if we clear the graphics webGL data + * @type {Number} + */ + this.clearDirty = 0; + + /** + * Used to detect if we we need to recalculate local bounds + * @type {Number} + */ + this.boundsDirty = -1; /** * Used to detect if the cached sprite object needs to be updated. @@ -192,8 +199,7 @@ clone.blendMode = this.blendMode; clone.isMask = this.isMask; clone.boundsPadding = this.boundsPadding; - clone.dirty = true; - clone.glDirty = true; + clone.dirty = 0; clone.cachedSpriteDirty = this.cachedSpriteDirty; // copy graphics data @@ -271,7 +277,7 @@ Graphics.prototype.lineTo = function (x, y) { this.currentPath.shape.points.push(x, y); - this.dirty = true; + this.dirty++; return this; }; @@ -326,7 +332,7 @@ ya + ( ((cpY + ( (toY - cpY) * j )) - ya) * j ) ); } - this.dirty = this.boundsDirty = true; + this.dirty++; return this; }; @@ -365,7 +371,7 @@ bezierCurveTo(fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, points); - this.dirty = this.boundsDirty = true; + this.dirty++; return this; }; @@ -433,7 +439,7 @@ this.arc(cx + x1, cy + y1, radius, startAngle, endAngle, b1 * a2 > b2 * a1); } - this.dirty = this.boundsDirty = true; + this.dirty++; return this; }; @@ -513,7 +519,7 @@ ( (cTheta * -s) + (sTheta * c) ) * radius + cy); } - this.dirty = this.boundsDirty = true; + this.dirty++; return this; }; @@ -670,8 +676,8 @@ this.lineWidth = 0; this.filling = false; - this.dirty = true; - this.clearDirty = true; + this.dirty++; + this.clearDirty++; this.graphicsData = []; return this; @@ -694,15 +700,9 @@ Graphics.prototype._renderWebGL = function (renderer) { // if the sprite is not visible or the alpha is 0 then no need to render this element - - if (this.glDirty) + if(this.dirty !== this.fastRectDirty) { - this.dirty = true; - this.glDirty = false; - } - - if(this.dirty) - { + this.fastRectDirty = this.dirty; this._fastRect = this.isFastRect(); } @@ -782,13 +782,13 @@ return; } - if (this.boundsDirty) + if (this.boundsDirty !== this.dirty) { + this.boundsDirty = this.dirty; this.updateLocalBounds(); - this.glDirty = true; + this.dirty++; this.cachedSpriteDirty = true; - this.boundsDirty = false; } var lb = this._localBounds; @@ -957,7 +957,7 @@ this.currentPath = data; } - this.dirty = this.boundsDirty = true; + this.dirty++; return data; }; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index da99308..ccf1117 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -81,12 +81,17 @@ var webGLData; - if (graphics.dirty || !graphics._webGL[this.CONTEXT_UID]) + var webGL = graphics._webGL[this.CONTEXT_UID]; + + if (!webGL || graphics.dirty !== webGL.dirty ) { + this.updateGraphics(graphics); + + webGL = graphics._webGL[this.CONTEXT_UID]; } - var webGL = graphics._webGL[this.CONTEXT_UID]; + // This could be speeded up for sure! var shader = this.primitiveShader; @@ -125,19 +130,19 @@ // if the graphics object does not exist in the webGL context time to create it! if (!webGL) { - webGL = graphics._webGL[this.CONTEXT_UID] = {lastIndex:0, data:[], gl:gl}; + webGL = graphics._webGL[this.CONTEXT_UID] = {lastIndex:0, data:[], gl:gl, clearDirty:-1, dirty:-1}; } // flag the graphics as not dirty as we are about to update it... - graphics.dirty = false; + webGL.dirty = graphics.dirty; var i; // if the user cleared the graphics object we will need to clear every object - if (graphics.clearDirty) + if (graphics.clearDirty !== webGL.clearDirty) { - graphics.clearDirty = false; + webGL.clearDirty = graphics.clearDirty; // loop through and return all the webGLDatas to the object pool so than can be reused later on for (i = 0; i < webGL.data.length; i++) diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index e3eedb7..afbb4b3 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -56,10 +56,10 @@ /** * Whether the Mesh is dirty or not * - * @member {boolean} + * @member {number} */ - this.dirty = true; - this.indexDirty = true; + this.dirty = 0; + this.indexDirty = 0; /** * The blend mode to be applied to the sprite. Set to `PIXI.BLEND_MODES.NORMAL` to remove any blend mode. @@ -187,7 +187,9 @@ uvBuffer:glCore.GLBuffer.createVertexBuffer(gl, this.uvs, gl.STREAM_DRAW), indexBuffer:glCore.GLBuffer.createIndexBuffer(gl, this.indices, gl.STATIC_DRAW), // build the vao object that will render.. - vao:new glCore.VertexArrayObject(gl) + vao:new glCore.VertexArrayObject(gl), + dirty:this.dirty, + indexDirty:this.indexDirty }; // build the vao object that will render.. @@ -199,19 +201,18 @@ this._glDatas[renderer.CONTEXT_UID] = glData; - this.indexDirty = false; } - if(this.dirty) + if(this.dirty !== glData.dirty) { - this.dirty = false; + glData.dirty = this.dirty; glData.uvBuffer.upload(); } - if(this.indexDirty) + if(this.indexDirty !== glData.indexDirty) { - this.indexDirty = false; + glData.indexDirty = this.indexDirty; glData.indexBuffer.upload(); }