diff --git a/bin/pixi.dev.js b/bin/pixi.dev.js index 12a3c53..3bcf0a8 100644 --- a/bin/pixi.dev.js +++ b/bin/pixi.dev.js @@ -4,7 +4,7 @@ * Copyright (c) 2012, Mat Groves * http://goodboydigital.com/ * - * Compiled: 2013-12-29 + * Compiled: 2013-12-30 * * Pixi.JS is licensed under the MIT License. * http://www.opensource.org/licenses/mit-license.php @@ -1095,6 +1095,7 @@ this.vcount = PIXI.visibleCount; }; + PIXI.DisplayObject.prototype.getBounds = function() { return PIXI.EmptyRectangle; @@ -1395,7 +1396,7 @@ if(this._mask) { renderSession.spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); renderSession.spriteBatch.start(); } @@ -1415,7 +1416,7 @@ renderSession.spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); renderSession.spriteBatch.start(); } @@ -1705,7 +1706,7 @@ if(this._mask) { spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); spriteBatch.start(); } @@ -1729,7 +1730,7 @@ spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); spriteBatch.start(); } @@ -4349,7 +4350,7 @@ * @param graphics {Graphics} * @param projection {Object} */ -PIXI.WebGLGraphics.renderGraphics = function(graphics, projection) +PIXI.WebGLGraphics.renderGraphics = function(graphics, projection, offset) { var gl = PIXI.gl; @@ -4387,7 +4388,7 @@ gl.uniformMatrix3fv(PIXI.primitiveShader.translationMatrix, false, m); gl.uniform2f(PIXI.primitiveShader.projectionVector, projection.x, -projection.y); - gl.uniform2f(PIXI.primitiveShader.offsetVector, -PIXI.offset.x, -PIXI.offset.y); + gl.uniform2f(PIXI.primitiveShader.offsetVector, -offset.x, -offset.y); gl.uniform3fv(PIXI.primitiveShader.tintColor, PIXI.hex2rgb(graphics.tint)); @@ -4924,14 +4925,16 @@ var gl = this.gl; - PIXI.blendModesWebGL = []; + if(!PIXI.blendModesWebGL) + { + PIXI.blendModesWebGL = []; - PIXI.blendModesWebGL[PIXI.blendModes.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.SCREEN] = [gl.SRC_ALPHA, gl.ONE]; + PIXI.blendModesWebGL[PIXI.blendModes.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.SCREEN] = [gl.SRC_ALPHA, gl.ONE]; + } - console.log( PIXI.blendModesWebGL[PIXI.blendModes.SCREEN]) gl.useProgram(PIXI.defaultShader.program); PIXI.WebGLRenderer.gl = gl; @@ -4942,13 +4945,14 @@ gl.enable(gl.BLEND); gl.colorMask(true, true, true, this.transparent); - PIXI.projection = new PIXI.Point(400, 300); - PIXI.offset = new PIXI.Point(0, 0); - + + this.projection = new PIXI.Point(400, 300); + this.offset = new PIXI.Point(0, 0); + this.resize(this.width, this.height); this.contextLost = false; - this.spriteBatch = new PIXI.WebGLSpriteBatch(gl)//this.gl, PIXI.WebGLRenderer.batchSize); + this.spriteBatch = new PIXI.WebGLSpriteBatch(gl); this.maskManager = new PIXI.WebGLMaskManager(gl); this.filterManager = new PIXI.WebGLFilterManager(this.transparent); @@ -4999,19 +5003,23 @@ gl.clearColor(stage.backgroundColorSplit[0],stage.backgroundColorSplit[1],stage.backgroundColorSplit[2], !this.transparent); gl.clear(gl.COLOR_BUFFER_BIT); - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; + + this.projection.x = this.width/2; + this.projection.y = -this.height/2; + // reset the render session data.. this.renderSession.drawCount = 0; this.renderSession.currentBlendMode = 9999; - this.renderSession.projection = PIXI.projection; + + this.renderSession.projection = this.projection; + this.renderSession.offset = this.offset; // start the sprite batch this.spriteBatch.begin(this.renderSession); // start the filter manager - this.filterManager.begin(PIXI.projection, null); + this.filterManager.begin(this.renderSession, null); // render the scene! stage._renderWebGL(this.renderSession); @@ -5029,6 +5037,27 @@ stage.interactionManager.setTarget(this); } } + + //can simulate context loss in Chrome like so: + // this.view.onmousedown = function(ev) { + // console.dir(this.gl.getSupportedExtensions()); + // var ext = ( + // gl.getExtension("WEBGL_scompressed_texture_s3tc") + // // gl.getExtension("WEBGL_compressed_texture_s3tc") || + // // gl.getExtension("MOZ_WEBGL_compressed_texture_s3tc") || + // // gl.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc") + // ); + // console.dir(ext); + + // var loseCtx = this.gl.getExtension("WEBGL_lose_context"); + // console.log("killing context"); + // loseCtx.loseContext(); + + // setTimeout(function() { + // console.log("restoring context..."); + // loseCtx.restoreContext(); + // }.bind(this), 1000); + // }.bind(this); }; /** @@ -5147,8 +5176,8 @@ this.gl.viewport(0, 0, this.width, this.height); - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; + this.projection.x = this.width/2; + this.projection.y = -this.height/2; }; /** @@ -5211,7 +5240,7 @@ this.maskPosition = 0; } -PIXI.WebGLMaskManager.prototype.pushMask = function(maskData, projection) +PIXI.WebGLMaskManager.prototype.pushMask = function(maskData, renderSession) { var gl = this.gl; @@ -5221,19 +5250,21 @@ gl.stencilFunc(gl.ALWAYS,1,1); } + maskData.visible = false; + this.maskStack.push(maskData); gl.colorMask(false, false, false, false); gl.stencilOp(gl.KEEP,gl.KEEP,gl.INCR); - PIXI.WebGLGraphics.renderGraphics(maskData, projection); + PIXI.WebGLGraphics.renderGraphics(maskData, renderSession.projection, renderSession.offset); gl.colorMask(true, true, true, true); gl.stencilFunc(gl.NOTEQUAL,0, this.maskStack.length); gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP); } -PIXI.WebGLMaskManager.prototype.popMask = function(projection) +PIXI.WebGLMaskManager.prototype.popMask = function(renderSession) { var gl = this.gl; @@ -5246,7 +5277,7 @@ //gl.stencilFunc(gl.ALWAYS,1,1); gl.stencilOp(gl.KEEP,gl.KEEP,gl.DECR); - PIXI.WebGLGraphics.renderGraphics(maskData, projection); + PIXI.WebGLGraphics.renderGraphics(maskData, renderSession.projection, renderSession.offset); gl.colorMask(true, true, true, true); gl.stencilFunc(gl.NOTEQUAL,0,this.maskStack.length); @@ -5626,8 +5657,12 @@ // API -PIXI.WebGLFilterManager.prototype.begin = function(projection, buffer) +PIXI.WebGLFilterManager.prototype.begin = function(renderSession, buffer) { + this.renderSession = renderSession; + + var projection = this.renderSession.projection; + this.width = projection.x * 2; this.height = -projection.y * 2; this.buffer = buffer; @@ -5637,6 +5672,10 @@ { var gl = PIXI.gl; + var projection = this.renderSession.projection; + var offset = this.renderSession.offset; + + // filter program // OPTIMISATION - the first filter is free if its a simple color change? this.filterStack.push(filterBlock); @@ -5661,6 +5700,7 @@ this.getBounds(filterBlock.target); filterBlock.target.filterArea = filterBlock.target.getBounds(); + // console.log(filterBlock.target.filterArea); // addpadding? //displayObject.filterArea.x @@ -5686,11 +5726,11 @@ // set view port gl.viewport(0, 0, filterArea.width, filterArea.height); - PIXI.projection.x = filterArea.width/2; - PIXI.projection.y = -filterArea.height/2; + projection.x = filterArea.width/2; + projection.y = -filterArea.height/2; - PIXI.offset.x = -filterArea.x; - PIXI.offset.y = -filterArea.y; + offset.x = -filterArea.x; + offset.y = -filterArea.y; //console.log(PIXI.defaultShader.projectionVector) // update projection @@ -5715,6 +5755,8 @@ var filterBlock = this.filterStack.pop(); var filterArea = filterBlock.target.filterArea; var texture = filterBlock._glFilterTexture; + var projection = this.renderSession.projection; + var offset = this.renderSession.offset; if(filterBlock.filterPasses.length > 1) { @@ -5817,11 +5859,11 @@ // TODO need toremove thease global elements.. - PIXI.projection.x = sizeX/2; - PIXI.projection.y = -sizeY/2; + projection.x = sizeX/2; + projection.y = -sizeY/2; - PIXI.offset.x = offsetX; - PIXI.offset.y = offsetY; + offset.x = offsetX; + offset.y = offsetY; filterArea = filterBlock.target.filterArea; @@ -6151,7 +6193,7 @@ PIXI.CanvasMaskManager.prototype.pushMask = function(maskData, context) { context.save(); - + maskData.visible = false; maskData.alpha = 0; @@ -7153,6 +7195,9 @@ PIXI.Graphics.prototype._renderWebGL = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + renderSession.spriteBatch.stop(); // check blend mode @@ -7163,13 +7208,16 @@ this.spriteBatch.gl.blendFunc(blendModeWebGL[0], blendModeWebGL[1]); } - PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection); + PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection, renderSession.offset); renderSession.spriteBatch.start(); } PIXI.Graphics.prototype._renderCanvas = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + var context = renderSession.context; var transform = this.worldTransform; diff --git a/bin/pixi.dev.js b/bin/pixi.dev.js index 12a3c53..3bcf0a8 100644 --- a/bin/pixi.dev.js +++ b/bin/pixi.dev.js @@ -4,7 +4,7 @@ * Copyright (c) 2012, Mat Groves * http://goodboydigital.com/ * - * Compiled: 2013-12-29 + * Compiled: 2013-12-30 * * Pixi.JS is licensed under the MIT License. * http://www.opensource.org/licenses/mit-license.php @@ -1095,6 +1095,7 @@ this.vcount = PIXI.visibleCount; }; + PIXI.DisplayObject.prototype.getBounds = function() { return PIXI.EmptyRectangle; @@ -1395,7 +1396,7 @@ if(this._mask) { renderSession.spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); renderSession.spriteBatch.start(); } @@ -1415,7 +1416,7 @@ renderSession.spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); renderSession.spriteBatch.start(); } @@ -1705,7 +1706,7 @@ if(this._mask) { spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); spriteBatch.start(); } @@ -1729,7 +1730,7 @@ spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); spriteBatch.start(); } @@ -4349,7 +4350,7 @@ * @param graphics {Graphics} * @param projection {Object} */ -PIXI.WebGLGraphics.renderGraphics = function(graphics, projection) +PIXI.WebGLGraphics.renderGraphics = function(graphics, projection, offset) { var gl = PIXI.gl; @@ -4387,7 +4388,7 @@ gl.uniformMatrix3fv(PIXI.primitiveShader.translationMatrix, false, m); gl.uniform2f(PIXI.primitiveShader.projectionVector, projection.x, -projection.y); - gl.uniform2f(PIXI.primitiveShader.offsetVector, -PIXI.offset.x, -PIXI.offset.y); + gl.uniform2f(PIXI.primitiveShader.offsetVector, -offset.x, -offset.y); gl.uniform3fv(PIXI.primitiveShader.tintColor, PIXI.hex2rgb(graphics.tint)); @@ -4924,14 +4925,16 @@ var gl = this.gl; - PIXI.blendModesWebGL = []; + if(!PIXI.blendModesWebGL) + { + PIXI.blendModesWebGL = []; - PIXI.blendModesWebGL[PIXI.blendModes.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.SCREEN] = [gl.SRC_ALPHA, gl.ONE]; + PIXI.blendModesWebGL[PIXI.blendModes.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.SCREEN] = [gl.SRC_ALPHA, gl.ONE]; + } - console.log( PIXI.blendModesWebGL[PIXI.blendModes.SCREEN]) gl.useProgram(PIXI.defaultShader.program); PIXI.WebGLRenderer.gl = gl; @@ -4942,13 +4945,14 @@ gl.enable(gl.BLEND); gl.colorMask(true, true, true, this.transparent); - PIXI.projection = new PIXI.Point(400, 300); - PIXI.offset = new PIXI.Point(0, 0); - + + this.projection = new PIXI.Point(400, 300); + this.offset = new PIXI.Point(0, 0); + this.resize(this.width, this.height); this.contextLost = false; - this.spriteBatch = new PIXI.WebGLSpriteBatch(gl)//this.gl, PIXI.WebGLRenderer.batchSize); + this.spriteBatch = new PIXI.WebGLSpriteBatch(gl); this.maskManager = new PIXI.WebGLMaskManager(gl); this.filterManager = new PIXI.WebGLFilterManager(this.transparent); @@ -4999,19 +5003,23 @@ gl.clearColor(stage.backgroundColorSplit[0],stage.backgroundColorSplit[1],stage.backgroundColorSplit[2], !this.transparent); gl.clear(gl.COLOR_BUFFER_BIT); - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; + + this.projection.x = this.width/2; + this.projection.y = -this.height/2; + // reset the render session data.. this.renderSession.drawCount = 0; this.renderSession.currentBlendMode = 9999; - this.renderSession.projection = PIXI.projection; + + this.renderSession.projection = this.projection; + this.renderSession.offset = this.offset; // start the sprite batch this.spriteBatch.begin(this.renderSession); // start the filter manager - this.filterManager.begin(PIXI.projection, null); + this.filterManager.begin(this.renderSession, null); // render the scene! stage._renderWebGL(this.renderSession); @@ -5029,6 +5037,27 @@ stage.interactionManager.setTarget(this); } } + + //can simulate context loss in Chrome like so: + // this.view.onmousedown = function(ev) { + // console.dir(this.gl.getSupportedExtensions()); + // var ext = ( + // gl.getExtension("WEBGL_scompressed_texture_s3tc") + // // gl.getExtension("WEBGL_compressed_texture_s3tc") || + // // gl.getExtension("MOZ_WEBGL_compressed_texture_s3tc") || + // // gl.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc") + // ); + // console.dir(ext); + + // var loseCtx = this.gl.getExtension("WEBGL_lose_context"); + // console.log("killing context"); + // loseCtx.loseContext(); + + // setTimeout(function() { + // console.log("restoring context..."); + // loseCtx.restoreContext(); + // }.bind(this), 1000); + // }.bind(this); }; /** @@ -5147,8 +5176,8 @@ this.gl.viewport(0, 0, this.width, this.height); - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; + this.projection.x = this.width/2; + this.projection.y = -this.height/2; }; /** @@ -5211,7 +5240,7 @@ this.maskPosition = 0; } -PIXI.WebGLMaskManager.prototype.pushMask = function(maskData, projection) +PIXI.WebGLMaskManager.prototype.pushMask = function(maskData, renderSession) { var gl = this.gl; @@ -5221,19 +5250,21 @@ gl.stencilFunc(gl.ALWAYS,1,1); } + maskData.visible = false; + this.maskStack.push(maskData); gl.colorMask(false, false, false, false); gl.stencilOp(gl.KEEP,gl.KEEP,gl.INCR); - PIXI.WebGLGraphics.renderGraphics(maskData, projection); + PIXI.WebGLGraphics.renderGraphics(maskData, renderSession.projection, renderSession.offset); gl.colorMask(true, true, true, true); gl.stencilFunc(gl.NOTEQUAL,0, this.maskStack.length); gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP); } -PIXI.WebGLMaskManager.prototype.popMask = function(projection) +PIXI.WebGLMaskManager.prototype.popMask = function(renderSession) { var gl = this.gl; @@ -5246,7 +5277,7 @@ //gl.stencilFunc(gl.ALWAYS,1,1); gl.stencilOp(gl.KEEP,gl.KEEP,gl.DECR); - PIXI.WebGLGraphics.renderGraphics(maskData, projection); + PIXI.WebGLGraphics.renderGraphics(maskData, renderSession.projection, renderSession.offset); gl.colorMask(true, true, true, true); gl.stencilFunc(gl.NOTEQUAL,0,this.maskStack.length); @@ -5626,8 +5657,12 @@ // API -PIXI.WebGLFilterManager.prototype.begin = function(projection, buffer) +PIXI.WebGLFilterManager.prototype.begin = function(renderSession, buffer) { + this.renderSession = renderSession; + + var projection = this.renderSession.projection; + this.width = projection.x * 2; this.height = -projection.y * 2; this.buffer = buffer; @@ -5637,6 +5672,10 @@ { var gl = PIXI.gl; + var projection = this.renderSession.projection; + var offset = this.renderSession.offset; + + // filter program // OPTIMISATION - the first filter is free if its a simple color change? this.filterStack.push(filterBlock); @@ -5661,6 +5700,7 @@ this.getBounds(filterBlock.target); filterBlock.target.filterArea = filterBlock.target.getBounds(); + // console.log(filterBlock.target.filterArea); // addpadding? //displayObject.filterArea.x @@ -5686,11 +5726,11 @@ // set view port gl.viewport(0, 0, filterArea.width, filterArea.height); - PIXI.projection.x = filterArea.width/2; - PIXI.projection.y = -filterArea.height/2; + projection.x = filterArea.width/2; + projection.y = -filterArea.height/2; - PIXI.offset.x = -filterArea.x; - PIXI.offset.y = -filterArea.y; + offset.x = -filterArea.x; + offset.y = -filterArea.y; //console.log(PIXI.defaultShader.projectionVector) // update projection @@ -5715,6 +5755,8 @@ var filterBlock = this.filterStack.pop(); var filterArea = filterBlock.target.filterArea; var texture = filterBlock._glFilterTexture; + var projection = this.renderSession.projection; + var offset = this.renderSession.offset; if(filterBlock.filterPasses.length > 1) { @@ -5817,11 +5859,11 @@ // TODO need toremove thease global elements.. - PIXI.projection.x = sizeX/2; - PIXI.projection.y = -sizeY/2; + projection.x = sizeX/2; + projection.y = -sizeY/2; - PIXI.offset.x = offsetX; - PIXI.offset.y = offsetY; + offset.x = offsetX; + offset.y = offsetY; filterArea = filterBlock.target.filterArea; @@ -6151,7 +6193,7 @@ PIXI.CanvasMaskManager.prototype.pushMask = function(maskData, context) { context.save(); - + maskData.visible = false; maskData.alpha = 0; @@ -7153,6 +7195,9 @@ PIXI.Graphics.prototype._renderWebGL = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + renderSession.spriteBatch.stop(); // check blend mode @@ -7163,13 +7208,16 @@ this.spriteBatch.gl.blendFunc(blendModeWebGL[0], blendModeWebGL[1]); } - PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection); + PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection, renderSession.offset); renderSession.spriteBatch.start(); } PIXI.Graphics.prototype._renderCanvas = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + var context = renderSession.context; var transform = this.worldTransform; diff --git a/src/pixi/display/DisplayObject.js b/src/pixi/display/DisplayObject.js index bd09ead..42b44fd 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -401,6 +401,7 @@ this.vcount = PIXI.visibleCount; }; + PIXI.DisplayObject.prototype.getBounds = function() { return PIXI.EmptyRectangle; diff --git a/bin/pixi.dev.js b/bin/pixi.dev.js index 12a3c53..3bcf0a8 100644 --- a/bin/pixi.dev.js +++ b/bin/pixi.dev.js @@ -4,7 +4,7 @@ * Copyright (c) 2012, Mat Groves * http://goodboydigital.com/ * - * Compiled: 2013-12-29 + * Compiled: 2013-12-30 * * Pixi.JS is licensed under the MIT License. * http://www.opensource.org/licenses/mit-license.php @@ -1095,6 +1095,7 @@ this.vcount = PIXI.visibleCount; }; + PIXI.DisplayObject.prototype.getBounds = function() { return PIXI.EmptyRectangle; @@ -1395,7 +1396,7 @@ if(this._mask) { renderSession.spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); renderSession.spriteBatch.start(); } @@ -1415,7 +1416,7 @@ renderSession.spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); renderSession.spriteBatch.start(); } @@ -1705,7 +1706,7 @@ if(this._mask) { spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); spriteBatch.start(); } @@ -1729,7 +1730,7 @@ spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); spriteBatch.start(); } @@ -4349,7 +4350,7 @@ * @param graphics {Graphics} * @param projection {Object} */ -PIXI.WebGLGraphics.renderGraphics = function(graphics, projection) +PIXI.WebGLGraphics.renderGraphics = function(graphics, projection, offset) { var gl = PIXI.gl; @@ -4387,7 +4388,7 @@ gl.uniformMatrix3fv(PIXI.primitiveShader.translationMatrix, false, m); gl.uniform2f(PIXI.primitiveShader.projectionVector, projection.x, -projection.y); - gl.uniform2f(PIXI.primitiveShader.offsetVector, -PIXI.offset.x, -PIXI.offset.y); + gl.uniform2f(PIXI.primitiveShader.offsetVector, -offset.x, -offset.y); gl.uniform3fv(PIXI.primitiveShader.tintColor, PIXI.hex2rgb(graphics.tint)); @@ -4924,14 +4925,16 @@ var gl = this.gl; - PIXI.blendModesWebGL = []; + if(!PIXI.blendModesWebGL) + { + PIXI.blendModesWebGL = []; - PIXI.blendModesWebGL[PIXI.blendModes.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.SCREEN] = [gl.SRC_ALPHA, gl.ONE]; + PIXI.blendModesWebGL[PIXI.blendModes.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.SCREEN] = [gl.SRC_ALPHA, gl.ONE]; + } - console.log( PIXI.blendModesWebGL[PIXI.blendModes.SCREEN]) gl.useProgram(PIXI.defaultShader.program); PIXI.WebGLRenderer.gl = gl; @@ -4942,13 +4945,14 @@ gl.enable(gl.BLEND); gl.colorMask(true, true, true, this.transparent); - PIXI.projection = new PIXI.Point(400, 300); - PIXI.offset = new PIXI.Point(0, 0); - + + this.projection = new PIXI.Point(400, 300); + this.offset = new PIXI.Point(0, 0); + this.resize(this.width, this.height); this.contextLost = false; - this.spriteBatch = new PIXI.WebGLSpriteBatch(gl)//this.gl, PIXI.WebGLRenderer.batchSize); + this.spriteBatch = new PIXI.WebGLSpriteBatch(gl); this.maskManager = new PIXI.WebGLMaskManager(gl); this.filterManager = new PIXI.WebGLFilterManager(this.transparent); @@ -4999,19 +5003,23 @@ gl.clearColor(stage.backgroundColorSplit[0],stage.backgroundColorSplit[1],stage.backgroundColorSplit[2], !this.transparent); gl.clear(gl.COLOR_BUFFER_BIT); - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; + + this.projection.x = this.width/2; + this.projection.y = -this.height/2; + // reset the render session data.. this.renderSession.drawCount = 0; this.renderSession.currentBlendMode = 9999; - this.renderSession.projection = PIXI.projection; + + this.renderSession.projection = this.projection; + this.renderSession.offset = this.offset; // start the sprite batch this.spriteBatch.begin(this.renderSession); // start the filter manager - this.filterManager.begin(PIXI.projection, null); + this.filterManager.begin(this.renderSession, null); // render the scene! stage._renderWebGL(this.renderSession); @@ -5029,6 +5037,27 @@ stage.interactionManager.setTarget(this); } } + + //can simulate context loss in Chrome like so: + // this.view.onmousedown = function(ev) { + // console.dir(this.gl.getSupportedExtensions()); + // var ext = ( + // gl.getExtension("WEBGL_scompressed_texture_s3tc") + // // gl.getExtension("WEBGL_compressed_texture_s3tc") || + // // gl.getExtension("MOZ_WEBGL_compressed_texture_s3tc") || + // // gl.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc") + // ); + // console.dir(ext); + + // var loseCtx = this.gl.getExtension("WEBGL_lose_context"); + // console.log("killing context"); + // loseCtx.loseContext(); + + // setTimeout(function() { + // console.log("restoring context..."); + // loseCtx.restoreContext(); + // }.bind(this), 1000); + // }.bind(this); }; /** @@ -5147,8 +5176,8 @@ this.gl.viewport(0, 0, this.width, this.height); - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; + this.projection.x = this.width/2; + this.projection.y = -this.height/2; }; /** @@ -5211,7 +5240,7 @@ this.maskPosition = 0; } -PIXI.WebGLMaskManager.prototype.pushMask = function(maskData, projection) +PIXI.WebGLMaskManager.prototype.pushMask = function(maskData, renderSession) { var gl = this.gl; @@ -5221,19 +5250,21 @@ gl.stencilFunc(gl.ALWAYS,1,1); } + maskData.visible = false; + this.maskStack.push(maskData); gl.colorMask(false, false, false, false); gl.stencilOp(gl.KEEP,gl.KEEP,gl.INCR); - PIXI.WebGLGraphics.renderGraphics(maskData, projection); + PIXI.WebGLGraphics.renderGraphics(maskData, renderSession.projection, renderSession.offset); gl.colorMask(true, true, true, true); gl.stencilFunc(gl.NOTEQUAL,0, this.maskStack.length); gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP); } -PIXI.WebGLMaskManager.prototype.popMask = function(projection) +PIXI.WebGLMaskManager.prototype.popMask = function(renderSession) { var gl = this.gl; @@ -5246,7 +5277,7 @@ //gl.stencilFunc(gl.ALWAYS,1,1); gl.stencilOp(gl.KEEP,gl.KEEP,gl.DECR); - PIXI.WebGLGraphics.renderGraphics(maskData, projection); + PIXI.WebGLGraphics.renderGraphics(maskData, renderSession.projection, renderSession.offset); gl.colorMask(true, true, true, true); gl.stencilFunc(gl.NOTEQUAL,0,this.maskStack.length); @@ -5626,8 +5657,12 @@ // API -PIXI.WebGLFilterManager.prototype.begin = function(projection, buffer) +PIXI.WebGLFilterManager.prototype.begin = function(renderSession, buffer) { + this.renderSession = renderSession; + + var projection = this.renderSession.projection; + this.width = projection.x * 2; this.height = -projection.y * 2; this.buffer = buffer; @@ -5637,6 +5672,10 @@ { var gl = PIXI.gl; + var projection = this.renderSession.projection; + var offset = this.renderSession.offset; + + // filter program // OPTIMISATION - the first filter is free if its a simple color change? this.filterStack.push(filterBlock); @@ -5661,6 +5700,7 @@ this.getBounds(filterBlock.target); filterBlock.target.filterArea = filterBlock.target.getBounds(); + // console.log(filterBlock.target.filterArea); // addpadding? //displayObject.filterArea.x @@ -5686,11 +5726,11 @@ // set view port gl.viewport(0, 0, filterArea.width, filterArea.height); - PIXI.projection.x = filterArea.width/2; - PIXI.projection.y = -filterArea.height/2; + projection.x = filterArea.width/2; + projection.y = -filterArea.height/2; - PIXI.offset.x = -filterArea.x; - PIXI.offset.y = -filterArea.y; + offset.x = -filterArea.x; + offset.y = -filterArea.y; //console.log(PIXI.defaultShader.projectionVector) // update projection @@ -5715,6 +5755,8 @@ var filterBlock = this.filterStack.pop(); var filterArea = filterBlock.target.filterArea; var texture = filterBlock._glFilterTexture; + var projection = this.renderSession.projection; + var offset = this.renderSession.offset; if(filterBlock.filterPasses.length > 1) { @@ -5817,11 +5859,11 @@ // TODO need toremove thease global elements.. - PIXI.projection.x = sizeX/2; - PIXI.projection.y = -sizeY/2; + projection.x = sizeX/2; + projection.y = -sizeY/2; - PIXI.offset.x = offsetX; - PIXI.offset.y = offsetY; + offset.x = offsetX; + offset.y = offsetY; filterArea = filterBlock.target.filterArea; @@ -6151,7 +6193,7 @@ PIXI.CanvasMaskManager.prototype.pushMask = function(maskData, context) { context.save(); - + maskData.visible = false; maskData.alpha = 0; @@ -7153,6 +7195,9 @@ PIXI.Graphics.prototype._renderWebGL = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + renderSession.spriteBatch.stop(); // check blend mode @@ -7163,13 +7208,16 @@ this.spriteBatch.gl.blendFunc(blendModeWebGL[0], blendModeWebGL[1]); } - PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection); + PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection, renderSession.offset); renderSession.spriteBatch.start(); } PIXI.Graphics.prototype._renderCanvas = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + var context = renderSession.context; var transform = this.worldTransform; diff --git a/src/pixi/display/DisplayObject.js b/src/pixi/display/DisplayObject.js index bd09ead..42b44fd 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -401,6 +401,7 @@ this.vcount = PIXI.visibleCount; }; + PIXI.DisplayObject.prototype.getBounds = function() { return PIXI.EmptyRectangle; diff --git a/src/pixi/display/DisplayObjectContainer.js b/src/pixi/display/DisplayObjectContainer.js index 0a8441b..4846abd 100644 --- a/src/pixi/display/DisplayObjectContainer.js +++ b/src/pixi/display/DisplayObjectContainer.js @@ -279,7 +279,7 @@ if(this._mask) { renderSession.spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); renderSession.spriteBatch.start(); } @@ -299,7 +299,7 @@ renderSession.spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); renderSession.spriteBatch.start(); } diff --git a/bin/pixi.dev.js b/bin/pixi.dev.js index 12a3c53..3bcf0a8 100644 --- a/bin/pixi.dev.js +++ b/bin/pixi.dev.js @@ -4,7 +4,7 @@ * Copyright (c) 2012, Mat Groves * http://goodboydigital.com/ * - * Compiled: 2013-12-29 + * Compiled: 2013-12-30 * * Pixi.JS is licensed under the MIT License. * http://www.opensource.org/licenses/mit-license.php @@ -1095,6 +1095,7 @@ this.vcount = PIXI.visibleCount; }; + PIXI.DisplayObject.prototype.getBounds = function() { return PIXI.EmptyRectangle; @@ -1395,7 +1396,7 @@ if(this._mask) { renderSession.spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); renderSession.spriteBatch.start(); } @@ -1415,7 +1416,7 @@ renderSession.spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); renderSession.spriteBatch.start(); } @@ -1705,7 +1706,7 @@ if(this._mask) { spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); spriteBatch.start(); } @@ -1729,7 +1730,7 @@ spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); spriteBatch.start(); } @@ -4349,7 +4350,7 @@ * @param graphics {Graphics} * @param projection {Object} */ -PIXI.WebGLGraphics.renderGraphics = function(graphics, projection) +PIXI.WebGLGraphics.renderGraphics = function(graphics, projection, offset) { var gl = PIXI.gl; @@ -4387,7 +4388,7 @@ gl.uniformMatrix3fv(PIXI.primitiveShader.translationMatrix, false, m); gl.uniform2f(PIXI.primitiveShader.projectionVector, projection.x, -projection.y); - gl.uniform2f(PIXI.primitiveShader.offsetVector, -PIXI.offset.x, -PIXI.offset.y); + gl.uniform2f(PIXI.primitiveShader.offsetVector, -offset.x, -offset.y); gl.uniform3fv(PIXI.primitiveShader.tintColor, PIXI.hex2rgb(graphics.tint)); @@ -4924,14 +4925,16 @@ var gl = this.gl; - PIXI.blendModesWebGL = []; + if(!PIXI.blendModesWebGL) + { + PIXI.blendModesWebGL = []; - PIXI.blendModesWebGL[PIXI.blendModes.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.SCREEN] = [gl.SRC_ALPHA, gl.ONE]; + PIXI.blendModesWebGL[PIXI.blendModes.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.SCREEN] = [gl.SRC_ALPHA, gl.ONE]; + } - console.log( PIXI.blendModesWebGL[PIXI.blendModes.SCREEN]) gl.useProgram(PIXI.defaultShader.program); PIXI.WebGLRenderer.gl = gl; @@ -4942,13 +4945,14 @@ gl.enable(gl.BLEND); gl.colorMask(true, true, true, this.transparent); - PIXI.projection = new PIXI.Point(400, 300); - PIXI.offset = new PIXI.Point(0, 0); - + + this.projection = new PIXI.Point(400, 300); + this.offset = new PIXI.Point(0, 0); + this.resize(this.width, this.height); this.contextLost = false; - this.spriteBatch = new PIXI.WebGLSpriteBatch(gl)//this.gl, PIXI.WebGLRenderer.batchSize); + this.spriteBatch = new PIXI.WebGLSpriteBatch(gl); this.maskManager = new PIXI.WebGLMaskManager(gl); this.filterManager = new PIXI.WebGLFilterManager(this.transparent); @@ -4999,19 +5003,23 @@ gl.clearColor(stage.backgroundColorSplit[0],stage.backgroundColorSplit[1],stage.backgroundColorSplit[2], !this.transparent); gl.clear(gl.COLOR_BUFFER_BIT); - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; + + this.projection.x = this.width/2; + this.projection.y = -this.height/2; + // reset the render session data.. this.renderSession.drawCount = 0; this.renderSession.currentBlendMode = 9999; - this.renderSession.projection = PIXI.projection; + + this.renderSession.projection = this.projection; + this.renderSession.offset = this.offset; // start the sprite batch this.spriteBatch.begin(this.renderSession); // start the filter manager - this.filterManager.begin(PIXI.projection, null); + this.filterManager.begin(this.renderSession, null); // render the scene! stage._renderWebGL(this.renderSession); @@ -5029,6 +5037,27 @@ stage.interactionManager.setTarget(this); } } + + //can simulate context loss in Chrome like so: + // this.view.onmousedown = function(ev) { + // console.dir(this.gl.getSupportedExtensions()); + // var ext = ( + // gl.getExtension("WEBGL_scompressed_texture_s3tc") + // // gl.getExtension("WEBGL_compressed_texture_s3tc") || + // // gl.getExtension("MOZ_WEBGL_compressed_texture_s3tc") || + // // gl.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc") + // ); + // console.dir(ext); + + // var loseCtx = this.gl.getExtension("WEBGL_lose_context"); + // console.log("killing context"); + // loseCtx.loseContext(); + + // setTimeout(function() { + // console.log("restoring context..."); + // loseCtx.restoreContext(); + // }.bind(this), 1000); + // }.bind(this); }; /** @@ -5147,8 +5176,8 @@ this.gl.viewport(0, 0, this.width, this.height); - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; + this.projection.x = this.width/2; + this.projection.y = -this.height/2; }; /** @@ -5211,7 +5240,7 @@ this.maskPosition = 0; } -PIXI.WebGLMaskManager.prototype.pushMask = function(maskData, projection) +PIXI.WebGLMaskManager.prototype.pushMask = function(maskData, renderSession) { var gl = this.gl; @@ -5221,19 +5250,21 @@ gl.stencilFunc(gl.ALWAYS,1,1); } + maskData.visible = false; + this.maskStack.push(maskData); gl.colorMask(false, false, false, false); gl.stencilOp(gl.KEEP,gl.KEEP,gl.INCR); - PIXI.WebGLGraphics.renderGraphics(maskData, projection); + PIXI.WebGLGraphics.renderGraphics(maskData, renderSession.projection, renderSession.offset); gl.colorMask(true, true, true, true); gl.stencilFunc(gl.NOTEQUAL,0, this.maskStack.length); gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP); } -PIXI.WebGLMaskManager.prototype.popMask = function(projection) +PIXI.WebGLMaskManager.prototype.popMask = function(renderSession) { var gl = this.gl; @@ -5246,7 +5277,7 @@ //gl.stencilFunc(gl.ALWAYS,1,1); gl.stencilOp(gl.KEEP,gl.KEEP,gl.DECR); - PIXI.WebGLGraphics.renderGraphics(maskData, projection); + PIXI.WebGLGraphics.renderGraphics(maskData, renderSession.projection, renderSession.offset); gl.colorMask(true, true, true, true); gl.stencilFunc(gl.NOTEQUAL,0,this.maskStack.length); @@ -5626,8 +5657,12 @@ // API -PIXI.WebGLFilterManager.prototype.begin = function(projection, buffer) +PIXI.WebGLFilterManager.prototype.begin = function(renderSession, buffer) { + this.renderSession = renderSession; + + var projection = this.renderSession.projection; + this.width = projection.x * 2; this.height = -projection.y * 2; this.buffer = buffer; @@ -5637,6 +5672,10 @@ { var gl = PIXI.gl; + var projection = this.renderSession.projection; + var offset = this.renderSession.offset; + + // filter program // OPTIMISATION - the first filter is free if its a simple color change? this.filterStack.push(filterBlock); @@ -5661,6 +5700,7 @@ this.getBounds(filterBlock.target); filterBlock.target.filterArea = filterBlock.target.getBounds(); + // console.log(filterBlock.target.filterArea); // addpadding? //displayObject.filterArea.x @@ -5686,11 +5726,11 @@ // set view port gl.viewport(0, 0, filterArea.width, filterArea.height); - PIXI.projection.x = filterArea.width/2; - PIXI.projection.y = -filterArea.height/2; + projection.x = filterArea.width/2; + projection.y = -filterArea.height/2; - PIXI.offset.x = -filterArea.x; - PIXI.offset.y = -filterArea.y; + offset.x = -filterArea.x; + offset.y = -filterArea.y; //console.log(PIXI.defaultShader.projectionVector) // update projection @@ -5715,6 +5755,8 @@ var filterBlock = this.filterStack.pop(); var filterArea = filterBlock.target.filterArea; var texture = filterBlock._glFilterTexture; + var projection = this.renderSession.projection; + var offset = this.renderSession.offset; if(filterBlock.filterPasses.length > 1) { @@ -5817,11 +5859,11 @@ // TODO need toremove thease global elements.. - PIXI.projection.x = sizeX/2; - PIXI.projection.y = -sizeY/2; + projection.x = sizeX/2; + projection.y = -sizeY/2; - PIXI.offset.x = offsetX; - PIXI.offset.y = offsetY; + offset.x = offsetX; + offset.y = offsetY; filterArea = filterBlock.target.filterArea; @@ -6151,7 +6193,7 @@ PIXI.CanvasMaskManager.prototype.pushMask = function(maskData, context) { context.save(); - + maskData.visible = false; maskData.alpha = 0; @@ -7153,6 +7195,9 @@ PIXI.Graphics.prototype._renderWebGL = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + renderSession.spriteBatch.stop(); // check blend mode @@ -7163,13 +7208,16 @@ this.spriteBatch.gl.blendFunc(blendModeWebGL[0], blendModeWebGL[1]); } - PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection); + PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection, renderSession.offset); renderSession.spriteBatch.start(); } PIXI.Graphics.prototype._renderCanvas = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + var context = renderSession.context; var transform = this.worldTransform; diff --git a/src/pixi/display/DisplayObject.js b/src/pixi/display/DisplayObject.js index bd09ead..42b44fd 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -401,6 +401,7 @@ this.vcount = PIXI.visibleCount; }; + PIXI.DisplayObject.prototype.getBounds = function() { return PIXI.EmptyRectangle; diff --git a/src/pixi/display/DisplayObjectContainer.js b/src/pixi/display/DisplayObjectContainer.js index 0a8441b..4846abd 100644 --- a/src/pixi/display/DisplayObjectContainer.js +++ b/src/pixi/display/DisplayObjectContainer.js @@ -279,7 +279,7 @@ if(this._mask) { renderSession.spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); renderSession.spriteBatch.start(); } @@ -299,7 +299,7 @@ renderSession.spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); renderSession.spriteBatch.start(); } diff --git a/src/pixi/display/Sprite.js b/src/pixi/display/Sprite.js index 33e59ae..55e77ab 100644 --- a/src/pixi/display/Sprite.js +++ b/src/pixi/display/Sprite.js @@ -252,7 +252,7 @@ if(this._mask) { spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); spriteBatch.start(); } @@ -276,7 +276,7 @@ spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); spriteBatch.start(); } diff --git a/bin/pixi.dev.js b/bin/pixi.dev.js index 12a3c53..3bcf0a8 100644 --- a/bin/pixi.dev.js +++ b/bin/pixi.dev.js @@ -4,7 +4,7 @@ * Copyright (c) 2012, Mat Groves * http://goodboydigital.com/ * - * Compiled: 2013-12-29 + * Compiled: 2013-12-30 * * Pixi.JS is licensed under the MIT License. * http://www.opensource.org/licenses/mit-license.php @@ -1095,6 +1095,7 @@ this.vcount = PIXI.visibleCount; }; + PIXI.DisplayObject.prototype.getBounds = function() { return PIXI.EmptyRectangle; @@ -1395,7 +1396,7 @@ if(this._mask) { renderSession.spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); renderSession.spriteBatch.start(); } @@ -1415,7 +1416,7 @@ renderSession.spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); renderSession.spriteBatch.start(); } @@ -1705,7 +1706,7 @@ if(this._mask) { spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); spriteBatch.start(); } @@ -1729,7 +1730,7 @@ spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); spriteBatch.start(); } @@ -4349,7 +4350,7 @@ * @param graphics {Graphics} * @param projection {Object} */ -PIXI.WebGLGraphics.renderGraphics = function(graphics, projection) +PIXI.WebGLGraphics.renderGraphics = function(graphics, projection, offset) { var gl = PIXI.gl; @@ -4387,7 +4388,7 @@ gl.uniformMatrix3fv(PIXI.primitiveShader.translationMatrix, false, m); gl.uniform2f(PIXI.primitiveShader.projectionVector, projection.x, -projection.y); - gl.uniform2f(PIXI.primitiveShader.offsetVector, -PIXI.offset.x, -PIXI.offset.y); + gl.uniform2f(PIXI.primitiveShader.offsetVector, -offset.x, -offset.y); gl.uniform3fv(PIXI.primitiveShader.tintColor, PIXI.hex2rgb(graphics.tint)); @@ -4924,14 +4925,16 @@ var gl = this.gl; - PIXI.blendModesWebGL = []; + if(!PIXI.blendModesWebGL) + { + PIXI.blendModesWebGL = []; - PIXI.blendModesWebGL[PIXI.blendModes.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.SCREEN] = [gl.SRC_ALPHA, gl.ONE]; + PIXI.blendModesWebGL[PIXI.blendModes.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.SCREEN] = [gl.SRC_ALPHA, gl.ONE]; + } - console.log( PIXI.blendModesWebGL[PIXI.blendModes.SCREEN]) gl.useProgram(PIXI.defaultShader.program); PIXI.WebGLRenderer.gl = gl; @@ -4942,13 +4945,14 @@ gl.enable(gl.BLEND); gl.colorMask(true, true, true, this.transparent); - PIXI.projection = new PIXI.Point(400, 300); - PIXI.offset = new PIXI.Point(0, 0); - + + this.projection = new PIXI.Point(400, 300); + this.offset = new PIXI.Point(0, 0); + this.resize(this.width, this.height); this.contextLost = false; - this.spriteBatch = new PIXI.WebGLSpriteBatch(gl)//this.gl, PIXI.WebGLRenderer.batchSize); + this.spriteBatch = new PIXI.WebGLSpriteBatch(gl); this.maskManager = new PIXI.WebGLMaskManager(gl); this.filterManager = new PIXI.WebGLFilterManager(this.transparent); @@ -4999,19 +5003,23 @@ gl.clearColor(stage.backgroundColorSplit[0],stage.backgroundColorSplit[1],stage.backgroundColorSplit[2], !this.transparent); gl.clear(gl.COLOR_BUFFER_BIT); - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; + + this.projection.x = this.width/2; + this.projection.y = -this.height/2; + // reset the render session data.. this.renderSession.drawCount = 0; this.renderSession.currentBlendMode = 9999; - this.renderSession.projection = PIXI.projection; + + this.renderSession.projection = this.projection; + this.renderSession.offset = this.offset; // start the sprite batch this.spriteBatch.begin(this.renderSession); // start the filter manager - this.filterManager.begin(PIXI.projection, null); + this.filterManager.begin(this.renderSession, null); // render the scene! stage._renderWebGL(this.renderSession); @@ -5029,6 +5037,27 @@ stage.interactionManager.setTarget(this); } } + + //can simulate context loss in Chrome like so: + // this.view.onmousedown = function(ev) { + // console.dir(this.gl.getSupportedExtensions()); + // var ext = ( + // gl.getExtension("WEBGL_scompressed_texture_s3tc") + // // gl.getExtension("WEBGL_compressed_texture_s3tc") || + // // gl.getExtension("MOZ_WEBGL_compressed_texture_s3tc") || + // // gl.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc") + // ); + // console.dir(ext); + + // var loseCtx = this.gl.getExtension("WEBGL_lose_context"); + // console.log("killing context"); + // loseCtx.loseContext(); + + // setTimeout(function() { + // console.log("restoring context..."); + // loseCtx.restoreContext(); + // }.bind(this), 1000); + // }.bind(this); }; /** @@ -5147,8 +5176,8 @@ this.gl.viewport(0, 0, this.width, this.height); - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; + this.projection.x = this.width/2; + this.projection.y = -this.height/2; }; /** @@ -5211,7 +5240,7 @@ this.maskPosition = 0; } -PIXI.WebGLMaskManager.prototype.pushMask = function(maskData, projection) +PIXI.WebGLMaskManager.prototype.pushMask = function(maskData, renderSession) { var gl = this.gl; @@ -5221,19 +5250,21 @@ gl.stencilFunc(gl.ALWAYS,1,1); } + maskData.visible = false; + this.maskStack.push(maskData); gl.colorMask(false, false, false, false); gl.stencilOp(gl.KEEP,gl.KEEP,gl.INCR); - PIXI.WebGLGraphics.renderGraphics(maskData, projection); + PIXI.WebGLGraphics.renderGraphics(maskData, renderSession.projection, renderSession.offset); gl.colorMask(true, true, true, true); gl.stencilFunc(gl.NOTEQUAL,0, this.maskStack.length); gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP); } -PIXI.WebGLMaskManager.prototype.popMask = function(projection) +PIXI.WebGLMaskManager.prototype.popMask = function(renderSession) { var gl = this.gl; @@ -5246,7 +5277,7 @@ //gl.stencilFunc(gl.ALWAYS,1,1); gl.stencilOp(gl.KEEP,gl.KEEP,gl.DECR); - PIXI.WebGLGraphics.renderGraphics(maskData, projection); + PIXI.WebGLGraphics.renderGraphics(maskData, renderSession.projection, renderSession.offset); gl.colorMask(true, true, true, true); gl.stencilFunc(gl.NOTEQUAL,0,this.maskStack.length); @@ -5626,8 +5657,12 @@ // API -PIXI.WebGLFilterManager.prototype.begin = function(projection, buffer) +PIXI.WebGLFilterManager.prototype.begin = function(renderSession, buffer) { + this.renderSession = renderSession; + + var projection = this.renderSession.projection; + this.width = projection.x * 2; this.height = -projection.y * 2; this.buffer = buffer; @@ -5637,6 +5672,10 @@ { var gl = PIXI.gl; + var projection = this.renderSession.projection; + var offset = this.renderSession.offset; + + // filter program // OPTIMISATION - the first filter is free if its a simple color change? this.filterStack.push(filterBlock); @@ -5661,6 +5700,7 @@ this.getBounds(filterBlock.target); filterBlock.target.filterArea = filterBlock.target.getBounds(); + // console.log(filterBlock.target.filterArea); // addpadding? //displayObject.filterArea.x @@ -5686,11 +5726,11 @@ // set view port gl.viewport(0, 0, filterArea.width, filterArea.height); - PIXI.projection.x = filterArea.width/2; - PIXI.projection.y = -filterArea.height/2; + projection.x = filterArea.width/2; + projection.y = -filterArea.height/2; - PIXI.offset.x = -filterArea.x; - PIXI.offset.y = -filterArea.y; + offset.x = -filterArea.x; + offset.y = -filterArea.y; //console.log(PIXI.defaultShader.projectionVector) // update projection @@ -5715,6 +5755,8 @@ var filterBlock = this.filterStack.pop(); var filterArea = filterBlock.target.filterArea; var texture = filterBlock._glFilterTexture; + var projection = this.renderSession.projection; + var offset = this.renderSession.offset; if(filterBlock.filterPasses.length > 1) { @@ -5817,11 +5859,11 @@ // TODO need toremove thease global elements.. - PIXI.projection.x = sizeX/2; - PIXI.projection.y = -sizeY/2; + projection.x = sizeX/2; + projection.y = -sizeY/2; - PIXI.offset.x = offsetX; - PIXI.offset.y = offsetY; + offset.x = offsetX; + offset.y = offsetY; filterArea = filterBlock.target.filterArea; @@ -6151,7 +6193,7 @@ PIXI.CanvasMaskManager.prototype.pushMask = function(maskData, context) { context.save(); - + maskData.visible = false; maskData.alpha = 0; @@ -7153,6 +7195,9 @@ PIXI.Graphics.prototype._renderWebGL = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + renderSession.spriteBatch.stop(); // check blend mode @@ -7163,13 +7208,16 @@ this.spriteBatch.gl.blendFunc(blendModeWebGL[0], blendModeWebGL[1]); } - PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection); + PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection, renderSession.offset); renderSession.spriteBatch.start(); } PIXI.Graphics.prototype._renderCanvas = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + var context = renderSession.context; var transform = this.worldTransform; diff --git a/src/pixi/display/DisplayObject.js b/src/pixi/display/DisplayObject.js index bd09ead..42b44fd 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -401,6 +401,7 @@ this.vcount = PIXI.visibleCount; }; + PIXI.DisplayObject.prototype.getBounds = function() { return PIXI.EmptyRectangle; diff --git a/src/pixi/display/DisplayObjectContainer.js b/src/pixi/display/DisplayObjectContainer.js index 0a8441b..4846abd 100644 --- a/src/pixi/display/DisplayObjectContainer.js +++ b/src/pixi/display/DisplayObjectContainer.js @@ -279,7 +279,7 @@ if(this._mask) { renderSession.spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); renderSession.spriteBatch.start(); } @@ -299,7 +299,7 @@ renderSession.spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); renderSession.spriteBatch.start(); } diff --git a/src/pixi/display/Sprite.js b/src/pixi/display/Sprite.js index 33e59ae..55e77ab 100644 --- a/src/pixi/display/Sprite.js +++ b/src/pixi/display/Sprite.js @@ -252,7 +252,7 @@ if(this._mask) { spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); spriteBatch.start(); } @@ -276,7 +276,7 @@ spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); spriteBatch.start(); } diff --git a/src/pixi/primitives/Graphics.js b/src/pixi/primitives/Graphics.js index c6142aa..a4dba9e 100644 --- a/src/pixi/primitives/Graphics.js +++ b/src/pixi/primitives/Graphics.js @@ -235,6 +235,9 @@ PIXI.Graphics.prototype._renderWebGL = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + renderSession.spriteBatch.stop(); // check blend mode @@ -245,13 +248,16 @@ this.spriteBatch.gl.blendFunc(blendModeWebGL[0], blendModeWebGL[1]); } - PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection); + PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection, renderSession.offset); renderSession.spriteBatch.start(); } PIXI.Graphics.prototype._renderCanvas = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + var context = renderSession.context; var transform = this.worldTransform; diff --git a/bin/pixi.dev.js b/bin/pixi.dev.js index 12a3c53..3bcf0a8 100644 --- a/bin/pixi.dev.js +++ b/bin/pixi.dev.js @@ -4,7 +4,7 @@ * Copyright (c) 2012, Mat Groves * http://goodboydigital.com/ * - * Compiled: 2013-12-29 + * Compiled: 2013-12-30 * * Pixi.JS is licensed under the MIT License. * http://www.opensource.org/licenses/mit-license.php @@ -1095,6 +1095,7 @@ this.vcount = PIXI.visibleCount; }; + PIXI.DisplayObject.prototype.getBounds = function() { return PIXI.EmptyRectangle; @@ -1395,7 +1396,7 @@ if(this._mask) { renderSession.spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); renderSession.spriteBatch.start(); } @@ -1415,7 +1416,7 @@ renderSession.spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); renderSession.spriteBatch.start(); } @@ -1705,7 +1706,7 @@ if(this._mask) { spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); spriteBatch.start(); } @@ -1729,7 +1730,7 @@ spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); spriteBatch.start(); } @@ -4349,7 +4350,7 @@ * @param graphics {Graphics} * @param projection {Object} */ -PIXI.WebGLGraphics.renderGraphics = function(graphics, projection) +PIXI.WebGLGraphics.renderGraphics = function(graphics, projection, offset) { var gl = PIXI.gl; @@ -4387,7 +4388,7 @@ gl.uniformMatrix3fv(PIXI.primitiveShader.translationMatrix, false, m); gl.uniform2f(PIXI.primitiveShader.projectionVector, projection.x, -projection.y); - gl.uniform2f(PIXI.primitiveShader.offsetVector, -PIXI.offset.x, -PIXI.offset.y); + gl.uniform2f(PIXI.primitiveShader.offsetVector, -offset.x, -offset.y); gl.uniform3fv(PIXI.primitiveShader.tintColor, PIXI.hex2rgb(graphics.tint)); @@ -4924,14 +4925,16 @@ var gl = this.gl; - PIXI.blendModesWebGL = []; + if(!PIXI.blendModesWebGL) + { + PIXI.blendModesWebGL = []; - PIXI.blendModesWebGL[PIXI.blendModes.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.SCREEN] = [gl.SRC_ALPHA, gl.ONE]; + PIXI.blendModesWebGL[PIXI.blendModes.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.SCREEN] = [gl.SRC_ALPHA, gl.ONE]; + } - console.log( PIXI.blendModesWebGL[PIXI.blendModes.SCREEN]) gl.useProgram(PIXI.defaultShader.program); PIXI.WebGLRenderer.gl = gl; @@ -4942,13 +4945,14 @@ gl.enable(gl.BLEND); gl.colorMask(true, true, true, this.transparent); - PIXI.projection = new PIXI.Point(400, 300); - PIXI.offset = new PIXI.Point(0, 0); - + + this.projection = new PIXI.Point(400, 300); + this.offset = new PIXI.Point(0, 0); + this.resize(this.width, this.height); this.contextLost = false; - this.spriteBatch = new PIXI.WebGLSpriteBatch(gl)//this.gl, PIXI.WebGLRenderer.batchSize); + this.spriteBatch = new PIXI.WebGLSpriteBatch(gl); this.maskManager = new PIXI.WebGLMaskManager(gl); this.filterManager = new PIXI.WebGLFilterManager(this.transparent); @@ -4999,19 +5003,23 @@ gl.clearColor(stage.backgroundColorSplit[0],stage.backgroundColorSplit[1],stage.backgroundColorSplit[2], !this.transparent); gl.clear(gl.COLOR_BUFFER_BIT); - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; + + this.projection.x = this.width/2; + this.projection.y = -this.height/2; + // reset the render session data.. this.renderSession.drawCount = 0; this.renderSession.currentBlendMode = 9999; - this.renderSession.projection = PIXI.projection; + + this.renderSession.projection = this.projection; + this.renderSession.offset = this.offset; // start the sprite batch this.spriteBatch.begin(this.renderSession); // start the filter manager - this.filterManager.begin(PIXI.projection, null); + this.filterManager.begin(this.renderSession, null); // render the scene! stage._renderWebGL(this.renderSession); @@ -5029,6 +5037,27 @@ stage.interactionManager.setTarget(this); } } + + //can simulate context loss in Chrome like so: + // this.view.onmousedown = function(ev) { + // console.dir(this.gl.getSupportedExtensions()); + // var ext = ( + // gl.getExtension("WEBGL_scompressed_texture_s3tc") + // // gl.getExtension("WEBGL_compressed_texture_s3tc") || + // // gl.getExtension("MOZ_WEBGL_compressed_texture_s3tc") || + // // gl.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc") + // ); + // console.dir(ext); + + // var loseCtx = this.gl.getExtension("WEBGL_lose_context"); + // console.log("killing context"); + // loseCtx.loseContext(); + + // setTimeout(function() { + // console.log("restoring context..."); + // loseCtx.restoreContext(); + // }.bind(this), 1000); + // }.bind(this); }; /** @@ -5147,8 +5176,8 @@ this.gl.viewport(0, 0, this.width, this.height); - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; + this.projection.x = this.width/2; + this.projection.y = -this.height/2; }; /** @@ -5211,7 +5240,7 @@ this.maskPosition = 0; } -PIXI.WebGLMaskManager.prototype.pushMask = function(maskData, projection) +PIXI.WebGLMaskManager.prototype.pushMask = function(maskData, renderSession) { var gl = this.gl; @@ -5221,19 +5250,21 @@ gl.stencilFunc(gl.ALWAYS,1,1); } + maskData.visible = false; + this.maskStack.push(maskData); gl.colorMask(false, false, false, false); gl.stencilOp(gl.KEEP,gl.KEEP,gl.INCR); - PIXI.WebGLGraphics.renderGraphics(maskData, projection); + PIXI.WebGLGraphics.renderGraphics(maskData, renderSession.projection, renderSession.offset); gl.colorMask(true, true, true, true); gl.stencilFunc(gl.NOTEQUAL,0, this.maskStack.length); gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP); } -PIXI.WebGLMaskManager.prototype.popMask = function(projection) +PIXI.WebGLMaskManager.prototype.popMask = function(renderSession) { var gl = this.gl; @@ -5246,7 +5277,7 @@ //gl.stencilFunc(gl.ALWAYS,1,1); gl.stencilOp(gl.KEEP,gl.KEEP,gl.DECR); - PIXI.WebGLGraphics.renderGraphics(maskData, projection); + PIXI.WebGLGraphics.renderGraphics(maskData, renderSession.projection, renderSession.offset); gl.colorMask(true, true, true, true); gl.stencilFunc(gl.NOTEQUAL,0,this.maskStack.length); @@ -5626,8 +5657,12 @@ // API -PIXI.WebGLFilterManager.prototype.begin = function(projection, buffer) +PIXI.WebGLFilterManager.prototype.begin = function(renderSession, buffer) { + this.renderSession = renderSession; + + var projection = this.renderSession.projection; + this.width = projection.x * 2; this.height = -projection.y * 2; this.buffer = buffer; @@ -5637,6 +5672,10 @@ { var gl = PIXI.gl; + var projection = this.renderSession.projection; + var offset = this.renderSession.offset; + + // filter program // OPTIMISATION - the first filter is free if its a simple color change? this.filterStack.push(filterBlock); @@ -5661,6 +5700,7 @@ this.getBounds(filterBlock.target); filterBlock.target.filterArea = filterBlock.target.getBounds(); + // console.log(filterBlock.target.filterArea); // addpadding? //displayObject.filterArea.x @@ -5686,11 +5726,11 @@ // set view port gl.viewport(0, 0, filterArea.width, filterArea.height); - PIXI.projection.x = filterArea.width/2; - PIXI.projection.y = -filterArea.height/2; + projection.x = filterArea.width/2; + projection.y = -filterArea.height/2; - PIXI.offset.x = -filterArea.x; - PIXI.offset.y = -filterArea.y; + offset.x = -filterArea.x; + offset.y = -filterArea.y; //console.log(PIXI.defaultShader.projectionVector) // update projection @@ -5715,6 +5755,8 @@ var filterBlock = this.filterStack.pop(); var filterArea = filterBlock.target.filterArea; var texture = filterBlock._glFilterTexture; + var projection = this.renderSession.projection; + var offset = this.renderSession.offset; if(filterBlock.filterPasses.length > 1) { @@ -5817,11 +5859,11 @@ // TODO need toremove thease global elements.. - PIXI.projection.x = sizeX/2; - PIXI.projection.y = -sizeY/2; + projection.x = sizeX/2; + projection.y = -sizeY/2; - PIXI.offset.x = offsetX; - PIXI.offset.y = offsetY; + offset.x = offsetX; + offset.y = offsetY; filterArea = filterBlock.target.filterArea; @@ -6151,7 +6193,7 @@ PIXI.CanvasMaskManager.prototype.pushMask = function(maskData, context) { context.save(); - + maskData.visible = false; maskData.alpha = 0; @@ -7153,6 +7195,9 @@ PIXI.Graphics.prototype._renderWebGL = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + renderSession.spriteBatch.stop(); // check blend mode @@ -7163,13 +7208,16 @@ this.spriteBatch.gl.blendFunc(blendModeWebGL[0], blendModeWebGL[1]); } - PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection); + PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection, renderSession.offset); renderSession.spriteBatch.start(); } PIXI.Graphics.prototype._renderCanvas = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + var context = renderSession.context; var transform = this.worldTransform; diff --git a/src/pixi/display/DisplayObject.js b/src/pixi/display/DisplayObject.js index bd09ead..42b44fd 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -401,6 +401,7 @@ this.vcount = PIXI.visibleCount; }; + PIXI.DisplayObject.prototype.getBounds = function() { return PIXI.EmptyRectangle; diff --git a/src/pixi/display/DisplayObjectContainer.js b/src/pixi/display/DisplayObjectContainer.js index 0a8441b..4846abd 100644 --- a/src/pixi/display/DisplayObjectContainer.js +++ b/src/pixi/display/DisplayObjectContainer.js @@ -279,7 +279,7 @@ if(this._mask) { renderSession.spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); renderSession.spriteBatch.start(); } @@ -299,7 +299,7 @@ renderSession.spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); renderSession.spriteBatch.start(); } diff --git a/src/pixi/display/Sprite.js b/src/pixi/display/Sprite.js index 33e59ae..55e77ab 100644 --- a/src/pixi/display/Sprite.js +++ b/src/pixi/display/Sprite.js @@ -252,7 +252,7 @@ if(this._mask) { spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); spriteBatch.start(); } @@ -276,7 +276,7 @@ spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); spriteBatch.start(); } diff --git a/src/pixi/primitives/Graphics.js b/src/pixi/primitives/Graphics.js index c6142aa..a4dba9e 100644 --- a/src/pixi/primitives/Graphics.js +++ b/src/pixi/primitives/Graphics.js @@ -235,6 +235,9 @@ PIXI.Graphics.prototype._renderWebGL = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + renderSession.spriteBatch.stop(); // check blend mode @@ -245,13 +248,16 @@ this.spriteBatch.gl.blendFunc(blendModeWebGL[0], blendModeWebGL[1]); } - PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection); + PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection, renderSession.offset); renderSession.spriteBatch.start(); } PIXI.Graphics.prototype._renderCanvas = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + var context = renderSession.context; var transform = this.worldTransform; diff --git a/src/pixi/renderers/canvas/utils/CanvasMaskManager.js b/src/pixi/renderers/canvas/utils/CanvasMaskManager.js index 4b02f87..8af4061 100644 --- a/src/pixi/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/pixi/renderers/canvas/utils/CanvasMaskManager.js @@ -12,7 +12,7 @@ PIXI.CanvasMaskManager.prototype.pushMask = function(maskData, context) { context.save(); - + maskData.visible = false; maskData.alpha = 0; diff --git a/bin/pixi.dev.js b/bin/pixi.dev.js index 12a3c53..3bcf0a8 100644 --- a/bin/pixi.dev.js +++ b/bin/pixi.dev.js @@ -4,7 +4,7 @@ * Copyright (c) 2012, Mat Groves * http://goodboydigital.com/ * - * Compiled: 2013-12-29 + * Compiled: 2013-12-30 * * Pixi.JS is licensed under the MIT License. * http://www.opensource.org/licenses/mit-license.php @@ -1095,6 +1095,7 @@ this.vcount = PIXI.visibleCount; }; + PIXI.DisplayObject.prototype.getBounds = function() { return PIXI.EmptyRectangle; @@ -1395,7 +1396,7 @@ if(this._mask) { renderSession.spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); renderSession.spriteBatch.start(); } @@ -1415,7 +1416,7 @@ renderSession.spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); renderSession.spriteBatch.start(); } @@ -1705,7 +1706,7 @@ if(this._mask) { spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); spriteBatch.start(); } @@ -1729,7 +1730,7 @@ spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); spriteBatch.start(); } @@ -4349,7 +4350,7 @@ * @param graphics {Graphics} * @param projection {Object} */ -PIXI.WebGLGraphics.renderGraphics = function(graphics, projection) +PIXI.WebGLGraphics.renderGraphics = function(graphics, projection, offset) { var gl = PIXI.gl; @@ -4387,7 +4388,7 @@ gl.uniformMatrix3fv(PIXI.primitiveShader.translationMatrix, false, m); gl.uniform2f(PIXI.primitiveShader.projectionVector, projection.x, -projection.y); - gl.uniform2f(PIXI.primitiveShader.offsetVector, -PIXI.offset.x, -PIXI.offset.y); + gl.uniform2f(PIXI.primitiveShader.offsetVector, -offset.x, -offset.y); gl.uniform3fv(PIXI.primitiveShader.tintColor, PIXI.hex2rgb(graphics.tint)); @@ -4924,14 +4925,16 @@ var gl = this.gl; - PIXI.blendModesWebGL = []; + if(!PIXI.blendModesWebGL) + { + PIXI.blendModesWebGL = []; - PIXI.blendModesWebGL[PIXI.blendModes.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.SCREEN] = [gl.SRC_ALPHA, gl.ONE]; + PIXI.blendModesWebGL[PIXI.blendModes.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.SCREEN] = [gl.SRC_ALPHA, gl.ONE]; + } - console.log( PIXI.blendModesWebGL[PIXI.blendModes.SCREEN]) gl.useProgram(PIXI.defaultShader.program); PIXI.WebGLRenderer.gl = gl; @@ -4942,13 +4945,14 @@ gl.enable(gl.BLEND); gl.colorMask(true, true, true, this.transparent); - PIXI.projection = new PIXI.Point(400, 300); - PIXI.offset = new PIXI.Point(0, 0); - + + this.projection = new PIXI.Point(400, 300); + this.offset = new PIXI.Point(0, 0); + this.resize(this.width, this.height); this.contextLost = false; - this.spriteBatch = new PIXI.WebGLSpriteBatch(gl)//this.gl, PIXI.WebGLRenderer.batchSize); + this.spriteBatch = new PIXI.WebGLSpriteBatch(gl); this.maskManager = new PIXI.WebGLMaskManager(gl); this.filterManager = new PIXI.WebGLFilterManager(this.transparent); @@ -4999,19 +5003,23 @@ gl.clearColor(stage.backgroundColorSplit[0],stage.backgroundColorSplit[1],stage.backgroundColorSplit[2], !this.transparent); gl.clear(gl.COLOR_BUFFER_BIT); - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; + + this.projection.x = this.width/2; + this.projection.y = -this.height/2; + // reset the render session data.. this.renderSession.drawCount = 0; this.renderSession.currentBlendMode = 9999; - this.renderSession.projection = PIXI.projection; + + this.renderSession.projection = this.projection; + this.renderSession.offset = this.offset; // start the sprite batch this.spriteBatch.begin(this.renderSession); // start the filter manager - this.filterManager.begin(PIXI.projection, null); + this.filterManager.begin(this.renderSession, null); // render the scene! stage._renderWebGL(this.renderSession); @@ -5029,6 +5037,27 @@ stage.interactionManager.setTarget(this); } } + + //can simulate context loss in Chrome like so: + // this.view.onmousedown = function(ev) { + // console.dir(this.gl.getSupportedExtensions()); + // var ext = ( + // gl.getExtension("WEBGL_scompressed_texture_s3tc") + // // gl.getExtension("WEBGL_compressed_texture_s3tc") || + // // gl.getExtension("MOZ_WEBGL_compressed_texture_s3tc") || + // // gl.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc") + // ); + // console.dir(ext); + + // var loseCtx = this.gl.getExtension("WEBGL_lose_context"); + // console.log("killing context"); + // loseCtx.loseContext(); + + // setTimeout(function() { + // console.log("restoring context..."); + // loseCtx.restoreContext(); + // }.bind(this), 1000); + // }.bind(this); }; /** @@ -5147,8 +5176,8 @@ this.gl.viewport(0, 0, this.width, this.height); - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; + this.projection.x = this.width/2; + this.projection.y = -this.height/2; }; /** @@ -5211,7 +5240,7 @@ this.maskPosition = 0; } -PIXI.WebGLMaskManager.prototype.pushMask = function(maskData, projection) +PIXI.WebGLMaskManager.prototype.pushMask = function(maskData, renderSession) { var gl = this.gl; @@ -5221,19 +5250,21 @@ gl.stencilFunc(gl.ALWAYS,1,1); } + maskData.visible = false; + this.maskStack.push(maskData); gl.colorMask(false, false, false, false); gl.stencilOp(gl.KEEP,gl.KEEP,gl.INCR); - PIXI.WebGLGraphics.renderGraphics(maskData, projection); + PIXI.WebGLGraphics.renderGraphics(maskData, renderSession.projection, renderSession.offset); gl.colorMask(true, true, true, true); gl.stencilFunc(gl.NOTEQUAL,0, this.maskStack.length); gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP); } -PIXI.WebGLMaskManager.prototype.popMask = function(projection) +PIXI.WebGLMaskManager.prototype.popMask = function(renderSession) { var gl = this.gl; @@ -5246,7 +5277,7 @@ //gl.stencilFunc(gl.ALWAYS,1,1); gl.stencilOp(gl.KEEP,gl.KEEP,gl.DECR); - PIXI.WebGLGraphics.renderGraphics(maskData, projection); + PIXI.WebGLGraphics.renderGraphics(maskData, renderSession.projection, renderSession.offset); gl.colorMask(true, true, true, true); gl.stencilFunc(gl.NOTEQUAL,0,this.maskStack.length); @@ -5626,8 +5657,12 @@ // API -PIXI.WebGLFilterManager.prototype.begin = function(projection, buffer) +PIXI.WebGLFilterManager.prototype.begin = function(renderSession, buffer) { + this.renderSession = renderSession; + + var projection = this.renderSession.projection; + this.width = projection.x * 2; this.height = -projection.y * 2; this.buffer = buffer; @@ -5637,6 +5672,10 @@ { var gl = PIXI.gl; + var projection = this.renderSession.projection; + var offset = this.renderSession.offset; + + // filter program // OPTIMISATION - the first filter is free if its a simple color change? this.filterStack.push(filterBlock); @@ -5661,6 +5700,7 @@ this.getBounds(filterBlock.target); filterBlock.target.filterArea = filterBlock.target.getBounds(); + // console.log(filterBlock.target.filterArea); // addpadding? //displayObject.filterArea.x @@ -5686,11 +5726,11 @@ // set view port gl.viewport(0, 0, filterArea.width, filterArea.height); - PIXI.projection.x = filterArea.width/2; - PIXI.projection.y = -filterArea.height/2; + projection.x = filterArea.width/2; + projection.y = -filterArea.height/2; - PIXI.offset.x = -filterArea.x; - PIXI.offset.y = -filterArea.y; + offset.x = -filterArea.x; + offset.y = -filterArea.y; //console.log(PIXI.defaultShader.projectionVector) // update projection @@ -5715,6 +5755,8 @@ var filterBlock = this.filterStack.pop(); var filterArea = filterBlock.target.filterArea; var texture = filterBlock._glFilterTexture; + var projection = this.renderSession.projection; + var offset = this.renderSession.offset; if(filterBlock.filterPasses.length > 1) { @@ -5817,11 +5859,11 @@ // TODO need toremove thease global elements.. - PIXI.projection.x = sizeX/2; - PIXI.projection.y = -sizeY/2; + projection.x = sizeX/2; + projection.y = -sizeY/2; - PIXI.offset.x = offsetX; - PIXI.offset.y = offsetY; + offset.x = offsetX; + offset.y = offsetY; filterArea = filterBlock.target.filterArea; @@ -6151,7 +6193,7 @@ PIXI.CanvasMaskManager.prototype.pushMask = function(maskData, context) { context.save(); - + maskData.visible = false; maskData.alpha = 0; @@ -7153,6 +7195,9 @@ PIXI.Graphics.prototype._renderWebGL = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + renderSession.spriteBatch.stop(); // check blend mode @@ -7163,13 +7208,16 @@ this.spriteBatch.gl.blendFunc(blendModeWebGL[0], blendModeWebGL[1]); } - PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection); + PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection, renderSession.offset); renderSession.spriteBatch.start(); } PIXI.Graphics.prototype._renderCanvas = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + var context = renderSession.context; var transform = this.worldTransform; diff --git a/src/pixi/display/DisplayObject.js b/src/pixi/display/DisplayObject.js index bd09ead..42b44fd 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -401,6 +401,7 @@ this.vcount = PIXI.visibleCount; }; + PIXI.DisplayObject.prototype.getBounds = function() { return PIXI.EmptyRectangle; diff --git a/src/pixi/display/DisplayObjectContainer.js b/src/pixi/display/DisplayObjectContainer.js index 0a8441b..4846abd 100644 --- a/src/pixi/display/DisplayObjectContainer.js +++ b/src/pixi/display/DisplayObjectContainer.js @@ -279,7 +279,7 @@ if(this._mask) { renderSession.spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); renderSession.spriteBatch.start(); } @@ -299,7 +299,7 @@ renderSession.spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); renderSession.spriteBatch.start(); } diff --git a/src/pixi/display/Sprite.js b/src/pixi/display/Sprite.js index 33e59ae..55e77ab 100644 --- a/src/pixi/display/Sprite.js +++ b/src/pixi/display/Sprite.js @@ -252,7 +252,7 @@ if(this._mask) { spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); spriteBatch.start(); } @@ -276,7 +276,7 @@ spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); spriteBatch.start(); } diff --git a/src/pixi/primitives/Graphics.js b/src/pixi/primitives/Graphics.js index c6142aa..a4dba9e 100644 --- a/src/pixi/primitives/Graphics.js +++ b/src/pixi/primitives/Graphics.js @@ -235,6 +235,9 @@ PIXI.Graphics.prototype._renderWebGL = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + renderSession.spriteBatch.stop(); // check blend mode @@ -245,13 +248,16 @@ this.spriteBatch.gl.blendFunc(blendModeWebGL[0], blendModeWebGL[1]); } - PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection); + PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection, renderSession.offset); renderSession.spriteBatch.start(); } PIXI.Graphics.prototype._renderCanvas = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + var context = renderSession.context; var transform = this.worldTransform; diff --git a/src/pixi/renderers/canvas/utils/CanvasMaskManager.js b/src/pixi/renderers/canvas/utils/CanvasMaskManager.js index 4b02f87..8af4061 100644 --- a/src/pixi/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/pixi/renderers/canvas/utils/CanvasMaskManager.js @@ -12,7 +12,7 @@ PIXI.CanvasMaskManager.prototype.pushMask = function(maskData, context) { context.save(); - + maskData.visible = false; maskData.alpha = 0; diff --git a/src/pixi/renderers/webgl/WebGLRenderer.js b/src/pixi/renderers/webgl/WebGLRenderer.js index 83c2eac..bbbd6b3 100644 --- a/src/pixi/renderers/webgl/WebGLRenderer.js +++ b/src/pixi/renderers/webgl/WebGLRenderer.js @@ -69,14 +69,16 @@ var gl = this.gl; - PIXI.blendModesWebGL = []; + if(!PIXI.blendModesWebGL) + { + PIXI.blendModesWebGL = []; - PIXI.blendModesWebGL[PIXI.blendModes.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.SCREEN] = [gl.SRC_ALPHA, gl.ONE]; + PIXI.blendModesWebGL[PIXI.blendModes.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.SCREEN] = [gl.SRC_ALPHA, gl.ONE]; + } - console.log( PIXI.blendModesWebGL[PIXI.blendModes.SCREEN]) gl.useProgram(PIXI.defaultShader.program); PIXI.WebGLRenderer.gl = gl; @@ -87,13 +89,14 @@ gl.enable(gl.BLEND); gl.colorMask(true, true, true, this.transparent); - PIXI.projection = new PIXI.Point(400, 300); - PIXI.offset = new PIXI.Point(0, 0); - + + this.projection = new PIXI.Point(400, 300); + this.offset = new PIXI.Point(0, 0); + this.resize(this.width, this.height); this.contextLost = false; - this.spriteBatch = new PIXI.WebGLSpriteBatch(gl)//this.gl, PIXI.WebGLRenderer.batchSize); + this.spriteBatch = new PIXI.WebGLSpriteBatch(gl); this.maskManager = new PIXI.WebGLMaskManager(gl); this.filterManager = new PIXI.WebGLFilterManager(this.transparent); @@ -144,19 +147,23 @@ gl.clearColor(stage.backgroundColorSplit[0],stage.backgroundColorSplit[1],stage.backgroundColorSplit[2], !this.transparent); gl.clear(gl.COLOR_BUFFER_BIT); - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; + + this.projection.x = this.width/2; + this.projection.y = -this.height/2; + // reset the render session data.. this.renderSession.drawCount = 0; this.renderSession.currentBlendMode = 9999; - this.renderSession.projection = PIXI.projection; + + this.renderSession.projection = this.projection; + this.renderSession.offset = this.offset; // start the sprite batch this.spriteBatch.begin(this.renderSession); // start the filter manager - this.filterManager.begin(PIXI.projection, null); + this.filterManager.begin(this.renderSession, null); // render the scene! stage._renderWebGL(this.renderSession); @@ -174,6 +181,27 @@ stage.interactionManager.setTarget(this); } } + + //can simulate context loss in Chrome like so: + // this.view.onmousedown = function(ev) { + // console.dir(this.gl.getSupportedExtensions()); + // var ext = ( + // gl.getExtension("WEBGL_scompressed_texture_s3tc") + // // gl.getExtension("WEBGL_compressed_texture_s3tc") || + // // gl.getExtension("MOZ_WEBGL_compressed_texture_s3tc") || + // // gl.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc") + // ); + // console.dir(ext); + + // var loseCtx = this.gl.getExtension("WEBGL_lose_context"); + // console.log("killing context"); + // loseCtx.loseContext(); + + // setTimeout(function() { + // console.log("restoring context..."); + // loseCtx.restoreContext(); + // }.bind(this), 1000); + // }.bind(this); }; /** @@ -292,8 +320,8 @@ this.gl.viewport(0, 0, this.width, this.height); - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; + this.projection.x = this.width/2; + this.projection.y = -this.height/2; }; /** diff --git a/bin/pixi.dev.js b/bin/pixi.dev.js index 12a3c53..3bcf0a8 100644 --- a/bin/pixi.dev.js +++ b/bin/pixi.dev.js @@ -4,7 +4,7 @@ * Copyright (c) 2012, Mat Groves * http://goodboydigital.com/ * - * Compiled: 2013-12-29 + * Compiled: 2013-12-30 * * Pixi.JS is licensed under the MIT License. * http://www.opensource.org/licenses/mit-license.php @@ -1095,6 +1095,7 @@ this.vcount = PIXI.visibleCount; }; + PIXI.DisplayObject.prototype.getBounds = function() { return PIXI.EmptyRectangle; @@ -1395,7 +1396,7 @@ if(this._mask) { renderSession.spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); renderSession.spriteBatch.start(); } @@ -1415,7 +1416,7 @@ renderSession.spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); renderSession.spriteBatch.start(); } @@ -1705,7 +1706,7 @@ if(this._mask) { spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); spriteBatch.start(); } @@ -1729,7 +1730,7 @@ spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); spriteBatch.start(); } @@ -4349,7 +4350,7 @@ * @param graphics {Graphics} * @param projection {Object} */ -PIXI.WebGLGraphics.renderGraphics = function(graphics, projection) +PIXI.WebGLGraphics.renderGraphics = function(graphics, projection, offset) { var gl = PIXI.gl; @@ -4387,7 +4388,7 @@ gl.uniformMatrix3fv(PIXI.primitiveShader.translationMatrix, false, m); gl.uniform2f(PIXI.primitiveShader.projectionVector, projection.x, -projection.y); - gl.uniform2f(PIXI.primitiveShader.offsetVector, -PIXI.offset.x, -PIXI.offset.y); + gl.uniform2f(PIXI.primitiveShader.offsetVector, -offset.x, -offset.y); gl.uniform3fv(PIXI.primitiveShader.tintColor, PIXI.hex2rgb(graphics.tint)); @@ -4924,14 +4925,16 @@ var gl = this.gl; - PIXI.blendModesWebGL = []; + if(!PIXI.blendModesWebGL) + { + PIXI.blendModesWebGL = []; - PIXI.blendModesWebGL[PIXI.blendModes.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.SCREEN] = [gl.SRC_ALPHA, gl.ONE]; + PIXI.blendModesWebGL[PIXI.blendModes.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.SCREEN] = [gl.SRC_ALPHA, gl.ONE]; + } - console.log( PIXI.blendModesWebGL[PIXI.blendModes.SCREEN]) gl.useProgram(PIXI.defaultShader.program); PIXI.WebGLRenderer.gl = gl; @@ -4942,13 +4945,14 @@ gl.enable(gl.BLEND); gl.colorMask(true, true, true, this.transparent); - PIXI.projection = new PIXI.Point(400, 300); - PIXI.offset = new PIXI.Point(0, 0); - + + this.projection = new PIXI.Point(400, 300); + this.offset = new PIXI.Point(0, 0); + this.resize(this.width, this.height); this.contextLost = false; - this.spriteBatch = new PIXI.WebGLSpriteBatch(gl)//this.gl, PIXI.WebGLRenderer.batchSize); + this.spriteBatch = new PIXI.WebGLSpriteBatch(gl); this.maskManager = new PIXI.WebGLMaskManager(gl); this.filterManager = new PIXI.WebGLFilterManager(this.transparent); @@ -4999,19 +5003,23 @@ gl.clearColor(stage.backgroundColorSplit[0],stage.backgroundColorSplit[1],stage.backgroundColorSplit[2], !this.transparent); gl.clear(gl.COLOR_BUFFER_BIT); - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; + + this.projection.x = this.width/2; + this.projection.y = -this.height/2; + // reset the render session data.. this.renderSession.drawCount = 0; this.renderSession.currentBlendMode = 9999; - this.renderSession.projection = PIXI.projection; + + this.renderSession.projection = this.projection; + this.renderSession.offset = this.offset; // start the sprite batch this.spriteBatch.begin(this.renderSession); // start the filter manager - this.filterManager.begin(PIXI.projection, null); + this.filterManager.begin(this.renderSession, null); // render the scene! stage._renderWebGL(this.renderSession); @@ -5029,6 +5037,27 @@ stage.interactionManager.setTarget(this); } } + + //can simulate context loss in Chrome like so: + // this.view.onmousedown = function(ev) { + // console.dir(this.gl.getSupportedExtensions()); + // var ext = ( + // gl.getExtension("WEBGL_scompressed_texture_s3tc") + // // gl.getExtension("WEBGL_compressed_texture_s3tc") || + // // gl.getExtension("MOZ_WEBGL_compressed_texture_s3tc") || + // // gl.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc") + // ); + // console.dir(ext); + + // var loseCtx = this.gl.getExtension("WEBGL_lose_context"); + // console.log("killing context"); + // loseCtx.loseContext(); + + // setTimeout(function() { + // console.log("restoring context..."); + // loseCtx.restoreContext(); + // }.bind(this), 1000); + // }.bind(this); }; /** @@ -5147,8 +5176,8 @@ this.gl.viewport(0, 0, this.width, this.height); - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; + this.projection.x = this.width/2; + this.projection.y = -this.height/2; }; /** @@ -5211,7 +5240,7 @@ this.maskPosition = 0; } -PIXI.WebGLMaskManager.prototype.pushMask = function(maskData, projection) +PIXI.WebGLMaskManager.prototype.pushMask = function(maskData, renderSession) { var gl = this.gl; @@ -5221,19 +5250,21 @@ gl.stencilFunc(gl.ALWAYS,1,1); } + maskData.visible = false; + this.maskStack.push(maskData); gl.colorMask(false, false, false, false); gl.stencilOp(gl.KEEP,gl.KEEP,gl.INCR); - PIXI.WebGLGraphics.renderGraphics(maskData, projection); + PIXI.WebGLGraphics.renderGraphics(maskData, renderSession.projection, renderSession.offset); gl.colorMask(true, true, true, true); gl.stencilFunc(gl.NOTEQUAL,0, this.maskStack.length); gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP); } -PIXI.WebGLMaskManager.prototype.popMask = function(projection) +PIXI.WebGLMaskManager.prototype.popMask = function(renderSession) { var gl = this.gl; @@ -5246,7 +5277,7 @@ //gl.stencilFunc(gl.ALWAYS,1,1); gl.stencilOp(gl.KEEP,gl.KEEP,gl.DECR); - PIXI.WebGLGraphics.renderGraphics(maskData, projection); + PIXI.WebGLGraphics.renderGraphics(maskData, renderSession.projection, renderSession.offset); gl.colorMask(true, true, true, true); gl.stencilFunc(gl.NOTEQUAL,0,this.maskStack.length); @@ -5626,8 +5657,12 @@ // API -PIXI.WebGLFilterManager.prototype.begin = function(projection, buffer) +PIXI.WebGLFilterManager.prototype.begin = function(renderSession, buffer) { + this.renderSession = renderSession; + + var projection = this.renderSession.projection; + this.width = projection.x * 2; this.height = -projection.y * 2; this.buffer = buffer; @@ -5637,6 +5672,10 @@ { var gl = PIXI.gl; + var projection = this.renderSession.projection; + var offset = this.renderSession.offset; + + // filter program // OPTIMISATION - the first filter is free if its a simple color change? this.filterStack.push(filterBlock); @@ -5661,6 +5700,7 @@ this.getBounds(filterBlock.target); filterBlock.target.filterArea = filterBlock.target.getBounds(); + // console.log(filterBlock.target.filterArea); // addpadding? //displayObject.filterArea.x @@ -5686,11 +5726,11 @@ // set view port gl.viewport(0, 0, filterArea.width, filterArea.height); - PIXI.projection.x = filterArea.width/2; - PIXI.projection.y = -filterArea.height/2; + projection.x = filterArea.width/2; + projection.y = -filterArea.height/2; - PIXI.offset.x = -filterArea.x; - PIXI.offset.y = -filterArea.y; + offset.x = -filterArea.x; + offset.y = -filterArea.y; //console.log(PIXI.defaultShader.projectionVector) // update projection @@ -5715,6 +5755,8 @@ var filterBlock = this.filterStack.pop(); var filterArea = filterBlock.target.filterArea; var texture = filterBlock._glFilterTexture; + var projection = this.renderSession.projection; + var offset = this.renderSession.offset; if(filterBlock.filterPasses.length > 1) { @@ -5817,11 +5859,11 @@ // TODO need toremove thease global elements.. - PIXI.projection.x = sizeX/2; - PIXI.projection.y = -sizeY/2; + projection.x = sizeX/2; + projection.y = -sizeY/2; - PIXI.offset.x = offsetX; - PIXI.offset.y = offsetY; + offset.x = offsetX; + offset.y = offsetY; filterArea = filterBlock.target.filterArea; @@ -6151,7 +6193,7 @@ PIXI.CanvasMaskManager.prototype.pushMask = function(maskData, context) { context.save(); - + maskData.visible = false; maskData.alpha = 0; @@ -7153,6 +7195,9 @@ PIXI.Graphics.prototype._renderWebGL = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + renderSession.spriteBatch.stop(); // check blend mode @@ -7163,13 +7208,16 @@ this.spriteBatch.gl.blendFunc(blendModeWebGL[0], blendModeWebGL[1]); } - PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection); + PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection, renderSession.offset); renderSession.spriteBatch.start(); } PIXI.Graphics.prototype._renderCanvas = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + var context = renderSession.context; var transform = this.worldTransform; diff --git a/src/pixi/display/DisplayObject.js b/src/pixi/display/DisplayObject.js index bd09ead..42b44fd 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -401,6 +401,7 @@ this.vcount = PIXI.visibleCount; }; + PIXI.DisplayObject.prototype.getBounds = function() { return PIXI.EmptyRectangle; diff --git a/src/pixi/display/DisplayObjectContainer.js b/src/pixi/display/DisplayObjectContainer.js index 0a8441b..4846abd 100644 --- a/src/pixi/display/DisplayObjectContainer.js +++ b/src/pixi/display/DisplayObjectContainer.js @@ -279,7 +279,7 @@ if(this._mask) { renderSession.spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); renderSession.spriteBatch.start(); } @@ -299,7 +299,7 @@ renderSession.spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); renderSession.spriteBatch.start(); } diff --git a/src/pixi/display/Sprite.js b/src/pixi/display/Sprite.js index 33e59ae..55e77ab 100644 --- a/src/pixi/display/Sprite.js +++ b/src/pixi/display/Sprite.js @@ -252,7 +252,7 @@ if(this._mask) { spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); spriteBatch.start(); } @@ -276,7 +276,7 @@ spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); spriteBatch.start(); } diff --git a/src/pixi/primitives/Graphics.js b/src/pixi/primitives/Graphics.js index c6142aa..a4dba9e 100644 --- a/src/pixi/primitives/Graphics.js +++ b/src/pixi/primitives/Graphics.js @@ -235,6 +235,9 @@ PIXI.Graphics.prototype._renderWebGL = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + renderSession.spriteBatch.stop(); // check blend mode @@ -245,13 +248,16 @@ this.spriteBatch.gl.blendFunc(blendModeWebGL[0], blendModeWebGL[1]); } - PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection); + PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection, renderSession.offset); renderSession.spriteBatch.start(); } PIXI.Graphics.prototype._renderCanvas = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + var context = renderSession.context; var transform = this.worldTransform; diff --git a/src/pixi/renderers/canvas/utils/CanvasMaskManager.js b/src/pixi/renderers/canvas/utils/CanvasMaskManager.js index 4b02f87..8af4061 100644 --- a/src/pixi/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/pixi/renderers/canvas/utils/CanvasMaskManager.js @@ -12,7 +12,7 @@ PIXI.CanvasMaskManager.prototype.pushMask = function(maskData, context) { context.save(); - + maskData.visible = false; maskData.alpha = 0; diff --git a/src/pixi/renderers/webgl/WebGLRenderer.js b/src/pixi/renderers/webgl/WebGLRenderer.js index 83c2eac..bbbd6b3 100644 --- a/src/pixi/renderers/webgl/WebGLRenderer.js +++ b/src/pixi/renderers/webgl/WebGLRenderer.js @@ -69,14 +69,16 @@ var gl = this.gl; - PIXI.blendModesWebGL = []; + if(!PIXI.blendModesWebGL) + { + PIXI.blendModesWebGL = []; - PIXI.blendModesWebGL[PIXI.blendModes.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.SCREEN] = [gl.SRC_ALPHA, gl.ONE]; + PIXI.blendModesWebGL[PIXI.blendModes.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.SCREEN] = [gl.SRC_ALPHA, gl.ONE]; + } - console.log( PIXI.blendModesWebGL[PIXI.blendModes.SCREEN]) gl.useProgram(PIXI.defaultShader.program); PIXI.WebGLRenderer.gl = gl; @@ -87,13 +89,14 @@ gl.enable(gl.BLEND); gl.colorMask(true, true, true, this.transparent); - PIXI.projection = new PIXI.Point(400, 300); - PIXI.offset = new PIXI.Point(0, 0); - + + this.projection = new PIXI.Point(400, 300); + this.offset = new PIXI.Point(0, 0); + this.resize(this.width, this.height); this.contextLost = false; - this.spriteBatch = new PIXI.WebGLSpriteBatch(gl)//this.gl, PIXI.WebGLRenderer.batchSize); + this.spriteBatch = new PIXI.WebGLSpriteBatch(gl); this.maskManager = new PIXI.WebGLMaskManager(gl); this.filterManager = new PIXI.WebGLFilterManager(this.transparent); @@ -144,19 +147,23 @@ gl.clearColor(stage.backgroundColorSplit[0],stage.backgroundColorSplit[1],stage.backgroundColorSplit[2], !this.transparent); gl.clear(gl.COLOR_BUFFER_BIT); - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; + + this.projection.x = this.width/2; + this.projection.y = -this.height/2; + // reset the render session data.. this.renderSession.drawCount = 0; this.renderSession.currentBlendMode = 9999; - this.renderSession.projection = PIXI.projection; + + this.renderSession.projection = this.projection; + this.renderSession.offset = this.offset; // start the sprite batch this.spriteBatch.begin(this.renderSession); // start the filter manager - this.filterManager.begin(PIXI.projection, null); + this.filterManager.begin(this.renderSession, null); // render the scene! stage._renderWebGL(this.renderSession); @@ -174,6 +181,27 @@ stage.interactionManager.setTarget(this); } } + + //can simulate context loss in Chrome like so: + // this.view.onmousedown = function(ev) { + // console.dir(this.gl.getSupportedExtensions()); + // var ext = ( + // gl.getExtension("WEBGL_scompressed_texture_s3tc") + // // gl.getExtension("WEBGL_compressed_texture_s3tc") || + // // gl.getExtension("MOZ_WEBGL_compressed_texture_s3tc") || + // // gl.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc") + // ); + // console.dir(ext); + + // var loseCtx = this.gl.getExtension("WEBGL_lose_context"); + // console.log("killing context"); + // loseCtx.loseContext(); + + // setTimeout(function() { + // console.log("restoring context..."); + // loseCtx.restoreContext(); + // }.bind(this), 1000); + // }.bind(this); }; /** @@ -292,8 +320,8 @@ this.gl.viewport(0, 0, this.width, this.height); - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; + this.projection.x = this.width/2; + this.projection.y = -this.height/2; }; /** diff --git a/src/pixi/renderers/webgl/utils/WebGLFilterManager.js b/src/pixi/renderers/webgl/utils/WebGLFilterManager.js index 7fffd67..7c81c00 100644 --- a/src/pixi/renderers/webgl/utils/WebGLFilterManager.js +++ b/src/pixi/renderers/webgl/utils/WebGLFilterManager.js @@ -18,8 +18,12 @@ // API -PIXI.WebGLFilterManager.prototype.begin = function(projection, buffer) +PIXI.WebGLFilterManager.prototype.begin = function(renderSession, buffer) { + this.renderSession = renderSession; + + var projection = this.renderSession.projection; + this.width = projection.x * 2; this.height = -projection.y * 2; this.buffer = buffer; @@ -29,6 +33,10 @@ { var gl = PIXI.gl; + var projection = this.renderSession.projection; + var offset = this.renderSession.offset; + + // filter program // OPTIMISATION - the first filter is free if its a simple color change? this.filterStack.push(filterBlock); @@ -53,6 +61,7 @@ this.getBounds(filterBlock.target); filterBlock.target.filterArea = filterBlock.target.getBounds(); + // console.log(filterBlock.target.filterArea); // addpadding? //displayObject.filterArea.x @@ -78,11 +87,11 @@ // set view port gl.viewport(0, 0, filterArea.width, filterArea.height); - PIXI.projection.x = filterArea.width/2; - PIXI.projection.y = -filterArea.height/2; + projection.x = filterArea.width/2; + projection.y = -filterArea.height/2; - PIXI.offset.x = -filterArea.x; - PIXI.offset.y = -filterArea.y; + offset.x = -filterArea.x; + offset.y = -filterArea.y; //console.log(PIXI.defaultShader.projectionVector) // update projection @@ -107,6 +116,8 @@ var filterBlock = this.filterStack.pop(); var filterArea = filterBlock.target.filterArea; var texture = filterBlock._glFilterTexture; + var projection = this.renderSession.projection; + var offset = this.renderSession.offset; if(filterBlock.filterPasses.length > 1) { @@ -209,11 +220,11 @@ // TODO need toremove thease global elements.. - PIXI.projection.x = sizeX/2; - PIXI.projection.y = -sizeY/2; + projection.x = sizeX/2; + projection.y = -sizeY/2; - PIXI.offset.x = offsetX; - PIXI.offset.y = offsetY; + offset.x = offsetX; + offset.y = offsetY; filterArea = filterBlock.target.filterArea; diff --git a/bin/pixi.dev.js b/bin/pixi.dev.js index 12a3c53..3bcf0a8 100644 --- a/bin/pixi.dev.js +++ b/bin/pixi.dev.js @@ -4,7 +4,7 @@ * Copyright (c) 2012, Mat Groves * http://goodboydigital.com/ * - * Compiled: 2013-12-29 + * Compiled: 2013-12-30 * * Pixi.JS is licensed under the MIT License. * http://www.opensource.org/licenses/mit-license.php @@ -1095,6 +1095,7 @@ this.vcount = PIXI.visibleCount; }; + PIXI.DisplayObject.prototype.getBounds = function() { return PIXI.EmptyRectangle; @@ -1395,7 +1396,7 @@ if(this._mask) { renderSession.spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); renderSession.spriteBatch.start(); } @@ -1415,7 +1416,7 @@ renderSession.spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); renderSession.spriteBatch.start(); } @@ -1705,7 +1706,7 @@ if(this._mask) { spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); spriteBatch.start(); } @@ -1729,7 +1730,7 @@ spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); spriteBatch.start(); } @@ -4349,7 +4350,7 @@ * @param graphics {Graphics} * @param projection {Object} */ -PIXI.WebGLGraphics.renderGraphics = function(graphics, projection) +PIXI.WebGLGraphics.renderGraphics = function(graphics, projection, offset) { var gl = PIXI.gl; @@ -4387,7 +4388,7 @@ gl.uniformMatrix3fv(PIXI.primitiveShader.translationMatrix, false, m); gl.uniform2f(PIXI.primitiveShader.projectionVector, projection.x, -projection.y); - gl.uniform2f(PIXI.primitiveShader.offsetVector, -PIXI.offset.x, -PIXI.offset.y); + gl.uniform2f(PIXI.primitiveShader.offsetVector, -offset.x, -offset.y); gl.uniform3fv(PIXI.primitiveShader.tintColor, PIXI.hex2rgb(graphics.tint)); @@ -4924,14 +4925,16 @@ var gl = this.gl; - PIXI.blendModesWebGL = []; + if(!PIXI.blendModesWebGL) + { + PIXI.blendModesWebGL = []; - PIXI.blendModesWebGL[PIXI.blendModes.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.SCREEN] = [gl.SRC_ALPHA, gl.ONE]; + PIXI.blendModesWebGL[PIXI.blendModes.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.SCREEN] = [gl.SRC_ALPHA, gl.ONE]; + } - console.log( PIXI.blendModesWebGL[PIXI.blendModes.SCREEN]) gl.useProgram(PIXI.defaultShader.program); PIXI.WebGLRenderer.gl = gl; @@ -4942,13 +4945,14 @@ gl.enable(gl.BLEND); gl.colorMask(true, true, true, this.transparent); - PIXI.projection = new PIXI.Point(400, 300); - PIXI.offset = new PIXI.Point(0, 0); - + + this.projection = new PIXI.Point(400, 300); + this.offset = new PIXI.Point(0, 0); + this.resize(this.width, this.height); this.contextLost = false; - this.spriteBatch = new PIXI.WebGLSpriteBatch(gl)//this.gl, PIXI.WebGLRenderer.batchSize); + this.spriteBatch = new PIXI.WebGLSpriteBatch(gl); this.maskManager = new PIXI.WebGLMaskManager(gl); this.filterManager = new PIXI.WebGLFilterManager(this.transparent); @@ -4999,19 +5003,23 @@ gl.clearColor(stage.backgroundColorSplit[0],stage.backgroundColorSplit[1],stage.backgroundColorSplit[2], !this.transparent); gl.clear(gl.COLOR_BUFFER_BIT); - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; + + this.projection.x = this.width/2; + this.projection.y = -this.height/2; + // reset the render session data.. this.renderSession.drawCount = 0; this.renderSession.currentBlendMode = 9999; - this.renderSession.projection = PIXI.projection; + + this.renderSession.projection = this.projection; + this.renderSession.offset = this.offset; // start the sprite batch this.spriteBatch.begin(this.renderSession); // start the filter manager - this.filterManager.begin(PIXI.projection, null); + this.filterManager.begin(this.renderSession, null); // render the scene! stage._renderWebGL(this.renderSession); @@ -5029,6 +5037,27 @@ stage.interactionManager.setTarget(this); } } + + //can simulate context loss in Chrome like so: + // this.view.onmousedown = function(ev) { + // console.dir(this.gl.getSupportedExtensions()); + // var ext = ( + // gl.getExtension("WEBGL_scompressed_texture_s3tc") + // // gl.getExtension("WEBGL_compressed_texture_s3tc") || + // // gl.getExtension("MOZ_WEBGL_compressed_texture_s3tc") || + // // gl.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc") + // ); + // console.dir(ext); + + // var loseCtx = this.gl.getExtension("WEBGL_lose_context"); + // console.log("killing context"); + // loseCtx.loseContext(); + + // setTimeout(function() { + // console.log("restoring context..."); + // loseCtx.restoreContext(); + // }.bind(this), 1000); + // }.bind(this); }; /** @@ -5147,8 +5176,8 @@ this.gl.viewport(0, 0, this.width, this.height); - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; + this.projection.x = this.width/2; + this.projection.y = -this.height/2; }; /** @@ -5211,7 +5240,7 @@ this.maskPosition = 0; } -PIXI.WebGLMaskManager.prototype.pushMask = function(maskData, projection) +PIXI.WebGLMaskManager.prototype.pushMask = function(maskData, renderSession) { var gl = this.gl; @@ -5221,19 +5250,21 @@ gl.stencilFunc(gl.ALWAYS,1,1); } + maskData.visible = false; + this.maskStack.push(maskData); gl.colorMask(false, false, false, false); gl.stencilOp(gl.KEEP,gl.KEEP,gl.INCR); - PIXI.WebGLGraphics.renderGraphics(maskData, projection); + PIXI.WebGLGraphics.renderGraphics(maskData, renderSession.projection, renderSession.offset); gl.colorMask(true, true, true, true); gl.stencilFunc(gl.NOTEQUAL,0, this.maskStack.length); gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP); } -PIXI.WebGLMaskManager.prototype.popMask = function(projection) +PIXI.WebGLMaskManager.prototype.popMask = function(renderSession) { var gl = this.gl; @@ -5246,7 +5277,7 @@ //gl.stencilFunc(gl.ALWAYS,1,1); gl.stencilOp(gl.KEEP,gl.KEEP,gl.DECR); - PIXI.WebGLGraphics.renderGraphics(maskData, projection); + PIXI.WebGLGraphics.renderGraphics(maskData, renderSession.projection, renderSession.offset); gl.colorMask(true, true, true, true); gl.stencilFunc(gl.NOTEQUAL,0,this.maskStack.length); @@ -5626,8 +5657,12 @@ // API -PIXI.WebGLFilterManager.prototype.begin = function(projection, buffer) +PIXI.WebGLFilterManager.prototype.begin = function(renderSession, buffer) { + this.renderSession = renderSession; + + var projection = this.renderSession.projection; + this.width = projection.x * 2; this.height = -projection.y * 2; this.buffer = buffer; @@ -5637,6 +5672,10 @@ { var gl = PIXI.gl; + var projection = this.renderSession.projection; + var offset = this.renderSession.offset; + + // filter program // OPTIMISATION - the first filter is free if its a simple color change? this.filterStack.push(filterBlock); @@ -5661,6 +5700,7 @@ this.getBounds(filterBlock.target); filterBlock.target.filterArea = filterBlock.target.getBounds(); + // console.log(filterBlock.target.filterArea); // addpadding? //displayObject.filterArea.x @@ -5686,11 +5726,11 @@ // set view port gl.viewport(0, 0, filterArea.width, filterArea.height); - PIXI.projection.x = filterArea.width/2; - PIXI.projection.y = -filterArea.height/2; + projection.x = filterArea.width/2; + projection.y = -filterArea.height/2; - PIXI.offset.x = -filterArea.x; - PIXI.offset.y = -filterArea.y; + offset.x = -filterArea.x; + offset.y = -filterArea.y; //console.log(PIXI.defaultShader.projectionVector) // update projection @@ -5715,6 +5755,8 @@ var filterBlock = this.filterStack.pop(); var filterArea = filterBlock.target.filterArea; var texture = filterBlock._glFilterTexture; + var projection = this.renderSession.projection; + var offset = this.renderSession.offset; if(filterBlock.filterPasses.length > 1) { @@ -5817,11 +5859,11 @@ // TODO need toremove thease global elements.. - PIXI.projection.x = sizeX/2; - PIXI.projection.y = -sizeY/2; + projection.x = sizeX/2; + projection.y = -sizeY/2; - PIXI.offset.x = offsetX; - PIXI.offset.y = offsetY; + offset.x = offsetX; + offset.y = offsetY; filterArea = filterBlock.target.filterArea; @@ -6151,7 +6193,7 @@ PIXI.CanvasMaskManager.prototype.pushMask = function(maskData, context) { context.save(); - + maskData.visible = false; maskData.alpha = 0; @@ -7153,6 +7195,9 @@ PIXI.Graphics.prototype._renderWebGL = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + renderSession.spriteBatch.stop(); // check blend mode @@ -7163,13 +7208,16 @@ this.spriteBatch.gl.blendFunc(blendModeWebGL[0], blendModeWebGL[1]); } - PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection); + PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection, renderSession.offset); renderSession.spriteBatch.start(); } PIXI.Graphics.prototype._renderCanvas = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + var context = renderSession.context; var transform = this.worldTransform; diff --git a/src/pixi/display/DisplayObject.js b/src/pixi/display/DisplayObject.js index bd09ead..42b44fd 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -401,6 +401,7 @@ this.vcount = PIXI.visibleCount; }; + PIXI.DisplayObject.prototype.getBounds = function() { return PIXI.EmptyRectangle; diff --git a/src/pixi/display/DisplayObjectContainer.js b/src/pixi/display/DisplayObjectContainer.js index 0a8441b..4846abd 100644 --- a/src/pixi/display/DisplayObjectContainer.js +++ b/src/pixi/display/DisplayObjectContainer.js @@ -279,7 +279,7 @@ if(this._mask) { renderSession.spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); renderSession.spriteBatch.start(); } @@ -299,7 +299,7 @@ renderSession.spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); renderSession.spriteBatch.start(); } diff --git a/src/pixi/display/Sprite.js b/src/pixi/display/Sprite.js index 33e59ae..55e77ab 100644 --- a/src/pixi/display/Sprite.js +++ b/src/pixi/display/Sprite.js @@ -252,7 +252,7 @@ if(this._mask) { spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); spriteBatch.start(); } @@ -276,7 +276,7 @@ spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); spriteBatch.start(); } diff --git a/src/pixi/primitives/Graphics.js b/src/pixi/primitives/Graphics.js index c6142aa..a4dba9e 100644 --- a/src/pixi/primitives/Graphics.js +++ b/src/pixi/primitives/Graphics.js @@ -235,6 +235,9 @@ PIXI.Graphics.prototype._renderWebGL = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + renderSession.spriteBatch.stop(); // check blend mode @@ -245,13 +248,16 @@ this.spriteBatch.gl.blendFunc(blendModeWebGL[0], blendModeWebGL[1]); } - PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection); + PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection, renderSession.offset); renderSession.spriteBatch.start(); } PIXI.Graphics.prototype._renderCanvas = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + var context = renderSession.context; var transform = this.worldTransform; diff --git a/src/pixi/renderers/canvas/utils/CanvasMaskManager.js b/src/pixi/renderers/canvas/utils/CanvasMaskManager.js index 4b02f87..8af4061 100644 --- a/src/pixi/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/pixi/renderers/canvas/utils/CanvasMaskManager.js @@ -12,7 +12,7 @@ PIXI.CanvasMaskManager.prototype.pushMask = function(maskData, context) { context.save(); - + maskData.visible = false; maskData.alpha = 0; diff --git a/src/pixi/renderers/webgl/WebGLRenderer.js b/src/pixi/renderers/webgl/WebGLRenderer.js index 83c2eac..bbbd6b3 100644 --- a/src/pixi/renderers/webgl/WebGLRenderer.js +++ b/src/pixi/renderers/webgl/WebGLRenderer.js @@ -69,14 +69,16 @@ var gl = this.gl; - PIXI.blendModesWebGL = []; + if(!PIXI.blendModesWebGL) + { + PIXI.blendModesWebGL = []; - PIXI.blendModesWebGL[PIXI.blendModes.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.SCREEN] = [gl.SRC_ALPHA, gl.ONE]; + PIXI.blendModesWebGL[PIXI.blendModes.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.SCREEN] = [gl.SRC_ALPHA, gl.ONE]; + } - console.log( PIXI.blendModesWebGL[PIXI.blendModes.SCREEN]) gl.useProgram(PIXI.defaultShader.program); PIXI.WebGLRenderer.gl = gl; @@ -87,13 +89,14 @@ gl.enable(gl.BLEND); gl.colorMask(true, true, true, this.transparent); - PIXI.projection = new PIXI.Point(400, 300); - PIXI.offset = new PIXI.Point(0, 0); - + + this.projection = new PIXI.Point(400, 300); + this.offset = new PIXI.Point(0, 0); + this.resize(this.width, this.height); this.contextLost = false; - this.spriteBatch = new PIXI.WebGLSpriteBatch(gl)//this.gl, PIXI.WebGLRenderer.batchSize); + this.spriteBatch = new PIXI.WebGLSpriteBatch(gl); this.maskManager = new PIXI.WebGLMaskManager(gl); this.filterManager = new PIXI.WebGLFilterManager(this.transparent); @@ -144,19 +147,23 @@ gl.clearColor(stage.backgroundColorSplit[0],stage.backgroundColorSplit[1],stage.backgroundColorSplit[2], !this.transparent); gl.clear(gl.COLOR_BUFFER_BIT); - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; + + this.projection.x = this.width/2; + this.projection.y = -this.height/2; + // reset the render session data.. this.renderSession.drawCount = 0; this.renderSession.currentBlendMode = 9999; - this.renderSession.projection = PIXI.projection; + + this.renderSession.projection = this.projection; + this.renderSession.offset = this.offset; // start the sprite batch this.spriteBatch.begin(this.renderSession); // start the filter manager - this.filterManager.begin(PIXI.projection, null); + this.filterManager.begin(this.renderSession, null); // render the scene! stage._renderWebGL(this.renderSession); @@ -174,6 +181,27 @@ stage.interactionManager.setTarget(this); } } + + //can simulate context loss in Chrome like so: + // this.view.onmousedown = function(ev) { + // console.dir(this.gl.getSupportedExtensions()); + // var ext = ( + // gl.getExtension("WEBGL_scompressed_texture_s3tc") + // // gl.getExtension("WEBGL_compressed_texture_s3tc") || + // // gl.getExtension("MOZ_WEBGL_compressed_texture_s3tc") || + // // gl.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc") + // ); + // console.dir(ext); + + // var loseCtx = this.gl.getExtension("WEBGL_lose_context"); + // console.log("killing context"); + // loseCtx.loseContext(); + + // setTimeout(function() { + // console.log("restoring context..."); + // loseCtx.restoreContext(); + // }.bind(this), 1000); + // }.bind(this); }; /** @@ -292,8 +320,8 @@ this.gl.viewport(0, 0, this.width, this.height); - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; + this.projection.x = this.width/2; + this.projection.y = -this.height/2; }; /** diff --git a/src/pixi/renderers/webgl/utils/WebGLFilterManager.js b/src/pixi/renderers/webgl/utils/WebGLFilterManager.js index 7fffd67..7c81c00 100644 --- a/src/pixi/renderers/webgl/utils/WebGLFilterManager.js +++ b/src/pixi/renderers/webgl/utils/WebGLFilterManager.js @@ -18,8 +18,12 @@ // API -PIXI.WebGLFilterManager.prototype.begin = function(projection, buffer) +PIXI.WebGLFilterManager.prototype.begin = function(renderSession, buffer) { + this.renderSession = renderSession; + + var projection = this.renderSession.projection; + this.width = projection.x * 2; this.height = -projection.y * 2; this.buffer = buffer; @@ -29,6 +33,10 @@ { var gl = PIXI.gl; + var projection = this.renderSession.projection; + var offset = this.renderSession.offset; + + // filter program // OPTIMISATION - the first filter is free if its a simple color change? this.filterStack.push(filterBlock); @@ -53,6 +61,7 @@ this.getBounds(filterBlock.target); filterBlock.target.filterArea = filterBlock.target.getBounds(); + // console.log(filterBlock.target.filterArea); // addpadding? //displayObject.filterArea.x @@ -78,11 +87,11 @@ // set view port gl.viewport(0, 0, filterArea.width, filterArea.height); - PIXI.projection.x = filterArea.width/2; - PIXI.projection.y = -filterArea.height/2; + projection.x = filterArea.width/2; + projection.y = -filterArea.height/2; - PIXI.offset.x = -filterArea.x; - PIXI.offset.y = -filterArea.y; + offset.x = -filterArea.x; + offset.y = -filterArea.y; //console.log(PIXI.defaultShader.projectionVector) // update projection @@ -107,6 +116,8 @@ var filterBlock = this.filterStack.pop(); var filterArea = filterBlock.target.filterArea; var texture = filterBlock._glFilterTexture; + var projection = this.renderSession.projection; + var offset = this.renderSession.offset; if(filterBlock.filterPasses.length > 1) { @@ -209,11 +220,11 @@ // TODO need toremove thease global elements.. - PIXI.projection.x = sizeX/2; - PIXI.projection.y = -sizeY/2; + projection.x = sizeX/2; + projection.y = -sizeY/2; - PIXI.offset.x = offsetX; - PIXI.offset.y = offsetY; + offset.x = offsetX; + offset.y = offsetY; filterArea = filterBlock.target.filterArea; diff --git a/src/pixi/renderers/webgl/utils/WebGLGraphics.js b/src/pixi/renderers/webgl/utils/WebGLGraphics.js index 99877cf..0309ae8 100644 --- a/src/pixi/renderers/webgl/utils/WebGLGraphics.js +++ b/src/pixi/renderers/webgl/utils/WebGLGraphics.js @@ -21,7 +21,7 @@ * @param graphics {Graphics} * @param projection {Object} */ -PIXI.WebGLGraphics.renderGraphics = function(graphics, projection) +PIXI.WebGLGraphics.renderGraphics = function(graphics, projection, offset) { var gl = PIXI.gl; @@ -59,7 +59,7 @@ gl.uniformMatrix3fv(PIXI.primitiveShader.translationMatrix, false, m); gl.uniform2f(PIXI.primitiveShader.projectionVector, projection.x, -projection.y); - gl.uniform2f(PIXI.primitiveShader.offsetVector, -PIXI.offset.x, -PIXI.offset.y); + gl.uniform2f(PIXI.primitiveShader.offsetVector, -offset.x, -offset.y); gl.uniform3fv(PIXI.primitiveShader.tintColor, PIXI.hex2rgb(graphics.tint)); diff --git a/bin/pixi.dev.js b/bin/pixi.dev.js index 12a3c53..3bcf0a8 100644 --- a/bin/pixi.dev.js +++ b/bin/pixi.dev.js @@ -4,7 +4,7 @@ * Copyright (c) 2012, Mat Groves * http://goodboydigital.com/ * - * Compiled: 2013-12-29 + * Compiled: 2013-12-30 * * Pixi.JS is licensed under the MIT License. * http://www.opensource.org/licenses/mit-license.php @@ -1095,6 +1095,7 @@ this.vcount = PIXI.visibleCount; }; + PIXI.DisplayObject.prototype.getBounds = function() { return PIXI.EmptyRectangle; @@ -1395,7 +1396,7 @@ if(this._mask) { renderSession.spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); renderSession.spriteBatch.start(); } @@ -1415,7 +1416,7 @@ renderSession.spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); renderSession.spriteBatch.start(); } @@ -1705,7 +1706,7 @@ if(this._mask) { spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); spriteBatch.start(); } @@ -1729,7 +1730,7 @@ spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); spriteBatch.start(); } @@ -4349,7 +4350,7 @@ * @param graphics {Graphics} * @param projection {Object} */ -PIXI.WebGLGraphics.renderGraphics = function(graphics, projection) +PIXI.WebGLGraphics.renderGraphics = function(graphics, projection, offset) { var gl = PIXI.gl; @@ -4387,7 +4388,7 @@ gl.uniformMatrix3fv(PIXI.primitiveShader.translationMatrix, false, m); gl.uniform2f(PIXI.primitiveShader.projectionVector, projection.x, -projection.y); - gl.uniform2f(PIXI.primitiveShader.offsetVector, -PIXI.offset.x, -PIXI.offset.y); + gl.uniform2f(PIXI.primitiveShader.offsetVector, -offset.x, -offset.y); gl.uniform3fv(PIXI.primitiveShader.tintColor, PIXI.hex2rgb(graphics.tint)); @@ -4924,14 +4925,16 @@ var gl = this.gl; - PIXI.blendModesWebGL = []; + if(!PIXI.blendModesWebGL) + { + PIXI.blendModesWebGL = []; - PIXI.blendModesWebGL[PIXI.blendModes.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.SCREEN] = [gl.SRC_ALPHA, gl.ONE]; + PIXI.blendModesWebGL[PIXI.blendModes.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.SCREEN] = [gl.SRC_ALPHA, gl.ONE]; + } - console.log( PIXI.blendModesWebGL[PIXI.blendModes.SCREEN]) gl.useProgram(PIXI.defaultShader.program); PIXI.WebGLRenderer.gl = gl; @@ -4942,13 +4945,14 @@ gl.enable(gl.BLEND); gl.colorMask(true, true, true, this.transparent); - PIXI.projection = new PIXI.Point(400, 300); - PIXI.offset = new PIXI.Point(0, 0); - + + this.projection = new PIXI.Point(400, 300); + this.offset = new PIXI.Point(0, 0); + this.resize(this.width, this.height); this.contextLost = false; - this.spriteBatch = new PIXI.WebGLSpriteBatch(gl)//this.gl, PIXI.WebGLRenderer.batchSize); + this.spriteBatch = new PIXI.WebGLSpriteBatch(gl); this.maskManager = new PIXI.WebGLMaskManager(gl); this.filterManager = new PIXI.WebGLFilterManager(this.transparent); @@ -4999,19 +5003,23 @@ gl.clearColor(stage.backgroundColorSplit[0],stage.backgroundColorSplit[1],stage.backgroundColorSplit[2], !this.transparent); gl.clear(gl.COLOR_BUFFER_BIT); - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; + + this.projection.x = this.width/2; + this.projection.y = -this.height/2; + // reset the render session data.. this.renderSession.drawCount = 0; this.renderSession.currentBlendMode = 9999; - this.renderSession.projection = PIXI.projection; + + this.renderSession.projection = this.projection; + this.renderSession.offset = this.offset; // start the sprite batch this.spriteBatch.begin(this.renderSession); // start the filter manager - this.filterManager.begin(PIXI.projection, null); + this.filterManager.begin(this.renderSession, null); // render the scene! stage._renderWebGL(this.renderSession); @@ -5029,6 +5037,27 @@ stage.interactionManager.setTarget(this); } } + + //can simulate context loss in Chrome like so: + // this.view.onmousedown = function(ev) { + // console.dir(this.gl.getSupportedExtensions()); + // var ext = ( + // gl.getExtension("WEBGL_scompressed_texture_s3tc") + // // gl.getExtension("WEBGL_compressed_texture_s3tc") || + // // gl.getExtension("MOZ_WEBGL_compressed_texture_s3tc") || + // // gl.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc") + // ); + // console.dir(ext); + + // var loseCtx = this.gl.getExtension("WEBGL_lose_context"); + // console.log("killing context"); + // loseCtx.loseContext(); + + // setTimeout(function() { + // console.log("restoring context..."); + // loseCtx.restoreContext(); + // }.bind(this), 1000); + // }.bind(this); }; /** @@ -5147,8 +5176,8 @@ this.gl.viewport(0, 0, this.width, this.height); - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; + this.projection.x = this.width/2; + this.projection.y = -this.height/2; }; /** @@ -5211,7 +5240,7 @@ this.maskPosition = 0; } -PIXI.WebGLMaskManager.prototype.pushMask = function(maskData, projection) +PIXI.WebGLMaskManager.prototype.pushMask = function(maskData, renderSession) { var gl = this.gl; @@ -5221,19 +5250,21 @@ gl.stencilFunc(gl.ALWAYS,1,1); } + maskData.visible = false; + this.maskStack.push(maskData); gl.colorMask(false, false, false, false); gl.stencilOp(gl.KEEP,gl.KEEP,gl.INCR); - PIXI.WebGLGraphics.renderGraphics(maskData, projection); + PIXI.WebGLGraphics.renderGraphics(maskData, renderSession.projection, renderSession.offset); gl.colorMask(true, true, true, true); gl.stencilFunc(gl.NOTEQUAL,0, this.maskStack.length); gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP); } -PIXI.WebGLMaskManager.prototype.popMask = function(projection) +PIXI.WebGLMaskManager.prototype.popMask = function(renderSession) { var gl = this.gl; @@ -5246,7 +5277,7 @@ //gl.stencilFunc(gl.ALWAYS,1,1); gl.stencilOp(gl.KEEP,gl.KEEP,gl.DECR); - PIXI.WebGLGraphics.renderGraphics(maskData, projection); + PIXI.WebGLGraphics.renderGraphics(maskData, renderSession.projection, renderSession.offset); gl.colorMask(true, true, true, true); gl.stencilFunc(gl.NOTEQUAL,0,this.maskStack.length); @@ -5626,8 +5657,12 @@ // API -PIXI.WebGLFilterManager.prototype.begin = function(projection, buffer) +PIXI.WebGLFilterManager.prototype.begin = function(renderSession, buffer) { + this.renderSession = renderSession; + + var projection = this.renderSession.projection; + this.width = projection.x * 2; this.height = -projection.y * 2; this.buffer = buffer; @@ -5637,6 +5672,10 @@ { var gl = PIXI.gl; + var projection = this.renderSession.projection; + var offset = this.renderSession.offset; + + // filter program // OPTIMISATION - the first filter is free if its a simple color change? this.filterStack.push(filterBlock); @@ -5661,6 +5700,7 @@ this.getBounds(filterBlock.target); filterBlock.target.filterArea = filterBlock.target.getBounds(); + // console.log(filterBlock.target.filterArea); // addpadding? //displayObject.filterArea.x @@ -5686,11 +5726,11 @@ // set view port gl.viewport(0, 0, filterArea.width, filterArea.height); - PIXI.projection.x = filterArea.width/2; - PIXI.projection.y = -filterArea.height/2; + projection.x = filterArea.width/2; + projection.y = -filterArea.height/2; - PIXI.offset.x = -filterArea.x; - PIXI.offset.y = -filterArea.y; + offset.x = -filterArea.x; + offset.y = -filterArea.y; //console.log(PIXI.defaultShader.projectionVector) // update projection @@ -5715,6 +5755,8 @@ var filterBlock = this.filterStack.pop(); var filterArea = filterBlock.target.filterArea; var texture = filterBlock._glFilterTexture; + var projection = this.renderSession.projection; + var offset = this.renderSession.offset; if(filterBlock.filterPasses.length > 1) { @@ -5817,11 +5859,11 @@ // TODO need toremove thease global elements.. - PIXI.projection.x = sizeX/2; - PIXI.projection.y = -sizeY/2; + projection.x = sizeX/2; + projection.y = -sizeY/2; - PIXI.offset.x = offsetX; - PIXI.offset.y = offsetY; + offset.x = offsetX; + offset.y = offsetY; filterArea = filterBlock.target.filterArea; @@ -6151,7 +6193,7 @@ PIXI.CanvasMaskManager.prototype.pushMask = function(maskData, context) { context.save(); - + maskData.visible = false; maskData.alpha = 0; @@ -7153,6 +7195,9 @@ PIXI.Graphics.prototype._renderWebGL = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + renderSession.spriteBatch.stop(); // check blend mode @@ -7163,13 +7208,16 @@ this.spriteBatch.gl.blendFunc(blendModeWebGL[0], blendModeWebGL[1]); } - PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection); + PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection, renderSession.offset); renderSession.spriteBatch.start(); } PIXI.Graphics.prototype._renderCanvas = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + var context = renderSession.context; var transform = this.worldTransform; diff --git a/src/pixi/display/DisplayObject.js b/src/pixi/display/DisplayObject.js index bd09ead..42b44fd 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -401,6 +401,7 @@ this.vcount = PIXI.visibleCount; }; + PIXI.DisplayObject.prototype.getBounds = function() { return PIXI.EmptyRectangle; diff --git a/src/pixi/display/DisplayObjectContainer.js b/src/pixi/display/DisplayObjectContainer.js index 0a8441b..4846abd 100644 --- a/src/pixi/display/DisplayObjectContainer.js +++ b/src/pixi/display/DisplayObjectContainer.js @@ -279,7 +279,7 @@ if(this._mask) { renderSession.spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); renderSession.spriteBatch.start(); } @@ -299,7 +299,7 @@ renderSession.spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); renderSession.spriteBatch.start(); } diff --git a/src/pixi/display/Sprite.js b/src/pixi/display/Sprite.js index 33e59ae..55e77ab 100644 --- a/src/pixi/display/Sprite.js +++ b/src/pixi/display/Sprite.js @@ -252,7 +252,7 @@ if(this._mask) { spriteBatch.stop(); - renderSession.maskManager.pushMask(this.mask, renderSession.projection); + renderSession.maskManager.pushMask(this.mask, renderSession); spriteBatch.start(); } @@ -276,7 +276,7 @@ spriteBatch.stop(); if(this._filters)renderSession.filterManager.popFilter(); - if(this._mask)renderSession.maskManager.popMask(renderSession.projection); + if(this._mask)renderSession.maskManager.popMask(renderSession); spriteBatch.start(); } diff --git a/src/pixi/primitives/Graphics.js b/src/pixi/primitives/Graphics.js index c6142aa..a4dba9e 100644 --- a/src/pixi/primitives/Graphics.js +++ b/src/pixi/primitives/Graphics.js @@ -235,6 +235,9 @@ PIXI.Graphics.prototype._renderWebGL = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + renderSession.spriteBatch.stop(); // check blend mode @@ -245,13 +248,16 @@ this.spriteBatch.gl.blendFunc(blendModeWebGL[0], blendModeWebGL[1]); } - PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection); + PIXI.WebGLGraphics.renderGraphics(this, renderSession.projection, renderSession.offset); renderSession.spriteBatch.start(); } PIXI.Graphics.prototype._renderCanvas = function(renderSession) { + // if the sprite is not visible or the alpha is 0 then no need to render this element + if(this.visible === false || this.alpha === 0)return; + var context = renderSession.context; var transform = this.worldTransform; diff --git a/src/pixi/renderers/canvas/utils/CanvasMaskManager.js b/src/pixi/renderers/canvas/utils/CanvasMaskManager.js index 4b02f87..8af4061 100644 --- a/src/pixi/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/pixi/renderers/canvas/utils/CanvasMaskManager.js @@ -12,7 +12,7 @@ PIXI.CanvasMaskManager.prototype.pushMask = function(maskData, context) { context.save(); - + maskData.visible = false; maskData.alpha = 0; diff --git a/src/pixi/renderers/webgl/WebGLRenderer.js b/src/pixi/renderers/webgl/WebGLRenderer.js index 83c2eac..bbbd6b3 100644 --- a/src/pixi/renderers/webgl/WebGLRenderer.js +++ b/src/pixi/renderers/webgl/WebGLRenderer.js @@ -69,14 +69,16 @@ var gl = this.gl; - PIXI.blendModesWebGL = []; + if(!PIXI.blendModesWebGL) + { + PIXI.blendModesWebGL = []; - PIXI.blendModesWebGL[PIXI.blendModes.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; - PIXI.blendModesWebGL[PIXI.blendModes.SCREEN] = [gl.SRC_ALPHA, gl.ONE]; + PIXI.blendModesWebGL[PIXI.blendModes.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; + PIXI.blendModesWebGL[PIXI.blendModes.SCREEN] = [gl.SRC_ALPHA, gl.ONE]; + } - console.log( PIXI.blendModesWebGL[PIXI.blendModes.SCREEN]) gl.useProgram(PIXI.defaultShader.program); PIXI.WebGLRenderer.gl = gl; @@ -87,13 +89,14 @@ gl.enable(gl.BLEND); gl.colorMask(true, true, true, this.transparent); - PIXI.projection = new PIXI.Point(400, 300); - PIXI.offset = new PIXI.Point(0, 0); - + + this.projection = new PIXI.Point(400, 300); + this.offset = new PIXI.Point(0, 0); + this.resize(this.width, this.height); this.contextLost = false; - this.spriteBatch = new PIXI.WebGLSpriteBatch(gl)//this.gl, PIXI.WebGLRenderer.batchSize); + this.spriteBatch = new PIXI.WebGLSpriteBatch(gl); this.maskManager = new PIXI.WebGLMaskManager(gl); this.filterManager = new PIXI.WebGLFilterManager(this.transparent); @@ -144,19 +147,23 @@ gl.clearColor(stage.backgroundColorSplit[0],stage.backgroundColorSplit[1],stage.backgroundColorSplit[2], !this.transparent); gl.clear(gl.COLOR_BUFFER_BIT); - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; + + this.projection.x = this.width/2; + this.projection.y = -this.height/2; + // reset the render session data.. this.renderSession.drawCount = 0; this.renderSession.currentBlendMode = 9999; - this.renderSession.projection = PIXI.projection; + + this.renderSession.projection = this.projection; + this.renderSession.offset = this.offset; // start the sprite batch this.spriteBatch.begin(this.renderSession); // start the filter manager - this.filterManager.begin(PIXI.projection, null); + this.filterManager.begin(this.renderSession, null); // render the scene! stage._renderWebGL(this.renderSession); @@ -174,6 +181,27 @@ stage.interactionManager.setTarget(this); } } + + //can simulate context loss in Chrome like so: + // this.view.onmousedown = function(ev) { + // console.dir(this.gl.getSupportedExtensions()); + // var ext = ( + // gl.getExtension("WEBGL_scompressed_texture_s3tc") + // // gl.getExtension("WEBGL_compressed_texture_s3tc") || + // // gl.getExtension("MOZ_WEBGL_compressed_texture_s3tc") || + // // gl.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc") + // ); + // console.dir(ext); + + // var loseCtx = this.gl.getExtension("WEBGL_lose_context"); + // console.log("killing context"); + // loseCtx.loseContext(); + + // setTimeout(function() { + // console.log("restoring context..."); + // loseCtx.restoreContext(); + // }.bind(this), 1000); + // }.bind(this); }; /** @@ -292,8 +320,8 @@ this.gl.viewport(0, 0, this.width, this.height); - PIXI.projection.x = this.width/2; - PIXI.projection.y = -this.height/2; + this.projection.x = this.width/2; + this.projection.y = -this.height/2; }; /** diff --git a/src/pixi/renderers/webgl/utils/WebGLFilterManager.js b/src/pixi/renderers/webgl/utils/WebGLFilterManager.js index 7fffd67..7c81c00 100644 --- a/src/pixi/renderers/webgl/utils/WebGLFilterManager.js +++ b/src/pixi/renderers/webgl/utils/WebGLFilterManager.js @@ -18,8 +18,12 @@ // API -PIXI.WebGLFilterManager.prototype.begin = function(projection, buffer) +PIXI.WebGLFilterManager.prototype.begin = function(renderSession, buffer) { + this.renderSession = renderSession; + + var projection = this.renderSession.projection; + this.width = projection.x * 2; this.height = -projection.y * 2; this.buffer = buffer; @@ -29,6 +33,10 @@ { var gl = PIXI.gl; + var projection = this.renderSession.projection; + var offset = this.renderSession.offset; + + // filter program // OPTIMISATION - the first filter is free if its a simple color change? this.filterStack.push(filterBlock); @@ -53,6 +61,7 @@ this.getBounds(filterBlock.target); filterBlock.target.filterArea = filterBlock.target.getBounds(); + // console.log(filterBlock.target.filterArea); // addpadding? //displayObject.filterArea.x @@ -78,11 +87,11 @@ // set view port gl.viewport(0, 0, filterArea.width, filterArea.height); - PIXI.projection.x = filterArea.width/2; - PIXI.projection.y = -filterArea.height/2; + projection.x = filterArea.width/2; + projection.y = -filterArea.height/2; - PIXI.offset.x = -filterArea.x; - PIXI.offset.y = -filterArea.y; + offset.x = -filterArea.x; + offset.y = -filterArea.y; //console.log(PIXI.defaultShader.projectionVector) // update projection @@ -107,6 +116,8 @@ var filterBlock = this.filterStack.pop(); var filterArea = filterBlock.target.filterArea; var texture = filterBlock._glFilterTexture; + var projection = this.renderSession.projection; + var offset = this.renderSession.offset; if(filterBlock.filterPasses.length > 1) { @@ -209,11 +220,11 @@ // TODO need toremove thease global elements.. - PIXI.projection.x = sizeX/2; - PIXI.projection.y = -sizeY/2; + projection.x = sizeX/2; + projection.y = -sizeY/2; - PIXI.offset.x = offsetX; - PIXI.offset.y = offsetY; + offset.x = offsetX; + offset.y = offsetY; filterArea = filterBlock.target.filterArea; diff --git a/src/pixi/renderers/webgl/utils/WebGLGraphics.js b/src/pixi/renderers/webgl/utils/WebGLGraphics.js index 99877cf..0309ae8 100644 --- a/src/pixi/renderers/webgl/utils/WebGLGraphics.js +++ b/src/pixi/renderers/webgl/utils/WebGLGraphics.js @@ -21,7 +21,7 @@ * @param graphics {Graphics} * @param projection {Object} */ -PIXI.WebGLGraphics.renderGraphics = function(graphics, projection) +PIXI.WebGLGraphics.renderGraphics = function(graphics, projection, offset) { var gl = PIXI.gl; @@ -59,7 +59,7 @@ gl.uniformMatrix3fv(PIXI.primitiveShader.translationMatrix, false, m); gl.uniform2f(PIXI.primitiveShader.projectionVector, projection.x, -projection.y); - gl.uniform2f(PIXI.primitiveShader.offsetVector, -PIXI.offset.x, -PIXI.offset.y); + gl.uniform2f(PIXI.primitiveShader.offsetVector, -offset.x, -offset.y); gl.uniform3fv(PIXI.primitiveShader.tintColor, PIXI.hex2rgb(graphics.tint)); diff --git a/src/pixi/renderers/webgl/utils/WebGLMaskManager.js b/src/pixi/renderers/webgl/utils/WebGLMaskManager.js index 38b0661..43e7342 100644 --- a/src/pixi/renderers/webgl/utils/WebGLMaskManager.js +++ b/src/pixi/renderers/webgl/utils/WebGLMaskManager.js @@ -12,7 +12,7 @@ this.maskPosition = 0; } -PIXI.WebGLMaskManager.prototype.pushMask = function(maskData, projection) +PIXI.WebGLMaskManager.prototype.pushMask = function(maskData, renderSession) { var gl = this.gl; @@ -22,19 +22,21 @@ gl.stencilFunc(gl.ALWAYS,1,1); } + maskData.visible = false; + this.maskStack.push(maskData); gl.colorMask(false, false, false, false); gl.stencilOp(gl.KEEP,gl.KEEP,gl.INCR); - PIXI.WebGLGraphics.renderGraphics(maskData, projection); + PIXI.WebGLGraphics.renderGraphics(maskData, renderSession.projection, renderSession.offset); gl.colorMask(true, true, true, true); gl.stencilFunc(gl.NOTEQUAL,0, this.maskStack.length); gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP); } -PIXI.WebGLMaskManager.prototype.popMask = function(projection) +PIXI.WebGLMaskManager.prototype.popMask = function(renderSession) { var gl = this.gl; @@ -47,7 +49,7 @@ //gl.stencilFunc(gl.ALWAYS,1,1); gl.stencilOp(gl.KEEP,gl.KEEP,gl.DECR); - PIXI.WebGLGraphics.renderGraphics(maskData, projection); + PIXI.WebGLGraphics.renderGraphics(maskData, renderSession.projection, renderSession.offset); gl.colorMask(true, true, true, true); gl.stencilFunc(gl.NOTEQUAL,0,this.maskStack.length);