diff --git a/bin/pixi.dev.js b/bin/pixi.dev.js index a989ed2..16820e7 100644 --- a/bin/pixi.dev.js +++ b/bin/pixi.dev.js @@ -1,14 +1,3 @@ -/** - * @license - * pixi.js - v1.6.1 - * Copyright (c) 2012-2014, Mat Groves - * http://goodboydigital.com/ - * - * Compiled: 2014-10-10 - * - * pixi.js is licensed under the MIT License. - * http://www.opensource.org/licenses/mit-license.php - */ /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -2068,6 +2057,7 @@ */ this.blendMode = PIXI.blendModes.NORMAL; +// this.shader = PIXI. if(texture.baseTexture.hasLoaded) { this.onTextureUpdate(); @@ -2079,6 +2069,8 @@ } this.renderable = true; + + this.customShader = null; }; // constructor @@ -2278,17 +2270,50 @@ } else { - renderSession.spriteBatch.render(this); - - // simple render children! - for(i=0,j=this.children.length; i= this.size) { - //return; this.flush(); this.currentBaseTexture = texture.baseTexture; } @@ -8078,11 +8145,11 @@ if(!uvs)return; // get the sprites current alpha - var alpha = sprite.worldAlpha; + var alpha = sprite.worldAlpha * 255; var tint = sprite.tint; var verticies = this.vertices; - + var byteBuffer = this.byteBuffer; // TODO trim?? var aX = sprite.anchor.x; @@ -8130,9 +8197,10 @@ // uv verticies[index++] = uvs.x0; verticies[index++] = uvs.y0; - // color - verticies[index++] = alpha; - verticies[index++] = tint; + + + this.byteBuffer32[index++] = tint; + byteBuffer[(index-1) * 4 + 3] = alpha; // xy verticies[index++] = a * w0 + c * h1 + tx; @@ -8141,8 +8209,8 @@ verticies[index++] = uvs.x1; verticies[index++] = uvs.y1; // color - verticies[index++] = alpha; - verticies[index++] = tint; + this.byteBuffer32[index++] = tint + byteBuffer[(index-1) * 4 + 3] = alpha; // xy verticies[index++] = a * w0 + c * h0 + tx; @@ -8151,8 +8219,8 @@ verticies[index++] = uvs.x2; verticies[index++] = uvs.y2; // color - verticies[index++] = alpha; - verticies[index++] = tint; + this.byteBuffer32[index++] = tint + byteBuffer[(index-1) * 4 + 3] = alpha; // xy verticies[index++] = a * w1 + c * h0 + tx; @@ -8161,14 +8229,11 @@ verticies[index++] = uvs.x3; verticies[index++] = uvs.y3; // color - verticies[index++] = alpha; - verticies[index++] = tint; - - // increment the batchsize - this.textures[this.currentBatchSize] = sprite.texture.baseTexture; - this.blendModes[this.currentBatchSize] = sprite.blendMode; + this.byteBuffer32[index++] = tint + byteBuffer[(index-1) * 4 + 3] = alpha; - this.currentBatchSize++; + // increment the batchsize + this.sprites[this.currentBatchSize++] = sprite; }; @@ -8182,7 +8247,8 @@ { var texture = tilingSprite.tilingTexture; - + if(this.customShader) + // check texture.. if(this.currentBatchSize >= this.size) { @@ -8309,8 +8375,12 @@ if (this.currentBatchSize===0)return; var gl = this.gl; - - this.renderSession.shaderManager.setShader(this.renderSession.shaderManager.defaultShader); + + for (var i = this.byteBuffer.length - 1; i >= 0; i--) { + // this.byteBuffer[i] = 0; + }; +// console.log(this.byteBuffer); + // console.log(this.vertices); if(this.dirty) { @@ -8322,15 +8392,13 @@ gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); - // set the projection - var projection = this.renderSession.projection; - gl.uniform2f(this.shader.projectionVector, projection.x, projection.y); + var shader = this.defaultShader.shaders[gl.id]; - // set the pointers + // 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.colorAttribute, 2, gl.FLOAT, false, stride, 4 * 4); + gl.vertexAttribPointer(shader.aVertexPosition, 2, gl.FLOAT, false, stride, 0); + gl.vertexAttribPointer(shader.aTextureCoord, 2, gl.FLOAT, false, stride, 2 * 4); + gl.vertexAttribPointer(shader.colorAttribute, 4, gl.UNSIGNED_BYTE, true, stride, 4 * 4); } // upload the verts to the buffer @@ -8348,26 +8416,67 @@ var batchSize = 0; var start = 0; - var currentBaseTexture = null; + var currentBaseTexture = this.emptyTexture; var currentBlendMode = this.renderSession.blendModeManager.currentBlendMode; + var currentShader = this.emptyTexture; + var blendSwap = false; + var shaderSwap = false; + var sprite; for (var i = 0, j = this.currentBatchSize; i < j; i++) { - nextTexture = this.textures[i]; - nextBlendMode = this.blendModes[i]; - blendSwap = currentBlendMode !== nextBlendMode; + var sprite = this.sprites[i]; - if(currentBaseTexture !== nextTexture || blendSwap) + nextTexture = sprite.texture.baseTexture; + nextBlendMode = sprite.blendMode + nextShader = sprite.shader || this.defaultShader; + + blendSwap = currentBlendMode !== nextBlendMode; + shaderSwap = currentShader !== nextShader; // should I use _UIDS??? + + if(currentBaseTexture._UID !== nextTexture._UID || blendSwap || shaderSwap) { this.renderBatch(currentBaseTexture, batchSize, start); start = i; batchSize = 0; currentBaseTexture = nextTexture; - currentBlendMode = nextBlendMode; - - if( blendSwap )this.renderSession.blendModeManager.setBlendMode( currentBlendMode ); + + if( blendSwap ) + { + currentBlendMode = nextBlendMode; + this.renderSession.blendModeManager.setBlendMode( currentBlendMode ); + } + + if( shaderSwap ) + { + currentShader = nextShader; + + var shader = currentShader.shaders[gl.id]; + + if(!shader) + { + shader = new PIXI.PixiShader(gl); + + shader.fragmentSrc =currentShader.fragmentSrc; + shader.uniforms =currentShader.uniforms; + shader.init(); + + currentShader.shaders[gl.id] = shader; + } + + // set shader function??? + var change = this.renderSession.shaderManager.setShader(shader); + + if(shader.dirty)shader.syncUniforms(); + + // set the projection + var projection = this.renderSession.projection; + gl.uniform2f(shader.projectionVector, projection.x, projection.y); + + // set the pointers + } } batchSize++; @@ -8404,6 +8513,7 @@ this.renderSession.drawCount++; }; + /** * * @method stop @@ -9338,6 +9448,60 @@ }; /** + * @author Mat Groves + * + * + */ + +/** + * Creates a Canvas element of the given size + * + * @method CanvasBuffer + * @param width {Number} the width for the newly created canvas + * @param height {Number} the height for the newly created canvas + * @static + * @private + */ +PIXI.CanvasBuffer = function(width, height) +{ + this.width = width; + this.height = height; + + this.canvas = document.createElement( "canvas" ); + this.context = this.canvas.getContext( "2d" ); + + this.canvas.width = width; + this.canvas.height = height; +}; + +/** + * Clears the canvas that was created by the CanvasBuffer class + * + * @method clear + * @private + */ +PIXI.CanvasBuffer.prototype.clear = function() +{ + this.context.clearRect(0,0, this.width, this.height); +}; + +/** + * Resizes the canvas that was created by the CanvasBuffer class to the specified width and height + * + * @method resize + * @param width {Number} the new width of the canvas + * @param height {Number} the new height of the canvas + * @private + */ + +PIXI.CanvasBuffer.prototype.resize = function(width, height) +{ + this.width = this.canvas.width = width; + this.height = this.canvas.height = height; +}; + + +/** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -9697,53 +9861,7 @@ */ this.transparent = options.transparent; - if(!PIXI.blendModesCanvas) - { - PIXI.blendModesCanvas = []; - - if(PIXI.canUseNewCanvasBlendModes()) - { - PIXI.blendModesCanvas[PIXI.blendModes.NORMAL] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.ADD] = "lighter"; //IS THIS OK??? - PIXI.blendModesCanvas[PIXI.blendModes.MULTIPLY] = "multiply"; - PIXI.blendModesCanvas[PIXI.blendModes.SCREEN] = "screen"; - PIXI.blendModesCanvas[PIXI.blendModes.OVERLAY] = "overlay"; - PIXI.blendModesCanvas[PIXI.blendModes.DARKEN] = "darken"; - PIXI.blendModesCanvas[PIXI.blendModes.LIGHTEN] = "lighten"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR_DODGE] = "color-dodge"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR_BURN] = "color-burn"; - PIXI.blendModesCanvas[PIXI.blendModes.HARD_LIGHT] = "hard-light"; - PIXI.blendModesCanvas[PIXI.blendModes.SOFT_LIGHT] = "soft-light"; - PIXI.blendModesCanvas[PIXI.blendModes.DIFFERENCE] = "difference"; - PIXI.blendModesCanvas[PIXI.blendModes.EXCLUSION] = "exclusion"; - PIXI.blendModesCanvas[PIXI.blendModes.HUE] = "hue"; - PIXI.blendModesCanvas[PIXI.blendModes.SATURATION] = "saturation"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR] = "color"; - PIXI.blendModesCanvas[PIXI.blendModes.LUMINOSITY] = "luminosity"; - } - else - { - // this means that the browser does not support the cool new blend modes in canvas "cough" ie "cough" - PIXI.blendModesCanvas[PIXI.blendModes.NORMAL] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.ADD] = "lighter"; //IS THIS OK??? - PIXI.blendModesCanvas[PIXI.blendModes.MULTIPLY] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.SCREEN] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.OVERLAY] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.DARKEN] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.LIGHTEN] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR_DODGE] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR_BURN] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.HARD_LIGHT] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.SOFT_LIGHT] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.DIFFERENCE] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.EXCLUSION] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.HUE] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.SATURATION] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.LUMINOSITY] = "source-over"; - } - } - + /** * The width of the canvas view * @@ -9805,7 +9923,6 @@ maskManager: this.maskManager, scaleMode: null, smoothProperty: null, - /** * If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. * Handy for crisp pixel art and speed on legacy devices. @@ -9872,7 +9989,6 @@ stage.interactionManager.setTarget(this); } } - }; /** @@ -9892,7 +10008,6 @@ this.view.style.width = this.width / this.resolution + "px"; this.view.style.height = this.height / this.resolution + "px"; - }; /** @@ -9905,154 +10020,64 @@ */ PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject, context) { - // no longer recursive! - //var transform; - //var context = this.context; - this.renderSession.context = context || this.context; this.renderSession.resolution = this.resolution; displayObject._renderCanvas(this.renderSession); }; -/** - * Renders a flat strip - * - * @method renderStripFlat - * @param strip {Strip} The Strip to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderStripFlat = function(strip) + + +PIXI.CanvasRenderer.prototype.mapBlendModes = function() { - var context = this.context; - var verticies = strip.verticies; - - var length = verticies.length/2; - this.count++; - - context.beginPath(); - for (var i=1; i < length-2; i++) + if(!PIXI.blendModesCanvas) { - // draw some triangles! - var index = i*2; + PIXI.blendModesCanvas = []; - var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; - var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - - context.moveTo(x0, y0); - context.lineTo(x1, y1); - context.lineTo(x2, y2); - } - - context.fillStyle = "#FF0000"; - context.fill(); - context.closePath(); -}; - -/** - * Renders a strip - * - * @method renderStrip - * @param strip {Strip} The Strip to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderStrip = function(strip) -{ - var context = this.context; - - // draw triangles!! - var verticies = strip.verticies; - var uvs = strip.uvs; - - var length = verticies.length/2; - this.count++; - - for (var i = 1; i < length-2; i++) - { - // draw some triangles! - var index = i*2; - - var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; - var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - - var u0 = uvs[index] * strip.texture.width, u1 = uvs[index+2] * strip.texture.width, u2 = uvs[index+4]* strip.texture.width; - var v0 = uvs[index+1]* strip.texture.height, v1 = uvs[index+3] * strip.texture.height, v2 = uvs[index+5]* strip.texture.height; - - context.save(); - context.beginPath(); - context.moveTo(x0, y0); - context.lineTo(x1, y1); - context.lineTo(x2, y2); - context.closePath(); - - context.clip(); - - // Compute matrix transform - var delta = u0*v1 + v0*u2 + u1*v2 - v1*u2 - v0*u1 - u0*v2; - var deltaA = x0*v1 + v0*x2 + x1*v2 - v1*x2 - v0*x1 - x0*v2; - var deltaB = u0*x1 + x0*u2 + u1*x2 - x1*u2 - x0*u1 - u0*x2; - var deltaC = u0*v1*x2 + v0*x1*u2 + x0*u1*v2 - x0*v1*u2 - v0*u1*x2 - u0*x1*v2; - var deltaD = y0*v1 + v0*y2 + y1*v2 - v1*y2 - v0*y1 - y0*v2; - var deltaE = u0*y1 + y0*u2 + u1*y2 - y1*u2 - y0*u1 - u0*y2; - var deltaF = u0*v1*y2 + v0*y1*u2 + y0*u1*v2 - y0*v1*u2 - v0*u1*y2 - u0*y1*v2; - - context.transform(deltaA / delta, deltaD / delta, - deltaB / delta, deltaE / delta, - deltaC / delta, deltaF / delta); - - context.drawImage(strip.texture.baseTexture.source, 0, 0); - context.restore(); + if(PIXI.canUseNewCanvasBlendModes()) + { + PIXI.blendModesCanvas[PIXI.blendModes.NORMAL] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.ADD] = "lighter"; //IS THIS OK??? + PIXI.blendModesCanvas[PIXI.blendModes.MULTIPLY] = "multiply"; + PIXI.blendModesCanvas[PIXI.blendModes.SCREEN] = "screen"; + PIXI.blendModesCanvas[PIXI.blendModes.OVERLAY] = "overlay"; + PIXI.blendModesCanvas[PIXI.blendModes.DARKEN] = "darken"; + PIXI.blendModesCanvas[PIXI.blendModes.LIGHTEN] = "lighten"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR_DODGE] = "color-dodge"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR_BURN] = "color-burn"; + PIXI.blendModesCanvas[PIXI.blendModes.HARD_LIGHT] = "hard-light"; + PIXI.blendModesCanvas[PIXI.blendModes.SOFT_LIGHT] = "soft-light"; + PIXI.blendModesCanvas[PIXI.blendModes.DIFFERENCE] = "difference"; + PIXI.blendModesCanvas[PIXI.blendModes.EXCLUSION] = "exclusion"; + PIXI.blendModesCanvas[PIXI.blendModes.HUE] = "hue"; + PIXI.blendModesCanvas[PIXI.blendModes.SATURATION] = "saturation"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR] = "color"; + PIXI.blendModesCanvas[PIXI.blendModes.LUMINOSITY] = "luminosity"; + } + else + { + // this means that the browser does not support the cool new blend modes in canvas "cough" ie "cough" + PIXI.blendModesCanvas[PIXI.blendModes.NORMAL] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.ADD] = "lighter"; //IS THIS OK??? + PIXI.blendModesCanvas[PIXI.blendModes.MULTIPLY] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.SCREEN] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.OVERLAY] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.DARKEN] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.LIGHTEN] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR_DODGE] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR_BURN] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.HARD_LIGHT] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.SOFT_LIGHT] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.DIFFERENCE] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.EXCLUSION] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.HUE] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.SATURATION] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.LUMINOSITY] = "source-over"; + } } }; /** - * Creates a Canvas element of the given size - * - * @method CanvasBuffer - * @param width {Number} the width for the newly created canvas - * @param height {Number} the height for the newly created canvas - * @static - * @private - */ -PIXI.CanvasBuffer = function(width, height) -{ - this.width = width; - this.height = height; - - this.canvas = document.createElement( "canvas" ); - this.context = this.canvas.getContext( "2d" ); - - this.canvas.width = width; - this.canvas.height = height; -}; - -/** - * Clears the canvas that was created by the CanvasBuffer class - * - * @method clear - * @private - */ -PIXI.CanvasBuffer.prototype.clear = function() -{ - this.context.clearRect(0,0, this.width, this.height); -}; - -/** - * Resizes the canvas that was created by the CanvasBuffer class to the specified width and height - * - * @method resize - * @param width {Number} the new width of the canvas - * @param height {Number} the new height of the canvas - * @private - */ - -PIXI.CanvasBuffer.prototype.resize = function(width, height) -{ - this.width = this.canvas.width = width; - this.height = this.canvas.height = height; -}; - - -/** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -10470,7 +10495,7 @@ * @property boundsPadding * @type Number */ - this.boundsPadding = 10; + this.boundsPadding = 0; /** * Used to detect if the graphics object has changed if this is set to true then the graphics object will be recalculated @@ -11448,14 +11473,14 @@ // set up the main bits.. this.uvs = new PIXI.Float32Array([0, 1, - 1, 1, - 1, 0, - 0,1]); + 1, 1, + 1, 0, + 0, 1]); this.verticies = new PIXI.Float32Array([0, 0, - 100,0, - 100,100, - 0, 100]); + 100, 0, + 100, 100, + 0, 100]); this.colors = new PIXI.Float32Array([1, 1, 1, 1]); @@ -11546,7 +11571,7 @@ gl.uniformMatrix3fv(shader.translationMatrix, false, this.worldTransform.toArray(true)); gl.uniform2f(shader.projectionVector, projection.x, -projection.y); gl.uniform2f(shader.offsetVector, -offset.x, -offset.y); - gl.uniform1f(shader.alpha, 1); + gl.uniform1f(shader.alpha, this.worldAlpha); if(!this.dirty) { @@ -11564,7 +11589,7 @@ // check if a texture is dirty.. if(this.texture.baseTexture._dirty[gl.id]) { - this.renderSession.renderer.updateTexture(this.texture.baseTexture); + renderSession.renderer.updateTexture(this.texture.baseTexture); } else { @@ -11615,6 +11640,8 @@ }; + + PIXI.Strip.prototype._renderCanvas = function(renderSession) { var context = renderSession.context; @@ -11646,10 +11673,8 @@ var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - if(this.padding === 0) + if(this.padding > 0) { - - //expand(); var centerX = (x0 + x1 + x2)/3; var centerY = (y0 + y1 + y2)/3; @@ -11675,7 +11700,6 @@ dist = Math.sqrt( normX * normX + normY * normY ); x2 = centerX + (normX / dist) * (dist + 3); y2 = centerY + (normY / dist) * (dist + 3); - } var u0 = uvs[index] * strip.texture.width, u1 = uvs[index+2] * strip.texture.width, u2 = uvs[index+4]* strip.texture.width; @@ -11711,13 +11735,40 @@ } }; -/* - * Sets the texture that the Strip will use + +/** + * Renders a flat strip * - * @method setTexture - * @param texture {Texture} the texture that will be used + * @method renderStripFlat + * @param strip {Strip} The Strip to render * @private */ +PIXI.Strip.prototype.renderStripFlat = function(strip) +{ + var context = this.context; + var verticies = strip.verticies; + + var length = verticies.length/2; + this.count++; + + context.beginPath(); + for (var i=1; i < length-2; i++) + { + // draw some triangles! + var index = i*2; + + var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; + var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; + + context.moveTo(x0, y0); + context.lineTo(x1, y1); + context.lineTo(x2, y2); + } + + context.fillStyle = "#FF0000"; + context.fill(); + context.closePath(); +}; /* PIXI.Strip.prototype.setTexture = function(texture) @@ -11745,17 +11796,19 @@ { this.updateFrame = true; }; -/* @author Mat Groves http://matgroves.com/ @Doormat23 +/** + * @author Mat Groves http://matgroves.com/ @Doormat23 + * @copyright Mat Groves, Rovanion Luckey */ /** - * + * * @class Rope * @constructor * @extends Strip - * @param texture {Texture} The texture to use - * @param points {Array} - * + * @param {Texture} texture - The texture to use on the rope. + * @param {Array} points - An array of {PIXI.Point}. + * */ PIXI.Rope = function(texture, points) { @@ -11766,7 +11819,7 @@ this.uvs = new PIXI.Float32Array(points.length * 4); this.colors = new PIXI.Float32Array(points.length * 2); this.indices = new PIXI.Uint16Array(points.length * 2); - + this.refresh(); }; @@ -11777,7 +11830,7 @@ PIXI.Rope.prototype.constructor = PIXI.Rope; /* - * Refreshes + * Refreshes * * @method refresh */ @@ -11906,7 +11959,7 @@ PIXI.DisplayObjectContainer.prototype.updateTransform.call( this ); }; /* - * Sets the texture that the Rope will use + * Sets the texture that the Rope will use * * @method setTexture * @param texture {Texture} the texture that will be used @@ -13927,7 +13980,7 @@ this.source = source; //TODO will be used for futer pixi 1.5... - this.id = PIXI.BaseTextureCacheIdGenerator++; + this._UID = PIXI._UID++; /** * Controls if RGB channels should be premultiplied by Alpha (WebGL only) @@ -14535,7 +14588,6 @@ this.baseTexture.width = this.width * this.resolution; this.baseTexture.height = this.height * this.resolution; this.baseTexture._glTextures = []; - this.baseTexture.resolution = this.resolution; this.baseTexture.scaleMode = scaleMode || PIXI.scaleModes.DEFAULT; @@ -14553,6 +14605,7 @@ if(this.renderer.type === PIXI.WEBGL_RENDERER) { var gl = this.renderer.gl; + this.baseTexture._dirty[gl.id] = false this.textureBuffer = new PIXI.FilterTexture(gl, this.width * this.resolution, this.height * this.resolution, this.baseTexture.scaleMode); this.baseTexture._glTextures[gl.id] = this.textureBuffer.texture; @@ -14689,7 +14742,7 @@ var wt = displayObject.worldTransform; wt.identity(); - wt.append(matrix); + if(matrix)wt.append(matrix); // Time to update all the children of the displayObject with the new matrix.. var children = displayObject.children; @@ -15810,6 +15863,18 @@ this.fragmentSrc = fragmentSrc || []; }; +PIXI.AbstractFilter.prototype.syncUniforms = function() +{ + for(var i=0,j=this.shaders.length; i= this.size) { - //return; this.flush(); this.currentBaseTexture = texture.baseTexture; } @@ -8078,11 +8145,11 @@ if(!uvs)return; // get the sprites current alpha - var alpha = sprite.worldAlpha; + var alpha = sprite.worldAlpha * 255; var tint = sprite.tint; var verticies = this.vertices; - + var byteBuffer = this.byteBuffer; // TODO trim?? var aX = sprite.anchor.x; @@ -8130,9 +8197,10 @@ // uv verticies[index++] = uvs.x0; verticies[index++] = uvs.y0; - // color - verticies[index++] = alpha; - verticies[index++] = tint; + + + this.byteBuffer32[index++] = tint; + byteBuffer[(index-1) * 4 + 3] = alpha; // xy verticies[index++] = a * w0 + c * h1 + tx; @@ -8141,8 +8209,8 @@ verticies[index++] = uvs.x1; verticies[index++] = uvs.y1; // color - verticies[index++] = alpha; - verticies[index++] = tint; + this.byteBuffer32[index++] = tint + byteBuffer[(index-1) * 4 + 3] = alpha; // xy verticies[index++] = a * w0 + c * h0 + tx; @@ -8151,8 +8219,8 @@ verticies[index++] = uvs.x2; verticies[index++] = uvs.y2; // color - verticies[index++] = alpha; - verticies[index++] = tint; + this.byteBuffer32[index++] = tint + byteBuffer[(index-1) * 4 + 3] = alpha; // xy verticies[index++] = a * w1 + c * h0 + tx; @@ -8161,14 +8229,11 @@ verticies[index++] = uvs.x3; verticies[index++] = uvs.y3; // color - verticies[index++] = alpha; - verticies[index++] = tint; - - // increment the batchsize - this.textures[this.currentBatchSize] = sprite.texture.baseTexture; - this.blendModes[this.currentBatchSize] = sprite.blendMode; + this.byteBuffer32[index++] = tint + byteBuffer[(index-1) * 4 + 3] = alpha; - this.currentBatchSize++; + // increment the batchsize + this.sprites[this.currentBatchSize++] = sprite; }; @@ -8182,7 +8247,8 @@ { var texture = tilingSprite.tilingTexture; - + if(this.customShader) + // check texture.. if(this.currentBatchSize >= this.size) { @@ -8309,8 +8375,12 @@ if (this.currentBatchSize===0)return; var gl = this.gl; - - this.renderSession.shaderManager.setShader(this.renderSession.shaderManager.defaultShader); + + for (var i = this.byteBuffer.length - 1; i >= 0; i--) { + // this.byteBuffer[i] = 0; + }; +// console.log(this.byteBuffer); + // console.log(this.vertices); if(this.dirty) { @@ -8322,15 +8392,13 @@ gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); - // set the projection - var projection = this.renderSession.projection; - gl.uniform2f(this.shader.projectionVector, projection.x, projection.y); + var shader = this.defaultShader.shaders[gl.id]; - // set the pointers + // 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.colorAttribute, 2, gl.FLOAT, false, stride, 4 * 4); + gl.vertexAttribPointer(shader.aVertexPosition, 2, gl.FLOAT, false, stride, 0); + gl.vertexAttribPointer(shader.aTextureCoord, 2, gl.FLOAT, false, stride, 2 * 4); + gl.vertexAttribPointer(shader.colorAttribute, 4, gl.UNSIGNED_BYTE, true, stride, 4 * 4); } // upload the verts to the buffer @@ -8348,26 +8416,67 @@ var batchSize = 0; var start = 0; - var currentBaseTexture = null; + var currentBaseTexture = this.emptyTexture; var currentBlendMode = this.renderSession.blendModeManager.currentBlendMode; + var currentShader = this.emptyTexture; + var blendSwap = false; + var shaderSwap = false; + var sprite; for (var i = 0, j = this.currentBatchSize; i < j; i++) { - nextTexture = this.textures[i]; - nextBlendMode = this.blendModes[i]; - blendSwap = currentBlendMode !== nextBlendMode; + var sprite = this.sprites[i]; - if(currentBaseTexture !== nextTexture || blendSwap) + nextTexture = sprite.texture.baseTexture; + nextBlendMode = sprite.blendMode + nextShader = sprite.shader || this.defaultShader; + + blendSwap = currentBlendMode !== nextBlendMode; + shaderSwap = currentShader !== nextShader; // should I use _UIDS??? + + if(currentBaseTexture._UID !== nextTexture._UID || blendSwap || shaderSwap) { this.renderBatch(currentBaseTexture, batchSize, start); start = i; batchSize = 0; currentBaseTexture = nextTexture; - currentBlendMode = nextBlendMode; - - if( blendSwap )this.renderSession.blendModeManager.setBlendMode( currentBlendMode ); + + if( blendSwap ) + { + currentBlendMode = nextBlendMode; + this.renderSession.blendModeManager.setBlendMode( currentBlendMode ); + } + + if( shaderSwap ) + { + currentShader = nextShader; + + var shader = currentShader.shaders[gl.id]; + + if(!shader) + { + shader = new PIXI.PixiShader(gl); + + shader.fragmentSrc =currentShader.fragmentSrc; + shader.uniforms =currentShader.uniforms; + shader.init(); + + currentShader.shaders[gl.id] = shader; + } + + // set shader function??? + var change = this.renderSession.shaderManager.setShader(shader); + + if(shader.dirty)shader.syncUniforms(); + + // set the projection + var projection = this.renderSession.projection; + gl.uniform2f(shader.projectionVector, projection.x, projection.y); + + // set the pointers + } } batchSize++; @@ -8404,6 +8513,7 @@ this.renderSession.drawCount++; }; + /** * * @method stop @@ -9338,6 +9448,60 @@ }; /** + * @author Mat Groves + * + * + */ + +/** + * Creates a Canvas element of the given size + * + * @method CanvasBuffer + * @param width {Number} the width for the newly created canvas + * @param height {Number} the height for the newly created canvas + * @static + * @private + */ +PIXI.CanvasBuffer = function(width, height) +{ + this.width = width; + this.height = height; + + this.canvas = document.createElement( "canvas" ); + this.context = this.canvas.getContext( "2d" ); + + this.canvas.width = width; + this.canvas.height = height; +}; + +/** + * Clears the canvas that was created by the CanvasBuffer class + * + * @method clear + * @private + */ +PIXI.CanvasBuffer.prototype.clear = function() +{ + this.context.clearRect(0,0, this.width, this.height); +}; + +/** + * Resizes the canvas that was created by the CanvasBuffer class to the specified width and height + * + * @method resize + * @param width {Number} the new width of the canvas + * @param height {Number} the new height of the canvas + * @private + */ + +PIXI.CanvasBuffer.prototype.resize = function(width, height) +{ + this.width = this.canvas.width = width; + this.height = this.canvas.height = height; +}; + + +/** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -9697,53 +9861,7 @@ */ this.transparent = options.transparent; - if(!PIXI.blendModesCanvas) - { - PIXI.blendModesCanvas = []; - - if(PIXI.canUseNewCanvasBlendModes()) - { - PIXI.blendModesCanvas[PIXI.blendModes.NORMAL] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.ADD] = "lighter"; //IS THIS OK??? - PIXI.blendModesCanvas[PIXI.blendModes.MULTIPLY] = "multiply"; - PIXI.blendModesCanvas[PIXI.blendModes.SCREEN] = "screen"; - PIXI.blendModesCanvas[PIXI.blendModes.OVERLAY] = "overlay"; - PIXI.blendModesCanvas[PIXI.blendModes.DARKEN] = "darken"; - PIXI.blendModesCanvas[PIXI.blendModes.LIGHTEN] = "lighten"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR_DODGE] = "color-dodge"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR_BURN] = "color-burn"; - PIXI.blendModesCanvas[PIXI.blendModes.HARD_LIGHT] = "hard-light"; - PIXI.blendModesCanvas[PIXI.blendModes.SOFT_LIGHT] = "soft-light"; - PIXI.blendModesCanvas[PIXI.blendModes.DIFFERENCE] = "difference"; - PIXI.blendModesCanvas[PIXI.blendModes.EXCLUSION] = "exclusion"; - PIXI.blendModesCanvas[PIXI.blendModes.HUE] = "hue"; - PIXI.blendModesCanvas[PIXI.blendModes.SATURATION] = "saturation"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR] = "color"; - PIXI.blendModesCanvas[PIXI.blendModes.LUMINOSITY] = "luminosity"; - } - else - { - // this means that the browser does not support the cool new blend modes in canvas "cough" ie "cough" - PIXI.blendModesCanvas[PIXI.blendModes.NORMAL] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.ADD] = "lighter"; //IS THIS OK??? - PIXI.blendModesCanvas[PIXI.blendModes.MULTIPLY] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.SCREEN] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.OVERLAY] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.DARKEN] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.LIGHTEN] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR_DODGE] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR_BURN] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.HARD_LIGHT] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.SOFT_LIGHT] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.DIFFERENCE] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.EXCLUSION] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.HUE] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.SATURATION] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.LUMINOSITY] = "source-over"; - } - } - + /** * The width of the canvas view * @@ -9805,7 +9923,6 @@ maskManager: this.maskManager, scaleMode: null, smoothProperty: null, - /** * If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. * Handy for crisp pixel art and speed on legacy devices. @@ -9872,7 +9989,6 @@ stage.interactionManager.setTarget(this); } } - }; /** @@ -9892,7 +10008,6 @@ this.view.style.width = this.width / this.resolution + "px"; this.view.style.height = this.height / this.resolution + "px"; - }; /** @@ -9905,154 +10020,64 @@ */ PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject, context) { - // no longer recursive! - //var transform; - //var context = this.context; - this.renderSession.context = context || this.context; this.renderSession.resolution = this.resolution; displayObject._renderCanvas(this.renderSession); }; -/** - * Renders a flat strip - * - * @method renderStripFlat - * @param strip {Strip} The Strip to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderStripFlat = function(strip) + + +PIXI.CanvasRenderer.prototype.mapBlendModes = function() { - var context = this.context; - var verticies = strip.verticies; - - var length = verticies.length/2; - this.count++; - - context.beginPath(); - for (var i=1; i < length-2; i++) + if(!PIXI.blendModesCanvas) { - // draw some triangles! - var index = i*2; + PIXI.blendModesCanvas = []; - var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; - var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - - context.moveTo(x0, y0); - context.lineTo(x1, y1); - context.lineTo(x2, y2); - } - - context.fillStyle = "#FF0000"; - context.fill(); - context.closePath(); -}; - -/** - * Renders a strip - * - * @method renderStrip - * @param strip {Strip} The Strip to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderStrip = function(strip) -{ - var context = this.context; - - // draw triangles!! - var verticies = strip.verticies; - var uvs = strip.uvs; - - var length = verticies.length/2; - this.count++; - - for (var i = 1; i < length-2; i++) - { - // draw some triangles! - var index = i*2; - - var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; - var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - - var u0 = uvs[index] * strip.texture.width, u1 = uvs[index+2] * strip.texture.width, u2 = uvs[index+4]* strip.texture.width; - var v0 = uvs[index+1]* strip.texture.height, v1 = uvs[index+3] * strip.texture.height, v2 = uvs[index+5]* strip.texture.height; - - context.save(); - context.beginPath(); - context.moveTo(x0, y0); - context.lineTo(x1, y1); - context.lineTo(x2, y2); - context.closePath(); - - context.clip(); - - // Compute matrix transform - var delta = u0*v1 + v0*u2 + u1*v2 - v1*u2 - v0*u1 - u0*v2; - var deltaA = x0*v1 + v0*x2 + x1*v2 - v1*x2 - v0*x1 - x0*v2; - var deltaB = u0*x1 + x0*u2 + u1*x2 - x1*u2 - x0*u1 - u0*x2; - var deltaC = u0*v1*x2 + v0*x1*u2 + x0*u1*v2 - x0*v1*u2 - v0*u1*x2 - u0*x1*v2; - var deltaD = y0*v1 + v0*y2 + y1*v2 - v1*y2 - v0*y1 - y0*v2; - var deltaE = u0*y1 + y0*u2 + u1*y2 - y1*u2 - y0*u1 - u0*y2; - var deltaF = u0*v1*y2 + v0*y1*u2 + y0*u1*v2 - y0*v1*u2 - v0*u1*y2 - u0*y1*v2; - - context.transform(deltaA / delta, deltaD / delta, - deltaB / delta, deltaE / delta, - deltaC / delta, deltaF / delta); - - context.drawImage(strip.texture.baseTexture.source, 0, 0); - context.restore(); + if(PIXI.canUseNewCanvasBlendModes()) + { + PIXI.blendModesCanvas[PIXI.blendModes.NORMAL] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.ADD] = "lighter"; //IS THIS OK??? + PIXI.blendModesCanvas[PIXI.blendModes.MULTIPLY] = "multiply"; + PIXI.blendModesCanvas[PIXI.blendModes.SCREEN] = "screen"; + PIXI.blendModesCanvas[PIXI.blendModes.OVERLAY] = "overlay"; + PIXI.blendModesCanvas[PIXI.blendModes.DARKEN] = "darken"; + PIXI.blendModesCanvas[PIXI.blendModes.LIGHTEN] = "lighten"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR_DODGE] = "color-dodge"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR_BURN] = "color-burn"; + PIXI.blendModesCanvas[PIXI.blendModes.HARD_LIGHT] = "hard-light"; + PIXI.blendModesCanvas[PIXI.blendModes.SOFT_LIGHT] = "soft-light"; + PIXI.blendModesCanvas[PIXI.blendModes.DIFFERENCE] = "difference"; + PIXI.blendModesCanvas[PIXI.blendModes.EXCLUSION] = "exclusion"; + PIXI.blendModesCanvas[PIXI.blendModes.HUE] = "hue"; + PIXI.blendModesCanvas[PIXI.blendModes.SATURATION] = "saturation"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR] = "color"; + PIXI.blendModesCanvas[PIXI.blendModes.LUMINOSITY] = "luminosity"; + } + else + { + // this means that the browser does not support the cool new blend modes in canvas "cough" ie "cough" + PIXI.blendModesCanvas[PIXI.blendModes.NORMAL] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.ADD] = "lighter"; //IS THIS OK??? + PIXI.blendModesCanvas[PIXI.blendModes.MULTIPLY] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.SCREEN] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.OVERLAY] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.DARKEN] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.LIGHTEN] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR_DODGE] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR_BURN] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.HARD_LIGHT] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.SOFT_LIGHT] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.DIFFERENCE] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.EXCLUSION] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.HUE] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.SATURATION] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.LUMINOSITY] = "source-over"; + } } }; /** - * Creates a Canvas element of the given size - * - * @method CanvasBuffer - * @param width {Number} the width for the newly created canvas - * @param height {Number} the height for the newly created canvas - * @static - * @private - */ -PIXI.CanvasBuffer = function(width, height) -{ - this.width = width; - this.height = height; - - this.canvas = document.createElement( "canvas" ); - this.context = this.canvas.getContext( "2d" ); - - this.canvas.width = width; - this.canvas.height = height; -}; - -/** - * Clears the canvas that was created by the CanvasBuffer class - * - * @method clear - * @private - */ -PIXI.CanvasBuffer.prototype.clear = function() -{ - this.context.clearRect(0,0, this.width, this.height); -}; - -/** - * Resizes the canvas that was created by the CanvasBuffer class to the specified width and height - * - * @method resize - * @param width {Number} the new width of the canvas - * @param height {Number} the new height of the canvas - * @private - */ - -PIXI.CanvasBuffer.prototype.resize = function(width, height) -{ - this.width = this.canvas.width = width; - this.height = this.canvas.height = height; -}; - - -/** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -10470,7 +10495,7 @@ * @property boundsPadding * @type Number */ - this.boundsPadding = 10; + this.boundsPadding = 0; /** * Used to detect if the graphics object has changed if this is set to true then the graphics object will be recalculated @@ -11448,14 +11473,14 @@ // set up the main bits.. this.uvs = new PIXI.Float32Array([0, 1, - 1, 1, - 1, 0, - 0,1]); + 1, 1, + 1, 0, + 0, 1]); this.verticies = new PIXI.Float32Array([0, 0, - 100,0, - 100,100, - 0, 100]); + 100, 0, + 100, 100, + 0, 100]); this.colors = new PIXI.Float32Array([1, 1, 1, 1]); @@ -11546,7 +11571,7 @@ gl.uniformMatrix3fv(shader.translationMatrix, false, this.worldTransform.toArray(true)); gl.uniform2f(shader.projectionVector, projection.x, -projection.y); gl.uniform2f(shader.offsetVector, -offset.x, -offset.y); - gl.uniform1f(shader.alpha, 1); + gl.uniform1f(shader.alpha, this.worldAlpha); if(!this.dirty) { @@ -11564,7 +11589,7 @@ // check if a texture is dirty.. if(this.texture.baseTexture._dirty[gl.id]) { - this.renderSession.renderer.updateTexture(this.texture.baseTexture); + renderSession.renderer.updateTexture(this.texture.baseTexture); } else { @@ -11615,6 +11640,8 @@ }; + + PIXI.Strip.prototype._renderCanvas = function(renderSession) { var context = renderSession.context; @@ -11646,10 +11673,8 @@ var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - if(this.padding === 0) + if(this.padding > 0) { - - //expand(); var centerX = (x0 + x1 + x2)/3; var centerY = (y0 + y1 + y2)/3; @@ -11675,7 +11700,6 @@ dist = Math.sqrt( normX * normX + normY * normY ); x2 = centerX + (normX / dist) * (dist + 3); y2 = centerY + (normY / dist) * (dist + 3); - } var u0 = uvs[index] * strip.texture.width, u1 = uvs[index+2] * strip.texture.width, u2 = uvs[index+4]* strip.texture.width; @@ -11711,13 +11735,40 @@ } }; -/* - * Sets the texture that the Strip will use + +/** + * Renders a flat strip * - * @method setTexture - * @param texture {Texture} the texture that will be used + * @method renderStripFlat + * @param strip {Strip} The Strip to render * @private */ +PIXI.Strip.prototype.renderStripFlat = function(strip) +{ + var context = this.context; + var verticies = strip.verticies; + + var length = verticies.length/2; + this.count++; + + context.beginPath(); + for (var i=1; i < length-2; i++) + { + // draw some triangles! + var index = i*2; + + var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; + var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; + + context.moveTo(x0, y0); + context.lineTo(x1, y1); + context.lineTo(x2, y2); + } + + context.fillStyle = "#FF0000"; + context.fill(); + context.closePath(); +}; /* PIXI.Strip.prototype.setTexture = function(texture) @@ -11745,17 +11796,19 @@ { this.updateFrame = true; }; -/* @author Mat Groves http://matgroves.com/ @Doormat23 +/** + * @author Mat Groves http://matgroves.com/ @Doormat23 + * @copyright Mat Groves, Rovanion Luckey */ /** - * + * * @class Rope * @constructor * @extends Strip - * @param texture {Texture} The texture to use - * @param points {Array} - * + * @param {Texture} texture - The texture to use on the rope. + * @param {Array} points - An array of {PIXI.Point}. + * */ PIXI.Rope = function(texture, points) { @@ -11766,7 +11819,7 @@ this.uvs = new PIXI.Float32Array(points.length * 4); this.colors = new PIXI.Float32Array(points.length * 2); this.indices = new PIXI.Uint16Array(points.length * 2); - + this.refresh(); }; @@ -11777,7 +11830,7 @@ PIXI.Rope.prototype.constructor = PIXI.Rope; /* - * Refreshes + * Refreshes * * @method refresh */ @@ -11906,7 +11959,7 @@ PIXI.DisplayObjectContainer.prototype.updateTransform.call( this ); }; /* - * Sets the texture that the Rope will use + * Sets the texture that the Rope will use * * @method setTexture * @param texture {Texture} the texture that will be used @@ -13927,7 +13980,7 @@ this.source = source; //TODO will be used for futer pixi 1.5... - this.id = PIXI.BaseTextureCacheIdGenerator++; + this._UID = PIXI._UID++; /** * Controls if RGB channels should be premultiplied by Alpha (WebGL only) @@ -14535,7 +14588,6 @@ this.baseTexture.width = this.width * this.resolution; this.baseTexture.height = this.height * this.resolution; this.baseTexture._glTextures = []; - this.baseTexture.resolution = this.resolution; this.baseTexture.scaleMode = scaleMode || PIXI.scaleModes.DEFAULT; @@ -14553,6 +14605,7 @@ if(this.renderer.type === PIXI.WEBGL_RENDERER) { var gl = this.renderer.gl; + this.baseTexture._dirty[gl.id] = false this.textureBuffer = new PIXI.FilterTexture(gl, this.width * this.resolution, this.height * this.resolution, this.baseTexture.scaleMode); this.baseTexture._glTextures[gl.id] = this.textureBuffer.texture; @@ -14689,7 +14742,7 @@ var wt = displayObject.worldTransform; wt.identity(); - wt.append(matrix); + if(matrix)wt.append(matrix); // Time to update all the children of the displayObject with the new matrix.. var children = displayObject.children; @@ -15810,6 +15863,18 @@ this.fragmentSrc = fragmentSrc || []; }; +PIXI.AbstractFilter.prototype.syncUniforms = function() +{ + for(var i=0,j=this.shaders.length; i= this.size) { - //return; this.flush(); this.currentBaseTexture = texture.baseTexture; } @@ -8078,11 +8145,11 @@ if(!uvs)return; // get the sprites current alpha - var alpha = sprite.worldAlpha; + var alpha = sprite.worldAlpha * 255; var tint = sprite.tint; var verticies = this.vertices; - + var byteBuffer = this.byteBuffer; // TODO trim?? var aX = sprite.anchor.x; @@ -8130,9 +8197,10 @@ // uv verticies[index++] = uvs.x0; verticies[index++] = uvs.y0; - // color - verticies[index++] = alpha; - verticies[index++] = tint; + + + this.byteBuffer32[index++] = tint; + byteBuffer[(index-1) * 4 + 3] = alpha; // xy verticies[index++] = a * w0 + c * h1 + tx; @@ -8141,8 +8209,8 @@ verticies[index++] = uvs.x1; verticies[index++] = uvs.y1; // color - verticies[index++] = alpha; - verticies[index++] = tint; + this.byteBuffer32[index++] = tint + byteBuffer[(index-1) * 4 + 3] = alpha; // xy verticies[index++] = a * w0 + c * h0 + tx; @@ -8151,8 +8219,8 @@ verticies[index++] = uvs.x2; verticies[index++] = uvs.y2; // color - verticies[index++] = alpha; - verticies[index++] = tint; + this.byteBuffer32[index++] = tint + byteBuffer[(index-1) * 4 + 3] = alpha; // xy verticies[index++] = a * w1 + c * h0 + tx; @@ -8161,14 +8229,11 @@ verticies[index++] = uvs.x3; verticies[index++] = uvs.y3; // color - verticies[index++] = alpha; - verticies[index++] = tint; - - // increment the batchsize - this.textures[this.currentBatchSize] = sprite.texture.baseTexture; - this.blendModes[this.currentBatchSize] = sprite.blendMode; + this.byteBuffer32[index++] = tint + byteBuffer[(index-1) * 4 + 3] = alpha; - this.currentBatchSize++; + // increment the batchsize + this.sprites[this.currentBatchSize++] = sprite; }; @@ -8182,7 +8247,8 @@ { var texture = tilingSprite.tilingTexture; - + if(this.customShader) + // check texture.. if(this.currentBatchSize >= this.size) { @@ -8309,8 +8375,12 @@ if (this.currentBatchSize===0)return; var gl = this.gl; - - this.renderSession.shaderManager.setShader(this.renderSession.shaderManager.defaultShader); + + for (var i = this.byteBuffer.length - 1; i >= 0; i--) { + // this.byteBuffer[i] = 0; + }; +// console.log(this.byteBuffer); + // console.log(this.vertices); if(this.dirty) { @@ -8322,15 +8392,13 @@ gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); - // set the projection - var projection = this.renderSession.projection; - gl.uniform2f(this.shader.projectionVector, projection.x, projection.y); + var shader = this.defaultShader.shaders[gl.id]; - // set the pointers + // 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.colorAttribute, 2, gl.FLOAT, false, stride, 4 * 4); + gl.vertexAttribPointer(shader.aVertexPosition, 2, gl.FLOAT, false, stride, 0); + gl.vertexAttribPointer(shader.aTextureCoord, 2, gl.FLOAT, false, stride, 2 * 4); + gl.vertexAttribPointer(shader.colorAttribute, 4, gl.UNSIGNED_BYTE, true, stride, 4 * 4); } // upload the verts to the buffer @@ -8348,26 +8416,67 @@ var batchSize = 0; var start = 0; - var currentBaseTexture = null; + var currentBaseTexture = this.emptyTexture; var currentBlendMode = this.renderSession.blendModeManager.currentBlendMode; + var currentShader = this.emptyTexture; + var blendSwap = false; + var shaderSwap = false; + var sprite; for (var i = 0, j = this.currentBatchSize; i < j; i++) { - nextTexture = this.textures[i]; - nextBlendMode = this.blendModes[i]; - blendSwap = currentBlendMode !== nextBlendMode; + var sprite = this.sprites[i]; - if(currentBaseTexture !== nextTexture || blendSwap) + nextTexture = sprite.texture.baseTexture; + nextBlendMode = sprite.blendMode + nextShader = sprite.shader || this.defaultShader; + + blendSwap = currentBlendMode !== nextBlendMode; + shaderSwap = currentShader !== nextShader; // should I use _UIDS??? + + if(currentBaseTexture._UID !== nextTexture._UID || blendSwap || shaderSwap) { this.renderBatch(currentBaseTexture, batchSize, start); start = i; batchSize = 0; currentBaseTexture = nextTexture; - currentBlendMode = nextBlendMode; - - if( blendSwap )this.renderSession.blendModeManager.setBlendMode( currentBlendMode ); + + if( blendSwap ) + { + currentBlendMode = nextBlendMode; + this.renderSession.blendModeManager.setBlendMode( currentBlendMode ); + } + + if( shaderSwap ) + { + currentShader = nextShader; + + var shader = currentShader.shaders[gl.id]; + + if(!shader) + { + shader = new PIXI.PixiShader(gl); + + shader.fragmentSrc =currentShader.fragmentSrc; + shader.uniforms =currentShader.uniforms; + shader.init(); + + currentShader.shaders[gl.id] = shader; + } + + // set shader function??? + var change = this.renderSession.shaderManager.setShader(shader); + + if(shader.dirty)shader.syncUniforms(); + + // set the projection + var projection = this.renderSession.projection; + gl.uniform2f(shader.projectionVector, projection.x, projection.y); + + // set the pointers + } } batchSize++; @@ -8404,6 +8513,7 @@ this.renderSession.drawCount++; }; + /** * * @method stop @@ -9338,6 +9448,60 @@ }; /** + * @author Mat Groves + * + * + */ + +/** + * Creates a Canvas element of the given size + * + * @method CanvasBuffer + * @param width {Number} the width for the newly created canvas + * @param height {Number} the height for the newly created canvas + * @static + * @private + */ +PIXI.CanvasBuffer = function(width, height) +{ + this.width = width; + this.height = height; + + this.canvas = document.createElement( "canvas" ); + this.context = this.canvas.getContext( "2d" ); + + this.canvas.width = width; + this.canvas.height = height; +}; + +/** + * Clears the canvas that was created by the CanvasBuffer class + * + * @method clear + * @private + */ +PIXI.CanvasBuffer.prototype.clear = function() +{ + this.context.clearRect(0,0, this.width, this.height); +}; + +/** + * Resizes the canvas that was created by the CanvasBuffer class to the specified width and height + * + * @method resize + * @param width {Number} the new width of the canvas + * @param height {Number} the new height of the canvas + * @private + */ + +PIXI.CanvasBuffer.prototype.resize = function(width, height) +{ + this.width = this.canvas.width = width; + this.height = this.canvas.height = height; +}; + + +/** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -9697,53 +9861,7 @@ */ this.transparent = options.transparent; - if(!PIXI.blendModesCanvas) - { - PIXI.blendModesCanvas = []; - - if(PIXI.canUseNewCanvasBlendModes()) - { - PIXI.blendModesCanvas[PIXI.blendModes.NORMAL] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.ADD] = "lighter"; //IS THIS OK??? - PIXI.blendModesCanvas[PIXI.blendModes.MULTIPLY] = "multiply"; - PIXI.blendModesCanvas[PIXI.blendModes.SCREEN] = "screen"; - PIXI.blendModesCanvas[PIXI.blendModes.OVERLAY] = "overlay"; - PIXI.blendModesCanvas[PIXI.blendModes.DARKEN] = "darken"; - PIXI.blendModesCanvas[PIXI.blendModes.LIGHTEN] = "lighten"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR_DODGE] = "color-dodge"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR_BURN] = "color-burn"; - PIXI.blendModesCanvas[PIXI.blendModes.HARD_LIGHT] = "hard-light"; - PIXI.blendModesCanvas[PIXI.blendModes.SOFT_LIGHT] = "soft-light"; - PIXI.blendModesCanvas[PIXI.blendModes.DIFFERENCE] = "difference"; - PIXI.blendModesCanvas[PIXI.blendModes.EXCLUSION] = "exclusion"; - PIXI.blendModesCanvas[PIXI.blendModes.HUE] = "hue"; - PIXI.blendModesCanvas[PIXI.blendModes.SATURATION] = "saturation"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR] = "color"; - PIXI.blendModesCanvas[PIXI.blendModes.LUMINOSITY] = "luminosity"; - } - else - { - // this means that the browser does not support the cool new blend modes in canvas "cough" ie "cough" - PIXI.blendModesCanvas[PIXI.blendModes.NORMAL] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.ADD] = "lighter"; //IS THIS OK??? - PIXI.blendModesCanvas[PIXI.blendModes.MULTIPLY] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.SCREEN] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.OVERLAY] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.DARKEN] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.LIGHTEN] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR_DODGE] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR_BURN] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.HARD_LIGHT] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.SOFT_LIGHT] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.DIFFERENCE] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.EXCLUSION] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.HUE] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.SATURATION] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.LUMINOSITY] = "source-over"; - } - } - + /** * The width of the canvas view * @@ -9805,7 +9923,6 @@ maskManager: this.maskManager, scaleMode: null, smoothProperty: null, - /** * If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. * Handy for crisp pixel art and speed on legacy devices. @@ -9872,7 +9989,6 @@ stage.interactionManager.setTarget(this); } } - }; /** @@ -9892,7 +10008,6 @@ this.view.style.width = this.width / this.resolution + "px"; this.view.style.height = this.height / this.resolution + "px"; - }; /** @@ -9905,154 +10020,64 @@ */ PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject, context) { - // no longer recursive! - //var transform; - //var context = this.context; - this.renderSession.context = context || this.context; this.renderSession.resolution = this.resolution; displayObject._renderCanvas(this.renderSession); }; -/** - * Renders a flat strip - * - * @method renderStripFlat - * @param strip {Strip} The Strip to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderStripFlat = function(strip) + + +PIXI.CanvasRenderer.prototype.mapBlendModes = function() { - var context = this.context; - var verticies = strip.verticies; - - var length = verticies.length/2; - this.count++; - - context.beginPath(); - for (var i=1; i < length-2; i++) + if(!PIXI.blendModesCanvas) { - // draw some triangles! - var index = i*2; + PIXI.blendModesCanvas = []; - var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; - var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - - context.moveTo(x0, y0); - context.lineTo(x1, y1); - context.lineTo(x2, y2); - } - - context.fillStyle = "#FF0000"; - context.fill(); - context.closePath(); -}; - -/** - * Renders a strip - * - * @method renderStrip - * @param strip {Strip} The Strip to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderStrip = function(strip) -{ - var context = this.context; - - // draw triangles!! - var verticies = strip.verticies; - var uvs = strip.uvs; - - var length = verticies.length/2; - this.count++; - - for (var i = 1; i < length-2; i++) - { - // draw some triangles! - var index = i*2; - - var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; - var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - - var u0 = uvs[index] * strip.texture.width, u1 = uvs[index+2] * strip.texture.width, u2 = uvs[index+4]* strip.texture.width; - var v0 = uvs[index+1]* strip.texture.height, v1 = uvs[index+3] * strip.texture.height, v2 = uvs[index+5]* strip.texture.height; - - context.save(); - context.beginPath(); - context.moveTo(x0, y0); - context.lineTo(x1, y1); - context.lineTo(x2, y2); - context.closePath(); - - context.clip(); - - // Compute matrix transform - var delta = u0*v1 + v0*u2 + u1*v2 - v1*u2 - v0*u1 - u0*v2; - var deltaA = x0*v1 + v0*x2 + x1*v2 - v1*x2 - v0*x1 - x0*v2; - var deltaB = u0*x1 + x0*u2 + u1*x2 - x1*u2 - x0*u1 - u0*x2; - var deltaC = u0*v1*x2 + v0*x1*u2 + x0*u1*v2 - x0*v1*u2 - v0*u1*x2 - u0*x1*v2; - var deltaD = y0*v1 + v0*y2 + y1*v2 - v1*y2 - v0*y1 - y0*v2; - var deltaE = u0*y1 + y0*u2 + u1*y2 - y1*u2 - y0*u1 - u0*y2; - var deltaF = u0*v1*y2 + v0*y1*u2 + y0*u1*v2 - y0*v1*u2 - v0*u1*y2 - u0*y1*v2; - - context.transform(deltaA / delta, deltaD / delta, - deltaB / delta, deltaE / delta, - deltaC / delta, deltaF / delta); - - context.drawImage(strip.texture.baseTexture.source, 0, 0); - context.restore(); + if(PIXI.canUseNewCanvasBlendModes()) + { + PIXI.blendModesCanvas[PIXI.blendModes.NORMAL] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.ADD] = "lighter"; //IS THIS OK??? + PIXI.blendModesCanvas[PIXI.blendModes.MULTIPLY] = "multiply"; + PIXI.blendModesCanvas[PIXI.blendModes.SCREEN] = "screen"; + PIXI.blendModesCanvas[PIXI.blendModes.OVERLAY] = "overlay"; + PIXI.blendModesCanvas[PIXI.blendModes.DARKEN] = "darken"; + PIXI.blendModesCanvas[PIXI.blendModes.LIGHTEN] = "lighten"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR_DODGE] = "color-dodge"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR_BURN] = "color-burn"; + PIXI.blendModesCanvas[PIXI.blendModes.HARD_LIGHT] = "hard-light"; + PIXI.blendModesCanvas[PIXI.blendModes.SOFT_LIGHT] = "soft-light"; + PIXI.blendModesCanvas[PIXI.blendModes.DIFFERENCE] = "difference"; + PIXI.blendModesCanvas[PIXI.blendModes.EXCLUSION] = "exclusion"; + PIXI.blendModesCanvas[PIXI.blendModes.HUE] = "hue"; + PIXI.blendModesCanvas[PIXI.blendModes.SATURATION] = "saturation"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR] = "color"; + PIXI.blendModesCanvas[PIXI.blendModes.LUMINOSITY] = "luminosity"; + } + else + { + // this means that the browser does not support the cool new blend modes in canvas "cough" ie "cough" + PIXI.blendModesCanvas[PIXI.blendModes.NORMAL] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.ADD] = "lighter"; //IS THIS OK??? + PIXI.blendModesCanvas[PIXI.blendModes.MULTIPLY] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.SCREEN] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.OVERLAY] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.DARKEN] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.LIGHTEN] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR_DODGE] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR_BURN] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.HARD_LIGHT] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.SOFT_LIGHT] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.DIFFERENCE] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.EXCLUSION] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.HUE] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.SATURATION] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.LUMINOSITY] = "source-over"; + } } }; /** - * Creates a Canvas element of the given size - * - * @method CanvasBuffer - * @param width {Number} the width for the newly created canvas - * @param height {Number} the height for the newly created canvas - * @static - * @private - */ -PIXI.CanvasBuffer = function(width, height) -{ - this.width = width; - this.height = height; - - this.canvas = document.createElement( "canvas" ); - this.context = this.canvas.getContext( "2d" ); - - this.canvas.width = width; - this.canvas.height = height; -}; - -/** - * Clears the canvas that was created by the CanvasBuffer class - * - * @method clear - * @private - */ -PIXI.CanvasBuffer.prototype.clear = function() -{ - this.context.clearRect(0,0, this.width, this.height); -}; - -/** - * Resizes the canvas that was created by the CanvasBuffer class to the specified width and height - * - * @method resize - * @param width {Number} the new width of the canvas - * @param height {Number} the new height of the canvas - * @private - */ - -PIXI.CanvasBuffer.prototype.resize = function(width, height) -{ - this.width = this.canvas.width = width; - this.height = this.canvas.height = height; -}; - - -/** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -10470,7 +10495,7 @@ * @property boundsPadding * @type Number */ - this.boundsPadding = 10; + this.boundsPadding = 0; /** * Used to detect if the graphics object has changed if this is set to true then the graphics object will be recalculated @@ -11448,14 +11473,14 @@ // set up the main bits.. this.uvs = new PIXI.Float32Array([0, 1, - 1, 1, - 1, 0, - 0,1]); + 1, 1, + 1, 0, + 0, 1]); this.verticies = new PIXI.Float32Array([0, 0, - 100,0, - 100,100, - 0, 100]); + 100, 0, + 100, 100, + 0, 100]); this.colors = new PIXI.Float32Array([1, 1, 1, 1]); @@ -11546,7 +11571,7 @@ gl.uniformMatrix3fv(shader.translationMatrix, false, this.worldTransform.toArray(true)); gl.uniform2f(shader.projectionVector, projection.x, -projection.y); gl.uniform2f(shader.offsetVector, -offset.x, -offset.y); - gl.uniform1f(shader.alpha, 1); + gl.uniform1f(shader.alpha, this.worldAlpha); if(!this.dirty) { @@ -11564,7 +11589,7 @@ // check if a texture is dirty.. if(this.texture.baseTexture._dirty[gl.id]) { - this.renderSession.renderer.updateTexture(this.texture.baseTexture); + renderSession.renderer.updateTexture(this.texture.baseTexture); } else { @@ -11615,6 +11640,8 @@ }; + + PIXI.Strip.prototype._renderCanvas = function(renderSession) { var context = renderSession.context; @@ -11646,10 +11673,8 @@ var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - if(this.padding === 0) + if(this.padding > 0) { - - //expand(); var centerX = (x0 + x1 + x2)/3; var centerY = (y0 + y1 + y2)/3; @@ -11675,7 +11700,6 @@ dist = Math.sqrt( normX * normX + normY * normY ); x2 = centerX + (normX / dist) * (dist + 3); y2 = centerY + (normY / dist) * (dist + 3); - } var u0 = uvs[index] * strip.texture.width, u1 = uvs[index+2] * strip.texture.width, u2 = uvs[index+4]* strip.texture.width; @@ -11711,13 +11735,40 @@ } }; -/* - * Sets the texture that the Strip will use + +/** + * Renders a flat strip * - * @method setTexture - * @param texture {Texture} the texture that will be used + * @method renderStripFlat + * @param strip {Strip} The Strip to render * @private */ +PIXI.Strip.prototype.renderStripFlat = function(strip) +{ + var context = this.context; + var verticies = strip.verticies; + + var length = verticies.length/2; + this.count++; + + context.beginPath(); + for (var i=1; i < length-2; i++) + { + // draw some triangles! + var index = i*2; + + var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; + var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; + + context.moveTo(x0, y0); + context.lineTo(x1, y1); + context.lineTo(x2, y2); + } + + context.fillStyle = "#FF0000"; + context.fill(); + context.closePath(); +}; /* PIXI.Strip.prototype.setTexture = function(texture) @@ -11745,17 +11796,19 @@ { this.updateFrame = true; }; -/* @author Mat Groves http://matgroves.com/ @Doormat23 +/** + * @author Mat Groves http://matgroves.com/ @Doormat23 + * @copyright Mat Groves, Rovanion Luckey */ /** - * + * * @class Rope * @constructor * @extends Strip - * @param texture {Texture} The texture to use - * @param points {Array} - * + * @param {Texture} texture - The texture to use on the rope. + * @param {Array} points - An array of {PIXI.Point}. + * */ PIXI.Rope = function(texture, points) { @@ -11766,7 +11819,7 @@ this.uvs = new PIXI.Float32Array(points.length * 4); this.colors = new PIXI.Float32Array(points.length * 2); this.indices = new PIXI.Uint16Array(points.length * 2); - + this.refresh(); }; @@ -11777,7 +11830,7 @@ PIXI.Rope.prototype.constructor = PIXI.Rope; /* - * Refreshes + * Refreshes * * @method refresh */ @@ -11906,7 +11959,7 @@ PIXI.DisplayObjectContainer.prototype.updateTransform.call( this ); }; /* - * Sets the texture that the Rope will use + * Sets the texture that the Rope will use * * @method setTexture * @param texture {Texture} the texture that will be used @@ -13927,7 +13980,7 @@ this.source = source; //TODO will be used for futer pixi 1.5... - this.id = PIXI.BaseTextureCacheIdGenerator++; + this._UID = PIXI._UID++; /** * Controls if RGB channels should be premultiplied by Alpha (WebGL only) @@ -14535,7 +14588,6 @@ this.baseTexture.width = this.width * this.resolution; this.baseTexture.height = this.height * this.resolution; this.baseTexture._glTextures = []; - this.baseTexture.resolution = this.resolution; this.baseTexture.scaleMode = scaleMode || PIXI.scaleModes.DEFAULT; @@ -14553,6 +14605,7 @@ if(this.renderer.type === PIXI.WEBGL_RENDERER) { var gl = this.renderer.gl; + this.baseTexture._dirty[gl.id] = false this.textureBuffer = new PIXI.FilterTexture(gl, this.width * this.resolution, this.height * this.resolution, this.baseTexture.scaleMode); this.baseTexture._glTextures[gl.id] = this.textureBuffer.texture; @@ -14689,7 +14742,7 @@ var wt = displayObject.worldTransform; wt.identity(); - wt.append(matrix); + if(matrix)wt.append(matrix); // Time to update all the children of the displayObject with the new matrix.. var children = displayObject.children; @@ -15810,6 +15863,18 @@ this.fragmentSrc = fragmentSrc || []; }; +PIXI.AbstractFilter.prototype.syncUniforms = function() +{ + for(var i=0,j=this.shaders.length; i= this.size) { - //return; this.flush(); this.currentBaseTexture = texture.baseTexture; } @@ -8078,11 +8145,11 @@ if(!uvs)return; // get the sprites current alpha - var alpha = sprite.worldAlpha; + var alpha = sprite.worldAlpha * 255; var tint = sprite.tint; var verticies = this.vertices; - + var byteBuffer = this.byteBuffer; // TODO trim?? var aX = sprite.anchor.x; @@ -8130,9 +8197,10 @@ // uv verticies[index++] = uvs.x0; verticies[index++] = uvs.y0; - // color - verticies[index++] = alpha; - verticies[index++] = tint; + + + this.byteBuffer32[index++] = tint; + byteBuffer[(index-1) * 4 + 3] = alpha; // xy verticies[index++] = a * w0 + c * h1 + tx; @@ -8141,8 +8209,8 @@ verticies[index++] = uvs.x1; verticies[index++] = uvs.y1; // color - verticies[index++] = alpha; - verticies[index++] = tint; + this.byteBuffer32[index++] = tint + byteBuffer[(index-1) * 4 + 3] = alpha; // xy verticies[index++] = a * w0 + c * h0 + tx; @@ -8151,8 +8219,8 @@ verticies[index++] = uvs.x2; verticies[index++] = uvs.y2; // color - verticies[index++] = alpha; - verticies[index++] = tint; + this.byteBuffer32[index++] = tint + byteBuffer[(index-1) * 4 + 3] = alpha; // xy verticies[index++] = a * w1 + c * h0 + tx; @@ -8161,14 +8229,11 @@ verticies[index++] = uvs.x3; verticies[index++] = uvs.y3; // color - verticies[index++] = alpha; - verticies[index++] = tint; - - // increment the batchsize - this.textures[this.currentBatchSize] = sprite.texture.baseTexture; - this.blendModes[this.currentBatchSize] = sprite.blendMode; + this.byteBuffer32[index++] = tint + byteBuffer[(index-1) * 4 + 3] = alpha; - this.currentBatchSize++; + // increment the batchsize + this.sprites[this.currentBatchSize++] = sprite; }; @@ -8182,7 +8247,8 @@ { var texture = tilingSprite.tilingTexture; - + if(this.customShader) + // check texture.. if(this.currentBatchSize >= this.size) { @@ -8309,8 +8375,12 @@ if (this.currentBatchSize===0)return; var gl = this.gl; - - this.renderSession.shaderManager.setShader(this.renderSession.shaderManager.defaultShader); + + for (var i = this.byteBuffer.length - 1; i >= 0; i--) { + // this.byteBuffer[i] = 0; + }; +// console.log(this.byteBuffer); + // console.log(this.vertices); if(this.dirty) { @@ -8322,15 +8392,13 @@ gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); - // set the projection - var projection = this.renderSession.projection; - gl.uniform2f(this.shader.projectionVector, projection.x, projection.y); + var shader = this.defaultShader.shaders[gl.id]; - // set the pointers + // 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.colorAttribute, 2, gl.FLOAT, false, stride, 4 * 4); + gl.vertexAttribPointer(shader.aVertexPosition, 2, gl.FLOAT, false, stride, 0); + gl.vertexAttribPointer(shader.aTextureCoord, 2, gl.FLOAT, false, stride, 2 * 4); + gl.vertexAttribPointer(shader.colorAttribute, 4, gl.UNSIGNED_BYTE, true, stride, 4 * 4); } // upload the verts to the buffer @@ -8348,26 +8416,67 @@ var batchSize = 0; var start = 0; - var currentBaseTexture = null; + var currentBaseTexture = this.emptyTexture; var currentBlendMode = this.renderSession.blendModeManager.currentBlendMode; + var currentShader = this.emptyTexture; + var blendSwap = false; + var shaderSwap = false; + var sprite; for (var i = 0, j = this.currentBatchSize; i < j; i++) { - nextTexture = this.textures[i]; - nextBlendMode = this.blendModes[i]; - blendSwap = currentBlendMode !== nextBlendMode; + var sprite = this.sprites[i]; - if(currentBaseTexture !== nextTexture || blendSwap) + nextTexture = sprite.texture.baseTexture; + nextBlendMode = sprite.blendMode + nextShader = sprite.shader || this.defaultShader; + + blendSwap = currentBlendMode !== nextBlendMode; + shaderSwap = currentShader !== nextShader; // should I use _UIDS??? + + if(currentBaseTexture._UID !== nextTexture._UID || blendSwap || shaderSwap) { this.renderBatch(currentBaseTexture, batchSize, start); start = i; batchSize = 0; currentBaseTexture = nextTexture; - currentBlendMode = nextBlendMode; - - if( blendSwap )this.renderSession.blendModeManager.setBlendMode( currentBlendMode ); + + if( blendSwap ) + { + currentBlendMode = nextBlendMode; + this.renderSession.blendModeManager.setBlendMode( currentBlendMode ); + } + + if( shaderSwap ) + { + currentShader = nextShader; + + var shader = currentShader.shaders[gl.id]; + + if(!shader) + { + shader = new PIXI.PixiShader(gl); + + shader.fragmentSrc =currentShader.fragmentSrc; + shader.uniforms =currentShader.uniforms; + shader.init(); + + currentShader.shaders[gl.id] = shader; + } + + // set shader function??? + var change = this.renderSession.shaderManager.setShader(shader); + + if(shader.dirty)shader.syncUniforms(); + + // set the projection + var projection = this.renderSession.projection; + gl.uniform2f(shader.projectionVector, projection.x, projection.y); + + // set the pointers + } } batchSize++; @@ -8404,6 +8513,7 @@ this.renderSession.drawCount++; }; + /** * * @method stop @@ -9338,6 +9448,60 @@ }; /** + * @author Mat Groves + * + * + */ + +/** + * Creates a Canvas element of the given size + * + * @method CanvasBuffer + * @param width {Number} the width for the newly created canvas + * @param height {Number} the height for the newly created canvas + * @static + * @private + */ +PIXI.CanvasBuffer = function(width, height) +{ + this.width = width; + this.height = height; + + this.canvas = document.createElement( "canvas" ); + this.context = this.canvas.getContext( "2d" ); + + this.canvas.width = width; + this.canvas.height = height; +}; + +/** + * Clears the canvas that was created by the CanvasBuffer class + * + * @method clear + * @private + */ +PIXI.CanvasBuffer.prototype.clear = function() +{ + this.context.clearRect(0,0, this.width, this.height); +}; + +/** + * Resizes the canvas that was created by the CanvasBuffer class to the specified width and height + * + * @method resize + * @param width {Number} the new width of the canvas + * @param height {Number} the new height of the canvas + * @private + */ + +PIXI.CanvasBuffer.prototype.resize = function(width, height) +{ + this.width = this.canvas.width = width; + this.height = this.canvas.height = height; +}; + + +/** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -9697,53 +9861,7 @@ */ this.transparent = options.transparent; - if(!PIXI.blendModesCanvas) - { - PIXI.blendModesCanvas = []; - - if(PIXI.canUseNewCanvasBlendModes()) - { - PIXI.blendModesCanvas[PIXI.blendModes.NORMAL] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.ADD] = "lighter"; //IS THIS OK??? - PIXI.blendModesCanvas[PIXI.blendModes.MULTIPLY] = "multiply"; - PIXI.blendModesCanvas[PIXI.blendModes.SCREEN] = "screen"; - PIXI.blendModesCanvas[PIXI.blendModes.OVERLAY] = "overlay"; - PIXI.blendModesCanvas[PIXI.blendModes.DARKEN] = "darken"; - PIXI.blendModesCanvas[PIXI.blendModes.LIGHTEN] = "lighten"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR_DODGE] = "color-dodge"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR_BURN] = "color-burn"; - PIXI.blendModesCanvas[PIXI.blendModes.HARD_LIGHT] = "hard-light"; - PIXI.blendModesCanvas[PIXI.blendModes.SOFT_LIGHT] = "soft-light"; - PIXI.blendModesCanvas[PIXI.blendModes.DIFFERENCE] = "difference"; - PIXI.blendModesCanvas[PIXI.blendModes.EXCLUSION] = "exclusion"; - PIXI.blendModesCanvas[PIXI.blendModes.HUE] = "hue"; - PIXI.blendModesCanvas[PIXI.blendModes.SATURATION] = "saturation"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR] = "color"; - PIXI.blendModesCanvas[PIXI.blendModes.LUMINOSITY] = "luminosity"; - } - else - { - // this means that the browser does not support the cool new blend modes in canvas "cough" ie "cough" - PIXI.blendModesCanvas[PIXI.blendModes.NORMAL] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.ADD] = "lighter"; //IS THIS OK??? - PIXI.blendModesCanvas[PIXI.blendModes.MULTIPLY] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.SCREEN] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.OVERLAY] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.DARKEN] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.LIGHTEN] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR_DODGE] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR_BURN] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.HARD_LIGHT] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.SOFT_LIGHT] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.DIFFERENCE] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.EXCLUSION] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.HUE] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.SATURATION] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.LUMINOSITY] = "source-over"; - } - } - + /** * The width of the canvas view * @@ -9805,7 +9923,6 @@ maskManager: this.maskManager, scaleMode: null, smoothProperty: null, - /** * If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. * Handy for crisp pixel art and speed on legacy devices. @@ -9872,7 +9989,6 @@ stage.interactionManager.setTarget(this); } } - }; /** @@ -9892,7 +10008,6 @@ this.view.style.width = this.width / this.resolution + "px"; this.view.style.height = this.height / this.resolution + "px"; - }; /** @@ -9905,154 +10020,64 @@ */ PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject, context) { - // no longer recursive! - //var transform; - //var context = this.context; - this.renderSession.context = context || this.context; this.renderSession.resolution = this.resolution; displayObject._renderCanvas(this.renderSession); }; -/** - * Renders a flat strip - * - * @method renderStripFlat - * @param strip {Strip} The Strip to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderStripFlat = function(strip) + + +PIXI.CanvasRenderer.prototype.mapBlendModes = function() { - var context = this.context; - var verticies = strip.verticies; - - var length = verticies.length/2; - this.count++; - - context.beginPath(); - for (var i=1; i < length-2; i++) + if(!PIXI.blendModesCanvas) { - // draw some triangles! - var index = i*2; + PIXI.blendModesCanvas = []; - var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; - var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - - context.moveTo(x0, y0); - context.lineTo(x1, y1); - context.lineTo(x2, y2); - } - - context.fillStyle = "#FF0000"; - context.fill(); - context.closePath(); -}; - -/** - * Renders a strip - * - * @method renderStrip - * @param strip {Strip} The Strip to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderStrip = function(strip) -{ - var context = this.context; - - // draw triangles!! - var verticies = strip.verticies; - var uvs = strip.uvs; - - var length = verticies.length/2; - this.count++; - - for (var i = 1; i < length-2; i++) - { - // draw some triangles! - var index = i*2; - - var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; - var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - - var u0 = uvs[index] * strip.texture.width, u1 = uvs[index+2] * strip.texture.width, u2 = uvs[index+4]* strip.texture.width; - var v0 = uvs[index+1]* strip.texture.height, v1 = uvs[index+3] * strip.texture.height, v2 = uvs[index+5]* strip.texture.height; - - context.save(); - context.beginPath(); - context.moveTo(x0, y0); - context.lineTo(x1, y1); - context.lineTo(x2, y2); - context.closePath(); - - context.clip(); - - // Compute matrix transform - var delta = u0*v1 + v0*u2 + u1*v2 - v1*u2 - v0*u1 - u0*v2; - var deltaA = x0*v1 + v0*x2 + x1*v2 - v1*x2 - v0*x1 - x0*v2; - var deltaB = u0*x1 + x0*u2 + u1*x2 - x1*u2 - x0*u1 - u0*x2; - var deltaC = u0*v1*x2 + v0*x1*u2 + x0*u1*v2 - x0*v1*u2 - v0*u1*x2 - u0*x1*v2; - var deltaD = y0*v1 + v0*y2 + y1*v2 - v1*y2 - v0*y1 - y0*v2; - var deltaE = u0*y1 + y0*u2 + u1*y2 - y1*u2 - y0*u1 - u0*y2; - var deltaF = u0*v1*y2 + v0*y1*u2 + y0*u1*v2 - y0*v1*u2 - v0*u1*y2 - u0*y1*v2; - - context.transform(deltaA / delta, deltaD / delta, - deltaB / delta, deltaE / delta, - deltaC / delta, deltaF / delta); - - context.drawImage(strip.texture.baseTexture.source, 0, 0); - context.restore(); + if(PIXI.canUseNewCanvasBlendModes()) + { + PIXI.blendModesCanvas[PIXI.blendModes.NORMAL] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.ADD] = "lighter"; //IS THIS OK??? + PIXI.blendModesCanvas[PIXI.blendModes.MULTIPLY] = "multiply"; + PIXI.blendModesCanvas[PIXI.blendModes.SCREEN] = "screen"; + PIXI.blendModesCanvas[PIXI.blendModes.OVERLAY] = "overlay"; + PIXI.blendModesCanvas[PIXI.blendModes.DARKEN] = "darken"; + PIXI.blendModesCanvas[PIXI.blendModes.LIGHTEN] = "lighten"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR_DODGE] = "color-dodge"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR_BURN] = "color-burn"; + PIXI.blendModesCanvas[PIXI.blendModes.HARD_LIGHT] = "hard-light"; + PIXI.blendModesCanvas[PIXI.blendModes.SOFT_LIGHT] = "soft-light"; + PIXI.blendModesCanvas[PIXI.blendModes.DIFFERENCE] = "difference"; + PIXI.blendModesCanvas[PIXI.blendModes.EXCLUSION] = "exclusion"; + PIXI.blendModesCanvas[PIXI.blendModes.HUE] = "hue"; + PIXI.blendModesCanvas[PIXI.blendModes.SATURATION] = "saturation"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR] = "color"; + PIXI.blendModesCanvas[PIXI.blendModes.LUMINOSITY] = "luminosity"; + } + else + { + // this means that the browser does not support the cool new blend modes in canvas "cough" ie "cough" + PIXI.blendModesCanvas[PIXI.blendModes.NORMAL] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.ADD] = "lighter"; //IS THIS OK??? + PIXI.blendModesCanvas[PIXI.blendModes.MULTIPLY] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.SCREEN] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.OVERLAY] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.DARKEN] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.LIGHTEN] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR_DODGE] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR_BURN] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.HARD_LIGHT] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.SOFT_LIGHT] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.DIFFERENCE] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.EXCLUSION] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.HUE] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.SATURATION] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.LUMINOSITY] = "source-over"; + } } }; /** - * Creates a Canvas element of the given size - * - * @method CanvasBuffer - * @param width {Number} the width for the newly created canvas - * @param height {Number} the height for the newly created canvas - * @static - * @private - */ -PIXI.CanvasBuffer = function(width, height) -{ - this.width = width; - this.height = height; - - this.canvas = document.createElement( "canvas" ); - this.context = this.canvas.getContext( "2d" ); - - this.canvas.width = width; - this.canvas.height = height; -}; - -/** - * Clears the canvas that was created by the CanvasBuffer class - * - * @method clear - * @private - */ -PIXI.CanvasBuffer.prototype.clear = function() -{ - this.context.clearRect(0,0, this.width, this.height); -}; - -/** - * Resizes the canvas that was created by the CanvasBuffer class to the specified width and height - * - * @method resize - * @param width {Number} the new width of the canvas - * @param height {Number} the new height of the canvas - * @private - */ - -PIXI.CanvasBuffer.prototype.resize = function(width, height) -{ - this.width = this.canvas.width = width; - this.height = this.canvas.height = height; -}; - - -/** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -10470,7 +10495,7 @@ * @property boundsPadding * @type Number */ - this.boundsPadding = 10; + this.boundsPadding = 0; /** * Used to detect if the graphics object has changed if this is set to true then the graphics object will be recalculated @@ -11448,14 +11473,14 @@ // set up the main bits.. this.uvs = new PIXI.Float32Array([0, 1, - 1, 1, - 1, 0, - 0,1]); + 1, 1, + 1, 0, + 0, 1]); this.verticies = new PIXI.Float32Array([0, 0, - 100,0, - 100,100, - 0, 100]); + 100, 0, + 100, 100, + 0, 100]); this.colors = new PIXI.Float32Array([1, 1, 1, 1]); @@ -11546,7 +11571,7 @@ gl.uniformMatrix3fv(shader.translationMatrix, false, this.worldTransform.toArray(true)); gl.uniform2f(shader.projectionVector, projection.x, -projection.y); gl.uniform2f(shader.offsetVector, -offset.x, -offset.y); - gl.uniform1f(shader.alpha, 1); + gl.uniform1f(shader.alpha, this.worldAlpha); if(!this.dirty) { @@ -11564,7 +11589,7 @@ // check if a texture is dirty.. if(this.texture.baseTexture._dirty[gl.id]) { - this.renderSession.renderer.updateTexture(this.texture.baseTexture); + renderSession.renderer.updateTexture(this.texture.baseTexture); } else { @@ -11615,6 +11640,8 @@ }; + + PIXI.Strip.prototype._renderCanvas = function(renderSession) { var context = renderSession.context; @@ -11646,10 +11673,8 @@ var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - if(this.padding === 0) + if(this.padding > 0) { - - //expand(); var centerX = (x0 + x1 + x2)/3; var centerY = (y0 + y1 + y2)/3; @@ -11675,7 +11700,6 @@ dist = Math.sqrt( normX * normX + normY * normY ); x2 = centerX + (normX / dist) * (dist + 3); y2 = centerY + (normY / dist) * (dist + 3); - } var u0 = uvs[index] * strip.texture.width, u1 = uvs[index+2] * strip.texture.width, u2 = uvs[index+4]* strip.texture.width; @@ -11711,13 +11735,40 @@ } }; -/* - * Sets the texture that the Strip will use + +/** + * Renders a flat strip * - * @method setTexture - * @param texture {Texture} the texture that will be used + * @method renderStripFlat + * @param strip {Strip} The Strip to render * @private */ +PIXI.Strip.prototype.renderStripFlat = function(strip) +{ + var context = this.context; + var verticies = strip.verticies; + + var length = verticies.length/2; + this.count++; + + context.beginPath(); + for (var i=1; i < length-2; i++) + { + // draw some triangles! + var index = i*2; + + var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; + var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; + + context.moveTo(x0, y0); + context.lineTo(x1, y1); + context.lineTo(x2, y2); + } + + context.fillStyle = "#FF0000"; + context.fill(); + context.closePath(); +}; /* PIXI.Strip.prototype.setTexture = function(texture) @@ -11745,17 +11796,19 @@ { this.updateFrame = true; }; -/* @author Mat Groves http://matgroves.com/ @Doormat23 +/** + * @author Mat Groves http://matgroves.com/ @Doormat23 + * @copyright Mat Groves, Rovanion Luckey */ /** - * + * * @class Rope * @constructor * @extends Strip - * @param texture {Texture} The texture to use - * @param points {Array} - * + * @param {Texture} texture - The texture to use on the rope. + * @param {Array} points - An array of {PIXI.Point}. + * */ PIXI.Rope = function(texture, points) { @@ -11766,7 +11819,7 @@ this.uvs = new PIXI.Float32Array(points.length * 4); this.colors = new PIXI.Float32Array(points.length * 2); this.indices = new PIXI.Uint16Array(points.length * 2); - + this.refresh(); }; @@ -11777,7 +11830,7 @@ PIXI.Rope.prototype.constructor = PIXI.Rope; /* - * Refreshes + * Refreshes * * @method refresh */ @@ -11906,7 +11959,7 @@ PIXI.DisplayObjectContainer.prototype.updateTransform.call( this ); }; /* - * Sets the texture that the Rope will use + * Sets the texture that the Rope will use * * @method setTexture * @param texture {Texture} the texture that will be used @@ -13927,7 +13980,7 @@ this.source = source; //TODO will be used for futer pixi 1.5... - this.id = PIXI.BaseTextureCacheIdGenerator++; + this._UID = PIXI._UID++; /** * Controls if RGB channels should be premultiplied by Alpha (WebGL only) @@ -14535,7 +14588,6 @@ this.baseTexture.width = this.width * this.resolution; this.baseTexture.height = this.height * this.resolution; this.baseTexture._glTextures = []; - this.baseTexture.resolution = this.resolution; this.baseTexture.scaleMode = scaleMode || PIXI.scaleModes.DEFAULT; @@ -14553,6 +14605,7 @@ if(this.renderer.type === PIXI.WEBGL_RENDERER) { var gl = this.renderer.gl; + this.baseTexture._dirty[gl.id] = false this.textureBuffer = new PIXI.FilterTexture(gl, this.width * this.resolution, this.height * this.resolution, this.baseTexture.scaleMode); this.baseTexture._glTextures[gl.id] = this.textureBuffer.texture; @@ -14689,7 +14742,7 @@ var wt = displayObject.worldTransform; wt.identity(); - wt.append(matrix); + if(matrix)wt.append(matrix); // Time to update all the children of the displayObject with the new matrix.. var children = displayObject.children; @@ -15810,6 +15863,18 @@ this.fragmentSrc = fragmentSrc || []; }; +PIXI.AbstractFilter.prototype.syncUniforms = function() +{ + for(var i=0,j=this.shaders.length; i= this.size) { - //return; this.flush(); this.currentBaseTexture = texture.baseTexture; } @@ -8078,11 +8145,11 @@ if(!uvs)return; // get the sprites current alpha - var alpha = sprite.worldAlpha; + var alpha = sprite.worldAlpha * 255; var tint = sprite.tint; var verticies = this.vertices; - + var byteBuffer = this.byteBuffer; // TODO trim?? var aX = sprite.anchor.x; @@ -8130,9 +8197,10 @@ // uv verticies[index++] = uvs.x0; verticies[index++] = uvs.y0; - // color - verticies[index++] = alpha; - verticies[index++] = tint; + + + this.byteBuffer32[index++] = tint; + byteBuffer[(index-1) * 4 + 3] = alpha; // xy verticies[index++] = a * w0 + c * h1 + tx; @@ -8141,8 +8209,8 @@ verticies[index++] = uvs.x1; verticies[index++] = uvs.y1; // color - verticies[index++] = alpha; - verticies[index++] = tint; + this.byteBuffer32[index++] = tint + byteBuffer[(index-1) * 4 + 3] = alpha; // xy verticies[index++] = a * w0 + c * h0 + tx; @@ -8151,8 +8219,8 @@ verticies[index++] = uvs.x2; verticies[index++] = uvs.y2; // color - verticies[index++] = alpha; - verticies[index++] = tint; + this.byteBuffer32[index++] = tint + byteBuffer[(index-1) * 4 + 3] = alpha; // xy verticies[index++] = a * w1 + c * h0 + tx; @@ -8161,14 +8229,11 @@ verticies[index++] = uvs.x3; verticies[index++] = uvs.y3; // color - verticies[index++] = alpha; - verticies[index++] = tint; - - // increment the batchsize - this.textures[this.currentBatchSize] = sprite.texture.baseTexture; - this.blendModes[this.currentBatchSize] = sprite.blendMode; + this.byteBuffer32[index++] = tint + byteBuffer[(index-1) * 4 + 3] = alpha; - this.currentBatchSize++; + // increment the batchsize + this.sprites[this.currentBatchSize++] = sprite; }; @@ -8182,7 +8247,8 @@ { var texture = tilingSprite.tilingTexture; - + if(this.customShader) + // check texture.. if(this.currentBatchSize >= this.size) { @@ -8309,8 +8375,12 @@ if (this.currentBatchSize===0)return; var gl = this.gl; - - this.renderSession.shaderManager.setShader(this.renderSession.shaderManager.defaultShader); + + for (var i = this.byteBuffer.length - 1; i >= 0; i--) { + // this.byteBuffer[i] = 0; + }; +// console.log(this.byteBuffer); + // console.log(this.vertices); if(this.dirty) { @@ -8322,15 +8392,13 @@ gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); - // set the projection - var projection = this.renderSession.projection; - gl.uniform2f(this.shader.projectionVector, projection.x, projection.y); + var shader = this.defaultShader.shaders[gl.id]; - // set the pointers + // 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.colorAttribute, 2, gl.FLOAT, false, stride, 4 * 4); + gl.vertexAttribPointer(shader.aVertexPosition, 2, gl.FLOAT, false, stride, 0); + gl.vertexAttribPointer(shader.aTextureCoord, 2, gl.FLOAT, false, stride, 2 * 4); + gl.vertexAttribPointer(shader.colorAttribute, 4, gl.UNSIGNED_BYTE, true, stride, 4 * 4); } // upload the verts to the buffer @@ -8348,26 +8416,67 @@ var batchSize = 0; var start = 0; - var currentBaseTexture = null; + var currentBaseTexture = this.emptyTexture; var currentBlendMode = this.renderSession.blendModeManager.currentBlendMode; + var currentShader = this.emptyTexture; + var blendSwap = false; + var shaderSwap = false; + var sprite; for (var i = 0, j = this.currentBatchSize; i < j; i++) { - nextTexture = this.textures[i]; - nextBlendMode = this.blendModes[i]; - blendSwap = currentBlendMode !== nextBlendMode; + var sprite = this.sprites[i]; - if(currentBaseTexture !== nextTexture || blendSwap) + nextTexture = sprite.texture.baseTexture; + nextBlendMode = sprite.blendMode + nextShader = sprite.shader || this.defaultShader; + + blendSwap = currentBlendMode !== nextBlendMode; + shaderSwap = currentShader !== nextShader; // should I use _UIDS??? + + if(currentBaseTexture._UID !== nextTexture._UID || blendSwap || shaderSwap) { this.renderBatch(currentBaseTexture, batchSize, start); start = i; batchSize = 0; currentBaseTexture = nextTexture; - currentBlendMode = nextBlendMode; - - if( blendSwap )this.renderSession.blendModeManager.setBlendMode( currentBlendMode ); + + if( blendSwap ) + { + currentBlendMode = nextBlendMode; + this.renderSession.blendModeManager.setBlendMode( currentBlendMode ); + } + + if( shaderSwap ) + { + currentShader = nextShader; + + var shader = currentShader.shaders[gl.id]; + + if(!shader) + { + shader = new PIXI.PixiShader(gl); + + shader.fragmentSrc =currentShader.fragmentSrc; + shader.uniforms =currentShader.uniforms; + shader.init(); + + currentShader.shaders[gl.id] = shader; + } + + // set shader function??? + var change = this.renderSession.shaderManager.setShader(shader); + + if(shader.dirty)shader.syncUniforms(); + + // set the projection + var projection = this.renderSession.projection; + gl.uniform2f(shader.projectionVector, projection.x, projection.y); + + // set the pointers + } } batchSize++; @@ -8404,6 +8513,7 @@ this.renderSession.drawCount++; }; + /** * * @method stop @@ -9338,6 +9448,60 @@ }; /** + * @author Mat Groves + * + * + */ + +/** + * Creates a Canvas element of the given size + * + * @method CanvasBuffer + * @param width {Number} the width for the newly created canvas + * @param height {Number} the height for the newly created canvas + * @static + * @private + */ +PIXI.CanvasBuffer = function(width, height) +{ + this.width = width; + this.height = height; + + this.canvas = document.createElement( "canvas" ); + this.context = this.canvas.getContext( "2d" ); + + this.canvas.width = width; + this.canvas.height = height; +}; + +/** + * Clears the canvas that was created by the CanvasBuffer class + * + * @method clear + * @private + */ +PIXI.CanvasBuffer.prototype.clear = function() +{ + this.context.clearRect(0,0, this.width, this.height); +}; + +/** + * Resizes the canvas that was created by the CanvasBuffer class to the specified width and height + * + * @method resize + * @param width {Number} the new width of the canvas + * @param height {Number} the new height of the canvas + * @private + */ + +PIXI.CanvasBuffer.prototype.resize = function(width, height) +{ + this.width = this.canvas.width = width; + this.height = this.canvas.height = height; +}; + + +/** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -9697,53 +9861,7 @@ */ this.transparent = options.transparent; - if(!PIXI.blendModesCanvas) - { - PIXI.blendModesCanvas = []; - - if(PIXI.canUseNewCanvasBlendModes()) - { - PIXI.blendModesCanvas[PIXI.blendModes.NORMAL] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.ADD] = "lighter"; //IS THIS OK??? - PIXI.blendModesCanvas[PIXI.blendModes.MULTIPLY] = "multiply"; - PIXI.blendModesCanvas[PIXI.blendModes.SCREEN] = "screen"; - PIXI.blendModesCanvas[PIXI.blendModes.OVERLAY] = "overlay"; - PIXI.blendModesCanvas[PIXI.blendModes.DARKEN] = "darken"; - PIXI.blendModesCanvas[PIXI.blendModes.LIGHTEN] = "lighten"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR_DODGE] = "color-dodge"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR_BURN] = "color-burn"; - PIXI.blendModesCanvas[PIXI.blendModes.HARD_LIGHT] = "hard-light"; - PIXI.blendModesCanvas[PIXI.blendModes.SOFT_LIGHT] = "soft-light"; - PIXI.blendModesCanvas[PIXI.blendModes.DIFFERENCE] = "difference"; - PIXI.blendModesCanvas[PIXI.blendModes.EXCLUSION] = "exclusion"; - PIXI.blendModesCanvas[PIXI.blendModes.HUE] = "hue"; - PIXI.blendModesCanvas[PIXI.blendModes.SATURATION] = "saturation"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR] = "color"; - PIXI.blendModesCanvas[PIXI.blendModes.LUMINOSITY] = "luminosity"; - } - else - { - // this means that the browser does not support the cool new blend modes in canvas "cough" ie "cough" - PIXI.blendModesCanvas[PIXI.blendModes.NORMAL] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.ADD] = "lighter"; //IS THIS OK??? - PIXI.blendModesCanvas[PIXI.blendModes.MULTIPLY] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.SCREEN] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.OVERLAY] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.DARKEN] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.LIGHTEN] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR_DODGE] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR_BURN] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.HARD_LIGHT] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.SOFT_LIGHT] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.DIFFERENCE] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.EXCLUSION] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.HUE] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.SATURATION] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.LUMINOSITY] = "source-over"; - } - } - + /** * The width of the canvas view * @@ -9805,7 +9923,6 @@ maskManager: this.maskManager, scaleMode: null, smoothProperty: null, - /** * If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. * Handy for crisp pixel art and speed on legacy devices. @@ -9872,7 +9989,6 @@ stage.interactionManager.setTarget(this); } } - }; /** @@ -9892,7 +10008,6 @@ this.view.style.width = this.width / this.resolution + "px"; this.view.style.height = this.height / this.resolution + "px"; - }; /** @@ -9905,154 +10020,64 @@ */ PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject, context) { - // no longer recursive! - //var transform; - //var context = this.context; - this.renderSession.context = context || this.context; this.renderSession.resolution = this.resolution; displayObject._renderCanvas(this.renderSession); }; -/** - * Renders a flat strip - * - * @method renderStripFlat - * @param strip {Strip} The Strip to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderStripFlat = function(strip) + + +PIXI.CanvasRenderer.prototype.mapBlendModes = function() { - var context = this.context; - var verticies = strip.verticies; - - var length = verticies.length/2; - this.count++; - - context.beginPath(); - for (var i=1; i < length-2; i++) + if(!PIXI.blendModesCanvas) { - // draw some triangles! - var index = i*2; + PIXI.blendModesCanvas = []; - var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; - var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - - context.moveTo(x0, y0); - context.lineTo(x1, y1); - context.lineTo(x2, y2); - } - - context.fillStyle = "#FF0000"; - context.fill(); - context.closePath(); -}; - -/** - * Renders a strip - * - * @method renderStrip - * @param strip {Strip} The Strip to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderStrip = function(strip) -{ - var context = this.context; - - // draw triangles!! - var verticies = strip.verticies; - var uvs = strip.uvs; - - var length = verticies.length/2; - this.count++; - - for (var i = 1; i < length-2; i++) - { - // draw some triangles! - var index = i*2; - - var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; - var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - - var u0 = uvs[index] * strip.texture.width, u1 = uvs[index+2] * strip.texture.width, u2 = uvs[index+4]* strip.texture.width; - var v0 = uvs[index+1]* strip.texture.height, v1 = uvs[index+3] * strip.texture.height, v2 = uvs[index+5]* strip.texture.height; - - context.save(); - context.beginPath(); - context.moveTo(x0, y0); - context.lineTo(x1, y1); - context.lineTo(x2, y2); - context.closePath(); - - context.clip(); - - // Compute matrix transform - var delta = u0*v1 + v0*u2 + u1*v2 - v1*u2 - v0*u1 - u0*v2; - var deltaA = x0*v1 + v0*x2 + x1*v2 - v1*x2 - v0*x1 - x0*v2; - var deltaB = u0*x1 + x0*u2 + u1*x2 - x1*u2 - x0*u1 - u0*x2; - var deltaC = u0*v1*x2 + v0*x1*u2 + x0*u1*v2 - x0*v1*u2 - v0*u1*x2 - u0*x1*v2; - var deltaD = y0*v1 + v0*y2 + y1*v2 - v1*y2 - v0*y1 - y0*v2; - var deltaE = u0*y1 + y0*u2 + u1*y2 - y1*u2 - y0*u1 - u0*y2; - var deltaF = u0*v1*y2 + v0*y1*u2 + y0*u1*v2 - y0*v1*u2 - v0*u1*y2 - u0*y1*v2; - - context.transform(deltaA / delta, deltaD / delta, - deltaB / delta, deltaE / delta, - deltaC / delta, deltaF / delta); - - context.drawImage(strip.texture.baseTexture.source, 0, 0); - context.restore(); + if(PIXI.canUseNewCanvasBlendModes()) + { + PIXI.blendModesCanvas[PIXI.blendModes.NORMAL] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.ADD] = "lighter"; //IS THIS OK??? + PIXI.blendModesCanvas[PIXI.blendModes.MULTIPLY] = "multiply"; + PIXI.blendModesCanvas[PIXI.blendModes.SCREEN] = "screen"; + PIXI.blendModesCanvas[PIXI.blendModes.OVERLAY] = "overlay"; + PIXI.blendModesCanvas[PIXI.blendModes.DARKEN] = "darken"; + PIXI.blendModesCanvas[PIXI.blendModes.LIGHTEN] = "lighten"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR_DODGE] = "color-dodge"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR_BURN] = "color-burn"; + PIXI.blendModesCanvas[PIXI.blendModes.HARD_LIGHT] = "hard-light"; + PIXI.blendModesCanvas[PIXI.blendModes.SOFT_LIGHT] = "soft-light"; + PIXI.blendModesCanvas[PIXI.blendModes.DIFFERENCE] = "difference"; + PIXI.blendModesCanvas[PIXI.blendModes.EXCLUSION] = "exclusion"; + PIXI.blendModesCanvas[PIXI.blendModes.HUE] = "hue"; + PIXI.blendModesCanvas[PIXI.blendModes.SATURATION] = "saturation"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR] = "color"; + PIXI.blendModesCanvas[PIXI.blendModes.LUMINOSITY] = "luminosity"; + } + else + { + // this means that the browser does not support the cool new blend modes in canvas "cough" ie "cough" + PIXI.blendModesCanvas[PIXI.blendModes.NORMAL] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.ADD] = "lighter"; //IS THIS OK??? + PIXI.blendModesCanvas[PIXI.blendModes.MULTIPLY] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.SCREEN] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.OVERLAY] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.DARKEN] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.LIGHTEN] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR_DODGE] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR_BURN] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.HARD_LIGHT] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.SOFT_LIGHT] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.DIFFERENCE] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.EXCLUSION] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.HUE] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.SATURATION] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.LUMINOSITY] = "source-over"; + } } }; /** - * Creates a Canvas element of the given size - * - * @method CanvasBuffer - * @param width {Number} the width for the newly created canvas - * @param height {Number} the height for the newly created canvas - * @static - * @private - */ -PIXI.CanvasBuffer = function(width, height) -{ - this.width = width; - this.height = height; - - this.canvas = document.createElement( "canvas" ); - this.context = this.canvas.getContext( "2d" ); - - this.canvas.width = width; - this.canvas.height = height; -}; - -/** - * Clears the canvas that was created by the CanvasBuffer class - * - * @method clear - * @private - */ -PIXI.CanvasBuffer.prototype.clear = function() -{ - this.context.clearRect(0,0, this.width, this.height); -}; - -/** - * Resizes the canvas that was created by the CanvasBuffer class to the specified width and height - * - * @method resize - * @param width {Number} the new width of the canvas - * @param height {Number} the new height of the canvas - * @private - */ - -PIXI.CanvasBuffer.prototype.resize = function(width, height) -{ - this.width = this.canvas.width = width; - this.height = this.canvas.height = height; -}; - - -/** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -10470,7 +10495,7 @@ * @property boundsPadding * @type Number */ - this.boundsPadding = 10; + this.boundsPadding = 0; /** * Used to detect if the graphics object has changed if this is set to true then the graphics object will be recalculated @@ -11448,14 +11473,14 @@ // set up the main bits.. this.uvs = new PIXI.Float32Array([0, 1, - 1, 1, - 1, 0, - 0,1]); + 1, 1, + 1, 0, + 0, 1]); this.verticies = new PIXI.Float32Array([0, 0, - 100,0, - 100,100, - 0, 100]); + 100, 0, + 100, 100, + 0, 100]); this.colors = new PIXI.Float32Array([1, 1, 1, 1]); @@ -11546,7 +11571,7 @@ gl.uniformMatrix3fv(shader.translationMatrix, false, this.worldTransform.toArray(true)); gl.uniform2f(shader.projectionVector, projection.x, -projection.y); gl.uniform2f(shader.offsetVector, -offset.x, -offset.y); - gl.uniform1f(shader.alpha, 1); + gl.uniform1f(shader.alpha, this.worldAlpha); if(!this.dirty) { @@ -11564,7 +11589,7 @@ // check if a texture is dirty.. if(this.texture.baseTexture._dirty[gl.id]) { - this.renderSession.renderer.updateTexture(this.texture.baseTexture); + renderSession.renderer.updateTexture(this.texture.baseTexture); } else { @@ -11615,6 +11640,8 @@ }; + + PIXI.Strip.prototype._renderCanvas = function(renderSession) { var context = renderSession.context; @@ -11646,10 +11673,8 @@ var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - if(this.padding === 0) + if(this.padding > 0) { - - //expand(); var centerX = (x0 + x1 + x2)/3; var centerY = (y0 + y1 + y2)/3; @@ -11675,7 +11700,6 @@ dist = Math.sqrt( normX * normX + normY * normY ); x2 = centerX + (normX / dist) * (dist + 3); y2 = centerY + (normY / dist) * (dist + 3); - } var u0 = uvs[index] * strip.texture.width, u1 = uvs[index+2] * strip.texture.width, u2 = uvs[index+4]* strip.texture.width; @@ -11711,13 +11735,40 @@ } }; -/* - * Sets the texture that the Strip will use + +/** + * Renders a flat strip * - * @method setTexture - * @param texture {Texture} the texture that will be used + * @method renderStripFlat + * @param strip {Strip} The Strip to render * @private */ +PIXI.Strip.prototype.renderStripFlat = function(strip) +{ + var context = this.context; + var verticies = strip.verticies; + + var length = verticies.length/2; + this.count++; + + context.beginPath(); + for (var i=1; i < length-2; i++) + { + // draw some triangles! + var index = i*2; + + var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; + var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; + + context.moveTo(x0, y0); + context.lineTo(x1, y1); + context.lineTo(x2, y2); + } + + context.fillStyle = "#FF0000"; + context.fill(); + context.closePath(); +}; /* PIXI.Strip.prototype.setTexture = function(texture) @@ -11745,17 +11796,19 @@ { this.updateFrame = true; }; -/* @author Mat Groves http://matgroves.com/ @Doormat23 +/** + * @author Mat Groves http://matgroves.com/ @Doormat23 + * @copyright Mat Groves, Rovanion Luckey */ /** - * + * * @class Rope * @constructor * @extends Strip - * @param texture {Texture} The texture to use - * @param points {Array} - * + * @param {Texture} texture - The texture to use on the rope. + * @param {Array} points - An array of {PIXI.Point}. + * */ PIXI.Rope = function(texture, points) { @@ -11766,7 +11819,7 @@ this.uvs = new PIXI.Float32Array(points.length * 4); this.colors = new PIXI.Float32Array(points.length * 2); this.indices = new PIXI.Uint16Array(points.length * 2); - + this.refresh(); }; @@ -11777,7 +11830,7 @@ PIXI.Rope.prototype.constructor = PIXI.Rope; /* - * Refreshes + * Refreshes * * @method refresh */ @@ -11906,7 +11959,7 @@ PIXI.DisplayObjectContainer.prototype.updateTransform.call( this ); }; /* - * Sets the texture that the Rope will use + * Sets the texture that the Rope will use * * @method setTexture * @param texture {Texture} the texture that will be used @@ -13927,7 +13980,7 @@ this.source = source; //TODO will be used for futer pixi 1.5... - this.id = PIXI.BaseTextureCacheIdGenerator++; + this._UID = PIXI._UID++; /** * Controls if RGB channels should be premultiplied by Alpha (WebGL only) @@ -14535,7 +14588,6 @@ this.baseTexture.width = this.width * this.resolution; this.baseTexture.height = this.height * this.resolution; this.baseTexture._glTextures = []; - this.baseTexture.resolution = this.resolution; this.baseTexture.scaleMode = scaleMode || PIXI.scaleModes.DEFAULT; @@ -14553,6 +14605,7 @@ if(this.renderer.type === PIXI.WEBGL_RENDERER) { var gl = this.renderer.gl; + this.baseTexture._dirty[gl.id] = false this.textureBuffer = new PIXI.FilterTexture(gl, this.width * this.resolution, this.height * this.resolution, this.baseTexture.scaleMode); this.baseTexture._glTextures[gl.id] = this.textureBuffer.texture; @@ -14689,7 +14742,7 @@ var wt = displayObject.worldTransform; wt.identity(); - wt.append(matrix); + if(matrix)wt.append(matrix); // Time to update all the children of the displayObject with the new matrix.. var children = displayObject.children; @@ -15810,6 +15863,18 @@ this.fragmentSrc = fragmentSrc || []; }; +PIXI.AbstractFilter.prototype.syncUniforms = function() +{ + for(var i=0,j=this.shaders.length; i= this.size) { - //return; this.flush(); this.currentBaseTexture = texture.baseTexture; } @@ -8078,11 +8145,11 @@ if(!uvs)return; // get the sprites current alpha - var alpha = sprite.worldAlpha; + var alpha = sprite.worldAlpha * 255; var tint = sprite.tint; var verticies = this.vertices; - + var byteBuffer = this.byteBuffer; // TODO trim?? var aX = sprite.anchor.x; @@ -8130,9 +8197,10 @@ // uv verticies[index++] = uvs.x0; verticies[index++] = uvs.y0; - // color - verticies[index++] = alpha; - verticies[index++] = tint; + + + this.byteBuffer32[index++] = tint; + byteBuffer[(index-1) * 4 + 3] = alpha; // xy verticies[index++] = a * w0 + c * h1 + tx; @@ -8141,8 +8209,8 @@ verticies[index++] = uvs.x1; verticies[index++] = uvs.y1; // color - verticies[index++] = alpha; - verticies[index++] = tint; + this.byteBuffer32[index++] = tint + byteBuffer[(index-1) * 4 + 3] = alpha; // xy verticies[index++] = a * w0 + c * h0 + tx; @@ -8151,8 +8219,8 @@ verticies[index++] = uvs.x2; verticies[index++] = uvs.y2; // color - verticies[index++] = alpha; - verticies[index++] = tint; + this.byteBuffer32[index++] = tint + byteBuffer[(index-1) * 4 + 3] = alpha; // xy verticies[index++] = a * w1 + c * h0 + tx; @@ -8161,14 +8229,11 @@ verticies[index++] = uvs.x3; verticies[index++] = uvs.y3; // color - verticies[index++] = alpha; - verticies[index++] = tint; - - // increment the batchsize - this.textures[this.currentBatchSize] = sprite.texture.baseTexture; - this.blendModes[this.currentBatchSize] = sprite.blendMode; + this.byteBuffer32[index++] = tint + byteBuffer[(index-1) * 4 + 3] = alpha; - this.currentBatchSize++; + // increment the batchsize + this.sprites[this.currentBatchSize++] = sprite; }; @@ -8182,7 +8247,8 @@ { var texture = tilingSprite.tilingTexture; - + if(this.customShader) + // check texture.. if(this.currentBatchSize >= this.size) { @@ -8309,8 +8375,12 @@ if (this.currentBatchSize===0)return; var gl = this.gl; - - this.renderSession.shaderManager.setShader(this.renderSession.shaderManager.defaultShader); + + for (var i = this.byteBuffer.length - 1; i >= 0; i--) { + // this.byteBuffer[i] = 0; + }; +// console.log(this.byteBuffer); + // console.log(this.vertices); if(this.dirty) { @@ -8322,15 +8392,13 @@ gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); - // set the projection - var projection = this.renderSession.projection; - gl.uniform2f(this.shader.projectionVector, projection.x, projection.y); + var shader = this.defaultShader.shaders[gl.id]; - // set the pointers + // 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.colorAttribute, 2, gl.FLOAT, false, stride, 4 * 4); + gl.vertexAttribPointer(shader.aVertexPosition, 2, gl.FLOAT, false, stride, 0); + gl.vertexAttribPointer(shader.aTextureCoord, 2, gl.FLOAT, false, stride, 2 * 4); + gl.vertexAttribPointer(shader.colorAttribute, 4, gl.UNSIGNED_BYTE, true, stride, 4 * 4); } // upload the verts to the buffer @@ -8348,26 +8416,67 @@ var batchSize = 0; var start = 0; - var currentBaseTexture = null; + var currentBaseTexture = this.emptyTexture; var currentBlendMode = this.renderSession.blendModeManager.currentBlendMode; + var currentShader = this.emptyTexture; + var blendSwap = false; + var shaderSwap = false; + var sprite; for (var i = 0, j = this.currentBatchSize; i < j; i++) { - nextTexture = this.textures[i]; - nextBlendMode = this.blendModes[i]; - blendSwap = currentBlendMode !== nextBlendMode; + var sprite = this.sprites[i]; - if(currentBaseTexture !== nextTexture || blendSwap) + nextTexture = sprite.texture.baseTexture; + nextBlendMode = sprite.blendMode + nextShader = sprite.shader || this.defaultShader; + + blendSwap = currentBlendMode !== nextBlendMode; + shaderSwap = currentShader !== nextShader; // should I use _UIDS??? + + if(currentBaseTexture._UID !== nextTexture._UID || blendSwap || shaderSwap) { this.renderBatch(currentBaseTexture, batchSize, start); start = i; batchSize = 0; currentBaseTexture = nextTexture; - currentBlendMode = nextBlendMode; - - if( blendSwap )this.renderSession.blendModeManager.setBlendMode( currentBlendMode ); + + if( blendSwap ) + { + currentBlendMode = nextBlendMode; + this.renderSession.blendModeManager.setBlendMode( currentBlendMode ); + } + + if( shaderSwap ) + { + currentShader = nextShader; + + var shader = currentShader.shaders[gl.id]; + + if(!shader) + { + shader = new PIXI.PixiShader(gl); + + shader.fragmentSrc =currentShader.fragmentSrc; + shader.uniforms =currentShader.uniforms; + shader.init(); + + currentShader.shaders[gl.id] = shader; + } + + // set shader function??? + var change = this.renderSession.shaderManager.setShader(shader); + + if(shader.dirty)shader.syncUniforms(); + + // set the projection + var projection = this.renderSession.projection; + gl.uniform2f(shader.projectionVector, projection.x, projection.y); + + // set the pointers + } } batchSize++; @@ -8404,6 +8513,7 @@ this.renderSession.drawCount++; }; + /** * * @method stop @@ -9338,6 +9448,60 @@ }; /** + * @author Mat Groves + * + * + */ + +/** + * Creates a Canvas element of the given size + * + * @method CanvasBuffer + * @param width {Number} the width for the newly created canvas + * @param height {Number} the height for the newly created canvas + * @static + * @private + */ +PIXI.CanvasBuffer = function(width, height) +{ + this.width = width; + this.height = height; + + this.canvas = document.createElement( "canvas" ); + this.context = this.canvas.getContext( "2d" ); + + this.canvas.width = width; + this.canvas.height = height; +}; + +/** + * Clears the canvas that was created by the CanvasBuffer class + * + * @method clear + * @private + */ +PIXI.CanvasBuffer.prototype.clear = function() +{ + this.context.clearRect(0,0, this.width, this.height); +}; + +/** + * Resizes the canvas that was created by the CanvasBuffer class to the specified width and height + * + * @method resize + * @param width {Number} the new width of the canvas + * @param height {Number} the new height of the canvas + * @private + */ + +PIXI.CanvasBuffer.prototype.resize = function(width, height) +{ + this.width = this.canvas.width = width; + this.height = this.canvas.height = height; +}; + + +/** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -9697,53 +9861,7 @@ */ this.transparent = options.transparent; - if(!PIXI.blendModesCanvas) - { - PIXI.blendModesCanvas = []; - - if(PIXI.canUseNewCanvasBlendModes()) - { - PIXI.blendModesCanvas[PIXI.blendModes.NORMAL] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.ADD] = "lighter"; //IS THIS OK??? - PIXI.blendModesCanvas[PIXI.blendModes.MULTIPLY] = "multiply"; - PIXI.blendModesCanvas[PIXI.blendModes.SCREEN] = "screen"; - PIXI.blendModesCanvas[PIXI.blendModes.OVERLAY] = "overlay"; - PIXI.blendModesCanvas[PIXI.blendModes.DARKEN] = "darken"; - PIXI.blendModesCanvas[PIXI.blendModes.LIGHTEN] = "lighten"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR_DODGE] = "color-dodge"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR_BURN] = "color-burn"; - PIXI.blendModesCanvas[PIXI.blendModes.HARD_LIGHT] = "hard-light"; - PIXI.blendModesCanvas[PIXI.blendModes.SOFT_LIGHT] = "soft-light"; - PIXI.blendModesCanvas[PIXI.blendModes.DIFFERENCE] = "difference"; - PIXI.blendModesCanvas[PIXI.blendModes.EXCLUSION] = "exclusion"; - PIXI.blendModesCanvas[PIXI.blendModes.HUE] = "hue"; - PIXI.blendModesCanvas[PIXI.blendModes.SATURATION] = "saturation"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR] = "color"; - PIXI.blendModesCanvas[PIXI.blendModes.LUMINOSITY] = "luminosity"; - } - else - { - // this means that the browser does not support the cool new blend modes in canvas "cough" ie "cough" - PIXI.blendModesCanvas[PIXI.blendModes.NORMAL] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.ADD] = "lighter"; //IS THIS OK??? - PIXI.blendModesCanvas[PIXI.blendModes.MULTIPLY] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.SCREEN] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.OVERLAY] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.DARKEN] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.LIGHTEN] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR_DODGE] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR_BURN] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.HARD_LIGHT] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.SOFT_LIGHT] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.DIFFERENCE] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.EXCLUSION] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.HUE] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.SATURATION] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.LUMINOSITY] = "source-over"; - } - } - + /** * The width of the canvas view * @@ -9805,7 +9923,6 @@ maskManager: this.maskManager, scaleMode: null, smoothProperty: null, - /** * If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. * Handy for crisp pixel art and speed on legacy devices. @@ -9872,7 +9989,6 @@ stage.interactionManager.setTarget(this); } } - }; /** @@ -9892,7 +10008,6 @@ this.view.style.width = this.width / this.resolution + "px"; this.view.style.height = this.height / this.resolution + "px"; - }; /** @@ -9905,154 +10020,64 @@ */ PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject, context) { - // no longer recursive! - //var transform; - //var context = this.context; - this.renderSession.context = context || this.context; this.renderSession.resolution = this.resolution; displayObject._renderCanvas(this.renderSession); }; -/** - * Renders a flat strip - * - * @method renderStripFlat - * @param strip {Strip} The Strip to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderStripFlat = function(strip) + + +PIXI.CanvasRenderer.prototype.mapBlendModes = function() { - var context = this.context; - var verticies = strip.verticies; - - var length = verticies.length/2; - this.count++; - - context.beginPath(); - for (var i=1; i < length-2; i++) + if(!PIXI.blendModesCanvas) { - // draw some triangles! - var index = i*2; + PIXI.blendModesCanvas = []; - var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; - var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - - context.moveTo(x0, y0); - context.lineTo(x1, y1); - context.lineTo(x2, y2); - } - - context.fillStyle = "#FF0000"; - context.fill(); - context.closePath(); -}; - -/** - * Renders a strip - * - * @method renderStrip - * @param strip {Strip} The Strip to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderStrip = function(strip) -{ - var context = this.context; - - // draw triangles!! - var verticies = strip.verticies; - var uvs = strip.uvs; - - var length = verticies.length/2; - this.count++; - - for (var i = 1; i < length-2; i++) - { - // draw some triangles! - var index = i*2; - - var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; - var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - - var u0 = uvs[index] * strip.texture.width, u1 = uvs[index+2] * strip.texture.width, u2 = uvs[index+4]* strip.texture.width; - var v0 = uvs[index+1]* strip.texture.height, v1 = uvs[index+3] * strip.texture.height, v2 = uvs[index+5]* strip.texture.height; - - context.save(); - context.beginPath(); - context.moveTo(x0, y0); - context.lineTo(x1, y1); - context.lineTo(x2, y2); - context.closePath(); - - context.clip(); - - // Compute matrix transform - var delta = u0*v1 + v0*u2 + u1*v2 - v1*u2 - v0*u1 - u0*v2; - var deltaA = x0*v1 + v0*x2 + x1*v2 - v1*x2 - v0*x1 - x0*v2; - var deltaB = u0*x1 + x0*u2 + u1*x2 - x1*u2 - x0*u1 - u0*x2; - var deltaC = u0*v1*x2 + v0*x1*u2 + x0*u1*v2 - x0*v1*u2 - v0*u1*x2 - u0*x1*v2; - var deltaD = y0*v1 + v0*y2 + y1*v2 - v1*y2 - v0*y1 - y0*v2; - var deltaE = u0*y1 + y0*u2 + u1*y2 - y1*u2 - y0*u1 - u0*y2; - var deltaF = u0*v1*y2 + v0*y1*u2 + y0*u1*v2 - y0*v1*u2 - v0*u1*y2 - u0*y1*v2; - - context.transform(deltaA / delta, deltaD / delta, - deltaB / delta, deltaE / delta, - deltaC / delta, deltaF / delta); - - context.drawImage(strip.texture.baseTexture.source, 0, 0); - context.restore(); + if(PIXI.canUseNewCanvasBlendModes()) + { + PIXI.blendModesCanvas[PIXI.blendModes.NORMAL] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.ADD] = "lighter"; //IS THIS OK??? + PIXI.blendModesCanvas[PIXI.blendModes.MULTIPLY] = "multiply"; + PIXI.blendModesCanvas[PIXI.blendModes.SCREEN] = "screen"; + PIXI.blendModesCanvas[PIXI.blendModes.OVERLAY] = "overlay"; + PIXI.blendModesCanvas[PIXI.blendModes.DARKEN] = "darken"; + PIXI.blendModesCanvas[PIXI.blendModes.LIGHTEN] = "lighten"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR_DODGE] = "color-dodge"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR_BURN] = "color-burn"; + PIXI.blendModesCanvas[PIXI.blendModes.HARD_LIGHT] = "hard-light"; + PIXI.blendModesCanvas[PIXI.blendModes.SOFT_LIGHT] = "soft-light"; + PIXI.blendModesCanvas[PIXI.blendModes.DIFFERENCE] = "difference"; + PIXI.blendModesCanvas[PIXI.blendModes.EXCLUSION] = "exclusion"; + PIXI.blendModesCanvas[PIXI.blendModes.HUE] = "hue"; + PIXI.blendModesCanvas[PIXI.blendModes.SATURATION] = "saturation"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR] = "color"; + PIXI.blendModesCanvas[PIXI.blendModes.LUMINOSITY] = "luminosity"; + } + else + { + // this means that the browser does not support the cool new blend modes in canvas "cough" ie "cough" + PIXI.blendModesCanvas[PIXI.blendModes.NORMAL] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.ADD] = "lighter"; //IS THIS OK??? + PIXI.blendModesCanvas[PIXI.blendModes.MULTIPLY] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.SCREEN] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.OVERLAY] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.DARKEN] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.LIGHTEN] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR_DODGE] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR_BURN] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.HARD_LIGHT] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.SOFT_LIGHT] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.DIFFERENCE] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.EXCLUSION] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.HUE] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.SATURATION] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.LUMINOSITY] = "source-over"; + } } }; /** - * Creates a Canvas element of the given size - * - * @method CanvasBuffer - * @param width {Number} the width for the newly created canvas - * @param height {Number} the height for the newly created canvas - * @static - * @private - */ -PIXI.CanvasBuffer = function(width, height) -{ - this.width = width; - this.height = height; - - this.canvas = document.createElement( "canvas" ); - this.context = this.canvas.getContext( "2d" ); - - this.canvas.width = width; - this.canvas.height = height; -}; - -/** - * Clears the canvas that was created by the CanvasBuffer class - * - * @method clear - * @private - */ -PIXI.CanvasBuffer.prototype.clear = function() -{ - this.context.clearRect(0,0, this.width, this.height); -}; - -/** - * Resizes the canvas that was created by the CanvasBuffer class to the specified width and height - * - * @method resize - * @param width {Number} the new width of the canvas - * @param height {Number} the new height of the canvas - * @private - */ - -PIXI.CanvasBuffer.prototype.resize = function(width, height) -{ - this.width = this.canvas.width = width; - this.height = this.canvas.height = height; -}; - - -/** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -10470,7 +10495,7 @@ * @property boundsPadding * @type Number */ - this.boundsPadding = 10; + this.boundsPadding = 0; /** * Used to detect if the graphics object has changed if this is set to true then the graphics object will be recalculated @@ -11448,14 +11473,14 @@ // set up the main bits.. this.uvs = new PIXI.Float32Array([0, 1, - 1, 1, - 1, 0, - 0,1]); + 1, 1, + 1, 0, + 0, 1]); this.verticies = new PIXI.Float32Array([0, 0, - 100,0, - 100,100, - 0, 100]); + 100, 0, + 100, 100, + 0, 100]); this.colors = new PIXI.Float32Array([1, 1, 1, 1]); @@ -11546,7 +11571,7 @@ gl.uniformMatrix3fv(shader.translationMatrix, false, this.worldTransform.toArray(true)); gl.uniform2f(shader.projectionVector, projection.x, -projection.y); gl.uniform2f(shader.offsetVector, -offset.x, -offset.y); - gl.uniform1f(shader.alpha, 1); + gl.uniform1f(shader.alpha, this.worldAlpha); if(!this.dirty) { @@ -11564,7 +11589,7 @@ // check if a texture is dirty.. if(this.texture.baseTexture._dirty[gl.id]) { - this.renderSession.renderer.updateTexture(this.texture.baseTexture); + renderSession.renderer.updateTexture(this.texture.baseTexture); } else { @@ -11615,6 +11640,8 @@ }; + + PIXI.Strip.prototype._renderCanvas = function(renderSession) { var context = renderSession.context; @@ -11646,10 +11673,8 @@ var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - if(this.padding === 0) + if(this.padding > 0) { - - //expand(); var centerX = (x0 + x1 + x2)/3; var centerY = (y0 + y1 + y2)/3; @@ -11675,7 +11700,6 @@ dist = Math.sqrt( normX * normX + normY * normY ); x2 = centerX + (normX / dist) * (dist + 3); y2 = centerY + (normY / dist) * (dist + 3); - } var u0 = uvs[index] * strip.texture.width, u1 = uvs[index+2] * strip.texture.width, u2 = uvs[index+4]* strip.texture.width; @@ -11711,13 +11735,40 @@ } }; -/* - * Sets the texture that the Strip will use + +/** + * Renders a flat strip * - * @method setTexture - * @param texture {Texture} the texture that will be used + * @method renderStripFlat + * @param strip {Strip} The Strip to render * @private */ +PIXI.Strip.prototype.renderStripFlat = function(strip) +{ + var context = this.context; + var verticies = strip.verticies; + + var length = verticies.length/2; + this.count++; + + context.beginPath(); + for (var i=1; i < length-2; i++) + { + // draw some triangles! + var index = i*2; + + var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; + var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; + + context.moveTo(x0, y0); + context.lineTo(x1, y1); + context.lineTo(x2, y2); + } + + context.fillStyle = "#FF0000"; + context.fill(); + context.closePath(); +}; /* PIXI.Strip.prototype.setTexture = function(texture) @@ -11745,17 +11796,19 @@ { this.updateFrame = true; }; -/* @author Mat Groves http://matgroves.com/ @Doormat23 +/** + * @author Mat Groves http://matgroves.com/ @Doormat23 + * @copyright Mat Groves, Rovanion Luckey */ /** - * + * * @class Rope * @constructor * @extends Strip - * @param texture {Texture} The texture to use - * @param points {Array} - * + * @param {Texture} texture - The texture to use on the rope. + * @param {Array} points - An array of {PIXI.Point}. + * */ PIXI.Rope = function(texture, points) { @@ -11766,7 +11819,7 @@ this.uvs = new PIXI.Float32Array(points.length * 4); this.colors = new PIXI.Float32Array(points.length * 2); this.indices = new PIXI.Uint16Array(points.length * 2); - + this.refresh(); }; @@ -11777,7 +11830,7 @@ PIXI.Rope.prototype.constructor = PIXI.Rope; /* - * Refreshes + * Refreshes * * @method refresh */ @@ -11906,7 +11959,7 @@ PIXI.DisplayObjectContainer.prototype.updateTransform.call( this ); }; /* - * Sets the texture that the Rope will use + * Sets the texture that the Rope will use * * @method setTexture * @param texture {Texture} the texture that will be used @@ -13927,7 +13980,7 @@ this.source = source; //TODO will be used for futer pixi 1.5... - this.id = PIXI.BaseTextureCacheIdGenerator++; + this._UID = PIXI._UID++; /** * Controls if RGB channels should be premultiplied by Alpha (WebGL only) @@ -14535,7 +14588,6 @@ this.baseTexture.width = this.width * this.resolution; this.baseTexture.height = this.height * this.resolution; this.baseTexture._glTextures = []; - this.baseTexture.resolution = this.resolution; this.baseTexture.scaleMode = scaleMode || PIXI.scaleModes.DEFAULT; @@ -14553,6 +14605,7 @@ if(this.renderer.type === PIXI.WEBGL_RENDERER) { var gl = this.renderer.gl; + this.baseTexture._dirty[gl.id] = false this.textureBuffer = new PIXI.FilterTexture(gl, this.width * this.resolution, this.height * this.resolution, this.baseTexture.scaleMode); this.baseTexture._glTextures[gl.id] = this.textureBuffer.texture; @@ -14689,7 +14742,7 @@ var wt = displayObject.worldTransform; wt.identity(); - wt.append(matrix); + if(matrix)wt.append(matrix); // Time to update all the children of the displayObject with the new matrix.. var children = displayObject.children; @@ -15810,6 +15863,18 @@ this.fragmentSrc = fragmentSrc || []; }; +PIXI.AbstractFilter.prototype.syncUniforms = function() +{ + for(var i=0,j=this.shaders.length; i= this.size) { - //return; this.flush(); this.currentBaseTexture = texture.baseTexture; } @@ -8078,11 +8145,11 @@ if(!uvs)return; // get the sprites current alpha - var alpha = sprite.worldAlpha; + var alpha = sprite.worldAlpha * 255; var tint = sprite.tint; var verticies = this.vertices; - + var byteBuffer = this.byteBuffer; // TODO trim?? var aX = sprite.anchor.x; @@ -8130,9 +8197,10 @@ // uv verticies[index++] = uvs.x0; verticies[index++] = uvs.y0; - // color - verticies[index++] = alpha; - verticies[index++] = tint; + + + this.byteBuffer32[index++] = tint; + byteBuffer[(index-1) * 4 + 3] = alpha; // xy verticies[index++] = a * w0 + c * h1 + tx; @@ -8141,8 +8209,8 @@ verticies[index++] = uvs.x1; verticies[index++] = uvs.y1; // color - verticies[index++] = alpha; - verticies[index++] = tint; + this.byteBuffer32[index++] = tint + byteBuffer[(index-1) * 4 + 3] = alpha; // xy verticies[index++] = a * w0 + c * h0 + tx; @@ -8151,8 +8219,8 @@ verticies[index++] = uvs.x2; verticies[index++] = uvs.y2; // color - verticies[index++] = alpha; - verticies[index++] = tint; + this.byteBuffer32[index++] = tint + byteBuffer[(index-1) * 4 + 3] = alpha; // xy verticies[index++] = a * w1 + c * h0 + tx; @@ -8161,14 +8229,11 @@ verticies[index++] = uvs.x3; verticies[index++] = uvs.y3; // color - verticies[index++] = alpha; - verticies[index++] = tint; - - // increment the batchsize - this.textures[this.currentBatchSize] = sprite.texture.baseTexture; - this.blendModes[this.currentBatchSize] = sprite.blendMode; + this.byteBuffer32[index++] = tint + byteBuffer[(index-1) * 4 + 3] = alpha; - this.currentBatchSize++; + // increment the batchsize + this.sprites[this.currentBatchSize++] = sprite; }; @@ -8182,7 +8247,8 @@ { var texture = tilingSprite.tilingTexture; - + if(this.customShader) + // check texture.. if(this.currentBatchSize >= this.size) { @@ -8309,8 +8375,12 @@ if (this.currentBatchSize===0)return; var gl = this.gl; - - this.renderSession.shaderManager.setShader(this.renderSession.shaderManager.defaultShader); + + for (var i = this.byteBuffer.length - 1; i >= 0; i--) { + // this.byteBuffer[i] = 0; + }; +// console.log(this.byteBuffer); + // console.log(this.vertices); if(this.dirty) { @@ -8322,15 +8392,13 @@ gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); - // set the projection - var projection = this.renderSession.projection; - gl.uniform2f(this.shader.projectionVector, projection.x, projection.y); + var shader = this.defaultShader.shaders[gl.id]; - // set the pointers + // 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.colorAttribute, 2, gl.FLOAT, false, stride, 4 * 4); + gl.vertexAttribPointer(shader.aVertexPosition, 2, gl.FLOAT, false, stride, 0); + gl.vertexAttribPointer(shader.aTextureCoord, 2, gl.FLOAT, false, stride, 2 * 4); + gl.vertexAttribPointer(shader.colorAttribute, 4, gl.UNSIGNED_BYTE, true, stride, 4 * 4); } // upload the verts to the buffer @@ -8348,26 +8416,67 @@ var batchSize = 0; var start = 0; - var currentBaseTexture = null; + var currentBaseTexture = this.emptyTexture; var currentBlendMode = this.renderSession.blendModeManager.currentBlendMode; + var currentShader = this.emptyTexture; + var blendSwap = false; + var shaderSwap = false; + var sprite; for (var i = 0, j = this.currentBatchSize; i < j; i++) { - nextTexture = this.textures[i]; - nextBlendMode = this.blendModes[i]; - blendSwap = currentBlendMode !== nextBlendMode; + var sprite = this.sprites[i]; - if(currentBaseTexture !== nextTexture || blendSwap) + nextTexture = sprite.texture.baseTexture; + nextBlendMode = sprite.blendMode + nextShader = sprite.shader || this.defaultShader; + + blendSwap = currentBlendMode !== nextBlendMode; + shaderSwap = currentShader !== nextShader; // should I use _UIDS??? + + if(currentBaseTexture._UID !== nextTexture._UID || blendSwap || shaderSwap) { this.renderBatch(currentBaseTexture, batchSize, start); start = i; batchSize = 0; currentBaseTexture = nextTexture; - currentBlendMode = nextBlendMode; - - if( blendSwap )this.renderSession.blendModeManager.setBlendMode( currentBlendMode ); + + if( blendSwap ) + { + currentBlendMode = nextBlendMode; + this.renderSession.blendModeManager.setBlendMode( currentBlendMode ); + } + + if( shaderSwap ) + { + currentShader = nextShader; + + var shader = currentShader.shaders[gl.id]; + + if(!shader) + { + shader = new PIXI.PixiShader(gl); + + shader.fragmentSrc =currentShader.fragmentSrc; + shader.uniforms =currentShader.uniforms; + shader.init(); + + currentShader.shaders[gl.id] = shader; + } + + // set shader function??? + var change = this.renderSession.shaderManager.setShader(shader); + + if(shader.dirty)shader.syncUniforms(); + + // set the projection + var projection = this.renderSession.projection; + gl.uniform2f(shader.projectionVector, projection.x, projection.y); + + // set the pointers + } } batchSize++; @@ -8404,6 +8513,7 @@ this.renderSession.drawCount++; }; + /** * * @method stop @@ -9338,6 +9448,60 @@ }; /** + * @author Mat Groves + * + * + */ + +/** + * Creates a Canvas element of the given size + * + * @method CanvasBuffer + * @param width {Number} the width for the newly created canvas + * @param height {Number} the height for the newly created canvas + * @static + * @private + */ +PIXI.CanvasBuffer = function(width, height) +{ + this.width = width; + this.height = height; + + this.canvas = document.createElement( "canvas" ); + this.context = this.canvas.getContext( "2d" ); + + this.canvas.width = width; + this.canvas.height = height; +}; + +/** + * Clears the canvas that was created by the CanvasBuffer class + * + * @method clear + * @private + */ +PIXI.CanvasBuffer.prototype.clear = function() +{ + this.context.clearRect(0,0, this.width, this.height); +}; + +/** + * Resizes the canvas that was created by the CanvasBuffer class to the specified width and height + * + * @method resize + * @param width {Number} the new width of the canvas + * @param height {Number} the new height of the canvas + * @private + */ + +PIXI.CanvasBuffer.prototype.resize = function(width, height) +{ + this.width = this.canvas.width = width; + this.height = this.canvas.height = height; +}; + + +/** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -9697,53 +9861,7 @@ */ this.transparent = options.transparent; - if(!PIXI.blendModesCanvas) - { - PIXI.blendModesCanvas = []; - - if(PIXI.canUseNewCanvasBlendModes()) - { - PIXI.blendModesCanvas[PIXI.blendModes.NORMAL] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.ADD] = "lighter"; //IS THIS OK??? - PIXI.blendModesCanvas[PIXI.blendModes.MULTIPLY] = "multiply"; - PIXI.blendModesCanvas[PIXI.blendModes.SCREEN] = "screen"; - PIXI.blendModesCanvas[PIXI.blendModes.OVERLAY] = "overlay"; - PIXI.blendModesCanvas[PIXI.blendModes.DARKEN] = "darken"; - PIXI.blendModesCanvas[PIXI.blendModes.LIGHTEN] = "lighten"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR_DODGE] = "color-dodge"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR_BURN] = "color-burn"; - PIXI.blendModesCanvas[PIXI.blendModes.HARD_LIGHT] = "hard-light"; - PIXI.blendModesCanvas[PIXI.blendModes.SOFT_LIGHT] = "soft-light"; - PIXI.blendModesCanvas[PIXI.blendModes.DIFFERENCE] = "difference"; - PIXI.blendModesCanvas[PIXI.blendModes.EXCLUSION] = "exclusion"; - PIXI.blendModesCanvas[PIXI.blendModes.HUE] = "hue"; - PIXI.blendModesCanvas[PIXI.blendModes.SATURATION] = "saturation"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR] = "color"; - PIXI.blendModesCanvas[PIXI.blendModes.LUMINOSITY] = "luminosity"; - } - else - { - // this means that the browser does not support the cool new blend modes in canvas "cough" ie "cough" - PIXI.blendModesCanvas[PIXI.blendModes.NORMAL] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.ADD] = "lighter"; //IS THIS OK??? - PIXI.blendModesCanvas[PIXI.blendModes.MULTIPLY] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.SCREEN] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.OVERLAY] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.DARKEN] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.LIGHTEN] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR_DODGE] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR_BURN] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.HARD_LIGHT] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.SOFT_LIGHT] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.DIFFERENCE] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.EXCLUSION] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.HUE] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.SATURATION] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.COLOR] = "source-over"; - PIXI.blendModesCanvas[PIXI.blendModes.LUMINOSITY] = "source-over"; - } - } - + /** * The width of the canvas view * @@ -9805,7 +9923,6 @@ maskManager: this.maskManager, scaleMode: null, smoothProperty: null, - /** * If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. * Handy for crisp pixel art and speed on legacy devices. @@ -9872,7 +9989,6 @@ stage.interactionManager.setTarget(this); } } - }; /** @@ -9892,7 +10008,6 @@ this.view.style.width = this.width / this.resolution + "px"; this.view.style.height = this.height / this.resolution + "px"; - }; /** @@ -9905,154 +10020,64 @@ */ PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject, context) { - // no longer recursive! - //var transform; - //var context = this.context; - this.renderSession.context = context || this.context; this.renderSession.resolution = this.resolution; displayObject._renderCanvas(this.renderSession); }; -/** - * Renders a flat strip - * - * @method renderStripFlat - * @param strip {Strip} The Strip to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderStripFlat = function(strip) + + +PIXI.CanvasRenderer.prototype.mapBlendModes = function() { - var context = this.context; - var verticies = strip.verticies; - - var length = verticies.length/2; - this.count++; - - context.beginPath(); - for (var i=1; i < length-2; i++) + if(!PIXI.blendModesCanvas) { - // draw some triangles! - var index = i*2; + PIXI.blendModesCanvas = []; - var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; - var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - - context.moveTo(x0, y0); - context.lineTo(x1, y1); - context.lineTo(x2, y2); - } - - context.fillStyle = "#FF0000"; - context.fill(); - context.closePath(); -}; - -/** - * Renders a strip - * - * @method renderStrip - * @param strip {Strip} The Strip to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderStrip = function(strip) -{ - var context = this.context; - - // draw triangles!! - var verticies = strip.verticies; - var uvs = strip.uvs; - - var length = verticies.length/2; - this.count++; - - for (var i = 1; i < length-2; i++) - { - // draw some triangles! - var index = i*2; - - var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; - var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - - var u0 = uvs[index] * strip.texture.width, u1 = uvs[index+2] * strip.texture.width, u2 = uvs[index+4]* strip.texture.width; - var v0 = uvs[index+1]* strip.texture.height, v1 = uvs[index+3] * strip.texture.height, v2 = uvs[index+5]* strip.texture.height; - - context.save(); - context.beginPath(); - context.moveTo(x0, y0); - context.lineTo(x1, y1); - context.lineTo(x2, y2); - context.closePath(); - - context.clip(); - - // Compute matrix transform - var delta = u0*v1 + v0*u2 + u1*v2 - v1*u2 - v0*u1 - u0*v2; - var deltaA = x0*v1 + v0*x2 + x1*v2 - v1*x2 - v0*x1 - x0*v2; - var deltaB = u0*x1 + x0*u2 + u1*x2 - x1*u2 - x0*u1 - u0*x2; - var deltaC = u0*v1*x2 + v0*x1*u2 + x0*u1*v2 - x0*v1*u2 - v0*u1*x2 - u0*x1*v2; - var deltaD = y0*v1 + v0*y2 + y1*v2 - v1*y2 - v0*y1 - y0*v2; - var deltaE = u0*y1 + y0*u2 + u1*y2 - y1*u2 - y0*u1 - u0*y2; - var deltaF = u0*v1*y2 + v0*y1*u2 + y0*u1*v2 - y0*v1*u2 - v0*u1*y2 - u0*y1*v2; - - context.transform(deltaA / delta, deltaD / delta, - deltaB / delta, deltaE / delta, - deltaC / delta, deltaF / delta); - - context.drawImage(strip.texture.baseTexture.source, 0, 0); - context.restore(); + if(PIXI.canUseNewCanvasBlendModes()) + { + PIXI.blendModesCanvas[PIXI.blendModes.NORMAL] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.ADD] = "lighter"; //IS THIS OK??? + PIXI.blendModesCanvas[PIXI.blendModes.MULTIPLY] = "multiply"; + PIXI.blendModesCanvas[PIXI.blendModes.SCREEN] = "screen"; + PIXI.blendModesCanvas[PIXI.blendModes.OVERLAY] = "overlay"; + PIXI.blendModesCanvas[PIXI.blendModes.DARKEN] = "darken"; + PIXI.blendModesCanvas[PIXI.blendModes.LIGHTEN] = "lighten"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR_DODGE] = "color-dodge"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR_BURN] = "color-burn"; + PIXI.blendModesCanvas[PIXI.blendModes.HARD_LIGHT] = "hard-light"; + PIXI.blendModesCanvas[PIXI.blendModes.SOFT_LIGHT] = "soft-light"; + PIXI.blendModesCanvas[PIXI.blendModes.DIFFERENCE] = "difference"; + PIXI.blendModesCanvas[PIXI.blendModes.EXCLUSION] = "exclusion"; + PIXI.blendModesCanvas[PIXI.blendModes.HUE] = "hue"; + PIXI.blendModesCanvas[PIXI.blendModes.SATURATION] = "saturation"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR] = "color"; + PIXI.blendModesCanvas[PIXI.blendModes.LUMINOSITY] = "luminosity"; + } + else + { + // this means that the browser does not support the cool new blend modes in canvas "cough" ie "cough" + PIXI.blendModesCanvas[PIXI.blendModes.NORMAL] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.ADD] = "lighter"; //IS THIS OK??? + PIXI.blendModesCanvas[PIXI.blendModes.MULTIPLY] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.SCREEN] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.OVERLAY] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.DARKEN] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.LIGHTEN] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR_DODGE] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR_BURN] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.HARD_LIGHT] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.SOFT_LIGHT] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.DIFFERENCE] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.EXCLUSION] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.HUE] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.SATURATION] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.COLOR] = "source-over"; + PIXI.blendModesCanvas[PIXI.blendModes.LUMINOSITY] = "source-over"; + } } }; /** - * Creates a Canvas element of the given size - * - * @method CanvasBuffer - * @param width {Number} the width for the newly created canvas - * @param height {Number} the height for the newly created canvas - * @static - * @private - */ -PIXI.CanvasBuffer = function(width, height) -{ - this.width = width; - this.height = height; - - this.canvas = document.createElement( "canvas" ); - this.context = this.canvas.getContext( "2d" ); - - this.canvas.width = width; - this.canvas.height = height; -}; - -/** - * Clears the canvas that was created by the CanvasBuffer class - * - * @method clear - * @private - */ -PIXI.CanvasBuffer.prototype.clear = function() -{ - this.context.clearRect(0,0, this.width, this.height); -}; - -/** - * Resizes the canvas that was created by the CanvasBuffer class to the specified width and height - * - * @method resize - * @param width {Number} the new width of the canvas - * @param height {Number} the new height of the canvas - * @private - */ - -PIXI.CanvasBuffer.prototype.resize = function(width, height) -{ - this.width = this.canvas.width = width; - this.height = this.canvas.height = height; -}; - - -/** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -10470,7 +10495,7 @@ * @property boundsPadding * @type Number */ - this.boundsPadding = 10; + this.boundsPadding = 0; /** * Used to detect if the graphics object has changed if this is set to true then the graphics object will be recalculated @@ -11448,14 +11473,14 @@ // set up the main bits.. this.uvs = new PIXI.Float32Array([0, 1, - 1, 1, - 1, 0, - 0,1]); + 1, 1, + 1, 0, + 0, 1]); this.verticies = new PIXI.Float32Array([0, 0, - 100,0, - 100,100, - 0, 100]); + 100, 0, + 100, 100, + 0, 100]); this.colors = new PIXI.Float32Array([1, 1, 1, 1]); @@ -11546,7 +11571,7 @@ gl.uniformMatrix3fv(shader.translationMatrix, false, this.worldTransform.toArray(true)); gl.uniform2f(shader.projectionVector, projection.x, -projection.y); gl.uniform2f(shader.offsetVector, -offset.x, -offset.y); - gl.uniform1f(shader.alpha, 1); + gl.uniform1f(shader.alpha, this.worldAlpha); if(!this.dirty) { @@ -11564,7 +11589,7 @@ // check if a texture is dirty.. if(this.texture.baseTexture._dirty[gl.id]) { - this.renderSession.renderer.updateTexture(this.texture.baseTexture); + renderSession.renderer.updateTexture(this.texture.baseTexture); } else { @@ -11615,6 +11640,8 @@ }; + + PIXI.Strip.prototype._renderCanvas = function(renderSession) { var context = renderSession.context; @@ -11646,10 +11673,8 @@ var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - if(this.padding === 0) + if(this.padding > 0) { - - //expand(); var centerX = (x0 + x1 + x2)/3; var centerY = (y0 + y1 + y2)/3; @@ -11675,7 +11700,6 @@ dist = Math.sqrt( normX * normX + normY * normY ); x2 = centerX + (normX / dist) * (dist + 3); y2 = centerY + (normY / dist) * (dist + 3); - } var u0 = uvs[index] * strip.texture.width, u1 = uvs[index+2] * strip.texture.width, u2 = uvs[index+4]* strip.texture.width; @@ -11711,13 +11735,40 @@ } }; -/* - * Sets the texture that the Strip will use + +/** + * Renders a flat strip * - * @method setTexture - * @param texture {Texture} the texture that will be used + * @method renderStripFlat + * @param strip {Strip} The Strip to render * @private */ +PIXI.Strip.prototype.renderStripFlat = function(strip) +{ + var context = this.context; + var verticies = strip.verticies; + + var length = verticies.length/2; + this.count++; + + context.beginPath(); + for (var i=1; i < length-2; i++) + { + // draw some triangles! + var index = i*2; + + var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; + var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; + + context.moveTo(x0, y0); + context.lineTo(x1, y1); + context.lineTo(x2, y2); + } + + context.fillStyle = "#FF0000"; + context.fill(); + context.closePath(); +}; /* PIXI.Strip.prototype.setTexture = function(texture) @@ -11745,17 +11796,19 @@ { this.updateFrame = true; }; -/* @author Mat Groves http://matgroves.com/ @Doormat23 +/** + * @author Mat Groves http://matgroves.com/ @Doormat23 + * @copyright Mat Groves, Rovanion Luckey */ /** - * + * * @class Rope * @constructor * @extends Strip - * @param texture {Texture} The texture to use - * @param points {Array} - * + * @param {Texture} texture - The texture to use on the rope. + * @param {Array} points - An array of {PIXI.Point}. + * */ PIXI.Rope = function(texture, points) { @@ -11766,7 +11819,7 @@ this.uvs = new PIXI.Float32Array(points.length * 4); this.colors = new PIXI.Float32Array(points.length * 2); this.indices = new PIXI.Uint16Array(points.length * 2); - + this.refresh(); }; @@ -11777,7 +11830,7 @@ PIXI.Rope.prototype.constructor = PIXI.Rope; /* - * Refreshes + * Refreshes * * @method refresh */ @@ -11906,7 +11959,7 @@ PIXI.DisplayObjectContainer.prototype.updateTransform.call( this ); }; /* - * Sets the texture that the Rope will use + * Sets the texture that the Rope will use * * @method setTexture * @param texture {Texture} the texture that will be used @@ -13927,7 +13980,7 @@ this.source = source; //TODO will be used for futer pixi 1.5... - this.id = PIXI.BaseTextureCacheIdGenerator++; + this._UID = PIXI._UID++; /** * Controls if RGB channels should be premultiplied by Alpha (WebGL only) @@ -14535,7 +14588,6 @@ this.baseTexture.width = this.width * this.resolution; this.baseTexture.height = this.height * this.resolution; this.baseTexture._glTextures = []; - this.baseTexture.resolution = this.resolution; this.baseTexture.scaleMode = scaleMode || PIXI.scaleModes.DEFAULT; @@ -14553,6 +14605,7 @@ if(this.renderer.type === PIXI.WEBGL_RENDERER) { var gl = this.renderer.gl; + this.baseTexture._dirty[gl.id] = false this.textureBuffer = new PIXI.FilterTexture(gl, this.width * this.resolution, this.height * this.resolution, this.baseTexture.scaleMode); this.baseTexture._glTextures[gl.id] = this.textureBuffer.texture; @@ -14689,7 +14742,7 @@ var wt = displayObject.worldTransform; wt.identity(); - wt.append(matrix); + if(matrix)wt.append(matrix); // Time to update all the children of the displayObject with the new matrix.. var children = displayObject.children; @@ -15810,6 +15863,18 @@ this.fragmentSrc = fragmentSrc || []; }; +PIXI.AbstractFilter.prototype.syncUniforms = function() +{ + for(var i=0,j=this.shaders.length; i= this.size) @@ -159,10 +186,11 @@ if(!uvs)return; // get the sprites current alpha - var alpha = sprite.worldAlpha; + var alpha = sprite.worldAlpha * 255; var tint = sprite.tint; var verticies = this.vertices; + var byteBuffer = this.byteBuffer; // TODO trim?? var aX = sprite.anchor.x; @@ -204,16 +232,16 @@ var tx = worldTransform.tx; var ty = worldTransform.ty; - // 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; + + + this.byteBuffer32[index++] = tint; + byteBuffer[(index-1) * 4 + 3] = alpha; // xy verticies[index++] = a * w0 + c * h1 + tx; @@ -222,8 +250,8 @@ verticies[index++] = uvs.x1; verticies[index++] = uvs.y1; // color - verticies[index++] = alpha; - verticies[index++] = tint; + this.byteBuffer32[index++] = tint + byteBuffer[(index-1) * 4 + 3] = alpha; // xy verticies[index++] = a * w0 + c * h0 + tx; @@ -232,8 +260,8 @@ verticies[index++] = uvs.x2; verticies[index++] = uvs.y2; // color - verticies[index++] = alpha; - verticies[index++] = tint; + this.byteBuffer32[index++] = tint + byteBuffer[(index-1) * 4 + 3] = alpha; // xy verticies[index++] = a * w1 + c * h0 + tx; @@ -242,14 +270,11 @@ verticies[index++] = uvs.x3; verticies[index++] = uvs.y3; // color - verticies[index++] = alpha; - verticies[index++] = tint; - - // increment the batchsize - this.textures[this.currentBatchSize] = sprite.texture.baseTexture; - this.blendModes[this.currentBatchSize] = sprite.blendMode; + this.byteBuffer32[index++] = tint + byteBuffer[(index-1) * 4 + 3] = alpha; - this.currentBatchSize++; + // increment the batchsize + this.sprites[this.currentBatchSize++] = sprite; }; @@ -263,7 +288,8 @@ { var texture = tilingSprite.tilingTexture; - + if(this.customShader) + // check texture.. if(this.currentBatchSize >= this.size) { @@ -384,21 +410,18 @@ * @method flush * */ -PIXI.WebGLSpriteBatch.prototype.flush = function(shader) +PIXI.WebGLSpriteBatch.prototype.flush = function() { // If the batch is length 0 then return as there is nothing to draw if (this.currentBatchSize===0)return; var gl = this.gl; - shader = shader || this.shader; - - var change = this.renderSession.shaderManager.setShader(shader); - if(shader.firstRun) - { - shader.firstRun = false; - this.dirty = true; - } - // this.dirty = change; + + for (var i = this.byteBuffer.length - 1; i >= 0; i--) { + // this.byteBuffer[i] = 0; + }; +// console.log(this.byteBuffer); + // console.log(this.vertices); if(this.dirty) { @@ -410,15 +433,13 @@ gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); - // set the projection - var projection = this.renderSession.projection; - gl.uniform2f(shader.projectionVector, projection.x, projection.y); + var shader = this.defaultShader.shaders[gl.id]; - // set the pointers + // this is the same for each shader? var stride = this.vertSize * 4; gl.vertexAttribPointer(shader.aVertexPosition, 2, gl.FLOAT, false, stride, 0); gl.vertexAttribPointer(shader.aTextureCoord, 2, gl.FLOAT, false, stride, 2 * 4); - gl.vertexAttribPointer(shader.colorAttribute, 2, gl.FLOAT, false, stride, 4 * 4); + gl.vertexAttribPointer(shader.colorAttribute, 4, gl.UNSIGNED_BYTE, true, stride, 4 * 4); } // upload the verts to the buffer @@ -438,24 +459,65 @@ var currentBaseTexture = this.emptyTexture; var currentBlendMode = this.renderSession.blendModeManager.currentBlendMode; + var currentShader = this.emptyTexture; + var blendSwap = false; + var shaderSwap = false; + var sprite; for (var i = 0, j = this.currentBatchSize; i < j; i++) { - nextTexture = this.textures[i]; - nextBlendMode = this.blendModes[i]; - blendSwap = currentBlendMode !== nextBlendMode; + var sprite = this.sprites[i]; - if(currentBaseTexture._UID !== nextTexture._UID || blendSwap) + nextTexture = sprite.texture.baseTexture; + nextBlendMode = sprite.blendMode + nextShader = sprite.shader || this.defaultShader; + + blendSwap = currentBlendMode !== nextBlendMode; + shaderSwap = currentShader !== nextShader; // should I use _UIDS??? + + if(currentBaseTexture._UID !== nextTexture._UID || blendSwap || shaderSwap) { this.renderBatch(currentBaseTexture, batchSize, start); start = i; batchSize = 0; currentBaseTexture = nextTexture; - currentBlendMode = nextBlendMode; - - if( blendSwap )this.renderSession.blendModeManager.setBlendMode( currentBlendMode ); + + if( blendSwap ) + { + currentBlendMode = nextBlendMode; + this.renderSession.blendModeManager.setBlendMode( currentBlendMode ); + } + + if( shaderSwap ) + { + currentShader = nextShader; + + var shader = currentShader.shaders[gl.id]; + + if(!shader) + { + shader = new PIXI.PixiShader(gl); + + shader.fragmentSrc =currentShader.fragmentSrc; + shader.uniforms =currentShader.uniforms; + shader.init(); + + currentShader.shaders[gl.id] = shader; + } + + // set shader function??? + var change = this.renderSession.shaderManager.setShader(shader); + + if(shader.dirty)shader.syncUniforms(); + + // set the projection + var projection = this.renderSession.projection; + gl.uniform2f(shader.projectionVector, projection.x, projection.y); + + // set the pointers + } } batchSize++;