diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 30c80e1..b998aef 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -132,6 +132,7 @@ { var renderTarget = this.texturePool.pop() || new RenderTarget(this.renderer.gl, this.textureSize.width, this.textureSize.height); renderTarget.frame = this.currentFrame; + return renderTarget; }; @@ -140,12 +141,17 @@ this.texturePool.push( renderTarget ); }; -FilterManager.prototype.applyFilter = function (shader, inputTarget, outputTarget) +FilterManager.prototype.applyFilter = function (shader, inputTarget, outputTarget, clear) { var gl = this.renderer.gl; this.renderer.setRenderTarget( outputTarget ); + if(clear) + { + outputTarget.clear(); + } + // set the shader this.renderer.shaderManager.setShader(shader); @@ -162,45 +168,13 @@ gl.bindTexture(gl.TEXTURE_2D, inputTarget.texture); gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 ); - - - // var m = this.calculateMappedMatrix(inputTarget.frame, this.__TEMP__) - -// gl.uniformMatrix3fv(shader.uniforms.projectionMatrix._location, false, this.renderer.currentRenderTarget.projectionMatrix.toArray(true)); - // gl.uniformMatrix3fv(shader.uniforms.otherMatrix._location, false, m.toArray(true)); -/* - /// custom // - this.textureCount = 1; - gl.activeTexture(gl.TEXTURE1); - - var maskTexture = shader.uniforms.mask.value.baseTexture; - - if (!maskTexture._glTextures[gl.id]) - { - this.renderer.updateTexture(maskTexture); - } - else - { - // bind the texture - gl.bindTexture(gl.TEXTURE_2D, shader.uniforms.mask.value.baseTexture._glTextures[gl.id]); - } - - // set uniform to texture index - gl.uniform1i(shader.uniforms.mask._location, 1); - - // increment next texture id - this.textureCount++; - -*/ - - }; // TODO playing around here.. this is temporary - (will end up in the shader) FilterManager.prototype.calculateMappedMatrix = function (filterArea, sprite, outputMatrix) { - worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX); + var worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite.texture.baseTexture; var mappedMatrix = outputMatrix.identity(); diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 30c80e1..b998aef 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -132,6 +132,7 @@ { var renderTarget = this.texturePool.pop() || new RenderTarget(this.renderer.gl, this.textureSize.width, this.textureSize.height); renderTarget.frame = this.currentFrame; + return renderTarget; }; @@ -140,12 +141,17 @@ this.texturePool.push( renderTarget ); }; -FilterManager.prototype.applyFilter = function (shader, inputTarget, outputTarget) +FilterManager.prototype.applyFilter = function (shader, inputTarget, outputTarget, clear) { var gl = this.renderer.gl; this.renderer.setRenderTarget( outputTarget ); + if(clear) + { + outputTarget.clear(); + } + // set the shader this.renderer.shaderManager.setShader(shader); @@ -162,45 +168,13 @@ gl.bindTexture(gl.TEXTURE_2D, inputTarget.texture); gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 ); - - - // var m = this.calculateMappedMatrix(inputTarget.frame, this.__TEMP__) - -// gl.uniformMatrix3fv(shader.uniforms.projectionMatrix._location, false, this.renderer.currentRenderTarget.projectionMatrix.toArray(true)); - // gl.uniformMatrix3fv(shader.uniforms.otherMatrix._location, false, m.toArray(true)); -/* - /// custom // - this.textureCount = 1; - gl.activeTexture(gl.TEXTURE1); - - var maskTexture = shader.uniforms.mask.value.baseTexture; - - if (!maskTexture._glTextures[gl.id]) - { - this.renderer.updateTexture(maskTexture); - } - else - { - // bind the texture - gl.bindTexture(gl.TEXTURE_2D, shader.uniforms.mask.value.baseTexture._glTextures[gl.id]); - } - - // set uniform to texture index - gl.uniform1i(shader.uniforms.mask._location, 1); - - // increment next texture id - this.textureCount++; - -*/ - - }; // TODO playing around here.. this is temporary - (will end up in the shader) FilterManager.prototype.calculateMappedMatrix = function (filterArea, sprite, outputMatrix) { - worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX); + var worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite.texture.baseTexture; var mappedMatrix = outputMatrix.identity(); diff --git a/src/core/renderers/webgl/utils/AbstractFilter.js b/src/core/renderers/webgl/utils/AbstractFilter.js index 8ec3947..c440914 100644 --- a/src/core/renderers/webgl/utils/AbstractFilter.js +++ b/src/core/renderers/webgl/utils/AbstractFilter.js @@ -75,13 +75,13 @@ return shader; }; -AbstractFilter.prototype.applyFilter = function (renderer, input, output) +AbstractFilter.prototype.applyFilter = function (renderer, input, output, clear) { var filterManager = renderer.filterManager, shader = this.getShader(renderer); // draw the filter... - filterManager.applyFilter(shader, input, output); + filterManager.applyFilter(shader, input, output, clear); }; /** diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 30c80e1..b998aef 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -132,6 +132,7 @@ { var renderTarget = this.texturePool.pop() || new RenderTarget(this.renderer.gl, this.textureSize.width, this.textureSize.height); renderTarget.frame = this.currentFrame; + return renderTarget; }; @@ -140,12 +141,17 @@ this.texturePool.push( renderTarget ); }; -FilterManager.prototype.applyFilter = function (shader, inputTarget, outputTarget) +FilterManager.prototype.applyFilter = function (shader, inputTarget, outputTarget, clear) { var gl = this.renderer.gl; this.renderer.setRenderTarget( outputTarget ); + if(clear) + { + outputTarget.clear(); + } + // set the shader this.renderer.shaderManager.setShader(shader); @@ -162,45 +168,13 @@ gl.bindTexture(gl.TEXTURE_2D, inputTarget.texture); gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 ); - - - // var m = this.calculateMappedMatrix(inputTarget.frame, this.__TEMP__) - -// gl.uniformMatrix3fv(shader.uniforms.projectionMatrix._location, false, this.renderer.currentRenderTarget.projectionMatrix.toArray(true)); - // gl.uniformMatrix3fv(shader.uniforms.otherMatrix._location, false, m.toArray(true)); -/* - /// custom // - this.textureCount = 1; - gl.activeTexture(gl.TEXTURE1); - - var maskTexture = shader.uniforms.mask.value.baseTexture; - - if (!maskTexture._glTextures[gl.id]) - { - this.renderer.updateTexture(maskTexture); - } - else - { - // bind the texture - gl.bindTexture(gl.TEXTURE_2D, shader.uniforms.mask.value.baseTexture._glTextures[gl.id]); - } - - // set uniform to texture index - gl.uniform1i(shader.uniforms.mask._location, 1); - - // increment next texture id - this.textureCount++; - -*/ - - }; // TODO playing around here.. this is temporary - (will end up in the shader) FilterManager.prototype.calculateMappedMatrix = function (filterArea, sprite, outputMatrix) { - worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX); + var worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite.texture.baseTexture; var mappedMatrix = outputMatrix.identity(); diff --git a/src/core/renderers/webgl/utils/AbstractFilter.js b/src/core/renderers/webgl/utils/AbstractFilter.js index 8ec3947..c440914 100644 --- a/src/core/renderers/webgl/utils/AbstractFilter.js +++ b/src/core/renderers/webgl/utils/AbstractFilter.js @@ -75,13 +75,13 @@ return shader; }; -AbstractFilter.prototype.applyFilter = function (renderer, input, output) +AbstractFilter.prototype.applyFilter = function (renderer, input, output, clear) { var filterManager = renderer.filterManager, shader = this.getShader(renderer); // draw the filter... - filterManager.applyFilter(shader, input, output); + filterManager.applyFilter(shader, input, output, clear); }; /** diff --git a/src/filters/BloomFilter.js b/src/filters/BloomFilter.js index 32f46e6..605f6f2 100644 --- a/src/filters/BloomFilter.js +++ b/src/filters/BloomFilter.js @@ -33,7 +33,7 @@ this.defaultFilter.applyFilter(renderer, input, output); - this.blurXFilter.applyFilter(renderer, input, renderTarget); + this.blurXFilter.applyFilter(renderer, input, renderTarget, true); renderer.blendModeManager.setBlendMode( CONST.blendModes.SCREEN ); diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 30c80e1..b998aef 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -132,6 +132,7 @@ { var renderTarget = this.texturePool.pop() || new RenderTarget(this.renderer.gl, this.textureSize.width, this.textureSize.height); renderTarget.frame = this.currentFrame; + return renderTarget; }; @@ -140,12 +141,17 @@ this.texturePool.push( renderTarget ); }; -FilterManager.prototype.applyFilter = function (shader, inputTarget, outputTarget) +FilterManager.prototype.applyFilter = function (shader, inputTarget, outputTarget, clear) { var gl = this.renderer.gl; this.renderer.setRenderTarget( outputTarget ); + if(clear) + { + outputTarget.clear(); + } + // set the shader this.renderer.shaderManager.setShader(shader); @@ -162,45 +168,13 @@ gl.bindTexture(gl.TEXTURE_2D, inputTarget.texture); gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 ); - - - // var m = this.calculateMappedMatrix(inputTarget.frame, this.__TEMP__) - -// gl.uniformMatrix3fv(shader.uniforms.projectionMatrix._location, false, this.renderer.currentRenderTarget.projectionMatrix.toArray(true)); - // gl.uniformMatrix3fv(shader.uniforms.otherMatrix._location, false, m.toArray(true)); -/* - /// custom // - this.textureCount = 1; - gl.activeTexture(gl.TEXTURE1); - - var maskTexture = shader.uniforms.mask.value.baseTexture; - - if (!maskTexture._glTextures[gl.id]) - { - this.renderer.updateTexture(maskTexture); - } - else - { - // bind the texture - gl.bindTexture(gl.TEXTURE_2D, shader.uniforms.mask.value.baseTexture._glTextures[gl.id]); - } - - // set uniform to texture index - gl.uniform1i(shader.uniforms.mask._location, 1); - - // increment next texture id - this.textureCount++; - -*/ - - }; // TODO playing around here.. this is temporary - (will end up in the shader) FilterManager.prototype.calculateMappedMatrix = function (filterArea, sprite, outputMatrix) { - worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX); + var worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite.texture.baseTexture; var mappedMatrix = outputMatrix.identity(); diff --git a/src/core/renderers/webgl/utils/AbstractFilter.js b/src/core/renderers/webgl/utils/AbstractFilter.js index 8ec3947..c440914 100644 --- a/src/core/renderers/webgl/utils/AbstractFilter.js +++ b/src/core/renderers/webgl/utils/AbstractFilter.js @@ -75,13 +75,13 @@ return shader; }; -AbstractFilter.prototype.applyFilter = function (renderer, input, output) +AbstractFilter.prototype.applyFilter = function (renderer, input, output, clear) { var filterManager = renderer.filterManager, shader = this.getShader(renderer); // draw the filter... - filterManager.applyFilter(shader, input, output); + filterManager.applyFilter(shader, input, output, clear); }; /** diff --git a/src/filters/BloomFilter.js b/src/filters/BloomFilter.js index 32f46e6..605f6f2 100644 --- a/src/filters/BloomFilter.js +++ b/src/filters/BloomFilter.js @@ -33,7 +33,7 @@ this.defaultFilter.applyFilter(renderer, input, output); - this.blurXFilter.applyFilter(renderer, input, renderTarget); + this.blurXFilter.applyFilter(renderer, input, renderTarget, true); renderer.blendModeManager.setBlendMode( CONST.blendModes.SCREEN ); diff --git a/src/filters/GrayFilter.js b/src/filters/GrayFilter.js index 380d165..7bdf651 100644 --- a/src/filters/GrayFilter.js +++ b/src/filters/GrayFilter.js @@ -10,6 +10,8 @@ function GrayFilter() { AbstractFilter.call(this, + null, + // fragment [ 'precision mediump float;',