import EventEmitter from 'eventemitter3';
import { type GPUDataOwner } from '../../../../renderers/types';
import { type GlTexture } from '../../../gl/texture/GlTexture';
import { type GPUTextureGpuData } from '../../../gpu/texture/GpuTextureSystem';
import { type GCable, type GCData } from '../../GCSystem';
import { TextureStyle } from '../TextureStyle';
import type { BindResource } from '../../../gpu/shader/BindResource';
import type { ALPHA_MODES, SCALE_MODE, TEXTURE_DIMENSIONS, TEXTURE_FORMATS, TEXTURE_VIEW_DIMENSIONS, WRAP_MODE } from '../const';
import type { TextureStyleOptions } from '../TextureStyle';
import type { TextureResourceOrOptions } from '../utils/textureFrom';
/**
 * options for creating a new TextureSource
 *
 * `depth`, which makes a 3D texture, is on {@link TextureShapeOptions}; the constructor takes both.
 * @category rendering
 * @advanced
 */
export interface TextureSourceOptions<T extends Record<string, any> = any> extends TextureStyleOptions {
    /**
     * the resource that will be uploaded to the GPU. This is where we get our pixels from
     * eg an ImageBimt / Canvas / Video etc
     */
    resource?: T;
    /** the pixel width of this texture source. This is the REAL pure number, not accounting resolution */
    width?: number;
    /** the pixel height of this texture source. This is the REAL pure number, not accounting resolution */
    height?: number;
    /** the resolution of the texture. */
    resolution?: number;
    /** the format that the texture data has */
    format?: TEXTURE_FORMATS;
    /**
     * Used by internal textures
     * @ignore
     */
    sampleCount?: number;
    /**
     * Only really affects RenderTextures.
     * Should we use antialiasing for this texture. It will look better, but may impact performance as a
     * Blit operation will be required to resolve the texture.
     */
    antialias?: boolean;
    /**
     * How the texture is stored. Derived from {@link TextureSourceOptions.viewDimension}: `'3d'` and `'1d'` views
     * are stored as themselves, every other view as `'2d'`.
     * @deprecated since 8.22.0 - derived from `viewDimension` and `depth`, so leave it out. A value that disagrees
     * with the view throws in debug builds.
     */
    dimensions?: TEXTURE_DIMENSIONS;
    /**
     * How this texture is viewed/sampled by shaders.
     *
     * This aligns with WebGPU's `GPUTextureViewDescriptor.dimension`. It defaults from the size:
     * `depth` gives `'3d'`, `arrayLayerCount > 1` gives `'2d-array'`, anything else `'2d'`.
     * Pass it only when the size doesn't decide it, e.g. `'cube'` for 6 layers viewed as a cube map.
     */
    viewDimension?: TEXTURE_VIEW_DIMENSIONS;
    /**
     * The number of array layers for this texture source. Setting it above 1 makes a `'2d-array'` texture.
     *
     * This maps to WebGPU's `GPUTextureDescriptor.size.depthOrArrayLayers` and is used for array-backed textures
     * such as cube maps (6 layers). Can't be combined with `depth`.
     * @default 1
     * @advanced
     */
    arrayLayerCount?: number;
    /** The number of mip levels to generate for this texture. this is  overridden if autoGenerateMipmaps is true */
    mipLevelCount?: number;
    /**
     * Should we auto generate mipmaps for this texture? This will automatically generate mipmaps
     * for this texture when uploading to the GPU. Mipmapped textures take up more memory, but
     * can look better when scaled down.
     *
     * For performance reasons, it is recommended to NOT use this with RenderTextures, as they are often updated every frame.
     * If you do, make sure to call `updateMipmaps` after you update the texture.
     *
     * A 3D texture on WebGPU needs {@link TextureSourceOptions.storage} and `rgba8unorm` or `rgba16float`,
     * because a compute shader writes the mips. WebGL fills the chain with `gl.generateMipmap`.
     */
    autoGenerateMipmaps?: boolean;
    /** the alpha mode of the texture */
    alphaMode?: ALPHA_MODES;
    /** optional label, can be used for debugging */
    label?: string;
    /** If true, the Garbage Collector will unload this texture if it is not used after a period of time */
    autoGarbageCollect?: boolean;
    /** Used by RenderTexture.create to allow resizing. Not used by TextureSource itself. */
    dynamic?: boolean;
    /**
     * WebGPU only. Marks an antialiased render target as single-pass: it is never rendered into again
     * with `clear: false`, never has a filter or mask pop back onto it, and its depth/stencil is never
     * needed after the pass. PixiJS then discards its multisample buffers at the end of the pass instead
     * of writing them to memory: depth/stencil, and on GPUs that aren't tile-based also colour (tile-based
     * GPUs already discard colour; see {@link GpuExtensions.tileBased}). If the target is reopened anyway,
     * the colour is restored from the resolved texture but the depth/stencil is lost.
     * @default false
     */
    transient?: boolean;
    /**
     * WebGPU only. Lets compute shaders write to this texture as a storage texture (a `texture_storage_2d` or
     * `texture_storage_3d` binding in WGSL). PixiJS still samples it as a normal texture. WebGL has no storage
     * textures and ignores this.
     *
     * Only some formats can be storage textures: every device supports `rgba8unorm`, `rgba16float`,
     * `r32float`, `rg32float`, `rgba32float` and the matching `rgba8`, `rgba16`, `r32`, `rg32` and `rgba32`
     * integer formats. `bgra8unorm` needs the `bgra8unorm-storage` feature and formats such as `r8unorm`
     * or `r16float` need `texture-formats-tier1`; PixiJS enables both when the GPU has them. WebGPU rejects any
     * other format when the texture is created.
     * @example
     * ```ts
     * const volume = new TextureSource({ width: 64, height: 64, depth: 64, format: 'rgba8unorm', storage: true });
     *
     * // write it from your own compute pass (renderer is a WebGPURenderer)
     * const view = renderer.texture.getGpuSource(volume).createView();
     * // ... bind `view` to a `texture_storage_3d<rgba8unorm, write>`, dispatch, submit
     *
     * // then sample it in any PixiJS shader as a texture_3d
     * ```
     * @default false
     */
    storage?: boolean;
}
/**
 * The `depth` option, which makes a 3D texture. A texture is 3D (`depth`) or layered (`arrayLayerCount`),
 * never both, and TypeScript rejects options that set both.
 *
 * `depth` lives here rather than on {@link TextureSourceOptions} so that options typed with that interface
 * still pass to the constructor.
 * @category rendering
 * @advanced
 */
