diff --git a/src/pixi/primitives/Graphics.js b/src/pixi/primitives/Graphics.js index 9efaff2..82204cf 100644 --- a/src/pixi/primitives/Graphics.js +++ b/src/pixi/primitives/Graphics.js @@ -887,21 +887,21 @@ var minY = Infinity; var maxY = -Infinity; - var points, x, y, w, h; + var shape, points, x, y, w, h; for (var i = 0; i < this.graphicsData.length; i++) { var data = this.graphicsData[i]; var type = data.type; var lineWidth = data.lineWidth; - - points = data.points; + shape = data.shape; + if(type === PIXI.Graphics.RECT) { - x = points[0] - lineWidth/2; - y = points[1] - lineWidth/2; - w = points[2] + lineWidth; - h = points[3] + lineWidth; + x = shape.x - lineWidth/2; + y = shape.y - lineWidth/2; + w = shape.width + lineWidth; + h = shape.height + lineWidth; minX = x < minX ? x : minX; maxX = x + w > maxX ? x + w : maxX; @@ -909,12 +909,25 @@ minY = y < minY ? y : minY; maxY = y + h > maxY ? y + h : maxY; } - else if(type === PIXI.Graphics.CIRC || type === PIXI.Graphics.ELIP) + else if(type === PIXI.Graphics.CIRC) { - x = points[0]; - y = points[1]; - w = points[2] + lineWidth/2; - h = points[3] + lineWidth/2; + x = shape.x; + y = shape.y; + w = shape.radius + lineWidth/2; + h = shape.radius + lineWidth/2; + + minX = x - w < minX ? x - w : minX; + maxX = x + w > maxX ? x + w : maxX; + + minY = y - h < minY ? y - h : minY; + maxY = y + h > maxY ? y + h : maxY; + } + else if(type === PIXI.Graphics.ELIP) + { + x = shape.x; + y = shape.y; + w = shape.width + lineWidth/2; + h = shape.height + lineWidth/2; minX = x - w < minX ? x - w : minX; maxX = x + w > maxX ? x + w : maxX; @@ -925,6 +938,8 @@ else { // POLY + points = shape.points; + for (var j = 0; j < points.length; j+=2) { diff --git a/src/pixi/primitives/Graphics.js b/src/pixi/primitives/Graphics.js index 9efaff2..82204cf 100644 --- a/src/pixi/primitives/Graphics.js +++ b/src/pixi/primitives/Graphics.js @@ -887,21 +887,21 @@ var minY = Infinity; var maxY = -Infinity; - var points, x, y, w, h; + var shape, points, x, y, w, h; for (var i = 0; i < this.graphicsData.length; i++) { var data = this.graphicsData[i]; var type = data.type; var lineWidth = data.lineWidth; - - points = data.points; + shape = data.shape; + if(type === PIXI.Graphics.RECT) { - x = points[0] - lineWidth/2; - y = points[1] - lineWidth/2; - w = points[2] + lineWidth; - h = points[3] + lineWidth; + x = shape.x - lineWidth/2; + y = shape.y - lineWidth/2; + w = shape.width + lineWidth; + h = shape.height + lineWidth; minX = x < minX ? x : minX; maxX = x + w > maxX ? x + w : maxX; @@ -909,12 +909,25 @@ minY = y < minY ? y : minY; maxY = y + h > maxY ? y + h : maxY; } - else if(type === PIXI.Graphics.CIRC || type === PIXI.Graphics.ELIP) + else if(type === PIXI.Graphics.CIRC) { - x = points[0]; - y = points[1]; - w = points[2] + lineWidth/2; - h = points[3] + lineWidth/2; + x = shape.x; + y = shape.y; + w = shape.radius + lineWidth/2; + h = shape.radius + lineWidth/2; + + minX = x - w < minX ? x - w : minX; + maxX = x + w > maxX ? x + w : maxX; + + minY = y - h < minY ? y - h : minY; + maxY = y + h > maxY ? y + h : maxY; + } + else if(type === PIXI.Graphics.ELIP) + { + x = shape.x; + y = shape.y; + w = shape.width + lineWidth/2; + h = shape.height + lineWidth/2; minX = x - w < minX ? x - w : minX; maxX = x + w > maxX ? x + w : maxX; @@ -925,6 +938,8 @@ else { // POLY + points = shape.points; + for (var j = 0; j < points.length; j+=2) { diff --git a/src/pixi/renderers/webgl/utils/WebGLTexture.js b/src/pixi/renderers/webgl/utils/WebGLTexture.js new file mode 100644 index 0000000..d203515 --- /dev/null +++ b/src/pixi/renderers/webgl/utils/WebGLTexture.js @@ -0,0 +1,105 @@ +/** + * @author Mat Groves http://matgroves.com/ @Doormat23 + */ + +/** +* @class WebGLTexture +* @constructor +* @param gl {WebGLContext} the current WebGL drawing context +* @param width {Number} the horizontal range of the filter +* @param height {Number} the vertical range of the filter +* @param scaleMode {Number} Should be one of the PIXI.scaleMode consts +* @private +*/ +PIXI.WebGLTexture = function(gl, width, height, scaleMode) +{ + /** + * @property gl + * @type WebGLContext + */ + this.gl = gl; + + // next time to create a frame buffer and texture + this.frameBuffer = gl.createFramebuffer(); + this.texture = gl.createTexture(); + + scaleMode = scaleMode || PIXI.scaleModes.DEFAULT; + + gl.bindTexture(gl.TEXTURE_2D, this.texture); + + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, scaleMode === PIXI.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.bindFramebuffer(gl.FRAMEBUFFER, this.frameBuffer ); + gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.texture, 0); + + // required for masking a mask?? + this.renderBuffer = gl.createRenderbuffer(); + gl.bindRenderbuffer(gl.RENDERBUFFER, this.renderBuffer); + gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, this.renderBuffer); + + this.resize(width, height); +}; + + +/** +* Clears the filter texture +* @method clear +*/ +PIXI.WebGLTexture.prototype.clear = function() +{ + var gl = this.gl; + + gl.clearColor(0,0,0, 0); + gl.clear(gl.COLOR_BUFFER_BIT); +}; + +/** + * Resizes the texture to the specified width and height + * + * @method resize + * @param width {Number} the new width of the texture + * @param height {Number} the new height of the texture + */ +PIXI.WebGLTexture.prototype.resize = function(width, height) +{ + if(this.width === width && this.height === height) return; + + this.width = width; + this.height = height; + + var gl = this.gl; + + 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.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, width , height ); +}; + + +PIXI.WebGLTexture.prototype.applyFilter = function(width, height) +{ + +} + +/** +* Destroys the filter texture +* @method destroy +*/ +PIXI.WebGLTexture.prototype.destroy = function() +{ + var gl = this.gl; + + gl.deleteFramebuffer( this.frameBuffer ); + gl.deleteTexture( this.texture ); + + this.frameBuffer = null; + this.texture = null; +};