phaser/src/textures/TextureSource.js

63 lines
1.4 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;
2017-09-20 23:15:31 +00:00
this.isCanvas = (source instanceof HTMLCanvasElement);
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)
{
2018-01-22 21:21:47 +00:00
game.renderer.createTextureFromSource(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)
{
2018-01-22 21:21:47 +00:00
game.renderer.setTextureFilter(this.glTexture, filterMode);
2017-07-04 12:23:58 +00:00
}
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;