2017-07-04 12:23:58 +00:00
|
|
|
var Class = require('../utils/Class');
|
2017-01-20 18:51:20 +00:00
|
|
|
var CONST = require('../const');
|
2016-12-08 16:21:16 +00:00
|
|
|
var IsSizePowerOfTwo = require('../math/pow2/IsSizePowerOfTwo');
|
2017-07-04 12:23:58 +00:00
|
|
|
var ScaleModes = require('../renderer/ScaleModes');
|
2016-12-06 16:18:28 +00:00
|
|
|
|
2017-07-04 12:23:58 +00:00
|
|
|
var TextureSource = new Class({
|
2016-12-06 16:18:28 +00:00
|
|
|
|
2017-07-04 12:23:58 +00:00
|
|
|
initialize:
|
2017-06-07 23:12:22 +00:00
|
|
|
|
2017-07-04 12:23:58 +00:00
|
|
|
function TextureSource (texture, source, width, height)
|
|
|
|
{
|
2017-09-13 20:54:32 +00:00
|
|
|
var game = texture.manager.game;
|
|
|
|
|
2017-07-04 12:23:58 +00:00
|
|
|
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;
|
|
|
|
|
2017-08-01 12:10:08 +00:00
|
|
|
this.isPowerOf2 = IsSizePowerOfTwo(this.width, this.height);
|
|
|
|
|
2017-09-13 20:54:32 +00:00
|
|
|
this.init(game);
|
|
|
|
},
|
2017-07-04 12:23:58 +00:00
|
|
|
|
2017-09-13 20:54:32 +00:00
|
|
|
init: function (game)
|
|
|
|
{
|
|
|
|
this.glTexture = null;
|
2017-07-04 12:23:58 +00:00
|
|
|
|
|
|
|
if (game.config.renderType === CONST.WEBGL)
|
|
|
|
{
|
2017-09-13 20:54:32 +00:00
|
|
|
game.renderer.createTexture(this, this.width, this.height);
|
2017-07-04 12:23:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (game.config.pixelArt)
|
|
|
|
{
|
|
|
|
this.setFilter(1);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setFilter: function (filterMode)
|
2017-05-20 01:16:45 +00:00
|
|
|
{
|
2017-07-04 12:23:58 +00:00
|
|
|
var game = this.texture.manager.game;
|
|
|
|
|
|
|
|
if (game.config.renderType === CONST.WEBGL)
|
|
|
|
{
|
|
|
|
game.renderer.setTextureFilterMode(this.glTexture, filterMode);
|
|
|
|
}
|
2017-05-20 01:16:45 +00:00
|
|
|
}
|
2017-07-04 12:23:58 +00:00
|
|
|
|
|
|
|
});
|
2017-05-20 01:16:45 +00:00
|
|
|
|
2016-12-06 16:18:28 +00:00
|
|
|
module.exports = TextureSource;
|