2016-12-06 16:18:28 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2016 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2017-01-20 18:51:20 +00:00
|
|
|
var CONST = require('../const');
|
2017-01-18 14:48:02 +00:00
|
|
|
var ScaleModes = require('../renderer/ScaleModes');
|
2016-12-08 16:21:16 +00:00
|
|
|
var IsSizePowerOfTwo = require('../math/pow2/IsSizePowerOfTwo');
|
2016-12-06 16:18:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @class Phaser.TextureSource
|
|
|
|
* @constructor
|
|
|
|
* @param {object} source
|
|
|
|
* @param {number} scaleMode
|
|
|
|
*/
|
2017-05-10 23:36:11 +00:00
|
|
|
var TextureSource = function (texture, source, width, height)
|
2016-12-06 16:18:28 +00:00
|
|
|
{
|
|
|
|
this.texture = texture;
|
|
|
|
|
|
|
|
this.image = source;
|
|
|
|
|
|
|
|
this.compressionAlgorithm = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Resolution of the texture.
|
|
|
|
*
|
|
|
|
* @property resolution
|
|
|
|
* @type Number
|
|
|
|
*/
|
|
|
|
this.resolution = 1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The width of the Texture.
|
|
|
|
*
|
|
|
|
* @property width
|
|
|
|
* @type Number
|
|
|
|
* @readOnly
|
|
|
|
*/
|
2017-05-10 23:36:11 +00:00
|
|
|
this.width = width || source.naturalWidth || source.width || 0;
|
2016-12-06 16:18:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The height of the Texture.
|
|
|
|
*
|
|
|
|
* @property height
|
|
|
|
* @type Number
|
|
|
|
* @readOnly
|
|
|
|
*/
|
2017-05-10 23:36:11 +00:00
|
|
|
this.height = height || source.naturalHeight || source.height || 0;
|
2016-12-06 16:18:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The scale mode to apply when scaling this texture.
|
|
|
|
* NEAREST or DEFAULT
|
|
|
|
*
|
|
|
|
* @property scaleMode
|
|
|
|
* @type {Number}
|
|
|
|
* @default Phaser.scaleModes.DEFAULT;
|
|
|
|
*/
|
2017-01-18 14:48:02 +00:00
|
|
|
this.scaleMode = ScaleModes.DEFAULT;
|
2016-12-06 16:18:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Controls if RGB channels should be pre-multiplied by Alpha (WebGL only)
|
|
|
|
*
|
|
|
|
* @property premultipliedAlpha
|
|
|
|
* @type Boolean
|
|
|
|
* @default true
|
|
|
|
*/
|
|
|
|
this.premultipliedAlpha = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set this to true if a mipmap of this texture needs to be generated. This value needs to be set before the texture is used
|
|
|
|
* Also the texture must be a power of two size to work
|
|
|
|
*
|
2017-01-20 18:51:20 +00:00
|
|
|
* @property mipmapLevel
|
|
|
|
* @type {integer}
|
2016-12-06 16:18:28 +00:00
|
|
|
*/
|
2017-01-20 18:51:20 +00:00
|
|
|
this.mipmapLevel = 0;
|
2016-12-06 16:18:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A BaseTexture can be set to skip the rendering phase in the WebGL Sprite Batch.
|
|
|
|
*
|
|
|
|
* You may want to do this if you have a parent Sprite with no visible texture (i.e. uses the internal `__default` texture)
|
|
|
|
* that has children that you do want to render, without causing a batch flush in the process.
|
|
|
|
*
|
|
|
|
* @property renderable
|
|
|
|
* @type Boolean
|
|
|
|
*/
|
|
|
|
this.renderable = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property isPowerOf2
|
|
|
|
* @type boolean
|
|
|
|
*/
|
2016-12-08 16:21:16 +00:00
|
|
|
this.isPowerOf2 = IsSizePowerOfTwo(this.width, this.height);
|
2016-12-06 16:18:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property glTexture
|
|
|
|
*/
|
|
|
|
this.glTexture = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The multi texture batching index number.
|
|
|
|
* @property glTextureIndex
|
|
|
|
* @type Number
|
|
|
|
*/
|
|
|
|
this.glTextureIndex = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The timestamp when this texture was last used by the WebGL renderer.
|
|
|
|
* Can be used to purge out 'dead' textures from GPU memory.
|
|
|
|
* @property glLastUsed
|
|
|
|
* @type Number
|
|
|
|
*/
|
|
|
|
this.glLastUsed = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property glDirty
|
|
|
|
*/
|
|
|
|
this.glDirty = true;
|
2017-01-20 18:51:20 +00:00
|
|
|
|
|
|
|
var game = texture.manager.game;
|
|
|
|
|
|
|
|
if (game.config.renderType === CONST.WEBGL)
|
|
|
|
{
|
2017-04-05 22:01:44 +00:00
|
|
|
game.renderer.createTexture(this);
|
2017-01-20 18:51:20 +00:00
|
|
|
}
|
2016-12-06 16:18:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = TextureSource;
|