import type { BufferData, GpuContext, GpuTexture } from "./types.js"; export interface TextureByteSizeOptions extends Partial> { width?: number; height?: number; /** Depth or array layer count. Falls back to `depthOrArrayLayers`. */ depth?: number; depthOrArrayLayers?: number; } /** * Estimated memory footprint of a texture, in bytes — from an existing * {@link GpuTexture} or from a descriptor, so allocation can be budgeted before * anything is created. * * An estimate, not a guarantee: depth/stencil texel sizes and any driver-side * padding, alignment or metadata (HTILE, DCC, ...) are implementation-defined. */ export declare function textureByteSize(descriptor: GpuTexture | TextureByteSizeOptions): number; export type ExternalImageSource = ImageBitmap | HTMLImageElement | HTMLVideoElement | VideoFrame | HTMLCanvasElement | OffscreenCanvas; export interface CreateTextureOptions extends GPUObjectDescriptorBase, Partial>, Partial, Pick, Pick { /** Texture format. Required in raw WebGPU; defaults to `"rgba8unorm"` here. */ format?: GPUTextureFormat; /** * Initial contents for mip level 0: raw data, or one or more * images/canvases/video frames — a single source makes a 2D texture, an array * of 6 with `viewDimension: "cube"` makes a cubemap, any other array makes a * 2D texture array (one source per layer). */ data?: BufferData | ExternalImageSource | ExternalImageSource[]; /** * Depth or array layer count. Falls back to `depthOrArrayLayers`, then to the * number of image sources in `data`. */ depth?: number; /** * Allocate and generate the full mip chain from the uploaded data. For * explicit level counts, see `mipLevelCount`. */ mipmap?: boolean; /** * Pre-computed mip chain, largest first, one entry per level — the way to mip * compressed formats, which cannot be rendered into and so cannot use * `mipmap`. Sets `mipLevelCount`, and each level's size is the base size * halved per level. */ mipLevels?: BufferData[]; /** Dimension of the cached default view, eg. "cube" for cubemaps. */ viewDimension?: GPUTextureViewDimension; /** * Usage flags. Required in raw WebGPU; defaults to `TEXTURE_BINDING | * COPY_DST | RENDER_ATTACHMENT` here — set explicitly to replace (not merge * with) that default. */ usage?: GPUTextureUsageFlags; } /** Number of mip levels in a full chain for the given dimensions. */ export declare const fullMipLevelCount: (width: number, height?: number) => number; /** Type guard for {@link GpuTexture} resource objects. */ export declare const isGpuTexture: (value: unknown) => value is GpuTexture; /** * Create a texture. Initial contents can be raw data or image sources — * dimensions, layer count and array view dimension are inferred from images. * * ```js * const texture = gpu.createTexture(ctx, { * width: 2, * height: 1, * data: [255, 255, 255, 255, 0, 0, 0, 255], * }); * const depth = gpu.createTexture(ctx, { * width, * height, * format: "depth24plus", * }); * const photo = gpu.createTexture(ctx, { * data: image, * mipmap: true, * flipY: true, * }); * const cubemap = gpu.createTexture(ctx, { * data: faces, * viewDimension: "cube", * }); * const compressed = gpu.createTexture(ctx, { * width, * height, * format: "bc7-rgba-unorm", * mipLevels: levels, * }); * ``` */ export declare function createTexture(ctx: GpuContext, options: CreateTextureOptions): GpuTexture; export interface UpdateTextureOptions extends Pick, Partial> { } /** * Upload raw data into a texture region. Float formats accept a plain number * array (packed at the format's precision); integer, unorm, snorm and packed * formats require a matching typed array — its bytes are uploaded as-is. * * ```js * gpu.updateTexture(ctx, texture, pixels); * gpu.updateTexture(ctx, cubemap, facePixels, { * origin: [0, 0, faceIndex], * }); * ``` */ export declare function updateTexture(ctx: GpuContext, target: GpuTexture, data: BufferData, options?: UpdateTextureOptions): void; export interface CopyExternalImageOptions extends Pick, Pick, Pick { /** * Copy extent override. Defaults to the source size, shifted down for mip * levels. */ width?: number; height?: number; } /** Copy an image, canvas or video frame into a texture. */ export declare function copyExternalImage(ctx: GpuContext, target: GpuTexture, source: ExternalImageSource, options?: CopyExternalImageOptions): void; export interface GenerateMipmapsOptions { /** * Record into this encoder instead of creating one. Pass the encoder of an * open batched frame (e.g. from inside `gpu.frame` or a frame graph pass) to * keep the mip chain in submission order with the rest of that frame; the * caller owns `finish()`/`submit()` in that case. Omitted, a dedicated * encoder is created and submitted immediately. */ encoder?: GPUCommandEncoder; } /** * Generate the full mip chain of a 2D or 2D-array texture by downsampling each * level with a linear-filtered blit. */ export declare function generateMipmaps(ctx: GpuContext, target: GpuTexture, options?: GenerateMipmapsOptions): void; /** * Row pitch aligned to 256, the alignment `copyBufferToTexture` and * `copyTextureToBuffer` require (`queue.writeTexture` does not — see * {@link texelCopyLayout}). Compressed formats are measured in whole blocks. */ export declare const paddedBytesPerRow: (width: number, format: GPUTextureFormat) => number; //# sourceMappingURL=texture.d.ts.map