diff --git a/src/pixi/display/Sprite.js b/src/pixi/display/Sprite.js index a39f49e..2168b28 100644 --- a/src/pixi/display/Sprite.js +++ b/src/pixi/display/Sprite.js @@ -86,6 +86,8 @@ } this.renderable = true; + + this.customShader = null; }; // constructor @@ -285,17 +287,49 @@ } 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; } @@ -164,7 +164,6 @@ var verticies = this.vertices; - // TODO trim?? var aX = sprite.anchor.x; var aY = sprite.anchor.y; @@ -205,6 +204,7 @@ var tx = worldTransform.tx; var ty = worldTransform.ty; + // xy verticies[index++] = a * w1 + c * h1 + tx; verticies[index++] = d * h1 + b * w1 + ty; @@ -384,14 +384,21 @@ * @method flush * */ -PIXI.WebGLSpriteBatch.prototype.flush = function() +PIXI.WebGLSpriteBatch.prototype.flush = function(shader) { // 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; - this.renderSession.shaderManager.setShader(this.renderSession.shaderManager.defaultShader); + var change = this.renderSession.shaderManager.setShader(shader); + if(shader.firstRun) + { + shader.firstRun = false; + this.dirty = true; + } + // this.dirty = change; if(this.dirty) { @@ -405,13 +412,13 @@ // set the projection var projection = this.renderSession.projection; - gl.uniform2f(this.shader.projectionVector, projection.x, projection.y); + gl.uniform2f(shader.projectionVector, projection.x, projection.y); // set the pointers 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, 2, gl.FLOAT, false, stride, 4 * 4); } // upload the verts to the buffer @@ -429,7 +436,7 @@ var batchSize = 0; var start = 0; - var currentBaseTexture = null; + var currentBaseTexture = this.emptyTexture; var currentBlendMode = this.renderSession.blendModeManager.currentBlendMode; var blendSwap = false; @@ -439,7 +446,7 @@ nextBlendMode = this.blendModes[i]; blendSwap = currentBlendMode !== nextBlendMode; - if(currentBaseTexture !== nextTexture || blendSwap) + if(currentBaseTexture._UID !== nextTexture._UID || blendSwap) { this.renderBatch(currentBaseTexture, batchSize, start); @@ -485,6 +492,7 @@ this.renderSession.drawCount++; }; + /** * * @method stop diff --git a/src/pixi/display/Sprite.js b/src/pixi/display/Sprite.js index a39f49e..2168b28 100644 --- a/src/pixi/display/Sprite.js +++ b/src/pixi/display/Sprite.js @@ -86,6 +86,8 @@ } this.renderable = true; + + this.customShader = null; }; // constructor @@ -285,17 +287,49 @@ } 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; } @@ -164,7 +164,6 @@ var verticies = this.vertices; - // TODO trim?? var aX = sprite.anchor.x; var aY = sprite.anchor.y; @@ -205,6 +204,7 @@ var tx = worldTransform.tx; var ty = worldTransform.ty; + // xy verticies[index++] = a * w1 + c * h1 + tx; verticies[index++] = d * h1 + b * w1 + ty; @@ -384,14 +384,21 @@ * @method flush * */ -PIXI.WebGLSpriteBatch.prototype.flush = function() +PIXI.WebGLSpriteBatch.prototype.flush = function(shader) { // 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; - this.renderSession.shaderManager.setShader(this.renderSession.shaderManager.defaultShader); + var change = this.renderSession.shaderManager.setShader(shader); + if(shader.firstRun) + { + shader.firstRun = false; + this.dirty = true; + } + // this.dirty = change; if(this.dirty) { @@ -405,13 +412,13 @@ // set the projection var projection = this.renderSession.projection; - gl.uniform2f(this.shader.projectionVector, projection.x, projection.y); + gl.uniform2f(shader.projectionVector, projection.x, projection.y); // set the pointers 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, 2, gl.FLOAT, false, stride, 4 * 4); } // upload the verts to the buffer @@ -429,7 +436,7 @@ var batchSize = 0; var start = 0; - var currentBaseTexture = null; + var currentBaseTexture = this.emptyTexture; var currentBlendMode = this.renderSession.blendModeManager.currentBlendMode; var blendSwap = false; @@ -439,7 +446,7 @@ nextBlendMode = this.blendModes[i]; blendSwap = currentBlendMode !== nextBlendMode; - if(currentBaseTexture !== nextTexture || blendSwap) + if(currentBaseTexture._UID !== nextTexture._UID || blendSwap) { this.renderBatch(currentBaseTexture, batchSize, start); @@ -485,6 +492,7 @@ this.renderSession.drawCount++; }; + /** * * @method stop diff --git a/src/pixi/textures/BaseTexture.js b/src/pixi/textures/BaseTexture.js index ed2705f..71763c6 100644 --- a/src/pixi/textures/BaseTexture.js +++ b/src/pixi/textures/BaseTexture.js @@ -69,7 +69,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)