phaser/v3/src/textures/TextureSource.js

61 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-07-04 12:23:58 +00:00
var Class = require('../utils/Class');
var CONST = require('../const');
var IsSizePowerOfTwo = require('../math/pow2/IsSizePowerOfTwo');
2017-07-04 12:23:58 +00:00
var ScaleModes = require('../renderer/ScaleModes');
2017-07-04 12:23:58 +00:00
var TextureSource = new Class({
2017-07-04 12:23:58 +00:00
initialize:
2017-07-04 12:23:58 +00:00
function TextureSource (texture, source, width, height)
{
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;
this.isPowerOf2 = IsSizePowerOfTwo(this.width, this.height);
this.init(game);
},
2017-07-04 12:23:58 +00:00
init: function (game)
{
this.glTexture = null;
2017-07-04 12:23:58 +00:00
if (game.config.renderType === CONST.WEBGL)
{
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
module.exports = TextureSource;