diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index db966b5..79325cb 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -260,6 +260,8 @@ /* * Updates the object transform for rendering * + * TODO - Optimization pass! + * * @private */ DisplayObject.prototype.updateTransform = function () { @@ -271,11 +273,9 @@ var a, b, c, d, tx, ty; // so if rotation is between 0 then we can simplify the multiplication process.. - if(this.rotation % math.PI_2) - { + if (this.rotation % math.PI_2) { // check to see if the rotation is the same as the previous render. This means we only need to use sin and cos when rotation actually changes - if(this.rotation !== this.rotationCache) - { + if (this.rotation !== this.rotationCache) { this.rotationCache = this.rotation; this._sr = Math.sin(this.rotation); this._cr = Math.cos(this.rotation); @@ -290,8 +290,7 @@ ty = this.position.y; // check for pivot.. not often used so geared towards that fact! - if(this.pivot.x || this.pivot.y) - { + if (this.pivot.x || this.pivot.y) { tx -= this.pivot.x * a + this.pivot.y * c; ty -= this.pivot.x * b + this.pivot.y * d; } @@ -303,11 +302,8 @@ wt.d = c * pt.b + d * pt.d; wt.tx = tx * pt.a + ty * pt.c + pt.tx; wt.ty = tx * pt.b + ty * pt.d + pt.ty; - - } - else - { + else { // lets do the fast version as we know there is no rotation.. a = this.scale.x; d = this.scale.y; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index db966b5..79325cb 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -260,6 +260,8 @@ /* * Updates the object transform for rendering * + * TODO - Optimization pass! + * * @private */ DisplayObject.prototype.updateTransform = function () { @@ -271,11 +273,9 @@ var a, b, c, d, tx, ty; // so if rotation is between 0 then we can simplify the multiplication process.. - if(this.rotation % math.PI_2) - { + if (this.rotation % math.PI_2) { // check to see if the rotation is the same as the previous render. This means we only need to use sin and cos when rotation actually changes - if(this.rotation !== this.rotationCache) - { + if (this.rotation !== this.rotationCache) { this.rotationCache = this.rotation; this._sr = Math.sin(this.rotation); this._cr = Math.cos(this.rotation); @@ -290,8 +290,7 @@ ty = this.position.y; // check for pivot.. not often used so geared towards that fact! - if(this.pivot.x || this.pivot.y) - { + if (this.pivot.x || this.pivot.y) { tx -= this.pivot.x * a + this.pivot.y * c; ty -= this.pivot.x * b + this.pivot.y * d; } @@ -303,11 +302,8 @@ wt.d = c * pt.b + d * pt.d; wt.tx = tx * pt.a + ty * pt.c + pt.tx; wt.ty = tx * pt.b + ty * pt.d + pt.ty; - - } - else - { + else { // lets do the fast version as we know there is no rotation.. a = this.scale.x; d = this.scale.y; diff --git a/src/core/display/DisplayObjectContainer.js b/src/core/display/DisplayObjectContainer.js index ce573c5..7b0afd3 100644 --- a/src/core/display/DisplayObjectContainer.js +++ b/src/core/display/DisplayObjectContainer.js @@ -138,6 +138,11 @@ * @return {DisplayObject} The child that was added. */ DisplayObjectContainer.prototype.addChildAt = function (child, index) { + // prevent adding self as child + if (child === this) { + return; + } + if (index >= 0 && index <= this.children.length) { if (child.parent) { child.parent.removeChild(child); @@ -419,6 +424,8 @@ /** * Renders the object using the WebGL renderer * + * TODO - Optimization pass! + * * @param renderer {WebGLRenderer} The renderer */ DisplayObjectContainer.prototype.renderWebGL = function (renderer) { @@ -449,7 +456,9 @@ } // add this object to the batch, only rendered if it has a texture. - renderer.spriteBatch.render(this); + if (this.texture) { + renderer.spriteBatch.render(this); + } // now loop through the children and make sure they get rendered for (i = 0, j = this.children.length; i < j; i++) { @@ -470,7 +479,9 @@ renderer.spriteBatch.start(); } else { - renderer.spriteBatch.render(this); + if (this.texture) { + renderer.spriteBatch.render(this); + } // simple render children! for (i = 0, j = this.children.length; i < j; ++i) { diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index db966b5..79325cb 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -260,6 +260,8 @@ /* * Updates the object transform for rendering * + * TODO - Optimization pass! + * * @private */ DisplayObject.prototype.updateTransform = function () { @@ -271,11 +273,9 @@ var a, b, c, d, tx, ty; // so if rotation is between 0 then we can simplify the multiplication process.. - if(this.rotation % math.PI_2) - { + if (this.rotation % math.PI_2) { // check to see if the rotation is the same as the previous render. This means we only need to use sin and cos when rotation actually changes - if(this.rotation !== this.rotationCache) - { + if (this.rotation !== this.rotationCache) { this.rotationCache = this.rotation; this._sr = Math.sin(this.rotation); this._cr = Math.cos(this.rotation); @@ -290,8 +290,7 @@ ty = this.position.y; // check for pivot.. not often used so geared towards that fact! - if(this.pivot.x || this.pivot.y) - { + if (this.pivot.x || this.pivot.y) { tx -= this.pivot.x * a + this.pivot.y * c; ty -= this.pivot.x * b + this.pivot.y * d; } @@ -303,11 +302,8 @@ wt.d = c * pt.b + d * pt.d; wt.tx = tx * pt.a + ty * pt.c + pt.tx; wt.ty = tx * pt.b + ty * pt.d + pt.ty; - - } - else - { + else { // lets do the fast version as we know there is no rotation.. a = this.scale.x; d = this.scale.y; diff --git a/src/core/display/DisplayObjectContainer.js b/src/core/display/DisplayObjectContainer.js index ce573c5..7b0afd3 100644 --- a/src/core/display/DisplayObjectContainer.js +++ b/src/core/display/DisplayObjectContainer.js @@ -138,6 +138,11 @@ * @return {DisplayObject} The child that was added. */ DisplayObjectContainer.prototype.addChildAt = function (child, index) { + // prevent adding self as child + if (child === this) { + return; + } + if (index >= 0 && index <= this.children.length) { if (child.parent) { child.parent.removeChild(child); @@ -419,6 +424,8 @@ /** * Renders the object using the WebGL renderer * + * TODO - Optimization pass! + * * @param renderer {WebGLRenderer} The renderer */ DisplayObjectContainer.prototype.renderWebGL = function (renderer) { @@ -449,7 +456,9 @@ } // add this object to the batch, only rendered if it has a texture. - renderer.spriteBatch.render(this); + if (this.texture) { + renderer.spriteBatch.render(this); + } // now loop through the children and make sure they get rendered for (i = 0, j = this.children.length; i < j; i++) { @@ -470,7 +479,9 @@ renderer.spriteBatch.start(); } else { - renderer.spriteBatch.render(this); + if (this.texture) { + renderer.spriteBatch.render(this); + } // simple render children! for (i = 0, j = this.children.length; i < j; ++i) { diff --git a/src/core/renderers/webgl/shaders/Shader.js b/src/core/renderers/webgl/shaders/Shader.js index 0d9d8f9..7365762 100644 --- a/src/core/renderers/webgl/shaders/Shader.js +++ b/src/core/renderers/webgl/shaders/Shader.js @@ -117,15 +117,16 @@ } // TODO: Check if this is needed anymore... + // Begin worst hack eva // // WHY??? ONLY on my chrome pixel the line above returns -1 when using filters? // maybe its something to do with the current state of the gl context. // I'm convinced this is a bug in the chrome browser as there is NO reason why this should be returning -1 especially as it only manifests on my chrome pixel // If theres any webGL people that know why could happen please help :) - if (this.attributes.aColor === -1) { - this.attributes.aColor = 2; - } + // if (this.attributes.aColor === -1) { + // this.attributes.aColor = 2; + // } // End worst hack eva // }; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index db966b5..79325cb 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -260,6 +260,8 @@ /* * Updates the object transform for rendering * + * TODO - Optimization pass! + * * @private */ DisplayObject.prototype.updateTransform = function () { @@ -271,11 +273,9 @@ var a, b, c, d, tx, ty; // so if rotation is between 0 then we can simplify the multiplication process.. - if(this.rotation % math.PI_2) - { + if (this.rotation % math.PI_2) { // check to see if the rotation is the same as the previous render. This means we only need to use sin and cos when rotation actually changes - if(this.rotation !== this.rotationCache) - { + if (this.rotation !== this.rotationCache) { this.rotationCache = this.rotation; this._sr = Math.sin(this.rotation); this._cr = Math.cos(this.rotation); @@ -290,8 +290,7 @@ ty = this.position.y; // check for pivot.. not often used so geared towards that fact! - if(this.pivot.x || this.pivot.y) - { + if (this.pivot.x || this.pivot.y) { tx -= this.pivot.x * a + this.pivot.y * c; ty -= this.pivot.x * b + this.pivot.y * d; } @@ -303,11 +302,8 @@ wt.d = c * pt.b + d * pt.d; wt.tx = tx * pt.a + ty * pt.c + pt.tx; wt.ty = tx * pt.b + ty * pt.d + pt.ty; - - } - else - { + else { // lets do the fast version as we know there is no rotation.. a = this.scale.x; d = this.scale.y; diff --git a/src/core/display/DisplayObjectContainer.js b/src/core/display/DisplayObjectContainer.js index ce573c5..7b0afd3 100644 --- a/src/core/display/DisplayObjectContainer.js +++ b/src/core/display/DisplayObjectContainer.js @@ -138,6 +138,11 @@ * @return {DisplayObject} The child that was added. */ DisplayObjectContainer.prototype.addChildAt = function (child, index) { + // prevent adding self as child + if (child === this) { + return; + } + if (index >= 0 && index <= this.children.length) { if (child.parent) { child.parent.removeChild(child); @@ -419,6 +424,8 @@ /** * Renders the object using the WebGL renderer * + * TODO - Optimization pass! + * * @param renderer {WebGLRenderer} The renderer */ DisplayObjectContainer.prototype.renderWebGL = function (renderer) { @@ -449,7 +456,9 @@ } // add this object to the batch, only rendered if it has a texture. - renderer.spriteBatch.render(this); + if (this.texture) { + renderer.spriteBatch.render(this); + } // now loop through the children and make sure they get rendered for (i = 0, j = this.children.length; i < j; i++) { @@ -470,7 +479,9 @@ renderer.spriteBatch.start(); } else { - renderer.spriteBatch.render(this); + if (this.texture) { + renderer.spriteBatch.render(this); + } // simple render children! for (i = 0, j = this.children.length; i < j; ++i) { diff --git a/src/core/renderers/webgl/shaders/Shader.js b/src/core/renderers/webgl/shaders/Shader.js index 0d9d8f9..7365762 100644 --- a/src/core/renderers/webgl/shaders/Shader.js +++ b/src/core/renderers/webgl/shaders/Shader.js @@ -117,15 +117,16 @@ } // TODO: Check if this is needed anymore... + // Begin worst hack eva // // WHY??? ONLY on my chrome pixel the line above returns -1 when using filters? // maybe its something to do with the current state of the gl context. // I'm convinced this is a bug in the chrome browser as there is NO reason why this should be returning -1 especially as it only manifests on my chrome pixel // If theres any webGL people that know why could happen please help :) - if (this.attributes.aColor === -1) { - this.attributes.aColor = 2; - } + // if (this.attributes.aColor === -1) { + // this.attributes.aColor = 2; + // } // End worst hack eva // }; diff --git a/src/core/renderers/webgl/utils/WebGLFastSpriteBatch.js b/src/core/renderers/webgl/utils/WebGLFastSpriteBatch.js index 7e988a7..3081078 100644 --- a/src/core/renderers/webgl/utils/WebGLFastSpriteBatch.js +++ b/src/core/renderers/webgl/utils/WebGLFastSpriteBatch.js @@ -364,12 +364,13 @@ var gl = this.renderer.gl; // bind the current texture - if (!this.currentBaseTexture._glTextures[gl.id]) { this.renderer.updateTexture(this.currentBaseTexture, gl); } - - gl.bindTexture(gl.TEXTURE_2D, this.currentBaseTexture._glTextures[gl.id]); + //TODO-SHOUD THIS BE ELSE??!?!?! + else { + gl.bindTexture(gl.TEXTURE_2D, this.currentBaseTexture._glTextures[gl.id]); + } // upload the verts to the buffer diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index db966b5..79325cb 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -260,6 +260,8 @@ /* * Updates the object transform for rendering * + * TODO - Optimization pass! + * * @private */ DisplayObject.prototype.updateTransform = function () { @@ -271,11 +273,9 @@ var a, b, c, d, tx, ty; // so if rotation is between 0 then we can simplify the multiplication process.. - if(this.rotation % math.PI_2) - { + if (this.rotation % math.PI_2) { // check to see if the rotation is the same as the previous render. This means we only need to use sin and cos when rotation actually changes - if(this.rotation !== this.rotationCache) - { + if (this.rotation !== this.rotationCache) { this.rotationCache = this.rotation; this._sr = Math.sin(this.rotation); this._cr = Math.cos(this.rotation); @@ -290,8 +290,7 @@ ty = this.position.y; // check for pivot.. not often used so geared towards that fact! - if(this.pivot.x || this.pivot.y) - { + if (this.pivot.x || this.pivot.y) { tx -= this.pivot.x * a + this.pivot.y * c; ty -= this.pivot.x * b + this.pivot.y * d; } @@ -303,11 +302,8 @@ wt.d = c * pt.b + d * pt.d; wt.tx = tx * pt.a + ty * pt.c + pt.tx; wt.ty = tx * pt.b + ty * pt.d + pt.ty; - - } - else - { + else { // lets do the fast version as we know there is no rotation.. a = this.scale.x; d = this.scale.y; diff --git a/src/core/display/DisplayObjectContainer.js b/src/core/display/DisplayObjectContainer.js index ce573c5..7b0afd3 100644 --- a/src/core/display/DisplayObjectContainer.js +++ b/src/core/display/DisplayObjectContainer.js @@ -138,6 +138,11 @@ * @return {DisplayObject} The child that was added. */ DisplayObjectContainer.prototype.addChildAt = function (child, index) { + // prevent adding self as child + if (child === this) { + return; + } + if (index >= 0 && index <= this.children.length) { if (child.parent) { child.parent.removeChild(child); @@ -419,6 +424,8 @@ /** * Renders the object using the WebGL renderer * + * TODO - Optimization pass! + * * @param renderer {WebGLRenderer} The renderer */ DisplayObjectContainer.prototype.renderWebGL = function (renderer) { @@ -449,7 +456,9 @@ } // add this object to the batch, only rendered if it has a texture. - renderer.spriteBatch.render(this); + if (this.texture) { + renderer.spriteBatch.render(this); + } // now loop through the children and make sure they get rendered for (i = 0, j = this.children.length; i < j; i++) { @@ -470,7 +479,9 @@ renderer.spriteBatch.start(); } else { - renderer.spriteBatch.render(this); + if (this.texture) { + renderer.spriteBatch.render(this); + } // simple render children! for (i = 0, j = this.children.length; i < j; ++i) { diff --git a/src/core/renderers/webgl/shaders/Shader.js b/src/core/renderers/webgl/shaders/Shader.js index 0d9d8f9..7365762 100644 --- a/src/core/renderers/webgl/shaders/Shader.js +++ b/src/core/renderers/webgl/shaders/Shader.js @@ -117,15 +117,16 @@ } // TODO: Check if this is needed anymore... + // Begin worst hack eva // // WHY??? ONLY on my chrome pixel the line above returns -1 when using filters? // maybe its something to do with the current state of the gl context. // I'm convinced this is a bug in the chrome browser as there is NO reason why this should be returning -1 especially as it only manifests on my chrome pixel // If theres any webGL people that know why could happen please help :) - if (this.attributes.aColor === -1) { - this.attributes.aColor = 2; - } + // if (this.attributes.aColor === -1) { + // this.attributes.aColor = 2; + // } // End worst hack eva // }; diff --git a/src/core/renderers/webgl/utils/WebGLFastSpriteBatch.js b/src/core/renderers/webgl/utils/WebGLFastSpriteBatch.js index 7e988a7..3081078 100644 --- a/src/core/renderers/webgl/utils/WebGLFastSpriteBatch.js +++ b/src/core/renderers/webgl/utils/WebGLFastSpriteBatch.js @@ -364,12 +364,13 @@ var gl = this.renderer.gl; // bind the current texture - if (!this.currentBaseTexture._glTextures[gl.id]) { this.renderer.updateTexture(this.currentBaseTexture, gl); } - - gl.bindTexture(gl.TEXTURE_2D, this.currentBaseTexture._glTextures[gl.id]); + //TODO-SHOUD THIS BE ELSE??!?!?! + else { + gl.bindTexture(gl.TEXTURE_2D, this.currentBaseTexture._glTextures[gl.id]); + } // upload the verts to the buffer diff --git a/src/core/renderers/webgl/utils/WebGLSpriteBatch.js b/src/core/renderers/webgl/utils/WebGLSpriteBatch.js index 6119cde..5dedfe3 100644 --- a/src/core/renderers/webgl/utils/WebGLSpriteBatch.js +++ b/src/core/renderers/webgl/utils/WebGLSpriteBatch.js @@ -207,10 +207,6 @@ * @param sprite {Sprite} the sprite to render when using this spritebatch */ WebGLSpriteBatch.prototype.render = function (sprite) { - if (!sprite.texture) { - return; - } - var texture = sprite.texture; //TODO set blend modes.. @@ -471,11 +467,11 @@ // this is the same for each shader? var stride = this.vertSize * 4; - gl.vertexAttribPointer(this.shader.aVertexPosition, 2, gl.FLOAT, false, stride, 0); - gl.vertexAttribPointer(this.shader.aTextureCoord, 2, gl.FLOAT, false, stride, 2 * 4); + gl.vertexAttribPointer(this.shader.attributes.aVertexPosition, 2, gl.FLOAT, false, stride, 0); + gl.vertexAttribPointer(this.shader.attributes.aTextureCoord, 2, gl.FLOAT, false, stride, 2 * 4); // color attributes will be interpreted as unsigned bytes and normalized - gl.vertexAttribPointer(this.shader.aColor, 4, gl.UNSIGNED_BYTE, true, stride, 4 * 4); + gl.vertexAttribPointer(this.shader.attributes.aColor, 4, gl.UNSIGNED_BYTE, true, stride, 4 * 4); } // upload the verts to the buffer @@ -525,7 +521,7 @@ if (shaderSwap) { currentShader = nextShader; - shader = currentShader.shaders ? currentShader.shaders[gl.id] : shader; + shader = currentShader.shaders ? currentShader.shaders[gl.id] : currentShader; if (!shader) { shader = new Shader(gl, null, currentShader.fragmentSrc, currentShader.uniforms); @@ -542,11 +538,11 @@ // both thease only need to be set if they are changing.. // set the projection var projection = this.renderer.projection; - gl.uniform2f(shader.projectionVector, projection.x, projection.y); + gl.uniform2f(shader.uniforms.projectionVector._location, projection.x, projection.y); // TODO - this is temprorary! var offsetVector = this.renderer.offset; - gl.uniform2f(shader.offsetVector, offsetVector.x, offsetVector.y); + gl.uniform2f(shader.uniforms.offsetVector._location, offsetVector.x, offsetVector.y); // set the pointers } @@ -573,8 +569,13 @@ var gl = this.renderer.gl; - // bind the current texture - gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id]); + if (!texture._glTextures[gl.id]) { + this.renderer.updateTexture(texture); + } + else { + // bind the current texture + gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id]); + } // now draw those suckas! gl.drawElements(gl.TRIANGLES, size * 6, gl.UNSIGNED_SHORT, startIndex * 6 * 2);