diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 0400d13..abf5d02 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -33,6 +33,11 @@ height = circleData.height; } + if (width === 0 || height === 0) + { + return; + } + const totalSegs = Math.floor(30 * Math.sqrt(circleData.radius)) || Math.floor(15 * Math.sqrt(circleData.width + circleData.height)); diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 0400d13..abf5d02 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -33,6 +33,11 @@ height = circleData.height; } + if (width === 0 || height === 0) + { + return; + } + const totalSegs = Math.floor(30 * Math.sqrt(circleData.radius)) || Math.floor(15 * Math.sqrt(circleData.width + circleData.height)); diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 9761b99..4f6f7c9 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -248,12 +248,11 @@ let currentState; - // this syncs the pixi filters uniforms with glsl uniforms - - if (shader.uniforms.data.filterArea) + if (uniforms.filterArea) { currentState = this.filterData.stack[this.filterData.index]; - const filterArea = shader.uniforms.filterArea; + + const filterArea = uniforms.filterArea; filterArea[0] = currentState.renderTarget.size.width; filterArea[1] = currentState.renderTarget.size.height; @@ -265,11 +264,11 @@ // use this to clamp displaced texture coords so they belong to filterArea // see displacementFilter fragment shader for an example - if (shader.uniforms.data.filterClamp) + if (uniforms.filterClamp) { currentState = this.filterData.stack[this.filterData.index]; - const filterClamp = shader.uniforms.filterClamp; + const filterClamp = uniforms.filterClamp; filterClamp[0] = 0; filterClamp[1] = 0; @@ -390,7 +389,7 @@ */ destroy() { - this.shaderCache = []; + this.shaderCache = {}; this.emptyPool(); } diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 0400d13..abf5d02 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -33,6 +33,11 @@ height = circleData.height; } + if (width === 0 || height === 0) + { + return; + } + const totalSegs = Math.floor(30 * Math.sqrt(circleData.radius)) || Math.floor(15 * Math.sqrt(circleData.width + circleData.height)); diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 9761b99..4f6f7c9 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -248,12 +248,11 @@ let currentState; - // this syncs the pixi filters uniforms with glsl uniforms - - if (shader.uniforms.data.filterArea) + if (uniforms.filterArea) { currentState = this.filterData.stack[this.filterData.index]; - const filterArea = shader.uniforms.filterArea; + + const filterArea = uniforms.filterArea; filterArea[0] = currentState.renderTarget.size.width; filterArea[1] = currentState.renderTarget.size.height; @@ -265,11 +264,11 @@ // use this to clamp displaced texture coords so they belong to filterArea // see displacementFilter fragment shader for an example - if (shader.uniforms.data.filterClamp) + if (uniforms.filterClamp) { currentState = this.filterData.stack[this.filterData.index]; - const filterClamp = shader.uniforms.filterClamp; + const filterClamp = uniforms.filterClamp; filterClamp[0] = 0; filterClamp[1] = 0; @@ -390,7 +389,7 @@ */ destroy() { - this.shaderCache = []; + this.shaderCache = {}; this.emptyPool(); } diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 836f109..1402e47 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -380,8 +380,12 @@ .addIndex(this.indexBuffer) .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aVertexPosition, gl.FLOAT, false, this.vertByteSize, 0) .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureCoord, gl.UNSIGNED_SHORT, true, this.vertByteSize, 2 * 4) - .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4) - .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); + .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4); + + if (this.shader.attributes.aTextureId) + { + this.vaos[this.vertexCount].addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); + } /* eslint-enable max-len */ } diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 0400d13..abf5d02 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -33,6 +33,11 @@ height = circleData.height; } + if (width === 0 || height === 0) + { + return; + } + const totalSegs = Math.floor(30 * Math.sqrt(circleData.radius)) || Math.floor(15 * Math.sqrt(circleData.width + circleData.height)); diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 9761b99..4f6f7c9 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -248,12 +248,11 @@ let currentState; - // this syncs the pixi filters uniforms with glsl uniforms - - if (shader.uniforms.data.filterArea) + if (uniforms.filterArea) { currentState = this.filterData.stack[this.filterData.index]; - const filterArea = shader.uniforms.filterArea; + + const filterArea = uniforms.filterArea; filterArea[0] = currentState.renderTarget.size.width; filterArea[1] = currentState.renderTarget.size.height; @@ -265,11 +264,11 @@ // use this to clamp displaced texture coords so they belong to filterArea // see displacementFilter fragment shader for an example - if (shader.uniforms.data.filterClamp) + if (uniforms.filterClamp) { currentState = this.filterData.stack[this.filterData.index]; - const filterClamp = shader.uniforms.filterClamp; + const filterClamp = uniforms.filterClamp; filterClamp[0] = 0; filterClamp[1] = 0; @@ -390,7 +389,7 @@ */ destroy() { - this.shaderCache = []; + this.shaderCache = {}; this.emptyPool(); } diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 836f109..1402e47 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -380,8 +380,12 @@ .addIndex(this.indexBuffer) .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aVertexPosition, gl.FLOAT, false, this.vertByteSize, 0) .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureCoord, gl.UNSIGNED_SHORT, true, this.vertByteSize, 2 * 4) - .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4) - .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); + .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4); + + if (this.shader.attributes.aTextureId) + { + this.vaos[this.vertexCount].addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); + } /* eslint-enable max-len */ } diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 5e7bc0b..18fb723 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -489,6 +489,19 @@ } /** + * Gets the local bounds of the text object. + * + * @param {Rectangle} rect - The output rectangle. + * @return {Rectangle} The bounds. + */ + getLocalBounds(rect) + { + this.updateText(true); + + return super.getLocalBounds.call(this, rect); + } + + /** * calculates the bounds of the Text as a rectangle. The bounds calculation takes the worldTransform into account. */ _calculateBounds() @@ -731,7 +744,7 @@ set text(text) // eslint-disable-line require-jsdoc { - text = String(text || ' '); + text = String(text === '' || text === null || text === undefined ? ' ' : text); if (this._text === text) { diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 0400d13..abf5d02 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -33,6 +33,11 @@ height = circleData.height; } + if (width === 0 || height === 0) + { + return; + } + const totalSegs = Math.floor(30 * Math.sqrt(circleData.radius)) || Math.floor(15 * Math.sqrt(circleData.width + circleData.height)); diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 9761b99..4f6f7c9 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -248,12 +248,11 @@ let currentState; - // this syncs the pixi filters uniforms with glsl uniforms - - if (shader.uniforms.data.filterArea) + if (uniforms.filterArea) { currentState = this.filterData.stack[this.filterData.index]; - const filterArea = shader.uniforms.filterArea; + + const filterArea = uniforms.filterArea; filterArea[0] = currentState.renderTarget.size.width; filterArea[1] = currentState.renderTarget.size.height; @@ -265,11 +264,11 @@ // use this to clamp displaced texture coords so they belong to filterArea // see displacementFilter fragment shader for an example - if (shader.uniforms.data.filterClamp) + if (uniforms.filterClamp) { currentState = this.filterData.stack[this.filterData.index]; - const filterClamp = shader.uniforms.filterClamp; + const filterClamp = uniforms.filterClamp; filterClamp[0] = 0; filterClamp[1] = 0; @@ -390,7 +389,7 @@ */ destroy() { - this.shaderCache = []; + this.shaderCache = {}; this.emptyPool(); } diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 836f109..1402e47 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -380,8 +380,12 @@ .addIndex(this.indexBuffer) .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aVertexPosition, gl.FLOAT, false, this.vertByteSize, 0) .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureCoord, gl.UNSIGNED_SHORT, true, this.vertByteSize, 2 * 4) - .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4) - .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); + .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4); + + if (this.shader.attributes.aTextureId) + { + this.vaos[this.vertexCount].addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); + } /* eslint-enable max-len */ } diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 5e7bc0b..18fb723 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -489,6 +489,19 @@ } /** + * Gets the local bounds of the text object. + * + * @param {Rectangle} rect - The output rectangle. + * @return {Rectangle} The bounds. + */ + getLocalBounds(rect) + { + this.updateText(true); + + return super.getLocalBounds.call(this, rect); + } + + /** * calculates the bounds of the Text as a rectangle. The bounds calculation takes the worldTransform into account. */ _calculateBounds() @@ -731,7 +744,7 @@ set text(text) // eslint-disable-line require-jsdoc { - text = String(text || ' '); + text = String(text === '' || text === null || text === undefined ? ' ' : text); if (this._text === text) { diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index ca31456..6403d4f 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -459,7 +459,9 @@ if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - throw new Error(`Texture Error: frame does not fit inside the base Texture dimensions ${this}`); + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions: ' + + `X: ${frame.x} + ${frame.width} > ${this.baseTexture.width} ` + + `Y: ${frame.y} + ${frame.height} > ${this.baseTexture.height}`); } // this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 0400d13..abf5d02 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -33,6 +33,11 @@ height = circleData.height; } + if (width === 0 || height === 0) + { + return; + } + const totalSegs = Math.floor(30 * Math.sqrt(circleData.radius)) || Math.floor(15 * Math.sqrt(circleData.width + circleData.height)); diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 9761b99..4f6f7c9 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -248,12 +248,11 @@ let currentState; - // this syncs the pixi filters uniforms with glsl uniforms - - if (shader.uniforms.data.filterArea) + if (uniforms.filterArea) { currentState = this.filterData.stack[this.filterData.index]; - const filterArea = shader.uniforms.filterArea; + + const filterArea = uniforms.filterArea; filterArea[0] = currentState.renderTarget.size.width; filterArea[1] = currentState.renderTarget.size.height; @@ -265,11 +264,11 @@ // use this to clamp displaced texture coords so they belong to filterArea // see displacementFilter fragment shader for an example - if (shader.uniforms.data.filterClamp) + if (uniforms.filterClamp) { currentState = this.filterData.stack[this.filterData.index]; - const filterClamp = shader.uniforms.filterClamp; + const filterClamp = uniforms.filterClamp; filterClamp[0] = 0; filterClamp[1] = 0; @@ -390,7 +389,7 @@ */ destroy() { - this.shaderCache = []; + this.shaderCache = {}; this.emptyPool(); } diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 836f109..1402e47 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -380,8 +380,12 @@ .addIndex(this.indexBuffer) .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aVertexPosition, gl.FLOAT, false, this.vertByteSize, 0) .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureCoord, gl.UNSIGNED_SHORT, true, this.vertByteSize, 2 * 4) - .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4) - .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); + .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4); + + if (this.shader.attributes.aTextureId) + { + this.vaos[this.vertexCount].addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); + } /* eslint-enable max-len */ } diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 5e7bc0b..18fb723 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -489,6 +489,19 @@ } /** + * Gets the local bounds of the text object. + * + * @param {Rectangle} rect - The output rectangle. + * @return {Rectangle} The bounds. + */ + getLocalBounds(rect) + { + this.updateText(true); + + return super.getLocalBounds.call(this, rect); + } + + /** * calculates the bounds of the Text as a rectangle. The bounds calculation takes the worldTransform into account. */ _calculateBounds() @@ -731,7 +744,7 @@ set text(text) // eslint-disable-line require-jsdoc { - text = String(text || ' '); + text = String(text === '' || text === null || text === undefined ? ' ' : text); if (this._text === text) { diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index ca31456..6403d4f 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -459,7 +459,9 @@ if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - throw new Error(`Texture Error: frame does not fit inside the base Texture dimensions ${this}`); + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions: ' + + `X: ${frame.x} + ${frame.width} > ${this.baseTexture.width} ` + + `Y: ${frame.y} + ${frame.height} > ${this.baseTexture.height}`); } // this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; diff --git a/src/core/utils/trimCanvas.js b/src/core/utils/trimCanvas.js index 37a0378..5af6de0 100644 --- a/src/core/utils/trimCanvas.js +++ b/src/core/utils/trimCanvas.js @@ -10,9 +10,15 @@ export default function trimCanvas(canvas) { // https://gist.github.com/remy/784508 + + let width = canvas.width; + let height = canvas.height; + const context = canvas.getContext('2d'); - const pixels = context.getImageData(0, 0, canvas.width, canvas.height); - const l = pixels.data.length; + const imageData = context.getImageData(0, 0, width, height); + const pixels = imageData.data; + const len = pixels.length; + const bound = { top: null, left: null, @@ -23,12 +29,12 @@ let x; let y; - for (i = 0; i < l; i += 4) + for (i = 0; i < len; i += 4) { - if (pixels.data[i + 3] !== 0) + if (pixels[i + 3] !== 0) { - x = (i / 4) % canvas.width; - y = ~~((i / 4) / canvas.width); + x = (i / 4) % width; + y = ~~((i / 4) / width); if (bound.top === null) { @@ -64,8 +70,9 @@ } } - const height = bound.bottom - bound.top + 1; - const width = bound.right - bound.left; + width = bound.right - bound.left; + height = bound.bottom - bound.top + 1; + const data = context.getImageData(bound.left, bound.top, width, height); return { diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 0400d13..abf5d02 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -33,6 +33,11 @@ height = circleData.height; } + if (width === 0 || height === 0) + { + return; + } + const totalSegs = Math.floor(30 * Math.sqrt(circleData.radius)) || Math.floor(15 * Math.sqrt(circleData.width + circleData.height)); diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 9761b99..4f6f7c9 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -248,12 +248,11 @@ let currentState; - // this syncs the pixi filters uniforms with glsl uniforms - - if (shader.uniforms.data.filterArea) + if (uniforms.filterArea) { currentState = this.filterData.stack[this.filterData.index]; - const filterArea = shader.uniforms.filterArea; + + const filterArea = uniforms.filterArea; filterArea[0] = currentState.renderTarget.size.width; filterArea[1] = currentState.renderTarget.size.height; @@ -265,11 +264,11 @@ // use this to clamp displaced texture coords so they belong to filterArea // see displacementFilter fragment shader for an example - if (shader.uniforms.data.filterClamp) + if (uniforms.filterClamp) { currentState = this.filterData.stack[this.filterData.index]; - const filterClamp = shader.uniforms.filterClamp; + const filterClamp = uniforms.filterClamp; filterClamp[0] = 0; filterClamp[1] = 0; @@ -390,7 +389,7 @@ */ destroy() { - this.shaderCache = []; + this.shaderCache = {}; this.emptyPool(); } diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 836f109..1402e47 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -380,8 +380,12 @@ .addIndex(this.indexBuffer) .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aVertexPosition, gl.FLOAT, false, this.vertByteSize, 0) .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureCoord, gl.UNSIGNED_SHORT, true, this.vertByteSize, 2 * 4) - .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4) - .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); + .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4); + + if (this.shader.attributes.aTextureId) + { + this.vaos[this.vertexCount].addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); + } /* eslint-enable max-len */ } diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 5e7bc0b..18fb723 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -489,6 +489,19 @@ } /** + * Gets the local bounds of the text object. + * + * @param {Rectangle} rect - The output rectangle. + * @return {Rectangle} The bounds. + */ + getLocalBounds(rect) + { + this.updateText(true); + + return super.getLocalBounds.call(this, rect); + } + + /** * calculates the bounds of the Text as a rectangle. The bounds calculation takes the worldTransform into account. */ _calculateBounds() @@ -731,7 +744,7 @@ set text(text) // eslint-disable-line require-jsdoc { - text = String(text || ' '); + text = String(text === '' || text === null || text === undefined ? ' ' : text); if (this._text === text) { diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index ca31456..6403d4f 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -459,7 +459,9 @@ if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - throw new Error(`Texture Error: frame does not fit inside the base Texture dimensions ${this}`); + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions: ' + + `X: ${frame.x} + ${frame.width} > ${this.baseTexture.width} ` + + `Y: ${frame.y} + ${frame.height} > ${this.baseTexture.height}`); } // this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; diff --git a/src/core/utils/trimCanvas.js b/src/core/utils/trimCanvas.js index 37a0378..5af6de0 100644 --- a/src/core/utils/trimCanvas.js +++ b/src/core/utils/trimCanvas.js @@ -10,9 +10,15 @@ export default function trimCanvas(canvas) { // https://gist.github.com/remy/784508 + + let width = canvas.width; + let height = canvas.height; + const context = canvas.getContext('2d'); - const pixels = context.getImageData(0, 0, canvas.width, canvas.height); - const l = pixels.data.length; + const imageData = context.getImageData(0, 0, width, height); + const pixels = imageData.data; + const len = pixels.length; + const bound = { top: null, left: null, @@ -23,12 +29,12 @@ let x; let y; - for (i = 0; i < l; i += 4) + for (i = 0; i < len; i += 4) { - if (pixels.data[i + 3] !== 0) + if (pixels[i + 3] !== 0) { - x = (i / 4) % canvas.width; - y = ~~((i / 4) / canvas.width); + x = (i / 4) % width; + y = ~~((i / 4) / width); if (bound.top === null) { @@ -64,8 +70,9 @@ } } - const height = bound.bottom - bound.top + 1; - const width = bound.right - bound.left; + width = bound.right - bound.left; + height = bound.bottom - bound.top + 1; + const data = context.getImageData(bound.left, bound.top, width, height); return { diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index f90d248..fe82451 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -220,20 +220,33 @@ transform.tx * resolution, transform.ty * resolution); - // TODO - this should be rolled into the setTransform above.. - context.scale(this.tileScale.x / baseTextureResolution, this.tileScale.y / baseTextureResolution); - - context.translate(modX + (this.anchor.x * -this._width), - modY + (this.anchor.y * -this._height)); - renderer.setBlendMode(this.blendMode); // fill the pattern! context.fillStyle = this._canvasPattern; - context.fillRect(-modX, - -modY, - this._width / this.tileScale.x * baseTextureResolution, - this._height / this.tileScale.y * baseTextureResolution); + + // TODO - this should be rolled into the setTransform above.. + context.scale(this.tileScale.x / baseTextureResolution, this.tileScale.y / baseTextureResolution); + + const anchorX = this.anchor.x * -this._width; + const anchorY = this.anchor.y * -this._height; + + if (this.uvRespectAnchor) + { + context.translate(modX, modY); + + context.fillRect(-modX + anchorX, -modY + anchorY, + this._width / this.tileScale.x * baseTextureResolution, + this._height / this.tileScale.y * baseTextureResolution); + } + else + { + context.translate(modX + anchorX, modY + anchorY); + + context.fillRect(-modX, -modY, + this._width / this.tileScale.x * baseTextureResolution, + this._height / this.tileScale.y * baseTextureResolution); + } } /** diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 0400d13..abf5d02 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -33,6 +33,11 @@ height = circleData.height; } + if (width === 0 || height === 0) + { + return; + } + const totalSegs = Math.floor(30 * Math.sqrt(circleData.radius)) || Math.floor(15 * Math.sqrt(circleData.width + circleData.height)); diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 9761b99..4f6f7c9 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -248,12 +248,11 @@ let currentState; - // this syncs the pixi filters uniforms with glsl uniforms - - if (shader.uniforms.data.filterArea) + if (uniforms.filterArea) { currentState = this.filterData.stack[this.filterData.index]; - const filterArea = shader.uniforms.filterArea; + + const filterArea = uniforms.filterArea; filterArea[0] = currentState.renderTarget.size.width; filterArea[1] = currentState.renderTarget.size.height; @@ -265,11 +264,11 @@ // use this to clamp displaced texture coords so they belong to filterArea // see displacementFilter fragment shader for an example - if (shader.uniforms.data.filterClamp) + if (uniforms.filterClamp) { currentState = this.filterData.stack[this.filterData.index]; - const filterClamp = shader.uniforms.filterClamp; + const filterClamp = uniforms.filterClamp; filterClamp[0] = 0; filterClamp[1] = 0; @@ -390,7 +389,7 @@ */ destroy() { - this.shaderCache = []; + this.shaderCache = {}; this.emptyPool(); } diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 836f109..1402e47 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -380,8 +380,12 @@ .addIndex(this.indexBuffer) .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aVertexPosition, gl.FLOAT, false, this.vertByteSize, 0) .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureCoord, gl.UNSIGNED_SHORT, true, this.vertByteSize, 2 * 4) - .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4) - .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); + .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4); + + if (this.shader.attributes.aTextureId) + { + this.vaos[this.vertexCount].addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); + } /* eslint-enable max-len */ } diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 5e7bc0b..18fb723 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -489,6 +489,19 @@ } /** + * Gets the local bounds of the text object. + * + * @param {Rectangle} rect - The output rectangle. + * @return {Rectangle} The bounds. + */ + getLocalBounds(rect) + { + this.updateText(true); + + return super.getLocalBounds.call(this, rect); + } + + /** * calculates the bounds of the Text as a rectangle. The bounds calculation takes the worldTransform into account. */ _calculateBounds() @@ -731,7 +744,7 @@ set text(text) // eslint-disable-line require-jsdoc { - text = String(text || ' '); + text = String(text === '' || text === null || text === undefined ? ' ' : text); if (this._text === text) { diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index ca31456..6403d4f 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -459,7 +459,9 @@ if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - throw new Error(`Texture Error: frame does not fit inside the base Texture dimensions ${this}`); + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions: ' + + `X: ${frame.x} + ${frame.width} > ${this.baseTexture.width} ` + + `Y: ${frame.y} + ${frame.height} > ${this.baseTexture.height}`); } // this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; diff --git a/src/core/utils/trimCanvas.js b/src/core/utils/trimCanvas.js index 37a0378..5af6de0 100644 --- a/src/core/utils/trimCanvas.js +++ b/src/core/utils/trimCanvas.js @@ -10,9 +10,15 @@ export default function trimCanvas(canvas) { // https://gist.github.com/remy/784508 + + let width = canvas.width; + let height = canvas.height; + const context = canvas.getContext('2d'); - const pixels = context.getImageData(0, 0, canvas.width, canvas.height); - const l = pixels.data.length; + const imageData = context.getImageData(0, 0, width, height); + const pixels = imageData.data; + const len = pixels.length; + const bound = { top: null, left: null, @@ -23,12 +29,12 @@ let x; let y; - for (i = 0; i < l; i += 4) + for (i = 0; i < len; i += 4) { - if (pixels.data[i + 3] !== 0) + if (pixels[i + 3] !== 0) { - x = (i / 4) % canvas.width; - y = ~~((i / 4) / canvas.width); + x = (i / 4) % width; + y = ~~((i / 4) / width); if (bound.top === null) { @@ -64,8 +70,9 @@ } } - const height = bound.bottom - bound.top + 1; - const width = bound.right - bound.left; + width = bound.right - bound.left; + height = bound.bottom - bound.top + 1; + const data = context.getImageData(bound.left, bound.top, width, height); return { diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index f90d248..fe82451 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -220,20 +220,33 @@ transform.tx * resolution, transform.ty * resolution); - // TODO - this should be rolled into the setTransform above.. - context.scale(this.tileScale.x / baseTextureResolution, this.tileScale.y / baseTextureResolution); - - context.translate(modX + (this.anchor.x * -this._width), - modY + (this.anchor.y * -this._height)); - renderer.setBlendMode(this.blendMode); // fill the pattern! context.fillStyle = this._canvasPattern; - context.fillRect(-modX, - -modY, - this._width / this.tileScale.x * baseTextureResolution, - this._height / this.tileScale.y * baseTextureResolution); + + // TODO - this should be rolled into the setTransform above.. + context.scale(this.tileScale.x / baseTextureResolution, this.tileScale.y / baseTextureResolution); + + const anchorX = this.anchor.x * -this._width; + const anchorY = this.anchor.y * -this._height; + + if (this.uvRespectAnchor) + { + context.translate(modX, modY); + + context.fillRect(-modX + anchorX, -modY + anchorY, + this._width / this.tileScale.x * baseTextureResolution, + this._height / this.tileScale.y * baseTextureResolution); + } + else + { + context.translate(modX + anchorX, modY + anchorY); + + context.fillRect(-modX, -modY, + this._width / this.tileScale.x * baseTextureResolution, + this._height / this.tileScale.y * baseTextureResolution); + } } /** diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 575aad4..5dd5640 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -41,7 +41,7 @@ * provide a performance benefit for complex static displayObjects. * To remove simply set this property to 'false' * - * IMPORTANT GOTCHA - make sure that all your textures are preloaded BEFORE calling setting this property + * IMPORTANT GOTCHA - make sure that all your textures are preloaded BEFORE setting this property to true * as it will take a snapshot of what is currently there. If the textures have not loaded then they will not appear. * * @member {boolean} diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 0400d13..abf5d02 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -33,6 +33,11 @@ height = circleData.height; } + if (width === 0 || height === 0) + { + return; + } + const totalSegs = Math.floor(30 * Math.sqrt(circleData.radius)) || Math.floor(15 * Math.sqrt(circleData.width + circleData.height)); diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 9761b99..4f6f7c9 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -248,12 +248,11 @@ let currentState; - // this syncs the pixi filters uniforms with glsl uniforms - - if (shader.uniforms.data.filterArea) + if (uniforms.filterArea) { currentState = this.filterData.stack[this.filterData.index]; - const filterArea = shader.uniforms.filterArea; + + const filterArea = uniforms.filterArea; filterArea[0] = currentState.renderTarget.size.width; filterArea[1] = currentState.renderTarget.size.height; @@ -265,11 +264,11 @@ // use this to clamp displaced texture coords so they belong to filterArea // see displacementFilter fragment shader for an example - if (shader.uniforms.data.filterClamp) + if (uniforms.filterClamp) { currentState = this.filterData.stack[this.filterData.index]; - const filterClamp = shader.uniforms.filterClamp; + const filterClamp = uniforms.filterClamp; filterClamp[0] = 0; filterClamp[1] = 0; @@ -390,7 +389,7 @@ */ destroy() { - this.shaderCache = []; + this.shaderCache = {}; this.emptyPool(); } diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 836f109..1402e47 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -380,8 +380,12 @@ .addIndex(this.indexBuffer) .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aVertexPosition, gl.FLOAT, false, this.vertByteSize, 0) .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureCoord, gl.UNSIGNED_SHORT, true, this.vertByteSize, 2 * 4) - .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4) - .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); + .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4); + + if (this.shader.attributes.aTextureId) + { + this.vaos[this.vertexCount].addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); + } /* eslint-enable max-len */ } diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 5e7bc0b..18fb723 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -489,6 +489,19 @@ } /** + * Gets the local bounds of the text object. + * + * @param {Rectangle} rect - The output rectangle. + * @return {Rectangle} The bounds. + */ + getLocalBounds(rect) + { + this.updateText(true); + + return super.getLocalBounds.call(this, rect); + } + + /** * calculates the bounds of the Text as a rectangle. The bounds calculation takes the worldTransform into account. */ _calculateBounds() @@ -731,7 +744,7 @@ set text(text) // eslint-disable-line require-jsdoc { - text = String(text || ' '); + text = String(text === '' || text === null || text === undefined ? ' ' : text); if (this._text === text) { diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index ca31456..6403d4f 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -459,7 +459,9 @@ if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - throw new Error(`Texture Error: frame does not fit inside the base Texture dimensions ${this}`); + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions: ' + + `X: ${frame.x} + ${frame.width} > ${this.baseTexture.width} ` + + `Y: ${frame.y} + ${frame.height} > ${this.baseTexture.height}`); } // this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; diff --git a/src/core/utils/trimCanvas.js b/src/core/utils/trimCanvas.js index 37a0378..5af6de0 100644 --- a/src/core/utils/trimCanvas.js +++ b/src/core/utils/trimCanvas.js @@ -10,9 +10,15 @@ export default function trimCanvas(canvas) { // https://gist.github.com/remy/784508 + + let width = canvas.width; + let height = canvas.height; + const context = canvas.getContext('2d'); - const pixels = context.getImageData(0, 0, canvas.width, canvas.height); - const l = pixels.data.length; + const imageData = context.getImageData(0, 0, width, height); + const pixels = imageData.data; + const len = pixels.length; + const bound = { top: null, left: null, @@ -23,12 +29,12 @@ let x; let y; - for (i = 0; i < l; i += 4) + for (i = 0; i < len; i += 4) { - if (pixels.data[i + 3] !== 0) + if (pixels[i + 3] !== 0) { - x = (i / 4) % canvas.width; - y = ~~((i / 4) / canvas.width); + x = (i / 4) % width; + y = ~~((i / 4) / width); if (bound.top === null) { @@ -64,8 +70,9 @@ } } - const height = bound.bottom - bound.top + 1; - const width = bound.right - bound.left; + width = bound.right - bound.left; + height = bound.bottom - bound.top + 1; + const data = context.getImageData(bound.left, bound.top, width, height); return { diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index f90d248..fe82451 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -220,20 +220,33 @@ transform.tx * resolution, transform.ty * resolution); - // TODO - this should be rolled into the setTransform above.. - context.scale(this.tileScale.x / baseTextureResolution, this.tileScale.y / baseTextureResolution); - - context.translate(modX + (this.anchor.x * -this._width), - modY + (this.anchor.y * -this._height)); - renderer.setBlendMode(this.blendMode); // fill the pattern! context.fillStyle = this._canvasPattern; - context.fillRect(-modX, - -modY, - this._width / this.tileScale.x * baseTextureResolution, - this._height / this.tileScale.y * baseTextureResolution); + + // TODO - this should be rolled into the setTransform above.. + context.scale(this.tileScale.x / baseTextureResolution, this.tileScale.y / baseTextureResolution); + + const anchorX = this.anchor.x * -this._width; + const anchorY = this.anchor.y * -this._height; + + if (this.uvRespectAnchor) + { + context.translate(modX, modY); + + context.fillRect(-modX + anchorX, -modY + anchorY, + this._width / this.tileScale.x * baseTextureResolution, + this._height / this.tileScale.y * baseTextureResolution); + } + else + { + context.translate(modX + anchorX, modY + anchorY); + + context.fillRect(-modX, -modY, + this._width / this.tileScale.x * baseTextureResolution, + this._height / this.tileScale.y * baseTextureResolution); + } } /** diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 575aad4..5dd5640 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -41,7 +41,7 @@ * provide a performance benefit for complex static displayObjects. * To remove simply set this property to 'false' * - * IMPORTANT GOTCHA - make sure that all your textures are preloaded BEFORE calling setting this property + * IMPORTANT GOTCHA - make sure that all your textures are preloaded BEFORE setting this property to true * as it will take a snapshot of what is currently there. If the textures have not loaded then they will not appear. * * @member {boolean} diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 112de0b..d5355c3 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -36,7 +36,7 @@ this.maskMatrix = maskMatrix; this.uniforms.mapSampler = sprite.texture; - this.uniforms.filterMatrix = maskMatrix.toArray(true); + this.uniforms.filterMatrix = maskMatrix; this.uniforms.scale = { x: 1, y: 1 }; if (scale === null || scale === undefined) diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 0400d13..abf5d02 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -33,6 +33,11 @@ height = circleData.height; } + if (width === 0 || height === 0) + { + return; + } + const totalSegs = Math.floor(30 * Math.sqrt(circleData.radius)) || Math.floor(15 * Math.sqrt(circleData.width + circleData.height)); diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 9761b99..4f6f7c9 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -248,12 +248,11 @@ let currentState; - // this syncs the pixi filters uniforms with glsl uniforms - - if (shader.uniforms.data.filterArea) + if (uniforms.filterArea) { currentState = this.filterData.stack[this.filterData.index]; - const filterArea = shader.uniforms.filterArea; + + const filterArea = uniforms.filterArea; filterArea[0] = currentState.renderTarget.size.width; filterArea[1] = currentState.renderTarget.size.height; @@ -265,11 +264,11 @@ // use this to clamp displaced texture coords so they belong to filterArea // see displacementFilter fragment shader for an example - if (shader.uniforms.data.filterClamp) + if (uniforms.filterClamp) { currentState = this.filterData.stack[this.filterData.index]; - const filterClamp = shader.uniforms.filterClamp; + const filterClamp = uniforms.filterClamp; filterClamp[0] = 0; filterClamp[1] = 0; @@ -390,7 +389,7 @@ */ destroy() { - this.shaderCache = []; + this.shaderCache = {}; this.emptyPool(); } diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 836f109..1402e47 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -380,8 +380,12 @@ .addIndex(this.indexBuffer) .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aVertexPosition, gl.FLOAT, false, this.vertByteSize, 0) .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureCoord, gl.UNSIGNED_SHORT, true, this.vertByteSize, 2 * 4) - .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4) - .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); + .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4); + + if (this.shader.attributes.aTextureId) + { + this.vaos[this.vertexCount].addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); + } /* eslint-enable max-len */ } diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 5e7bc0b..18fb723 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -489,6 +489,19 @@ } /** + * Gets the local bounds of the text object. + * + * @param {Rectangle} rect - The output rectangle. + * @return {Rectangle} The bounds. + */ + getLocalBounds(rect) + { + this.updateText(true); + + return super.getLocalBounds.call(this, rect); + } + + /** * calculates the bounds of the Text as a rectangle. The bounds calculation takes the worldTransform into account. */ _calculateBounds() @@ -731,7 +744,7 @@ set text(text) // eslint-disable-line require-jsdoc { - text = String(text || ' '); + text = String(text === '' || text === null || text === undefined ? ' ' : text); if (this._text === text) { diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index ca31456..6403d4f 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -459,7 +459,9 @@ if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - throw new Error(`Texture Error: frame does not fit inside the base Texture dimensions ${this}`); + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions: ' + + `X: ${frame.x} + ${frame.width} > ${this.baseTexture.width} ` + + `Y: ${frame.y} + ${frame.height} > ${this.baseTexture.height}`); } // this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; diff --git a/src/core/utils/trimCanvas.js b/src/core/utils/trimCanvas.js index 37a0378..5af6de0 100644 --- a/src/core/utils/trimCanvas.js +++ b/src/core/utils/trimCanvas.js @@ -10,9 +10,15 @@ export default function trimCanvas(canvas) { // https://gist.github.com/remy/784508 + + let width = canvas.width; + let height = canvas.height; + const context = canvas.getContext('2d'); - const pixels = context.getImageData(0, 0, canvas.width, canvas.height); - const l = pixels.data.length; + const imageData = context.getImageData(0, 0, width, height); + const pixels = imageData.data; + const len = pixels.length; + const bound = { top: null, left: null, @@ -23,12 +29,12 @@ let x; let y; - for (i = 0; i < l; i += 4) + for (i = 0; i < len; i += 4) { - if (pixels.data[i + 3] !== 0) + if (pixels[i + 3] !== 0) { - x = (i / 4) % canvas.width; - y = ~~((i / 4) / canvas.width); + x = (i / 4) % width; + y = ~~((i / 4) / width); if (bound.top === null) { @@ -64,8 +70,9 @@ } } - const height = bound.bottom - bound.top + 1; - const width = bound.right - bound.left; + width = bound.right - bound.left; + height = bound.bottom - bound.top + 1; + const data = context.getImageData(bound.left, bound.top, width, height); return { diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index f90d248..fe82451 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -220,20 +220,33 @@ transform.tx * resolution, transform.ty * resolution); - // TODO - this should be rolled into the setTransform above.. - context.scale(this.tileScale.x / baseTextureResolution, this.tileScale.y / baseTextureResolution); - - context.translate(modX + (this.anchor.x * -this._width), - modY + (this.anchor.y * -this._height)); - renderer.setBlendMode(this.blendMode); // fill the pattern! context.fillStyle = this._canvasPattern; - context.fillRect(-modX, - -modY, - this._width / this.tileScale.x * baseTextureResolution, - this._height / this.tileScale.y * baseTextureResolution); + + // TODO - this should be rolled into the setTransform above.. + context.scale(this.tileScale.x / baseTextureResolution, this.tileScale.y / baseTextureResolution); + + const anchorX = this.anchor.x * -this._width; + const anchorY = this.anchor.y * -this._height; + + if (this.uvRespectAnchor) + { + context.translate(modX, modY); + + context.fillRect(-modX + anchorX, -modY + anchorY, + this._width / this.tileScale.x * baseTextureResolution, + this._height / this.tileScale.y * baseTextureResolution); + } + else + { + context.translate(modX + anchorX, modY + anchorY); + + context.fillRect(-modX, -modY, + this._width / this.tileScale.x * baseTextureResolution, + this._height / this.tileScale.y * baseTextureResolution); + } } /** diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 575aad4..5dd5640 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -41,7 +41,7 @@ * provide a performance benefit for complex static displayObjects. * To remove simply set this property to 'false' * - * IMPORTANT GOTCHA - make sure that all your textures are preloaded BEFORE calling setting this property + * IMPORTANT GOTCHA - make sure that all your textures are preloaded BEFORE setting this property to true * as it will take a snapshot of what is currently there. If the textures have not loaded then they will not appear. * * @member {boolean} diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 112de0b..d5355c3 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -36,7 +36,7 @@ this.maskMatrix = maskMatrix; this.uniforms.mapSampler = sprite.texture; - this.uniforms.filterMatrix = maskMatrix.toArray(true); + this.uniforms.filterMatrix = maskMatrix; this.uniforms.scale = { x: 1, y: 1 }; if (scale === null || scale === undefined) diff --git a/src/mesh/Rope.js b/src/mesh/Rope.js index e448e6c..5621a7d 100644 --- a/src/mesh/Rope.js +++ b/src/mesh/Rope.js @@ -33,6 +33,7 @@ * @member {PIXI.Point[]} An array of points that determine the rope */ this.points = points; + this.refresh(); } /** @@ -40,8 +41,11 @@ */ refresh() { + const points = this.points; + if(!points)return; + const vertexBuffer = this.geometry.getAttribute('aVertexPosition'); const uvBuffer = this.geometry.getAttribute('aTextureCoord'); const indexBuffer = this.geometry.getIndex(); diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 0400d13..abf5d02 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -33,6 +33,11 @@ height = circleData.height; } + if (width === 0 || height === 0) + { + return; + } + const totalSegs = Math.floor(30 * Math.sqrt(circleData.radius)) || Math.floor(15 * Math.sqrt(circleData.width + circleData.height)); diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 9761b99..4f6f7c9 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -248,12 +248,11 @@ let currentState; - // this syncs the pixi filters uniforms with glsl uniforms - - if (shader.uniforms.data.filterArea) + if (uniforms.filterArea) { currentState = this.filterData.stack[this.filterData.index]; - const filterArea = shader.uniforms.filterArea; + + const filterArea = uniforms.filterArea; filterArea[0] = currentState.renderTarget.size.width; filterArea[1] = currentState.renderTarget.size.height; @@ -265,11 +264,11 @@ // use this to clamp displaced texture coords so they belong to filterArea // see displacementFilter fragment shader for an example - if (shader.uniforms.data.filterClamp) + if (uniforms.filterClamp) { currentState = this.filterData.stack[this.filterData.index]; - const filterClamp = shader.uniforms.filterClamp; + const filterClamp = uniforms.filterClamp; filterClamp[0] = 0; filterClamp[1] = 0; @@ -390,7 +389,7 @@ */ destroy() { - this.shaderCache = []; + this.shaderCache = {}; this.emptyPool(); } diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 836f109..1402e47 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -380,8 +380,12 @@ .addIndex(this.indexBuffer) .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aVertexPosition, gl.FLOAT, false, this.vertByteSize, 0) .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureCoord, gl.UNSIGNED_SHORT, true, this.vertByteSize, 2 * 4) - .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4) - .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); + .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4); + + if (this.shader.attributes.aTextureId) + { + this.vaos[this.vertexCount].addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); + } /* eslint-enable max-len */ } diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 5e7bc0b..18fb723 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -489,6 +489,19 @@ } /** + * Gets the local bounds of the text object. + * + * @param {Rectangle} rect - The output rectangle. + * @return {Rectangle} The bounds. + */ + getLocalBounds(rect) + { + this.updateText(true); + + return super.getLocalBounds.call(this, rect); + } + + /** * calculates the bounds of the Text as a rectangle. The bounds calculation takes the worldTransform into account. */ _calculateBounds() @@ -731,7 +744,7 @@ set text(text) // eslint-disable-line require-jsdoc { - text = String(text || ' '); + text = String(text === '' || text === null || text === undefined ? ' ' : text); if (this._text === text) { diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index ca31456..6403d4f 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -459,7 +459,9 @@ if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - throw new Error(`Texture Error: frame does not fit inside the base Texture dimensions ${this}`); + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions: ' + + `X: ${frame.x} + ${frame.width} > ${this.baseTexture.width} ` + + `Y: ${frame.y} + ${frame.height} > ${this.baseTexture.height}`); } // this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; diff --git a/src/core/utils/trimCanvas.js b/src/core/utils/trimCanvas.js index 37a0378..5af6de0 100644 --- a/src/core/utils/trimCanvas.js +++ b/src/core/utils/trimCanvas.js @@ -10,9 +10,15 @@ export default function trimCanvas(canvas) { // https://gist.github.com/remy/784508 + + let width = canvas.width; + let height = canvas.height; + const context = canvas.getContext('2d'); - const pixels = context.getImageData(0, 0, canvas.width, canvas.height); - const l = pixels.data.length; + const imageData = context.getImageData(0, 0, width, height); + const pixels = imageData.data; + const len = pixels.length; + const bound = { top: null, left: null, @@ -23,12 +29,12 @@ let x; let y; - for (i = 0; i < l; i += 4) + for (i = 0; i < len; i += 4) { - if (pixels.data[i + 3] !== 0) + if (pixels[i + 3] !== 0) { - x = (i / 4) % canvas.width; - y = ~~((i / 4) / canvas.width); + x = (i / 4) % width; + y = ~~((i / 4) / width); if (bound.top === null) { @@ -64,8 +70,9 @@ } } - const height = bound.bottom - bound.top + 1; - const width = bound.right - bound.left; + width = bound.right - bound.left; + height = bound.bottom - bound.top + 1; + const data = context.getImageData(bound.left, bound.top, width, height); return { diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index f90d248..fe82451 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -220,20 +220,33 @@ transform.tx * resolution, transform.ty * resolution); - // TODO - this should be rolled into the setTransform above.. - context.scale(this.tileScale.x / baseTextureResolution, this.tileScale.y / baseTextureResolution); - - context.translate(modX + (this.anchor.x * -this._width), - modY + (this.anchor.y * -this._height)); - renderer.setBlendMode(this.blendMode); // fill the pattern! context.fillStyle = this._canvasPattern; - context.fillRect(-modX, - -modY, - this._width / this.tileScale.x * baseTextureResolution, - this._height / this.tileScale.y * baseTextureResolution); + + // TODO - this should be rolled into the setTransform above.. + context.scale(this.tileScale.x / baseTextureResolution, this.tileScale.y / baseTextureResolution); + + const anchorX = this.anchor.x * -this._width; + const anchorY = this.anchor.y * -this._height; + + if (this.uvRespectAnchor) + { + context.translate(modX, modY); + + context.fillRect(-modX + anchorX, -modY + anchorY, + this._width / this.tileScale.x * baseTextureResolution, + this._height / this.tileScale.y * baseTextureResolution); + } + else + { + context.translate(modX + anchorX, modY + anchorY); + + context.fillRect(-modX, -modY, + this._width / this.tileScale.x * baseTextureResolution, + this._height / this.tileScale.y * baseTextureResolution); + } } /** diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 575aad4..5dd5640 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -41,7 +41,7 @@ * provide a performance benefit for complex static displayObjects. * To remove simply set this property to 'false' * - * IMPORTANT GOTCHA - make sure that all your textures are preloaded BEFORE calling setting this property + * IMPORTANT GOTCHA - make sure that all your textures are preloaded BEFORE setting this property to true * as it will take a snapshot of what is currently there. If the textures have not loaded then they will not appear. * * @member {boolean} diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 112de0b..d5355c3 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -36,7 +36,7 @@ this.maskMatrix = maskMatrix; this.uniforms.mapSampler = sprite.texture; - this.uniforms.filterMatrix = maskMatrix.toArray(true); + this.uniforms.filterMatrix = maskMatrix; this.uniforms.scale = { x: 1, y: 1 }; if (scale === null || scale === undefined) diff --git a/src/mesh/Rope.js b/src/mesh/Rope.js index e448e6c..5621a7d 100644 --- a/src/mesh/Rope.js +++ b/src/mesh/Rope.js @@ -33,6 +33,7 @@ * @member {PIXI.Point[]} An array of points that determine the rope */ this.points = points; + this.refresh(); } /** @@ -40,8 +41,11 @@ */ refresh() { + const points = this.points; + if(!points)return; + const vertexBuffer = this.geometry.getAttribute('aVertexPosition'); const uvBuffer = this.geometry.getAttribute('aTextureCoord'); const indexBuffer = this.geometry.getIndex(); diff --git a/test/core/Text.js b/test/core/Text.js index b8ce561..5799ad4 100644 --- a/test/core/Text.js +++ b/test/core/Text.js @@ -112,4 +112,42 @@ expect(text.width).to.equal(300); }); }); + + describe('text', function () + { + it('should convert numbers into strings', function () + { + const text = new PIXI.Text(2); + + expect(text.text).to.equal('2'); + }); + + it('should not change 0 to \'\'', function () + { + const text = new PIXI.Text(0); + + expect(text.text).to.equal('0'); + }); + + it('should prevent setting null', function () + { + const text = new PIXI.Text(null); + + expect(text.text).to.equal(' '); + }); + + it('should prevent setting undefined', function () + { + const text = new PIXI.Text(); + + expect(text.text).to.equal(' '); + }); + + it('should prevent setting \'\'', function () + { + const text = new PIXI.Text(''); + + expect(text.text).to.equal(' '); + }); + }); }); diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 0400d13..abf5d02 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -33,6 +33,11 @@ height = circleData.height; } + if (width === 0 || height === 0) + { + return; + } + const totalSegs = Math.floor(30 * Math.sqrt(circleData.radius)) || Math.floor(15 * Math.sqrt(circleData.width + circleData.height)); diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index 9761b99..4f6f7c9 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -248,12 +248,11 @@ let currentState; - // this syncs the pixi filters uniforms with glsl uniforms - - if (shader.uniforms.data.filterArea) + if (uniforms.filterArea) { currentState = this.filterData.stack[this.filterData.index]; - const filterArea = shader.uniforms.filterArea; + + const filterArea = uniforms.filterArea; filterArea[0] = currentState.renderTarget.size.width; filterArea[1] = currentState.renderTarget.size.height; @@ -265,11 +264,11 @@ // use this to clamp displaced texture coords so they belong to filterArea // see displacementFilter fragment shader for an example - if (shader.uniforms.data.filterClamp) + if (uniforms.filterClamp) { currentState = this.filterData.stack[this.filterData.index]; - const filterClamp = shader.uniforms.filterClamp; + const filterClamp = uniforms.filterClamp; filterClamp[0] = 0; filterClamp[1] = 0; @@ -390,7 +389,7 @@ */ destroy() { - this.shaderCache = []; + this.shaderCache = {}; this.emptyPool(); } diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 836f109..1402e47 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -380,8 +380,12 @@ .addIndex(this.indexBuffer) .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aVertexPosition, gl.FLOAT, false, this.vertByteSize, 0) .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureCoord, gl.UNSIGNED_SHORT, true, this.vertByteSize, 2 * 4) - .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4) - .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); + .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4); + + if (this.shader.attributes.aTextureId) + { + this.vaos[this.vertexCount].addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); + } /* eslint-enable max-len */ } diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 5e7bc0b..18fb723 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -489,6 +489,19 @@ } /** + * Gets the local bounds of the text object. + * + * @param {Rectangle} rect - The output rectangle. + * @return {Rectangle} The bounds. + */ + getLocalBounds(rect) + { + this.updateText(true); + + return super.getLocalBounds.call(this, rect); + } + + /** * calculates the bounds of the Text as a rectangle. The bounds calculation takes the worldTransform into account. */ _calculateBounds() @@ -731,7 +744,7 @@ set text(text) // eslint-disable-line require-jsdoc { - text = String(text || ' '); + text = String(text === '' || text === null || text === undefined ? ' ' : text); if (this._text === text) { diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index ca31456..6403d4f 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -459,7 +459,9 @@ if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - throw new Error(`Texture Error: frame does not fit inside the base Texture dimensions ${this}`); + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions: ' + + `X: ${frame.x} + ${frame.width} > ${this.baseTexture.width} ` + + `Y: ${frame.y} + ${frame.height} > ${this.baseTexture.height}`); } // this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; diff --git a/src/core/utils/trimCanvas.js b/src/core/utils/trimCanvas.js index 37a0378..5af6de0 100644 --- a/src/core/utils/trimCanvas.js +++ b/src/core/utils/trimCanvas.js @@ -10,9 +10,15 @@ export default function trimCanvas(canvas) { // https://gist.github.com/remy/784508 + + let width = canvas.width; + let height = canvas.height; + const context = canvas.getContext('2d'); - const pixels = context.getImageData(0, 0, canvas.width, canvas.height); - const l = pixels.data.length; + const imageData = context.getImageData(0, 0, width, height); + const pixels = imageData.data; + const len = pixels.length; + const bound = { top: null, left: null, @@ -23,12 +29,12 @@ let x; let y; - for (i = 0; i < l; i += 4) + for (i = 0; i < len; i += 4) { - if (pixels.data[i + 3] !== 0) + if (pixels[i + 3] !== 0) { - x = (i / 4) % canvas.width; - y = ~~((i / 4) / canvas.width); + x = (i / 4) % width; + y = ~~((i / 4) / width); if (bound.top === null) { @@ -64,8 +70,9 @@ } } - const height = bound.bottom - bound.top + 1; - const width = bound.right - bound.left; + width = bound.right - bound.left; + height = bound.bottom - bound.top + 1; + const data = context.getImageData(bound.left, bound.top, width, height); return { diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index f90d248..fe82451 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -220,20 +220,33 @@ transform.tx * resolution, transform.ty * resolution); - // TODO - this should be rolled into the setTransform above.. - context.scale(this.tileScale.x / baseTextureResolution, this.tileScale.y / baseTextureResolution); - - context.translate(modX + (this.anchor.x * -this._width), - modY + (this.anchor.y * -this._height)); - renderer.setBlendMode(this.blendMode); // fill the pattern! context.fillStyle = this._canvasPattern; - context.fillRect(-modX, - -modY, - this._width / this.tileScale.x * baseTextureResolution, - this._height / this.tileScale.y * baseTextureResolution); + + // TODO - this should be rolled into the setTransform above.. + context.scale(this.tileScale.x / baseTextureResolution, this.tileScale.y / baseTextureResolution); + + const anchorX = this.anchor.x * -this._width; + const anchorY = this.anchor.y * -this._height; + + if (this.uvRespectAnchor) + { + context.translate(modX, modY); + + context.fillRect(-modX + anchorX, -modY + anchorY, + this._width / this.tileScale.x * baseTextureResolution, + this._height / this.tileScale.y * baseTextureResolution); + } + else + { + context.translate(modX + anchorX, modY + anchorY); + + context.fillRect(-modX, -modY, + this._width / this.tileScale.x * baseTextureResolution, + this._height / this.tileScale.y * baseTextureResolution); + } } /** diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 575aad4..5dd5640 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -41,7 +41,7 @@ * provide a performance benefit for complex static displayObjects. * To remove simply set this property to 'false' * - * IMPORTANT GOTCHA - make sure that all your textures are preloaded BEFORE calling setting this property + * IMPORTANT GOTCHA - make sure that all your textures are preloaded BEFORE setting this property to true * as it will take a snapshot of what is currently there. If the textures have not loaded then they will not appear. * * @member {boolean} diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 112de0b..d5355c3 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -36,7 +36,7 @@ this.maskMatrix = maskMatrix; this.uniforms.mapSampler = sprite.texture; - this.uniforms.filterMatrix = maskMatrix.toArray(true); + this.uniforms.filterMatrix = maskMatrix; this.uniforms.scale = { x: 1, y: 1 }; if (scale === null || scale === undefined) diff --git a/src/mesh/Rope.js b/src/mesh/Rope.js index e448e6c..5621a7d 100644 --- a/src/mesh/Rope.js +++ b/src/mesh/Rope.js @@ -33,6 +33,7 @@ * @member {PIXI.Point[]} An array of points that determine the rope */ this.points = points; + this.refresh(); } /** @@ -40,8 +41,11 @@ */ refresh() { + const points = this.points; + if(!points)return; + const vertexBuffer = this.geometry.getAttribute('aVertexPosition'); const uvBuffer = this.geometry.getAttribute('aTextureCoord'); const indexBuffer = this.geometry.getIndex(); diff --git a/test/core/Text.js b/test/core/Text.js index b8ce561..5799ad4 100644 --- a/test/core/Text.js +++ b/test/core/Text.js @@ -112,4 +112,42 @@ expect(text.width).to.equal(300); }); }); + + describe('text', function () + { + it('should convert numbers into strings', function () + { + const text = new PIXI.Text(2); + + expect(text.text).to.equal('2'); + }); + + it('should not change 0 to \'\'', function () + { + const text = new PIXI.Text(0); + + expect(text.text).to.equal('0'); + }); + + it('should prevent setting null', function () + { + const text = new PIXI.Text(null); + + expect(text.text).to.equal(' '); + }); + + it('should prevent setting undefined', function () + { + const text = new PIXI.Text(); + + expect(text.text).to.equal(' '); + }); + + it('should prevent setting \'\'', function () + { + const text = new PIXI.Text(''); + + expect(text.text).to.equal(' '); + }); + }); }); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js index d160a56..309da0e 100644 --- a/test/core/getLocalBounds.js +++ b/test/core/getLocalBounds.js @@ -196,4 +196,13 @@ expect(bounds.width).to.equal(100); expect(bounds.height).to.equal(100); }); + + it('should register correct local-bounds with a Text', function () + { + const text = new PIXI.Text('hello'); + const bounds = text.getLocalBounds(); + + expect(bounds.width).to.not.equal(0); + expect(bounds.height).to.not.equal(0); + }); });