UNPKG

@awayjs/stage

Version:
140 lines (139 loc) 4.7 kB
import { __extends } from "tslib"; import { AssetBase, WeakAssetSet } 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; _this._owners = new WeakAssetSet(); 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.getImageType = function () { throw new AbstractMethodError(); }; ImageBase.prototype.addOwner = function (owner) { this._owners.add(owner); }; ImageBase.prototype.removeOwner = function (owner) { this._owners.remove(owner); }; ImageBase.prototype.invalidateOwners = function () { var _this = this; this._owners.forEach(function (owner) { return owner.onImageInvalidate(_this); }); }; ImageBase.prototype.clearOwners = function () { var _this = this; this._owners.forEach(function (owner) { return owner.onImageClear(_this); }); }; 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; }; Object.defineProperty(_Stage_ImageBase.prototype, "image", { get: function () { return this._useWeak ? this._asset.deref() : this._asset; }, enumerable: false, configurable: true }); _Stage_ImageBase.prototype.init = function (image, stage) { var _this = this; _super.prototype.init.call(this, image, stage, true); this._onInvalidateMipmapsDelegate = function (event) { return _this._onInvalidateMipmaps(event); }; image.addEventListener(ImageEvent.INVALIDATE_MIPMAPS, this._onInvalidateMipmapsDelegate); }; /** * */ _Stage_ImageBase.prototype.onClear = function () { var _a; if (this._texture) { this._texture.dispose(); this._texture = null; } (_a = this.image) === null || _a === void 0 ? void 0 : _a.removeEventListener(ImageEvent.INVALIDATE_MIPMAPS, this._onInvalidateMipmapsDelegate); _super.prototype.onClear.call(this); }; _Stage_ImageBase.prototype.activate = function (index, sampler) { if (sampler === void 0) { sampler = null; } if (!sampler) sampler = ImageUtils.getDefaultImageSampler(); var mipmap = (sampler.mipmap && !this._pool.globalDisableMipmap) ? sampler.mipmap : false; this._pool.setSamplerAt(index, sampler); this._pool.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 };