UNPKG

@awayjs/stage

Version:
117 lines (116 loc) 3.74 kB
import { __extends } from "tslib"; import { AssetBase } from '@awayjs/core'; import { ImageEvent } from '../events/ImageEvent'; var ImageBase = /** @class */ (function (_super) { __extends(ImageBase, _super); /** * */ function ImageBase() { var _this = _super.call(this) || this; _this._format = 'bgra'; _this._isDisposed = false; return _this; } Object.defineProperty(ImageBase.prototype, "isDisposed", { get: function () { return this._isDisposed; }, enumerable: false, configurable: true }); Object.defineProperty(ImageBase.prototype, "format", { /** * * @returns {string} */ get: function () { return this._format; }, enumerable: false, configurable: true }); ImageBase.prototype.dispose = function () { this._isDisposed = true; this.clear(); }; /** * */ ImageBase.prototype.invalidateMipmaps = function () { this.dispatchEvent(new ImageEvent(ImageEvent.INVALIDATE_MIPMAPS, this)); }; return ImageBase; }(AssetBase)); export { ImageBase }; import { AbstractMethodError, AbstractionBase } from '@awayjs/core'; import { ImageUtils } from '../utils/ImageUtils'; /** * * @class away.pool.GL_ImageBase */ var _Stage_ImageBase = /** @class */ (function (_super) { __extends(_Stage_ImageBase, _super); function _Stage_ImageBase() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.usages = 0; _this._invalidMipmaps = true; _this._invalidMapper = true; return _this; } _Stage_ImageBase.prototype.getTexture = function () { if (!this._texture) { this._createTexture(); this._invalid = true; } return this._texture; }; _Stage_ImageBase.prototype.getType = function () { throw new AbstractMethodError(); }; _Stage_ImageBase.prototype.init = function (asset, stage) { var _this = this; _super.prototype.init.call(this, asset, stage); this._stage = stage; this._onInvalidateMipmapsDelegate = function (event) { return _this._onInvalidateMipmaps(event); }; this._asset.addEventListener(ImageEvent.INVALIDATE_MIPMAPS, this._onInvalidateMipmapsDelegate); }; /** * */ _Stage_ImageBase.prototype.onClear = function (event) { _super.prototype.onClear.call(this, event); if (this._texture) { this._texture.dispose(); this._texture = null; } }; _Stage_ImageBase.prototype.activate = function (index, sampler) { if (sampler === void 0) { sampler = null; } if (!sampler) sampler = ImageUtils.getDefaultImageSampler(); var mipmap = (sampler.mipmap && !this._stage.globalDisableMipmap) ? sampler.mipmap : false; this._stage.setSamplerAt(index, sampler); this._stage.context.setTextureAt(index, this.getTexture()); if (!this._mipmap && mipmap) { this._mipmap = true; this._invalidMipmaps = true; } if (this._invalidMipmaps) { this._invalidMipmaps = false; if (mipmap) //todo: allow for non-generated mipmaps this._texture.generateMipmaps(); } }; _Stage_ImageBase.prototype._createTexture = function () { throw new AbstractMethodError(); }; /** * */ _Stage_ImageBase.prototype._onInvalidateMipmaps = function (event) { this._invalidMipmaps = true; }; return _Stage_ImageBase; }(AbstractionBase)); export { _Stage_ImageBase };