diff --git a/src/pixi/display/Sprite.js b/src/pixi/display/Sprite.js index e7605d0..aab559a 100644 --- a/src/pixi/display/Sprite.js +++ b/src/pixi/display/Sprite.js @@ -37,7 +37,7 @@ * @type Texture */ this.texture = texture || PIXI.Texture.emptyTexture; - + /** * The width of the sprite (this is initially set by the texture) * @@ -178,7 +178,7 @@ var h0 = height * (1-this.anchor.y); var h1 = height * -this.anchor.y; - var worldTransform = matrix || this.worldTransform; + var worldTransform = matrix || this.worldTransform ; var a = worldTransform.a; var b = worldTransform.b; @@ -200,7 +200,7 @@ if(d < 0)d *= -1; // this means there is no rotation going on right? RIGHT? - // if thats the case then we can avoid checking the bound values! yay + // if thats the case then we can avoid checking the bound values! yay minX = a * w1 + tx; maxX = a * w0 + tx; minY = d * h1 + ty; @@ -220,12 +220,6 @@ var x4 = a * w1 + c * h0 + tx; var y4 = d * h0 + b * w1 + ty; - maxX = -Infinity; - maxY = -Infinity; - - minX = Infinity; - minY = Infinity; - minX = x1 < minX ? x1 : minX; minX = x2 < minX ? x2 : minX; minX = x3 < minX ? x3 : minX; @@ -354,6 +348,17 @@ renderSession.context.globalAlpha = this.worldAlpha; + // If smoothingEnabled is supported and we need to change the smoothing property for this texture + if (renderSession.smoothProperty && renderSession.scaleMode !== this.texture.baseTexture.scaleMode) + { + renderSession.scaleMode = this.texture.baseTexture.scaleMode; + renderSession.context[renderSession.smoothProperty] = (renderSession.scaleMode === PIXI.scaleModes.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; + // Allow for pixel rounding if (renderSession.roundPixels) { @@ -362,8 +367,11 @@ this.worldTransform.b, this.worldTransform.c, this.worldTransform.d, - (this.worldTransform.tx* renderSession.resolution) | 0, - (this.worldTransform.ty* renderSession.resolution) | 0); + (this.worldTransform.tx * renderSession.resolution) | 0, + (this.worldTransform.ty * renderSession.resolution) | 0); + + dx = dx | 0; + dy = dy | 0; } else { @@ -376,17 +384,9 @@ this.worldTransform.ty * renderSession.resolution); } - // If smoothingEnabled is supported and we need to change the smoothing property for this texture - if (renderSession.smoothProperty && renderSession.scaleMode !== this.texture.baseTexture.scaleMode) - { - renderSession.scaleMode = this.texture.baseTexture.scaleMode; - renderSession.context[renderSession.smoothProperty] = (renderSession.scaleMode === PIXI.scaleModes.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 (this.tint !== 0xFFFFFF) { if (this.cachedTint !== this.tint) diff --git a/src/pixi/display/Sprite.js b/src/pixi/display/Sprite.js index e7605d0..aab559a 100644 --- a/src/pixi/display/Sprite.js +++ b/src/pixi/display/Sprite.js @@ -37,7 +37,7 @@ * @type Texture */ this.texture = texture || PIXI.Texture.emptyTexture; - + /** * The width of the sprite (this is initially set by the texture) * @@ -178,7 +178,7 @@ var h0 = height * (1-this.anchor.y); var h1 = height * -this.anchor.y; - var worldTransform = matrix || this.worldTransform; + var worldTransform = matrix || this.worldTransform ; var a = worldTransform.a; var b = worldTransform.b; @@ -200,7 +200,7 @@ if(d < 0)d *= -1; // this means there is no rotation going on right? RIGHT? - // if thats the case then we can avoid checking the bound values! yay + // if thats the case then we can avoid checking the bound values! yay minX = a * w1 + tx; maxX = a * w0 + tx; minY = d * h1 + ty; @@ -220,12 +220,6 @@ var x4 = a * w1 + c * h0 + tx; var y4 = d * h0 + b * w1 + ty; - maxX = -Infinity; - maxY = -Infinity; - - minX = Infinity; - minY = Infinity; - minX = x1 < minX ? x1 : minX; minX = x2 < minX ? x2 : minX; minX = x3 < minX ? x3 : minX; @@ -354,6 +348,17 @@ renderSession.context.globalAlpha = this.worldAlpha; + // If smoothingEnabled is supported and we need to change the smoothing property for this texture + if (renderSession.smoothProperty && renderSession.scaleMode !== this.texture.baseTexture.scaleMode) + { + renderSession.scaleMode = this.texture.baseTexture.scaleMode; + renderSession.context[renderSession.smoothProperty] = (renderSession.scaleMode === PIXI.scaleModes.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; + // Allow for pixel rounding if (renderSession.roundPixels) { @@ -362,8 +367,11 @@ this.worldTransform.b, this.worldTransform.c, this.worldTransform.d, - (this.worldTransform.tx* renderSession.resolution) | 0, - (this.worldTransform.ty* renderSession.resolution) | 0); + (this.worldTransform.tx * renderSession.resolution) | 0, + (this.worldTransform.ty * renderSession.resolution) | 0); + + dx = dx | 0; + dy = dy | 0; } else { @@ -376,17 +384,9 @@ this.worldTransform.ty * renderSession.resolution); } - // If smoothingEnabled is supported and we need to change the smoothing property for this texture - if (renderSession.smoothProperty && renderSession.scaleMode !== this.texture.baseTexture.scaleMode) - { - renderSession.scaleMode = this.texture.baseTexture.scaleMode; - renderSession.context[renderSession.smoothProperty] = (renderSession.scaleMode === PIXI.scaleModes.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 (this.tint !== 0xFFFFFF) { if (this.cachedTint !== this.tint) diff --git a/src/pixi/renderers/webgl/WebGLRenderer.js b/src/pixi/renderers/webgl/WebGLRenderer.js index eaf9d1d..b00ce59 100644 --- a/src/pixi/renderers/webgl/WebGLRenderer.js +++ b/src/pixi/renderers/webgl/WebGLRenderer.js @@ -421,7 +421,17 @@ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.source); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); + + + if(texture.mipmap && PIXI.isPowerOfTwo(texture.width, texture.height)) + { + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR_MIPMAP_LINEAR : gl.NEAREST_MIPMAP_NEAREST); + gl.generateMipmap(gl.TEXTURE_2D); + } + else + { + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); + } // reguler... if(!texture._powerOf2) diff --git a/src/pixi/display/Sprite.js b/src/pixi/display/Sprite.js index e7605d0..aab559a 100644 --- a/src/pixi/display/Sprite.js +++ b/src/pixi/display/Sprite.js @@ -37,7 +37,7 @@ * @type Texture */ this.texture = texture || PIXI.Texture.emptyTexture; - + /** * The width of the sprite (this is initially set by the texture) * @@ -178,7 +178,7 @@ var h0 = height * (1-this.anchor.y); var h1 = height * -this.anchor.y; - var worldTransform = matrix || this.worldTransform; + var worldTransform = matrix || this.worldTransform ; var a = worldTransform.a; var b = worldTransform.b; @@ -200,7 +200,7 @@ if(d < 0)d *= -1; // this means there is no rotation going on right? RIGHT? - // if thats the case then we can avoid checking the bound values! yay + // if thats the case then we can avoid checking the bound values! yay minX = a * w1 + tx; maxX = a * w0 + tx; minY = d * h1 + ty; @@ -220,12 +220,6 @@ var x4 = a * w1 + c * h0 + tx; var y4 = d * h0 + b * w1 + ty; - maxX = -Infinity; - maxY = -Infinity; - - minX = Infinity; - minY = Infinity; - minX = x1 < minX ? x1 : minX; minX = x2 < minX ? x2 : minX; minX = x3 < minX ? x3 : minX; @@ -354,6 +348,17 @@ renderSession.context.globalAlpha = this.worldAlpha; + // If smoothingEnabled is supported and we need to change the smoothing property for this texture + if (renderSession.smoothProperty && renderSession.scaleMode !== this.texture.baseTexture.scaleMode) + { + renderSession.scaleMode = this.texture.baseTexture.scaleMode; + renderSession.context[renderSession.smoothProperty] = (renderSession.scaleMode === PIXI.scaleModes.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; + // Allow for pixel rounding if (renderSession.roundPixels) { @@ -362,8 +367,11 @@ this.worldTransform.b, this.worldTransform.c, this.worldTransform.d, - (this.worldTransform.tx* renderSession.resolution) | 0, - (this.worldTransform.ty* renderSession.resolution) | 0); + (this.worldTransform.tx * renderSession.resolution) | 0, + (this.worldTransform.ty * renderSession.resolution) | 0); + + dx = dx | 0; + dy = dy | 0; } else { @@ -376,17 +384,9 @@ this.worldTransform.ty * renderSession.resolution); } - // If smoothingEnabled is supported and we need to change the smoothing property for this texture - if (renderSession.smoothProperty && renderSession.scaleMode !== this.texture.baseTexture.scaleMode) - { - renderSession.scaleMode = this.texture.baseTexture.scaleMode; - renderSession.context[renderSession.smoothProperty] = (renderSession.scaleMode === PIXI.scaleModes.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 (this.tint !== 0xFFFFFF) { if (this.cachedTint !== this.tint) diff --git a/src/pixi/renderers/webgl/WebGLRenderer.js b/src/pixi/renderers/webgl/WebGLRenderer.js index eaf9d1d..b00ce59 100644 --- a/src/pixi/renderers/webgl/WebGLRenderer.js +++ b/src/pixi/renderers/webgl/WebGLRenderer.js @@ -421,7 +421,17 @@ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.source); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); + + + if(texture.mipmap && PIXI.isPowerOfTwo(texture.width, texture.height)) + { + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR_MIPMAP_LINEAR : gl.NEAREST_MIPMAP_NEAREST); + gl.generateMipmap(gl.TEXTURE_2D); + } + else + { + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); + } // reguler... if(!texture._powerOf2) diff --git a/src/pixi/renderers/webgl/utils/WebGLGraphics.js b/src/pixi/renderers/webgl/utils/WebGLGraphics.js index 72ebd00..2598ffb 100644 --- a/src/pixi/renderers/webgl/utils/WebGLGraphics.js +++ b/src/pixi/renderers/webgl/utils/WebGLGraphics.js @@ -135,8 +135,8 @@ data.points = data.shape.points.slice(); if(data.shape.closed) { - // close the poly if the valu is true! - if(data.points[0] !== data.points[data.points.length-2] && data.points[1] !== data.points[data.points.length-1]) + // close the poly if the value is true! + if(data.points[0] !== data.points[data.points.length-2] || data.points[1] !== data.points[data.points.length-1]) { data.points.push(data.points[0], data.points[1]); } @@ -853,7 +853,6 @@ this.color = [0,0,0]; // color split! this.points = []; this.indices = []; - this.lastIndex = 0; this.buffer = gl.createBuffer(); this.indexBuffer = gl.createBuffer(); this.mode = 1; @@ -868,7 +867,6 @@ { this.points = []; this.indices = []; - this.lastIndex = 0; }; /** diff --git a/src/pixi/display/Sprite.js b/src/pixi/display/Sprite.js index e7605d0..aab559a 100644 --- a/src/pixi/display/Sprite.js +++ b/src/pixi/display/Sprite.js @@ -37,7 +37,7 @@ * @type Texture */ this.texture = texture || PIXI.Texture.emptyTexture; - + /** * The width of the sprite (this is initially set by the texture) * @@ -178,7 +178,7 @@ var h0 = height * (1-this.anchor.y); var h1 = height * -this.anchor.y; - var worldTransform = matrix || this.worldTransform; + var worldTransform = matrix || this.worldTransform ; var a = worldTransform.a; var b = worldTransform.b; @@ -200,7 +200,7 @@ if(d < 0)d *= -1; // this means there is no rotation going on right? RIGHT? - // if thats the case then we can avoid checking the bound values! yay + // if thats the case then we can avoid checking the bound values! yay minX = a * w1 + tx; maxX = a * w0 + tx; minY = d * h1 + ty; @@ -220,12 +220,6 @@ var x4 = a * w1 + c * h0 + tx; var y4 = d * h0 + b * w1 + ty; - maxX = -Infinity; - maxY = -Infinity; - - minX = Infinity; - minY = Infinity; - minX = x1 < minX ? x1 : minX; minX = x2 < minX ? x2 : minX; minX = x3 < minX ? x3 : minX; @@ -354,6 +348,17 @@ renderSession.context.globalAlpha = this.worldAlpha; + // If smoothingEnabled is supported and we need to change the smoothing property for this texture + if (renderSession.smoothProperty && renderSession.scaleMode !== this.texture.baseTexture.scaleMode) + { + renderSession.scaleMode = this.texture.baseTexture.scaleMode; + renderSession.context[renderSession.smoothProperty] = (renderSession.scaleMode === PIXI.scaleModes.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; + // Allow for pixel rounding if (renderSession.roundPixels) { @@ -362,8 +367,11 @@ this.worldTransform.b, this.worldTransform.c, this.worldTransform.d, - (this.worldTransform.tx* renderSession.resolution) | 0, - (this.worldTransform.ty* renderSession.resolution) | 0); + (this.worldTransform.tx * renderSession.resolution) | 0, + (this.worldTransform.ty * renderSession.resolution) | 0); + + dx = dx | 0; + dy = dy | 0; } else { @@ -376,17 +384,9 @@ this.worldTransform.ty * renderSession.resolution); } - // If smoothingEnabled is supported and we need to change the smoothing property for this texture - if (renderSession.smoothProperty && renderSession.scaleMode !== this.texture.baseTexture.scaleMode) - { - renderSession.scaleMode = this.texture.baseTexture.scaleMode; - renderSession.context[renderSession.smoothProperty] = (renderSession.scaleMode === PIXI.scaleModes.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 (this.tint !== 0xFFFFFF) { if (this.cachedTint !== this.tint) diff --git a/src/pixi/renderers/webgl/WebGLRenderer.js b/src/pixi/renderers/webgl/WebGLRenderer.js index eaf9d1d..b00ce59 100644 --- a/src/pixi/renderers/webgl/WebGLRenderer.js +++ b/src/pixi/renderers/webgl/WebGLRenderer.js @@ -421,7 +421,17 @@ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.source); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); + + + if(texture.mipmap && PIXI.isPowerOfTwo(texture.width, texture.height)) + { + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR_MIPMAP_LINEAR : gl.NEAREST_MIPMAP_NEAREST); + gl.generateMipmap(gl.TEXTURE_2D); + } + else + { + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); + } // reguler... if(!texture._powerOf2) diff --git a/src/pixi/renderers/webgl/utils/WebGLGraphics.js b/src/pixi/renderers/webgl/utils/WebGLGraphics.js index 72ebd00..2598ffb 100644 --- a/src/pixi/renderers/webgl/utils/WebGLGraphics.js +++ b/src/pixi/renderers/webgl/utils/WebGLGraphics.js @@ -135,8 +135,8 @@ data.points = data.shape.points.slice(); if(data.shape.closed) { - // close the poly if the valu is true! - if(data.points[0] !== data.points[data.points.length-2] && data.points[1] !== data.points[data.points.length-1]) + // close the poly if the value is true! + if(data.points[0] !== data.points[data.points.length-2] || data.points[1] !== data.points[data.points.length-1]) { data.points.push(data.points[0], data.points[1]); } @@ -853,7 +853,6 @@ this.color = [0,0,0]; // color split! this.points = []; this.indices = []; - this.lastIndex = 0; this.buffer = gl.createBuffer(); this.indexBuffer = gl.createBuffer(); this.mode = 1; @@ -868,7 +867,6 @@ { this.points = []; this.indices = []; - this.lastIndex = 0; }; /** diff --git a/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js b/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js index 7605158..a587edc 100755 --- a/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js +++ b/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js @@ -248,50 +248,71 @@ var tx = worldTransform.tx; var ty = worldTransform.ty; + if(this.renderSession.roundPixels) + { + //xy + verticies[index] = a * w1 + c * h1 + tx | 0; + verticies[index+1] = d * h1 + b * w1 + ty | 0; - // xy - verticies[index++] = a * w1 + c * h1 + tx; - verticies[index++] = d * h1 + b * w1 + ty; - // uv - verticies[index++] = uvs.x0; - verticies[index++] = uvs.y0; - // color - verticies[index++] = alpha; - verticies[index++] = tint; + // xy + verticies[index+6] = a * w0 + c * h1 + tx | 0; + verticies[index+7] = d * h1 + b * w0 + ty | 0; - // xy - verticies[index++] = a * w0 + c * h1 + tx; - verticies[index++] = d * h1 + b * w0 + ty; - // uv - verticies[index++] = uvs.x1; - verticies[index++] = uvs.y1; - // color - verticies[index++] = alpha; - verticies[index++] = tint; + // xy + verticies[index+12] = a * w0 + c * h0 + tx | 0; + verticies[index+13] = d * h0 + b * w0 + ty | 0; - // xy - verticies[index++] = a * w0 + c * h0 + tx; - verticies[index++] = d * h0 + b * w0 + ty; - // uv - verticies[index++] = uvs.x2; - verticies[index++] = uvs.y2; - // color - verticies[index++] = alpha; - verticies[index++] = tint; + // xy + verticies[index+18] = a * w1 + c * h0 + tx | 0; + verticies[index+19] = d * h0 + b * w1 + ty | 0; + } + else + { + //xy + verticies[index] = a * w1 + c * h1 + tx; + verticies[index+1] = d * h1 + b * w1 + ty; - // xy - verticies[index++] = a * w1 + c * h0 + tx; - verticies[index++] = d * h0 + b * w1 + ty; - // uv - verticies[index++] = uvs.x3; - verticies[index++] = uvs.y3; - // color - verticies[index++] = alpha; - verticies[index++] = tint; + // xy + verticies[index+6] = a * w0 + c * h1 + tx; + verticies[index+7] = d * h1 + b * w0 + ty; + + // xy + verticies[index+12] = a * w0 + c * h0 + tx; + verticies[index+13] = d * h0 + b * w0 + ty; + + // xy + verticies[index+18] = a * w1 + c * h0 + tx; + verticies[index+19] = d * h0 + b * w1 + ty; + } + // uv + verticies[index+2] = uvs.x0; + verticies[index+3] = uvs.y0; + + // uv + verticies[index+8] = uvs.x1; + verticies[index+9] = uvs.y1; + + // uv + verticies[index+14] = uvs.x2; + verticies[index+15] = uvs.y2; + + // uv + verticies[index+20] = uvs.x3; + verticies[index+21] = uvs.y3; + + // color + verticies[index+4] = verticies[index+10] = verticies[index+16] = verticies[index+22] = alpha; + + // alpha + verticies[index+5] = verticies[index+11] = verticies[index+17] = verticies[index+23] = tint; + + + // increment the batchsize this.sprites[this.currentBatchSize++] = sprite; + }; /** diff --git a/src/pixi/display/Sprite.js b/src/pixi/display/Sprite.js index e7605d0..aab559a 100644 --- a/src/pixi/display/Sprite.js +++ b/src/pixi/display/Sprite.js @@ -37,7 +37,7 @@ * @type Texture */ this.texture = texture || PIXI.Texture.emptyTexture; - + /** * The width of the sprite (this is initially set by the texture) * @@ -178,7 +178,7 @@ var h0 = height * (1-this.anchor.y); var h1 = height * -this.anchor.y; - var worldTransform = matrix || this.worldTransform; + var worldTransform = matrix || this.worldTransform ; var a = worldTransform.a; var b = worldTransform.b; @@ -200,7 +200,7 @@ if(d < 0)d *= -1; // this means there is no rotation going on right? RIGHT? - // if thats the case then we can avoid checking the bound values! yay + // if thats the case then we can avoid checking the bound values! yay minX = a * w1 + tx; maxX = a * w0 + tx; minY = d * h1 + ty; @@ -220,12 +220,6 @@ var x4 = a * w1 + c * h0 + tx; var y4 = d * h0 + b * w1 + ty; - maxX = -Infinity; - maxY = -Infinity; - - minX = Infinity; - minY = Infinity; - minX = x1 < minX ? x1 : minX; minX = x2 < minX ? x2 : minX; minX = x3 < minX ? x3 : minX; @@ -354,6 +348,17 @@ renderSession.context.globalAlpha = this.worldAlpha; + // If smoothingEnabled is supported and we need to change the smoothing property for this texture + if (renderSession.smoothProperty && renderSession.scaleMode !== this.texture.baseTexture.scaleMode) + { + renderSession.scaleMode = this.texture.baseTexture.scaleMode; + renderSession.context[renderSession.smoothProperty] = (renderSession.scaleMode === PIXI.scaleModes.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; + // Allow for pixel rounding if (renderSession.roundPixels) { @@ -362,8 +367,11 @@ this.worldTransform.b, this.worldTransform.c, this.worldTransform.d, - (this.worldTransform.tx* renderSession.resolution) | 0, - (this.worldTransform.ty* renderSession.resolution) | 0); + (this.worldTransform.tx * renderSession.resolution) | 0, + (this.worldTransform.ty * renderSession.resolution) | 0); + + dx = dx | 0; + dy = dy | 0; } else { @@ -376,17 +384,9 @@ this.worldTransform.ty * renderSession.resolution); } - // If smoothingEnabled is supported and we need to change the smoothing property for this texture - if (renderSession.smoothProperty && renderSession.scaleMode !== this.texture.baseTexture.scaleMode) - { - renderSession.scaleMode = this.texture.baseTexture.scaleMode; - renderSession.context[renderSession.smoothProperty] = (renderSession.scaleMode === PIXI.scaleModes.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 (this.tint !== 0xFFFFFF) { if (this.cachedTint !== this.tint) diff --git a/src/pixi/renderers/webgl/WebGLRenderer.js b/src/pixi/renderers/webgl/WebGLRenderer.js index eaf9d1d..b00ce59 100644 --- a/src/pixi/renderers/webgl/WebGLRenderer.js +++ b/src/pixi/renderers/webgl/WebGLRenderer.js @@ -421,7 +421,17 @@ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.source); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); + + + if(texture.mipmap && PIXI.isPowerOfTwo(texture.width, texture.height)) + { + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR_MIPMAP_LINEAR : gl.NEAREST_MIPMAP_NEAREST); + gl.generateMipmap(gl.TEXTURE_2D); + } + else + { + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); + } // reguler... if(!texture._powerOf2) diff --git a/src/pixi/renderers/webgl/utils/WebGLGraphics.js b/src/pixi/renderers/webgl/utils/WebGLGraphics.js index 72ebd00..2598ffb 100644 --- a/src/pixi/renderers/webgl/utils/WebGLGraphics.js +++ b/src/pixi/renderers/webgl/utils/WebGLGraphics.js @@ -135,8 +135,8 @@ data.points = data.shape.points.slice(); if(data.shape.closed) { - // close the poly if the valu is true! - if(data.points[0] !== data.points[data.points.length-2] && data.points[1] !== data.points[data.points.length-1]) + // close the poly if the value is true! + if(data.points[0] !== data.points[data.points.length-2] || data.points[1] !== data.points[data.points.length-1]) { data.points.push(data.points[0], data.points[1]); } @@ -853,7 +853,6 @@ this.color = [0,0,0]; // color split! this.points = []; this.indices = []; - this.lastIndex = 0; this.buffer = gl.createBuffer(); this.indexBuffer = gl.createBuffer(); this.mode = 1; @@ -868,7 +867,6 @@ { this.points = []; this.indices = []; - this.lastIndex = 0; }; /** diff --git a/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js b/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js index 7605158..a587edc 100755 --- a/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js +++ b/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js @@ -248,50 +248,71 @@ var tx = worldTransform.tx; var ty = worldTransform.ty; + if(this.renderSession.roundPixels) + { + //xy + verticies[index] = a * w1 + c * h1 + tx | 0; + verticies[index+1] = d * h1 + b * w1 + ty | 0; - // xy - verticies[index++] = a * w1 + c * h1 + tx; - verticies[index++] = d * h1 + b * w1 + ty; - // uv - verticies[index++] = uvs.x0; - verticies[index++] = uvs.y0; - // color - verticies[index++] = alpha; - verticies[index++] = tint; + // xy + verticies[index+6] = a * w0 + c * h1 + tx | 0; + verticies[index+7] = d * h1 + b * w0 + ty | 0; - // xy - verticies[index++] = a * w0 + c * h1 + tx; - verticies[index++] = d * h1 + b * w0 + ty; - // uv - verticies[index++] = uvs.x1; - verticies[index++] = uvs.y1; - // color - verticies[index++] = alpha; - verticies[index++] = tint; + // xy + verticies[index+12] = a * w0 + c * h0 + tx | 0; + verticies[index+13] = d * h0 + b * w0 + ty | 0; - // xy - verticies[index++] = a * w0 + c * h0 + tx; - verticies[index++] = d * h0 + b * w0 + ty; - // uv - verticies[index++] = uvs.x2; - verticies[index++] = uvs.y2; - // color - verticies[index++] = alpha; - verticies[index++] = tint; + // xy + verticies[index+18] = a * w1 + c * h0 + tx | 0; + verticies[index+19] = d * h0 + b * w1 + ty | 0; + } + else + { + //xy + verticies[index] = a * w1 + c * h1 + tx; + verticies[index+1] = d * h1 + b * w1 + ty; - // xy - verticies[index++] = a * w1 + c * h0 + tx; - verticies[index++] = d * h0 + b * w1 + ty; - // uv - verticies[index++] = uvs.x3; - verticies[index++] = uvs.y3; - // color - verticies[index++] = alpha; - verticies[index++] = tint; + // xy + verticies[index+6] = a * w0 + c * h1 + tx; + verticies[index+7] = d * h1 + b * w0 + ty; + + // xy + verticies[index+12] = a * w0 + c * h0 + tx; + verticies[index+13] = d * h0 + b * w0 + ty; + + // xy + verticies[index+18] = a * w1 + c * h0 + tx; + verticies[index+19] = d * h0 + b * w1 + ty; + } + // uv + verticies[index+2] = uvs.x0; + verticies[index+3] = uvs.y0; + + // uv + verticies[index+8] = uvs.x1; + verticies[index+9] = uvs.y1; + + // uv + verticies[index+14] = uvs.x2; + verticies[index+15] = uvs.y2; + + // uv + verticies[index+20] = uvs.x3; + verticies[index+21] = uvs.y3; + + // color + verticies[index+4] = verticies[index+10] = verticies[index+16] = verticies[index+22] = alpha; + + // alpha + verticies[index+5] = verticies[index+11] = verticies[index+17] = verticies[index+23] = tint; + + + // increment the batchsize this.sprites[this.currentBatchSize++] = sprite; + }; /** diff --git a/src/pixi/textures/BaseTexture.js b/src/pixi/textures/BaseTexture.js index 6de7215..0145849 100644 --- a/src/pixi/textures/BaseTexture.js +++ b/src/pixi/textures/BaseTexture.js @@ -89,6 +89,16 @@ */ this._glTextures = []; + /** + * + * Set this to true if a mipmap of this texture needs to be generated. This value needs to be set before the texture is used + * Also the texture must be a power of two size to work + * + * @property mipmap + * @type {Boolean} + */ + this.mipmap = false; + // used for webGL texture updating... // TODO - this needs to be addressed diff --git a/src/pixi/display/Sprite.js b/src/pixi/display/Sprite.js index e7605d0..aab559a 100644 --- a/src/pixi/display/Sprite.js +++ b/src/pixi/display/Sprite.js @@ -37,7 +37,7 @@ * @type Texture */ this.texture = texture || PIXI.Texture.emptyTexture; - + /** * The width of the sprite (this is initially set by the texture) * @@ -178,7 +178,7 @@ var h0 = height * (1-this.anchor.y); var h1 = height * -this.anchor.y; - var worldTransform = matrix || this.worldTransform; + var worldTransform = matrix || this.worldTransform ; var a = worldTransform.a; var b = worldTransform.b; @@ -200,7 +200,7 @@ if(d < 0)d *= -1; // this means there is no rotation going on right? RIGHT? - // if thats the case then we can avoid checking the bound values! yay + // if thats the case then we can avoid checking the bound values! yay minX = a * w1 + tx; maxX = a * w0 + tx; minY = d * h1 + ty; @@ -220,12 +220,6 @@ var x4 = a * w1 + c * h0 + tx; var y4 = d * h0 + b * w1 + ty; - maxX = -Infinity; - maxY = -Infinity; - - minX = Infinity; - minY = Infinity; - minX = x1 < minX ? x1 : minX; minX = x2 < minX ? x2 : minX; minX = x3 < minX ? x3 : minX; @@ -354,6 +348,17 @@ renderSession.context.globalAlpha = this.worldAlpha; + // If smoothingEnabled is supported and we need to change the smoothing property for this texture + if (renderSession.smoothProperty && renderSession.scaleMode !== this.texture.baseTexture.scaleMode) + { + renderSession.scaleMode = this.texture.baseTexture.scaleMode; + renderSession.context[renderSession.smoothProperty] = (renderSession.scaleMode === PIXI.scaleModes.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; + // Allow for pixel rounding if (renderSession.roundPixels) { @@ -362,8 +367,11 @@ this.worldTransform.b, this.worldTransform.c, this.worldTransform.d, - (this.worldTransform.tx* renderSession.resolution) | 0, - (this.worldTransform.ty* renderSession.resolution) | 0); + (this.worldTransform.tx * renderSession.resolution) | 0, + (this.worldTransform.ty * renderSession.resolution) | 0); + + dx = dx | 0; + dy = dy | 0; } else { @@ -376,17 +384,9 @@ this.worldTransform.ty * renderSession.resolution); } - // If smoothingEnabled is supported and we need to change the smoothing property for this texture - if (renderSession.smoothProperty && renderSession.scaleMode !== this.texture.baseTexture.scaleMode) - { - renderSession.scaleMode = this.texture.baseTexture.scaleMode; - renderSession.context[renderSession.smoothProperty] = (renderSession.scaleMode === PIXI.scaleModes.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 (this.tint !== 0xFFFFFF) { if (this.cachedTint !== this.tint) diff --git a/src/pixi/renderers/webgl/WebGLRenderer.js b/src/pixi/renderers/webgl/WebGLRenderer.js index eaf9d1d..b00ce59 100644 --- a/src/pixi/renderers/webgl/WebGLRenderer.js +++ b/src/pixi/renderers/webgl/WebGLRenderer.js @@ -421,7 +421,17 @@ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.source); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); + + + if(texture.mipmap && PIXI.isPowerOfTwo(texture.width, texture.height)) + { + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR_MIPMAP_LINEAR : gl.NEAREST_MIPMAP_NEAREST); + gl.generateMipmap(gl.TEXTURE_2D); + } + else + { + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); + } // reguler... if(!texture._powerOf2) diff --git a/src/pixi/renderers/webgl/utils/WebGLGraphics.js b/src/pixi/renderers/webgl/utils/WebGLGraphics.js index 72ebd00..2598ffb 100644 --- a/src/pixi/renderers/webgl/utils/WebGLGraphics.js +++ b/src/pixi/renderers/webgl/utils/WebGLGraphics.js @@ -135,8 +135,8 @@ data.points = data.shape.points.slice(); if(data.shape.closed) { - // close the poly if the valu is true! - if(data.points[0] !== data.points[data.points.length-2] && data.points[1] !== data.points[data.points.length-1]) + // close the poly if the value is true! + if(data.points[0] !== data.points[data.points.length-2] || data.points[1] !== data.points[data.points.length-1]) { data.points.push(data.points[0], data.points[1]); } @@ -853,7 +853,6 @@ this.color = [0,0,0]; // color split! this.points = []; this.indices = []; - this.lastIndex = 0; this.buffer = gl.createBuffer(); this.indexBuffer = gl.createBuffer(); this.mode = 1; @@ -868,7 +867,6 @@ { this.points = []; this.indices = []; - this.lastIndex = 0; }; /** diff --git a/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js b/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js index 7605158..a587edc 100755 --- a/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js +++ b/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js @@ -248,50 +248,71 @@ var tx = worldTransform.tx; var ty = worldTransform.ty; + if(this.renderSession.roundPixels) + { + //xy + verticies[index] = a * w1 + c * h1 + tx | 0; + verticies[index+1] = d * h1 + b * w1 + ty | 0; - // xy - verticies[index++] = a * w1 + c * h1 + tx; - verticies[index++] = d * h1 + b * w1 + ty; - // uv - verticies[index++] = uvs.x0; - verticies[index++] = uvs.y0; - // color - verticies[index++] = alpha; - verticies[index++] = tint; + // xy + verticies[index+6] = a * w0 + c * h1 + tx | 0; + verticies[index+7] = d * h1 + b * w0 + ty | 0; - // xy - verticies[index++] = a * w0 + c * h1 + tx; - verticies[index++] = d * h1 + b * w0 + ty; - // uv - verticies[index++] = uvs.x1; - verticies[index++] = uvs.y1; - // color - verticies[index++] = alpha; - verticies[index++] = tint; + // xy + verticies[index+12] = a * w0 + c * h0 + tx | 0; + verticies[index+13] = d * h0 + b * w0 + ty | 0; - // xy - verticies[index++] = a * w0 + c * h0 + tx; - verticies[index++] = d * h0 + b * w0 + ty; - // uv - verticies[index++] = uvs.x2; - verticies[index++] = uvs.y2; - // color - verticies[index++] = alpha; - verticies[index++] = tint; + // xy + verticies[index+18] = a * w1 + c * h0 + tx | 0; + verticies[index+19] = d * h0 + b * w1 + ty | 0; + } + else + { + //xy + verticies[index] = a * w1 + c * h1 + tx; + verticies[index+1] = d * h1 + b * w1 + ty; - // xy - verticies[index++] = a * w1 + c * h0 + tx; - verticies[index++] = d * h0 + b * w1 + ty; - // uv - verticies[index++] = uvs.x3; - verticies[index++] = uvs.y3; - // color - verticies[index++] = alpha; - verticies[index++] = tint; + // xy + verticies[index+6] = a * w0 + c * h1 + tx; + verticies[index+7] = d * h1 + b * w0 + ty; + + // xy + verticies[index+12] = a * w0 + c * h0 + tx; + verticies[index+13] = d * h0 + b * w0 + ty; + + // xy + verticies[index+18] = a * w1 + c * h0 + tx; + verticies[index+19] = d * h0 + b * w1 + ty; + } + // uv + verticies[index+2] = uvs.x0; + verticies[index+3] = uvs.y0; + + // uv + verticies[index+8] = uvs.x1; + verticies[index+9] = uvs.y1; + + // uv + verticies[index+14] = uvs.x2; + verticies[index+15] = uvs.y2; + + // uv + verticies[index+20] = uvs.x3; + verticies[index+21] = uvs.y3; + + // color + verticies[index+4] = verticies[index+10] = verticies[index+16] = verticies[index+22] = alpha; + + // alpha + verticies[index+5] = verticies[index+11] = verticies[index+17] = verticies[index+23] = tint; + + + // increment the batchsize this.sprites[this.currentBatchSize++] = sprite; + }; /** diff --git a/src/pixi/textures/BaseTexture.js b/src/pixi/textures/BaseTexture.js index 6de7215..0145849 100644 --- a/src/pixi/textures/BaseTexture.js +++ b/src/pixi/textures/BaseTexture.js @@ -89,6 +89,16 @@ */ this._glTextures = []; + /** + * + * Set this to true if a mipmap of this texture needs to be generated. This value needs to be set before the texture is used + * Also the texture must be a power of two size to work + * + * @property mipmap + * @type {Boolean} + */ + this.mipmap = false; + // used for webGL texture updating... // TODO - this needs to be addressed diff --git a/src/pixi/utils/Utils.js b/src/pixi/utils/Utils.js index 439dbb5..3cfcff8 100644 --- a/src/pixi/utils/Utils.js +++ b/src/pixi/utils/Utils.js @@ -205,3 +205,9 @@ return result; } }; + +PIXI.isPowerOfTwo = function(width, height) +{ + return (width > 0 && (width & (width - 1)) === 0 && height > 0 && (height & (height - 1)) === 0); + +};