diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index ced29a2..0896b88 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -35,8 +35,8 @@ */ this.texture = null - this.width = width; - this.height = height; + this.width = 0; + this.height = 0; this.resolution = 1; @@ -54,14 +54,7 @@ if(!this.root) { - this.flipY = true; - - this.projectionMatrix.a = 1/width*2; - this.projectionMatrix.d = 1/height*2; - - this.projectionMatrix.tx = -1; - this.projectionMatrix.ty = -1; - + // this.flipY = true; this.frameBuffer = gl.createFramebuffer(); @@ -79,10 +72,12 @@ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, scaleMode === CONST.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - + gl.bindFramebuffer(gl.FRAMEBUFFER, this.frameBuffer ); gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.texture, 0); + + /* The stencil buffer is used for masking in pixi lets create one and then add attach it to the framebuffer.. @@ -91,16 +86,9 @@ gl.bindRenderbuffer(gl.RENDERBUFFER, this.stencilBuffer); gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, this.stencilBuffer); } - else - { - this.projectionMatrix.a = 1/width*2; - this.projectionMatrix.d = -1/height*2; - this.projectionMatrix.tx = -1; - this.projectionMatrix.ty = 1; - - - } + this.resize(width, height); + }; RenderTarget.prototype.constructor = RenderTarget; @@ -140,27 +128,21 @@ this.projectionMatrix = new math.Matrix(); - this.projectionMatrix.a = 1/width*2; - this.projectionMatrix.d = -1/height*2; - - this.projectionMatrix.tx = -1; - this.projectionMatrix.ty = 1; - if(!this.root) { var gl = this.gl; this.projectionMatrix.a = 1/width*2; - this.projectionMatrix.d = 1/height*2; + this.projectionMatrix.d = -1/height*2; this.projectionMatrix.tx = -1; - this.projectionMatrix.ty = -1; - + this.projectionMatrix.ty = 1; + gl.bindTexture(gl.TEXTURE_2D, this.texture); gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width , height , 0, gl.RGBA, gl.UNSIGNED_BYTE, null); // update the stencil buffer width and height - gl.bindRenderbuffer(gl.RENDERBUFFER, this.renderBuffer); + gl.bindRenderbuffer(gl.RENDERBUFFER, this.stencilBuffer); gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, width , height ); } else diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index ced29a2..0896b88 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -35,8 +35,8 @@ */ this.texture = null - this.width = width; - this.height = height; + this.width = 0; + this.height = 0; this.resolution = 1; @@ -54,14 +54,7 @@ if(!this.root) { - this.flipY = true; - - this.projectionMatrix.a = 1/width*2; - this.projectionMatrix.d = 1/height*2; - - this.projectionMatrix.tx = -1; - this.projectionMatrix.ty = -1; - + // this.flipY = true; this.frameBuffer = gl.createFramebuffer(); @@ -79,10 +72,12 @@ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, scaleMode === CONST.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - + gl.bindFramebuffer(gl.FRAMEBUFFER, this.frameBuffer ); gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.texture, 0); + + /* The stencil buffer is used for masking in pixi lets create one and then add attach it to the framebuffer.. @@ -91,16 +86,9 @@ gl.bindRenderbuffer(gl.RENDERBUFFER, this.stencilBuffer); gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, this.stencilBuffer); } - else - { - this.projectionMatrix.a = 1/width*2; - this.projectionMatrix.d = -1/height*2; - this.projectionMatrix.tx = -1; - this.projectionMatrix.ty = 1; - - - } + this.resize(width, height); + }; RenderTarget.prototype.constructor = RenderTarget; @@ -140,27 +128,21 @@ this.projectionMatrix = new math.Matrix(); - this.projectionMatrix.a = 1/width*2; - this.projectionMatrix.d = -1/height*2; - - this.projectionMatrix.tx = -1; - this.projectionMatrix.ty = 1; - if(!this.root) { var gl = this.gl; this.projectionMatrix.a = 1/width*2; - this.projectionMatrix.d = 1/height*2; + this.projectionMatrix.d = -1/height*2; this.projectionMatrix.tx = -1; - this.projectionMatrix.ty = -1; - + this.projectionMatrix.ty = 1; + gl.bindTexture(gl.TEXTURE_2D, this.texture); gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width , height , 0, gl.RGBA, gl.UNSIGNED_BYTE, null); // update the stencil buffer width and height - gl.bindRenderbuffer(gl.RENDERBUFFER, this.renderBuffer); + gl.bindRenderbuffer(gl.RENDERBUFFER, this.stencilBuffer); gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, width , height ); } else diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index c0c4af4..63767bd 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,6 +1,6 @@ var BaseTexture = require('./BaseTexture'), Texture = require('./Texture'), - FilterTexture = require('../renderers/webgl/utils/FilterTexture'), + RenderTarget = require('../renderers/webgl/utils/RenderTarget'), CanvasBuffer = require('../renderers/canvas/utils/CanvasBuffer'), math = require('../math'), CONST = require('../const'); @@ -145,9 +145,9 @@ { var gl = this.renderer.gl; - this.textureBuffer = new FilterTexture(gl, this.width * this.resolution, this.height * this.resolution, this.baseTexture.scaleMode); + this.textureBuffer = new RenderTarget(gl, this.width * this.resolution, this.height * this.resolution)//, this.baseTexture.scaleMode); this.baseTexture._glTextures[gl.id] = this.textureBuffer.texture; - + this.render = this.renderWebGL; this.projection = new math.Point(this.width*0.5, -this.height*0.5); } @@ -305,7 +305,7 @@ gl.viewport(0, 0, this.width * this.resolution, this.height * this.resolution); gl.bindFramebuffer(gl.FRAMEBUFFER, this.textureBuffer.frameBuffer ); - + if (clear) { this.textureBuffer.clear(); @@ -313,7 +313,7 @@ // this.renderer.spriteRenderer.dirty = true; - this.renderer.renderDisplayObject(displayObject, this.projection, this.textureBuffer.frameBuffer); + this.renderer.renderDisplayObject(displayObject, this.textureBuffer)//this.projection, this.textureBuffer.frameBuffer); // this.renderer.spriteRenderer.dirty = true;