export type TextureShapeOptions = {
    /**
     * The depth of a 3D texture, in texels. Setting it makes a `'3d'` texture.
     *
     * Unlike `width` and `height`, `resolution` doesn't scale it. Can't be combined with `arrayLayerCount`.
     */
    depth: number;
    /** A 3D texture has no array layers */
    arrayLayerCount?: never;
    /** `depth` already makes the view `'3d'`, so only that value is accepted */
    viewDimension?: '3d';
    /** A 3D texture can't be multisampled. WebGPU has no such texture, and a volume is sampled, not resolved. */
    antialias?: false;
} | {
    /** Not a 3D texture: `arrayLayerCount` and `viewDimension` decide the shape */
    depth?: never;
};
/**
 * A TextureSource stores the information that represents an image.
 * All textures have require TextureSource, which contains information about the source.
 * Therefore you can have many textures all using a single TextureSource (eg a sprite sheet)
 *
 * This is an class is extended depending on the source of the texture.
 * Eg if you are using an an image as your resource, then an ImageSource is used.
 *
 * Pass `depth` for a 3D texture or `arrayLayerCount` for a 2D array (see {@link TextureShapeOptions}).
 * @category rendering
 * @advanced
 */
export declare class TextureSource<T extends Record<string, any> = any> extends EventEmitter<{
    change: BindResource;
    update: TextureSource;
    unload: TextureSource;
    destroy: TextureSource;
    resize: TextureSource;
    styleChange: TextureSource;
    updateMipmaps: TextureSource;
    error: Error;
}> implements BindResource, GPUDataOwner, GCable {
    protected readonly options: TextureSourceOptions<T> & TextureShapeOptions;
    /** The default options used when creating a new TextureSource. override these to add your own defaults */
    static defaultOptions: TextureSourceOptions;
    /** @internal */
    _gpuData: Record<number, GlTexture | GPUTextureGpuData>;
    /** GC tracking data, undefined if not being tracked */
    _gcData?: GCData;
    /** @internal */
    _gcLastUsed: number;
    /** unique id for this Texture source */
    readonly uid: number;
    /** optional label, can be used for debugging */
    label: string;
    /**
     * The resource type used by this TextureSource. This is used by the bind groups to determine
     * how to handle this resource.
     * @internal
     */
    readonly _resourceType = "textureSource";
    /**
     * i unique resource id, used by the bind group systems.
     * This can change if the texture is resized or its resource changes
     * @internal
     */
    _resourceId: number;
    /**
     * this is how the backends know how to upload this texture to the GPU
     * It changes depending on the resource type. Classes that extend TextureSource
     * should override this property.
     * @internal
     */
    uploadMethodId: string;
    /** @internal */
    _resolution: number;
    /** the pixel width of this texture source. This is the REAL pure number, not accounting resolution */
    pixelWidth: number;
    /** the pixel height of this texture source. This is the REAL pure number, not accounting resolution */
    pixelHeight: number;
    /**
     * the width of this texture source, accounting for resolution
     * eg pixelWidth 200, resolution 2, then width will be 100
     */
    width: number;
    /**
     * the height of this texture source, accounting for resolution
     * eg pixelHeight 200, resolution 2, then height will be 100
     */
    height: number;
    /**
     * the resource that will be uploaded to the GPU. This is where we get our pixels from
     * eg an ImageBimt / Canvas / Video etc
     */
    resource: T;
    /**
     * The number of samples of a multisample texture. This is always 1 for non-multisample textures.
     * To enable multisample for a texture, set antialias to true
     * @internal
     */
    sampleCount: number;
    /**
     * The number of mip levels to generate for this texture.
     * this is overridden if autoGenerateMipmaps is true. it is read only!
     */
    mipLevelCount: number;
    /**
     * Should we auto generate mipmaps for this texture? This will automatically generate mipmaps
     * for this texture when uploading to the GPU. Mipmapped textures take up more memory, but
     * can look better when scaled down.
     *
     * For performance reasons, it is recommended to NOT use this with RenderTextures, as they are often updated every frame.
     * If you do, make sure to call `updateMipmaps` after you update the texture.
     *
     * A 3D texture on WebGPU needs {@link TextureSourceOptions.storage} and `rgba8unorm` or `rgba16float`,
     * because a compute shader writes the mips. WebGL fills the chain with `gl.generateMipmap`.
     */
    autoGenerateMipmaps: boolean;
    /** the format that the texture data has */
    format: TEXTURE_FORMATS;
    /** how the texture is stored (WebGPU texture dimension), derived from {@link TextureSource#viewDimension} */
    dimension: TEXTURE_DIMENSIONS;
    /** how this texture is viewed/sampled by shaders (WebGPU view dimension) */
    viewDimension: TEXTURE_VIEW_DIMENSIONS;
    /** how many array layers this texture has; 1 for a 3D texture */
    arrayLayerCount: number;
    /** the depth of a 3D texture in texels; 1 for every other texture */
    depth: number;
    /**
     * The size along z that the GPU allocates: {@link TextureSource#depth} for a 3D texture,
     * {@link TextureSource#arrayLayerCount} otherwise. WebGPU's `depthOrArrayLayers`.
     */
    get depthOrArrayLayers(): number;
    /** the alpha mode of the texture */
    alphaMode: ALPHA_MODES;
    private _style;
    private _ownsStyle;
    /**
     * Only really affects RenderTextures.
     * Should we use antialiasing for this texture. It will look better, but may impact performance as a
     * Blit operation will be required to resolve the texture.
     */
    antialias: boolean;
    /**
     * Treat the underlying GPU texture as transient — see {@link TextureSourceOptions.transient}.
     * Internal flag, populated from options.
     * @internal
     */
    transient: boolean;
    /**
     * Whether compute shaders can write to this texture on WebGPU. See {@link TextureSourceOptions.storage}.
     * Read when the GPU texture is created.
     */
    storage: boolean;
    /**
     * Has the source been destroyed?
     * @readonly
     */
    destroyed: boolean;
    /**
     * Used by the batcher to build texture batches. faster to have the variable here!
     * @protected
     */
    _batchTick: number;
    /**
     * A temporary batch location for the texture batching. Here for performance reasons only!
     * @protected
     */
    _textureBindLocation: number;
    isPowerOfTwo: boolean;
    /** If true, the Garbage Collector will unload this texture if it is not used after a period of time */
    autoGarbageCollect: boolean;
    /**
     * used internally to know where a texture came from. Usually assigned by the asset loader!
     * @ignore
     */
    _sourceOrigin: string;
    /**
     * @param options - options for creating a new TextureSource
     */
    constructor(options?: TextureSourceOptions<T> & TextureShapeOptions);
    /** returns itself */
    get source(): TextureSource;
    /** the style of the texture */
    get style(): TextureStyle;
    set style(value: TextureStyle);
    /** Specifies the maximum anisotropy value clamp used by the sampler. */
    set maxAnisotropy(value: number);
    get maxAnisotropy(): number;
    /** setting this will set wrapModeU, wrapModeV and wrapModeW all at once! */
    get addressMode(): WRAP_MODE;
    set addressMode(value: WRAP_MODE);
    /** setting this will set wrapModeU, wrapModeV and wrapModeW all at once! */
    get repeatMode(): WRAP_MODE;
    set repeatMode(value: WRAP_MODE);
    /** Specifies the sampling behavior when the sample footprint is smaller than or equal to one texel. */
    get magFilter(): SCALE_MODE;
    set magFilter(value: SCALE_MODE);
    /** Specifies the sampling behavior when the sample footprint is larger than one texel. */
    get minFilter(): SCALE_MODE;
    set minFilter(value: SCALE_MODE);
    /** Specifies behavior for sampling between mipmap levels. */
    get mipmapFilter(): SCALE_MODE;
    set mipmapFilter(value: SCALE_MODE);
    /** Specifies the minimum and maximum levels of detail, respectively, used internally when sampling a texture. */
    get lodMinClamp(): number;
    set lodMinClamp(value: number);
    /** Specifies the minimum and maximum levels of detail, respectively, used internally when sampling a texture. */
    get lodMaxClamp(): number;
    set lodMaxClamp(value: number);
    private _onStyleChange;
    /** call this if you have modified the texture outside of the constructor */
    update(): void;
    /** Destroys this texture source */
    destroy(): void;
    /**
     * This will unload the Texture source from the GPU. This will free up the GPU memory
     * As soon as it is required fore rendering, it will be re-uploaded.
     */
    unload(): void;
    /** the width of the resource. This is the REAL pure number, not accounting resolution   */
    get resourceWidth(): number;
    /** the height of the resource. This is the REAL pure number, not accounting resolution */
    get resourceHeight(): number;
    /**
     * the resolution of the texture. Changing this number, will not change the number of pixels in the actual texture
     * but will the size of the texture when rendered.
     *
     * changing the resolution of this texture to 2 for example will make it appear twice as small when rendered (as pixel
     * density will have increased)
     */
    get resolution(): number;
    set resolution(resolution: number);
    /**
     * Resize the texture, this is handy if you want to use the texture as a render texture
     * @param width - the new width of the texture
     * @param height - the new height of the texture
     * @param resolution - the new resolution of the texture
     * @returns - if the texture was resized
     */
    resize(width?: number, height?: number, resolution?: number): boolean;
    /**
     * Lets the renderer know that this texture has been updated and its mipmaps should be re-generated.
     * This is only important for RenderTexture instances, as standard Texture instances will have their
     * mipmaps generated on upload. You should call this method after you make any change to the texture
     *
     * The reason for this is is can be quite expensive to update mipmaps for a texture. So by default,
     * We want you, the developer to specify when this action should happen.
     *
     * Generally you don't want to have mipmaps generated on Render targets that are changed every frame,
     */
    updateMipmaps(): void;
    set wrapMode(value: WRAP_MODE);
    get wrapMode(): WRAP_MODE;
    set scaleMode(value: SCALE_MODE);
    /** setting this will set magFilter,minFilter and mipmapFilter all at once!  */
    get scaleMode(): SCALE_MODE;
    /**
     * Refresh check for isPowerOfTwo texture based on size
     * @private
     */
    protected _refreshPOT(): void;
    static test(_resource: any): any;
    /**
     * A helper function that creates a new TextureSource based on the resource you provide.
     * @param resource - The resource to create the texture source from.
     */
    static from: (resource: TextureResourceOrOptions) => TextureSource;
}
