1 line
12 KiB
Plaintext
1 line
12 KiB
Plaintext
{"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\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 GPUCompareFunction}.\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 GPUSamplerDescriptor#maxAnisotropy} values in range\n * between 1 and 16, inclusive. The used value of {@link GPUSamplerDescriptor#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 * @memberof rendering\n */\nexport class TextureStyle extends EventEmitter<{\n change: TextureStyle,\n destroy: TextureStyle,\n}> implements BindResource\n{\n public _resourceType = 'textureSampler';\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 GPUCompareFunction}.\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 GPUSamplerDescriptor#maxAnisotropy} values in range\n * between 1 and 16, inclusive. The used value of {@link GPUSamplerDescriptor#maxAnisotropy} will\n * be clamped to the maximum value that the platform supports.\n * @internal\n * @ignore\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.emit('change', this);\n this._sharedResourceId = null;\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,mBAAwC,MAAA,CAAA,MAAA,CAAO,IAAI,CAAA,CAAA;AASzD,SAAS,2BAA2B,KACpC,EAAA;AACI,EAAM,MAAA,EAAA,GAAK,OAAO,KAAK,CAAA,CAAA;AAEvB,EAAA,IAAI,OAAO,KACX,CAAA,EAAA;AACI,IAAO,MAAA,CAAA,KAAK,CAAI,GAAA,GAAA,CAAI,UAAU,CAAA,CAAA;AAAA,GAClC;AAEA,EAAO,OAAA,EAAA,CAAA;AACX,CAAA;AAiDO,MAAM,aAAA,GAAN,MAAM,aAAA,SAAqB,YAIlC,CAAA;AAAA;AAAA;AAAA;AAAA,EAqDI,WAAA,CAAY,OAA+B,GAAA,EAC3C,EAAA;AACI,IAAM,KAAA,EAAA,CAAA;AAtDV,IAAA,IAAA,CAAO,aAAgB,GAAA,gBAAA,CAAA;AACvB,IAAA,IAAA,CAAO,QAAW,GAAA,CAAA,CAAA;AAwClB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,IAAA,CAAO,cAA0B,GAAA,CAAA,CAAA;A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