UNPKG

pixi.js

Version:

<p align="center"> <a href="https://pixijs.com" target="_blank" rel="noopener noreferrer"> <img height="150" src="https://files.pixijs.download/branding/pixijs-logo-transparent-dark.svg?v=1" alt="PixiJS logo"> </a> </p> <br/> <p align="center">

1 lines 12.1 kB
{"version":3,"file":"TextureStyle.mjs","sources":["../../../../../src/rendering/renderers/shared/texture/TextureStyle.ts"],"sourcesContent":["import EventEmitter from 'eventemitter3';\nimport { uid } from '../../../../utils/data/uid';\nimport { deprecation, v8_0_0 } from '../../../../utils/logging/deprecation';\n\nimport type { BindResource } from '../../gpu/shader/BindResource';\nimport type { COMPARE_FUNCTION, SCALE_MODE, WRAP_MODE } from './const';\n\nconst idHash: Record<string, number> = Object.create(null);\n\n/**\n * This takes a shader string and maps it to a resource id.\n * This is a little different than regular resource ids as these ids\n * are not unique to the resource. But must not overlap with other (non sampler) resources Ids.\n * @param value - the string to turn into a resource id\n * @returns a unique resource id\n */\nfunction createResourceIdFromString(value: string): number\n{\n const id = idHash[value];\n\n if (id === undefined)\n {\n idHash[value] = uid('resource');\n }\n\n return id;\n}\n\n/**\n * The options for the texture style.\n * @category rendering\n * @advanced\n */\nexport interface TextureStyleOptions extends Partial<TextureStyle>\n{\n /** setting this will set wrapModeU,wrapModeV and wrapModeW all at once! */\n addressMode?: WRAP_MODE;\n /** specifies the {{GPUAddressMode|address modes}} for the texture width, height, and depth coordinates, respectively. */\n addressModeU?: WRAP_MODE;\n /** specifies the {{GPUAddressMode|address modes}} for the texture width, height, and depth coordinates, respectively. */\n addressModeV?: WRAP_MODE;\n /** Specifies the {{GPUAddressMode|address modes}} for the texture width, height, and depth coordinates, respectively. */\n addressModeW?: WRAP_MODE;\n\n /** setting this will set magFilter,minFilter and mipmapFilter all at once! */\n scaleMode?: SCALE_MODE;\n\n /** specifies the sampling behavior when the sample footprint is smaller than or equal to one texel. */\n magFilter?: SCALE_MODE;\n /** specifies the sampling behavior when the sample footprint is larger than one texel. */\n minFilter?: SCALE_MODE;\n /** specifies behavior for sampling between mipmap levels. */\n mipmapFilter?: SCALE_MODE;\n\n /** specifies the minimum and maximum levels of detail, respectively, used internally when sampling a texture. */\n lodMinClamp?: number;\n /** Specifies the minimum and maximum levels of detail, respectively, used internally when sampling a texture. */\n lodMaxClamp?: number;\n /**\n * When provided the sampler will be a comparison sampler with the specified\n * {@link COMPARE_FUNCTION}.\n * Note: Comparison samplers may use filtering, but the sampling results will be\n * implementation-dependent and may differ from the normal filtering rules.\n */\n compare?: COMPARE_FUNCTION;\n /**\n * Specifies the maximum anisotropy value clamp used by the sampler.\n * Note: Most implementations support {@link TextureStyle#maxAnisotropy} values in range\n * between 1 and 16, inclusive. The used value of {@link TextureStyle#maxAnisotropy} will\n * be clamped to the maximum value that the platform supports.\n *\n * setting this to anything higher than 1 will set scale modes to 'linear'\n */\n maxAnisotropy?: number;\n}\n\n/**\n * A texture style describes how a texture should be sampled by a shader.\n * @category rendering\n * @advanced\n */\nexport class TextureStyle extends EventEmitter<{\n change: TextureStyle,\n destroy: TextureStyle,\n}> implements BindResource\n{\n /** @internal */\n public _resourceType = 'textureSampler';\n /** @internal */\n public _touched = 0;\n private _sharedResourceId: number;\n\n /** default options for the style */\n public static readonly defaultOptions: TextureStyleOptions = {\n addressMode: 'clamp-to-edge',\n scaleMode: 'linear'\n };\n\n /** */\n public addressModeU?: WRAP_MODE;\n /** */\n public addressModeV?: WRAP_MODE;\n /** Specifies the {{GPUAddressMode|address modes}} for the texture width, height, and depth coordinates, respectively. */\n public addressModeW?: WRAP_MODE;\n /** Specifies the sampling behavior when the sample footprint is smaller than or equal to one texel. */\n public magFilter?: SCALE_MODE;\n /** Specifies the sampling behavior when the sample footprint is larger than one texel. */\n public minFilter?: SCALE_MODE;\n /** Specifies behavior for sampling between mipmap levels. */\n public mipmapFilter?: SCALE_MODE;\n /** */\n public lodMinClamp?: number;\n /** Specifies the minimum and maximum levels of detail, respectively, used internally when sampling a texture. */\n public lodMaxClamp?: number;\n /**\n * When provided the sampler will be a comparison sampler with the specified\n * {@link COMPARE_FUNCTION}.\n * Note: Comparison samplers may use filtering, but the sampling results will be\n * implementation-dependent and may differ from the normal filtering rules.\n */\n public compare?: COMPARE_FUNCTION;\n /**\n * Specifies the maximum anisotropy value clamp used by the sampler.\n * Note: Most implementations support {@link TextureStyle#maxAnisotropy} values in range\n * between 1 and 16, inclusive. The used value of {@link TextureStyle#maxAnisotropy} will\n * be clamped to the maximum value that the platform supports.\n * @internal\n */\n public _maxAnisotropy?: number = 1;\n\n /**\n * Has the style been destroyed?\n * @readonly\n */\n public destroyed = false;\n\n /**\n * @param options - options for the style\n */\n constructor(options: TextureStyleOptions = {})\n {\n super();\n\n options = { ...TextureStyle.defaultOptions, ...options };\n\n this.addressMode = options.addressMode;\n\n this.addressModeU = options.addressModeU ?? this.addressModeU;\n this.addressModeV = options.addressModeV ?? this.addressModeV;\n this.addressModeW = options.addressModeW ?? this.addressModeW;\n\n this.scaleMode = options.scaleMode;\n\n this.magFilter = options.magFilter ?? this.magFilter;\n this.minFilter = options.minFilter ?? this.minFilter;\n this.mipmapFilter = options.mipmapFilter ?? this.mipmapFilter;\n\n this.lodMinClamp = options.lodMinClamp;\n this.lodMaxClamp = options.lodMaxClamp;\n\n this.compare = options.compare;\n\n this.maxAnisotropy = options.maxAnisotropy ?? 1;\n }\n\n set addressMode(value: WRAP_MODE)\n {\n this.addressModeU = value;\n this.addressModeV = value;\n this.addressModeW = value;\n }\n\n /** setting this will set wrapModeU,wrapModeV and wrapModeW all at once! */\n get addressMode(): WRAP_MODE\n {\n return this.addressModeU;\n }\n\n set wrapMode(value: WRAP_MODE)\n {\n // #if _DEBUG\n deprecation(v8_0_0, 'TextureStyle.wrapMode is now TextureStyle.addressMode');\n // #endif\n\n this.addressMode = value;\n }\n\n get wrapMode(): WRAP_MODE\n {\n return this.addressMode;\n }\n\n set scaleMode(value: SCALE_MODE)\n {\n this.magFilter = value;\n this.minFilter = value;\n this.mipmapFilter = value;\n }\n\n /** setting this will set magFilter,minFilter and mipmapFilter all at once! */\n get scaleMode(): SCALE_MODE\n {\n return this.magFilter;\n }\n\n /** Specifies the maximum anisotropy value clamp used by the sampler. */\n set maxAnisotropy(value: number)\n {\n this._maxAnisotropy = Math.min(value, 16);\n\n if (this._maxAnisotropy > 1)\n {\n this.scaleMode = 'linear';\n }\n }\n\n get maxAnisotropy(): number\n {\n return this._maxAnisotropy;\n }\n\n // TODO - move this to WebGL?\n get _resourceId(): number\n {\n return this._sharedResourceId || this._generateResourceId();\n }\n\n public update()\n {\n // manage the resource..\n this._sharedResourceId = null;\n this.emit('change', this);\n }\n\n private _generateResourceId(): number\n {\n // eslint-disable-next-line max-len\n const bigKey = `${this.addressModeU}-${this.addressModeV}-${this.addressModeW}-${this.magFilter}-${this.minFilter}-${this.mipmapFilter}-${this.lodMinClamp}-${this.lodMaxClamp}-${this.compare}-${this._maxAnisotropy}`;\n\n this._sharedResourceId = createResourceIdFromString(bigKey);\n\n return this._resourceId;\n }\n\n /** Destroys the style */\n public destroy()\n {\n this.destroyed = true;\n\n this.emit('destroy', this);\n this.emit('change', this);\n\n this.removeAllListeners();\n }\n}\n"],"names":[],"mappings":";;;;;AAOA,MAAM,MAAA,mBAAiC,MAAA,CAAO,MAAA,CAAO,IAAI,CAAA;AASzD,SAAS,2BAA2B,KAAA,EACpC;AACI,EAAA,MAAM,EAAA,GAAK,OAAO,KAAK,CAAA;AAEvB,EAAA,IAAI,OAAO,KAAA,CAAA,EACX;AACI,IAAA,MAAA,CAAO,KAAK,CAAA,GAAI,GAAA,CAAI,UAAU,CAAA;AAAA,EAClC;AAEA,EAAA,OAAO,EAAA;AACX;AAuDO,MAAM,aAAA,GAAN,MAAM,aAAA,SAAqB,YAAA,CAIlC;AAAA;AAAA;AAAA;AAAA,EAsDI,WAAA,CAAY,OAAA,GAA+B,EAAC,EAC5C;AACI,IAAA,KAAA,EAAM;AAtDV;AAAA,IAAA,IAAA,CAAO,aAAA,GAAgB,gBAAA;AAEvB;AAAA,IAAA,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