diff --git a/src/core/display/Container.js b/src/core/display/Container.js index a9afea0..fef5ef9 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -398,6 +398,8 @@ { this.children[i].updateTransform(); } + + this._currentBounds = null; }; // performance increase to avoid using call.. (10x faster) diff --git a/src/core/display/Container.js b/src/core/display/Container.js index a9afea0..fef5ef9 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -398,6 +398,8 @@ { this.children[i].updateTransform(); } + + this._currentBounds = null; }; // performance increase to avoid using call.. (10x faster) diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index a22781c..f112b5e 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -275,9 +275,9 @@ // fill in here.. } -WebGLRenderer.prototype.clear = function () +WebGLRenderer.prototype.clear = function (clearColor) { - this._activeRenderTarget.clear(); + this._activeRenderTarget.clear(clearColor); } //TOOD - required? diff --git a/src/core/display/Container.js b/src/core/display/Container.js index a9afea0..fef5ef9 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -398,6 +398,8 @@ { this.children[i].updateTransform(); } + + this._currentBounds = null; }; // performance increase to avoid using call.. (10x faster) diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index a22781c..f112b5e 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -275,9 +275,9 @@ // fill in here.. } -WebGLRenderer.prototype.clear = function () +WebGLRenderer.prototype.clear = function (clearColor) { - this._activeRenderTarget.clear(); + this._activeRenderTarget.clear(clearColor); } //TOOD - required? diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 0cc04a5..765e993 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -42,7 +42,10 @@ // this.uniforms = // this is where we store shader references.. // TODO we could cache this! - this.glShaders = []; + this.glShaders = []; + this.resolution = 1; + + //this.canBeUsedDirectl } // constructor diff --git a/src/core/display/Container.js b/src/core/display/Container.js index a9afea0..fef5ef9 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -398,6 +398,8 @@ { this.children[i].updateTransform(); } + + this._currentBounds = null; }; // performance increase to avoid using call.. (10x faster) diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index a22781c..f112b5e 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -275,9 +275,9 @@ // fill in here.. } -WebGLRenderer.prototype.clear = function () +WebGLRenderer.prototype.clear = function (clearColor) { - this._activeRenderTarget.clear(); + this._activeRenderTarget.clear(clearColor); } //TOOD - required? diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 0cc04a5..765e993 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -42,7 +42,10 @@ // this.uniforms = // this is where we store shader references.. // TODO we could cache this! - this.glShaders = []; + this.glShaders = []; + this.resolution = 1; + + //this.canBeUsedDirectl } // constructor diff --git a/src/core/renderers/webgl/managers/FilterManagerRoundTwo.js b/src/core/renderers/webgl/managers/FilterManagerRoundTwo.js index efa8173..0281a38 100644 --- a/src/core/renderers/webgl/managers/FilterManagerRoundTwo.js +++ b/src/core/renderers/webgl/managers/FilterManagerRoundTwo.js @@ -37,13 +37,20 @@ FilterManager.prototype.pushFilter = function(target, filters) { + var resolution = filters[0].resolution; - var bounds = target.getBounds(); - bounds.pad(4); + var bounds = target.getBounds().clone(); + + //TODO - should this be rounded to reoultion? not 1? + bounds.x = bounds.x | 0; + bounds.y = bounds.y | 0; + bounds.width = bounds.width | 0; + bounds.height = bounds.height | 0; + bounds.pad(4 / resolution); bounds.fit(new PIXI.Rectangle(0,0,800, 800)) //TODO - output.size? - var renderTarget = FilterManager.getPotRenderTarget(this.renderer.gl, bounds.width, bounds.height); - + var renderTarget = FilterManager.getPotRenderTarget(this.renderer.gl, bounds.width, bounds.height, resolution); + this.stackIndex++; if(!this.stack[this.stackIndex]) @@ -100,6 +107,12 @@ } this.renderer.bindRenderTarget(output); + + if(clear) + { + this.renderer.clear(); + } + this.renderer.bindShader(shader); this.syncUniforms(shader, filter); @@ -208,22 +221,34 @@ } //TODO move to a seperate class could be on renderer? -FilterManager.getPotRenderTarget = function(gl, minWidth, minHeight) +FilterManager.getPotRenderTarget = function(gl, minWidth, minHeight, resolution) { //TODO you coud return a bigger texture if there is not one in the pool? - minWidth = utils.getNextPowerOfTwo(minWidth); - minHeight = utils.getNextPowerOfTwo(minHeight); - + minWidth = utils.getNextPowerOfTwo(minWidth * resolution) | 0; + minHeight = utils.getNextPowerOfTwo(minHeight * resolution) | 0; + var key = ((minWidth & 0xFFFF) << 16) | ( minHeight & 0xFFFF); if(!FilterManager.pool[key])FilterManager.pool[key] = []; - return FilterManager.pool[key].pop() || new RenderTarget(gl, minWidth, minHeight); + var renderTarget = FilterManager.pool[key].pop() || new RenderTarget(gl, minWidth, minHeight, null, 1); + + + //manually tweak the resolution... + //this will not modify the size of the frame buffer, just its resolution. + renderTarget.resolution = resolution; + renderTarget.defaultFrame.width = renderTarget.size.width = minWidth / resolution; + renderTarget.defaultFrame.height = renderTarget.size.height = minHeight / resolution; + + return renderTarget; } FilterManager.freePotRenderTarget = function(renderTarget) { - var key = ((renderTarget.size.width & 0xFFFF) << 16) | ( renderTarget.size.height & 0xFFFF); + var minWidth = renderTarget.size.width * renderTarget.resolution; + var minHeight = renderTarget.size.height * renderTarget.resolution; + + var key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); FilterManager.pool[key].push(renderTarget) } diff --git a/src/core/display/Container.js b/src/core/display/Container.js index a9afea0..fef5ef9 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -398,6 +398,8 @@ { this.children[i].updateTransform(); } + + this._currentBounds = null; }; // performance increase to avoid using call.. (10x faster) diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index a22781c..f112b5e 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -275,9 +275,9 @@ // fill in here.. } -WebGLRenderer.prototype.clear = function () +WebGLRenderer.prototype.clear = function (clearColor) { - this._activeRenderTarget.clear(); + this._activeRenderTarget.clear(clearColor); } //TOOD - required? diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 0cc04a5..765e993 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -42,7 +42,10 @@ // this.uniforms = // this is where we store shader references.. // TODO we could cache this! - this.glShaders = []; + this.glShaders = []; + this.resolution = 1; + + //this.canBeUsedDirectl } // constructor diff --git a/src/core/renderers/webgl/managers/FilterManagerRoundTwo.js b/src/core/renderers/webgl/managers/FilterManagerRoundTwo.js index efa8173..0281a38 100644 --- a/src/core/renderers/webgl/managers/FilterManagerRoundTwo.js +++ b/src/core/renderers/webgl/managers/FilterManagerRoundTwo.js @@ -37,13 +37,20 @@ FilterManager.prototype.pushFilter = function(target, filters) { + var resolution = filters[0].resolution; - var bounds = target.getBounds(); - bounds.pad(4); + var bounds = target.getBounds().clone(); + + //TODO - should this be rounded to reoultion? not 1? + bounds.x = bounds.x | 0; + bounds.y = bounds.y | 0; + bounds.width = bounds.width | 0; + bounds.height = bounds.height | 0; + bounds.pad(4 / resolution); bounds.fit(new PIXI.Rectangle(0,0,800, 800)) //TODO - output.size? - var renderTarget = FilterManager.getPotRenderTarget(this.renderer.gl, bounds.width, bounds.height); - + var renderTarget = FilterManager.getPotRenderTarget(this.renderer.gl, bounds.width, bounds.height, resolution); + this.stackIndex++; if(!this.stack[this.stackIndex]) @@ -100,6 +107,12 @@ } this.renderer.bindRenderTarget(output); + + if(clear) + { + this.renderer.clear(); + } + this.renderer.bindShader(shader); this.syncUniforms(shader, filter); @@ -208,22 +221,34 @@ } //TODO move to a seperate class could be on renderer? -FilterManager.getPotRenderTarget = function(gl, minWidth, minHeight) +FilterManager.getPotRenderTarget = function(gl, minWidth, minHeight, resolution) { //TODO you coud return a bigger texture if there is not one in the pool? - minWidth = utils.getNextPowerOfTwo(minWidth); - minHeight = utils.getNextPowerOfTwo(minHeight); - + minWidth = utils.getNextPowerOfTwo(minWidth * resolution) | 0; + minHeight = utils.getNextPowerOfTwo(minHeight * resolution) | 0; + var key = ((minWidth & 0xFFFF) << 16) | ( minHeight & 0xFFFF); if(!FilterManager.pool[key])FilterManager.pool[key] = []; - return FilterManager.pool[key].pop() || new RenderTarget(gl, minWidth, minHeight); + var renderTarget = FilterManager.pool[key].pop() || new RenderTarget(gl, minWidth, minHeight, null, 1); + + + //manually tweak the resolution... + //this will not modify the size of the frame buffer, just its resolution. + renderTarget.resolution = resolution; + renderTarget.defaultFrame.width = renderTarget.size.width = minWidth / resolution; + renderTarget.defaultFrame.height = renderTarget.size.height = minHeight / resolution; + + return renderTarget; } FilterManager.freePotRenderTarget = function(renderTarget) { - var key = ((renderTarget.size.width & 0xFFFF) << 16) | ( renderTarget.size.height & 0xFFFF); + var minWidth = renderTarget.size.width * renderTarget.resolution; + var minHeight = renderTarget.size.height * renderTarget.resolution; + + var key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); FilterManager.pool[key].push(renderTarget) } diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index e9df73b..b42b0c0 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -213,7 +213,7 @@ if(this.destinationFrame !== this.sourceFrame) { gl.enable(gl.SCISSOR_TEST); - gl.scissor(this.destinationFrame.x,0, this.destinationFrame.width* this.resolution, this.destinationFrame.height* this.resolution); + gl.scissor(this.destinationFrame.x | 0,this.destinationFrame.y | 0, (this.destinationFrame.width * this.resolution) | 0, (this.destinationFrame.height* this.resolution) | 0); } else { @@ -222,7 +222,7 @@ // TODO - does not need to be updated all the time?? - gl.viewport(this.destinationFrame.x,this.destinationFrame.y, this.destinationFrame.width * this.resolution, this.destinationFrame.height * this.resolution); + gl.viewport(this.destinationFrame.x | 0,this.destinationFrame.y | 0, (this.destinationFrame.width * this.resolution) | 0, (this.destinationFrame.height * this.resolution)|0); }; diff --git a/src/core/display/Container.js b/src/core/display/Container.js index a9afea0..fef5ef9 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -398,6 +398,8 @@ { this.children[i].updateTransform(); } + + this._currentBounds = null; }; // performance increase to avoid using call.. (10x faster) diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index a22781c..f112b5e 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -275,9 +275,9 @@ // fill in here.. } -WebGLRenderer.prototype.clear = function () +WebGLRenderer.prototype.clear = function (clearColor) { - this._activeRenderTarget.clear(); + this._activeRenderTarget.clear(clearColor); } //TOOD - required? diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 0cc04a5..765e993 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -42,7 +42,10 @@ // this.uniforms = // this is where we store shader references.. // TODO we could cache this! - this.glShaders = []; + this.glShaders = []; + this.resolution = 1; + + //this.canBeUsedDirectl } // constructor diff --git a/src/core/renderers/webgl/managers/FilterManagerRoundTwo.js b/src/core/renderers/webgl/managers/FilterManagerRoundTwo.js index efa8173..0281a38 100644 --- a/src/core/renderers/webgl/managers/FilterManagerRoundTwo.js +++ b/src/core/renderers/webgl/managers/FilterManagerRoundTwo.js @@ -37,13 +37,20 @@ FilterManager.prototype.pushFilter = function(target, filters) { + var resolution = filters[0].resolution; - var bounds = target.getBounds(); - bounds.pad(4); + var bounds = target.getBounds().clone(); + + //TODO - should this be rounded to reoultion? not 1? + bounds.x = bounds.x | 0; + bounds.y = bounds.y | 0; + bounds.width = bounds.width | 0; + bounds.height = bounds.height | 0; + bounds.pad(4 / resolution); bounds.fit(new PIXI.Rectangle(0,0,800, 800)) //TODO - output.size? - var renderTarget = FilterManager.getPotRenderTarget(this.renderer.gl, bounds.width, bounds.height); - + var renderTarget = FilterManager.getPotRenderTarget(this.renderer.gl, bounds.width, bounds.height, resolution); + this.stackIndex++; if(!this.stack[this.stackIndex]) @@ -100,6 +107,12 @@ } this.renderer.bindRenderTarget(output); + + if(clear) + { + this.renderer.clear(); + } + this.renderer.bindShader(shader); this.syncUniforms(shader, filter); @@ -208,22 +221,34 @@ } //TODO move to a seperate class could be on renderer? -FilterManager.getPotRenderTarget = function(gl, minWidth, minHeight) +FilterManager.getPotRenderTarget = function(gl, minWidth, minHeight, resolution) { //TODO you coud return a bigger texture if there is not one in the pool? - minWidth = utils.getNextPowerOfTwo(minWidth); - minHeight = utils.getNextPowerOfTwo(minHeight); - + minWidth = utils.getNextPowerOfTwo(minWidth * resolution) | 0; + minHeight = utils.getNextPowerOfTwo(minHeight * resolution) | 0; + var key = ((minWidth & 0xFFFF) << 16) | ( minHeight & 0xFFFF); if(!FilterManager.pool[key])FilterManager.pool[key] = []; - return FilterManager.pool[key].pop() || new RenderTarget(gl, minWidth, minHeight); + var renderTarget = FilterManager.pool[key].pop() || new RenderTarget(gl, minWidth, minHeight, null, 1); + + + //manually tweak the resolution... + //this will not modify the size of the frame buffer, just its resolution. + renderTarget.resolution = resolution; + renderTarget.defaultFrame.width = renderTarget.size.width = minWidth / resolution; + renderTarget.defaultFrame.height = renderTarget.size.height = minHeight / resolution; + + return renderTarget; } FilterManager.freePotRenderTarget = function(renderTarget) { - var key = ((renderTarget.size.width & 0xFFFF) << 16) | ( renderTarget.size.height & 0xFFFF); + var minWidth = renderTarget.size.width * renderTarget.resolution; + var minHeight = renderTarget.size.height * renderTarget.resolution; + + var key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); FilterManager.pool[key].push(renderTarget) } diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index e9df73b..b42b0c0 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -213,7 +213,7 @@ if(this.destinationFrame !== this.sourceFrame) { gl.enable(gl.SCISSOR_TEST); - gl.scissor(this.destinationFrame.x,0, this.destinationFrame.width* this.resolution, this.destinationFrame.height* this.resolution); + gl.scissor(this.destinationFrame.x | 0,this.destinationFrame.y | 0, (this.destinationFrame.width * this.resolution) | 0, (this.destinationFrame.height* this.resolution) | 0); } else { @@ -222,7 +222,7 @@ // TODO - does not need to be updated all the time?? - gl.viewport(this.destinationFrame.x,this.destinationFrame.y, this.destinationFrame.width * this.resolution, this.destinationFrame.height * this.resolution); + gl.viewport(this.destinationFrame.x | 0,this.destinationFrame.y | 0, (this.destinationFrame.width * this.resolution) | 0, (this.destinationFrame.height * this.resolution)|0); }; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 9531bed..b174736 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -276,7 +276,7 @@ Sprite.prototype.getBounds = function (matrix) { //TODO lookinto caching.. - //if(!this._currentBounds) + if(!this._currentBounds) { // if(this.vertexDirty) {