{"version":3,"file":"TextureView.js","sources":["../../../../../src/rendering/renderers/shared/texture/TextureView.ts"],"sourcesContent":["import EventEmitter from 'eventemitter3';\nimport { uid } from '../../../../utils/data/uid';\n\nimport type { BindResource } from '../../gpu/shader/BindResource';\nimport type { TextureSource } from './sources/TextureSource';\n\n/**\n * A TextureView allows you to specify exactly how a `TextureSource` should be interpreted by the GPU.\n * This is particularly useful for advanced 3D rendering where you might need to view a depth/stencil\n * texture as purely a 'depth-only' or 'stencil-only' view.\n *\n * It implements `BindResource` so it can be passed directly into a `BindGroup` or `Shader`.\n * @category rendering\n * @advanced\n */\nexport class TextureView extends EventEmitter<{\n    change: TextureView;\n    destroy: TextureView;\n}> implements BindResource\n{\n    /** The type of resource this is (for BindGroup compatibility). */\n    public readonly _resourceType = 'textureView';\n    /** Unique ID for this resource. */\n    public readonly _resourceId: number = uid('resource');\n\n    /** The underlying texture source. */\n    public readonly source: TextureSource;\n    /** The WebGPU texture view descriptor. */\n    public readonly viewDescriptor: GPUTextureViewDescriptor;\n\n    /**\n     * @param source - The texture source to view.\n     * @param viewDescriptor - The WebGPU texture view descriptor.\n     */\n    constructor(source: TextureSource, viewDescriptor: GPUTextureViewDescriptor)\n    {\n        super();\n\n        this.source = source;\n        this.viewDescriptor = viewDescriptor;\n\n        this._onChange = this._onChange.bind(this);\n        this._onDestroy = this._onDestroy.bind(this);\n\n        // Proxy the source's change event so BindGroups know when to update\n        this.source.on('change', this._onChange);\n        this.source.on('destroy', this._onDestroy);\n    }\n\n    private _onChange(): void\n    {\n        this.emit('change', this);\n    }\n\n    private _onDestroy(): void\n    {\n        this.destroy();\n    }\n\n    /** Returns whether the underlying source is destroyed. */\n    get destroyed(): boolean\n    {\n        return this.source.destroyed;\n    }\n\n    /** Destroys the view and cleans up event listeners. */\n    public destroy(): void\n    {\n        if (this.source)\n        {\n            this.source.off('change', this._onChange);\n            this.source.off('destroy', this._onDestroy);\n        }\n\n        this.emit('destroy', this);\n        this.removeAllListeners();\n    }\n}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