var CanvasPool = require('../display/canvas/CanvasPool'); var Class = require('../utils/Class'); var IsSizePowerOfTwo = require('../math/pow2/IsSizePowerOfTwo'); var ScaleModes = require('../renderer/ScaleModes'); var TextureSource = new Class({ initialize: function TextureSource(texture, source, width, height){ var game = texture.manager.game; this.renderer = game.renderer; this.texture = texture; this.image = source; this.compressionAlgorithm = null ; this.resolution = 1; this.width = width || source.naturalWidth || source.width || 0; this.height = height || source.naturalHeight || source.height || 0; this.scaleMode = ScaleModes.DEFAULT; this.isCanvas = (source instanceof HTMLCanvasElement); this.isPowerOf2 = IsSizePowerOfTwo(this.width, this.height); this.glTexture = null ; _AN_Call_init('init', this, game); } , init: function (game){ if (this.renderer.gl) { if (this.isCanvas) { this.glTexture = this.renderer.canvasToTexture(this.image); } else { this.glTexture = this.renderer.createTextureFromSource(this.image, this.width, this.height, this.scaleMode); } } if (game.config.pixelArt) { this.setFilter(1); } } , setFilter: function (filterMode){ if (this.renderer.gl) { this.renderer.setTextureFilter(this.glTexture, filterMode); } } , update: function (){ if (this.renderer.gl && this.isCanvas) { this.renderer.canvasToTexture(this.image, this.glTexture); } } , destroy: function (){ if (this.glTexture) { this.renderer.deleteTexture(this.glTexture); } if (this.isCanvas) { CanvasPool.remove(this.image); } this.renderer = null ; this.texture = null ; this.image = null ; } } ); module.exports = TextureSource;