diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 949aab7..2e90422 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -79,6 +79,13 @@ this.valid = false; /** + * This will let a renderer know that a texture has been updated (used mainly for webGL uv updates) + * + * @member {boolean} + */ + this.requiresUpdate = false; + + /** * The WebGL UV data cache. * * @member {TextureUvs} @@ -128,9 +135,6 @@ { baseTexture.once('loaded', this.onBaseTextureLoaded, this); } - - // the base texture is updated we may need to update our frame - baseTexture.on('update', this.onBaseTextureLoaded, this); } Texture.prototype = Object.create(EventEmitter.prototype); @@ -152,6 +156,8 @@ this.width = frame.width; this.height = frame.height; + + if (!this.trim && !this.rotate && (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); @@ -173,23 +179,23 @@ this.crop = frame; } - if (this.valid) + if (this.valid) { this._updateUvs(); } - - this.emit('update', this); } } }); /** - * Updates this texture for drawing. + * Updates this texture on the gpu. * */ Texture.prototype.update = function () { this.baseTexture.update(); + + }; /** @@ -199,18 +205,17 @@ */ Texture.prototype.onBaseTextureLoaded = function (baseTexture) { - baseTexture = baseTexture || this.baseTexture; - - // if no frame then create one and run the frame setter + // TODO this code looks confusing.. boo to abusing getters and setterss! if (this.noFrame) { this.frame = new math.Rectangle(0, 0, baseTexture.width, baseTexture.height); } - // otherwise rerun the frame setter with the current frame to check for baseTexture validity else { this.frame = this._frame; } + + this.emit( 'update', this ); }; /**