Skip to content

UWAL / Texture

Type Aliases

Addresses

ts
type Addresses = Readonly<Record<"CLAMP" | "REPEAT" | "MIRROR", GPUAddressMode>>;

Type Parameters

Type Parameter

Filters

ts
type Filters = Readonly<Record<"NEAREST" | "LINEAR", GPUFilterMode>>;

Type Parameters

Type Parameter

OptionalGPUExtent3DStrict

ts
type OptionalGPUExtent3DStrict = Partial<GPUExtent3DDict> & Partial<Record<"size", Iterable<GPUIntegerCoordinate>>>;

Type Parameters

Type Parameter

TextureDescriptor

ts
type TextureDescriptor = Partial<GPUTextureDescriptor> & Partial<Record<"mipmaps", boolean>>;

Type Parameters

Type Parameter

Interfaces

SamplerDescriptor

Properties

addressModeUV?
ts
optional addressModeUV?: GPUAddressMode;

addressMode?
ts
optional addressMode?: GPUAddressMode;

minMagFilter?
ts
optional minMagFilter?: GPUFilterMode;

filter?
ts
optional filter?: GPUFilterMode;

CopyImageOptions

Properties

create?
ts
optional create?: boolean | TextureDescriptor;

colorSpace?
ts
optional colorSpace?: PredefinedColorSpace;

mipLevel?
ts
optional mipLevel?: number;

destinationOrigin?
ts
optional destinationOrigin?: GPUOrigin3D;

premultipliedAlpha?
ts
optional premultipliedAlpha?: boolean;

sourceOrigin?
ts
optional sourceOrigin?: GPUOrigin2D;

aspect?
ts
optional aspect?: GPUTextureAspect;

texture?
ts
optional texture?: GPUTexture;

mipmaps?
ts
optional mipmaps?: boolean;

flipY?
ts
optional flipY?: boolean;

CopyBufferOptions

Properties

create?
ts
optional create?: boolean | TextureDescriptor;

source?
ts
optional source?: GPUCopyExternalImageSource;

CopyTextureOptions

Properties

srcMipLevel?
ts
optional srcMipLevel?: number;

dstMipLevel?
ts
optional dstMipLevel?: number;

srcAspect?
ts
optional srcAspect?: GPUTextureAspect;

dstAspect?
ts
optional dstAspect?: GPUTextureAspect;

srcOrigin?
ts
optional srcOrigin?: GPUOrigin3D;

dstOrigin?
ts
optional dstOrigin?: GPUOrigin3D;

srcTexture?
ts
optional srcTexture?: GPUTexture;

dstTexture?
ts
optional dstTexture?: GPUTexture;

Classes

Texture

Utility class to manage textures and samplers.

Methods

CreateSampler()
ts
CreateSampler(descriptor?): GPUSampler;

Create a new sampler from the descriptor object.

Parameters
ParameterTypeDescription
descriptor?GPUSamplerDescriptor & SamplerDescriptorSamplerDescriptor.addressModeUV is for width and height; SamplerDescriptor.addressMode is for all 3 dimensions; SamplerDescriptor.minMagFilter is for min and mag, and SamplerDescriptor.filter is for min, mag and mipmapFilter.
Returns

GPUSampler

See

https://www.w3.org/TR/webgpu/#dom-gpudevice-createsampler

CreateTexture()
ts
CreateTexture(descriptor): GPUTexture;

Create a new texture from the descriptor object.

Parameters
ParameterTypeDescription
descriptorPick<Partial<GPUTextureDescriptor>, "usage" | "format"> & Omit<GPUTextureDescriptor, "usage" | "format">format and usage are optional and default to Device.PreferredCanvasFormat and USAGE.RENDER, respectively
Returns

GPUTexture

See

https://www.w3.org/TR/webgpu/#dom-gpudevice-createtexture

WriteTexture()
ts
WriteTexture(data, options): void;

Write data into a GPUTexture.

Parameters
ParameterTypeDescription
dataGPUAllowSharedBufferSourceData to write
optionsGPUTexelCopyTextureInfo & GPUTexelCopyBufferLayout & Partial<GPUExtent3DDict> & Partial<Record<"size", Iterable<number, any, any>>>A union of destination, dataLayout and size arguments
Returns

void

See

https://www.w3.org/TR/webgpu/#dom-gpuqueue-writetexture

CreateStorageTexture()
ts
CreateStorageTexture(descriptor?): GPUTexture;

Create a new storage texture.

Parameters
ParameterTypeDescription
descriptorPick<Partial<GPUTextureDescriptor>, "usage" | "size" | "format"> & Omit<GPUTextureDescriptor, "usage" | "size" | "format">format, usage and size are optional and default to PreferredStorageFormat, USAGE.STORAGE, and canvas size, respectively
Returns

GPUTexture

CreateTextureFromSource()
ts
CreateTextureFromSource(source, descriptor?): GPUTexture;

Create a new texture using an existing GPUTexture or any valid external image sources.

Parameters
ParameterTypeDescription
sourceGPUTexture | GPUCopyExternalImageSourceGPUTexture or an image source reference
descriptor?boolean | TextureDescriptorDefaults to { mipmaps: true }
Returns

GPUTexture

ImportExternalTexture()
ts
ImportExternalTexture(
   source, 
   label?, 
   colorSpace?): GPUExternalTexture;

Create a new GPUExternalTexture from a video source.

Parameters
ParameterTypeDescription
sourceHTMLVideoElement | VideoFrameVideo source reference
label?stringDescriptor label
colorSpace?PredefinedColorSpacePredefined color space
Returns

GPUExternalTexture

See

CreateImageBitmap()
ts
CreateImageBitmap(
   source, 
   options?, 
requestOptions?): Promise<ImageBitmap>;

Create a bitmap image from a valid source path.

Parameters
ParameterTypeDescription
sourcestringImage source path
options?ImageBitmapOptionsBitmap options
requestOptions?RequestInitfetch request options
Returns

Promise<ImageBitmap>

See

https://developer.mozilla.org/en-US/docs/Web/API/Window/createImageBitmap

CreateMultisampleTexture()
ts
CreateMultisampleTexture(
   force?, 
   sampleCount?, 
   label?): GPUTexture;

Create a multisampled texture for the Renderer.MultisampleTexture.

Parameters
ParameterTypeDefault valueDescription
force?booleanfalseForce a new texture to be created
sampleCount?number4Must be either 1 or 4
label?stringundefinedDescriptor label
Returns

GPUTexture

Throws

ERROR.RENDERER_NOT_FOUND if Renderer is not provided.

CopyImageToTexture()
ts
CopyImageToTexture(source, options?): Promise<GPUTexture>;

Copy an image source into a texture and optionally generate mipmaps for it. If options.texture is not provided, a new GPUTexture is created by default.

Parameters
ParameterTypeDescription
sourceGPUCopyExternalImageSourceImage source reference
options?Partial<GPUExtent3DDict> & Partial<Record<"size", Iterable<number, any, any>>> & CopyImageOptionsDefaults to { create: true, flipY: true }
Returns

Promise<GPUTexture>

See

https://www.w3.org/TR/webgpu/#dom-gpuqueue-copyexternalimagetotexture

Throws

ERROR.TEXTURE_NOT_FOUND if called without options.texture and with options.create being falsy when options.mipmaps is true or undefined.

CreateCubeTexture()
ts
CreateCubeTexture(
   sources, 
   bitmapOptions?, 
   textureDescriptor?, 
   copyOptions?, 
requestOptions?): Promise<GPUTexture>;

Create a "cube" texture from 6 image sources. All images must have the same dimensions. This method creates a bitmap image for each source and one cube texture and uses that as the destination when copying bitmaps with flipY option set to false.

Parameters
ParameterTypeDescription
sourcesstring[]Array of 6 valid source paths
bitmapOptions?ImageBitmapOptionsBitmap options for CreateImageBitmap method
textureDescriptor?TextureDescriptorTexture descriptor for CreateTextureFromSource method
copyOptions?CopyImageOptionsCopy options for CopyImageToTexture method
requestOptions?RequestInitfetch request options for CreateImageBitmap method
Returns

Promise<GPUTexture>

Throws

ERROR.RENDERER_NOT_FOUND if Renderer is not provided.

See

CopyTextureToTexture()
ts
CopyTextureToTexture(options): void;

Copy options.srcTexture into options.dstTexture. If options.dstTexture is omitted, it defaults to options.srcTexture. If options.srcTexture is omitted, it defaults first to options.source and then, if it's not defined, this method creates a new texture using options.create descriptor.

Parameters
ParameterTypeDescription
optionsPartial<GPUExtent3DDict> & Partial<Record<"size", Iterable<number, any, any>>> & CopyBufferOptions & CopyTextureOptionsCopy options
Returns

void

See

https://www.w3.org/TR/webgpu/#dom-gpucommandencoder-copytexturetotexture

Throws

ERROR.RENDERER_NOT_FOUND if Renderer is not provided and ERROR.TEXTURE_NOT_FOUND if called without options.srcTexture, options.source, and with options.create being falsy.

CopyTextureToBuffer()
ts
CopyTextureToBuffer(options): void;

Copy options.texture into options.buffer. If options.texture is omitted, a new one is created using options.source reference.

Parameters
ParameterTypeDescription
optionsGPUTexelCopyBufferInfo & Partial<GPUTexelCopyTextureInfo> & Partial<GPUExtent3DDict> & Partial<Record<"size", Iterable<number, any, any>>> & CopyBufferOptionsCopy options
Returns

void

See

https://www.w3.org/TR/webgpu/#dom-gpucommandencoder-copytexturetobuffer

Throws

ERROR.RENDERER_NOT_FOUND if Renderer is not provided and ERROR.TEXTURE_NOT_FOUND if called without options.texture, options.source, and with options.create being falsy.

CopyBufferToTexture()
ts
CopyBufferToTexture(options): void;

Copy options.buffer into options.texture. If options.texture is omitted, a new one is created using options.source reference.

Parameters
ParameterTypeDescription
optionsGPUTexelCopyBufferInfo & Partial<GPUTexelCopyTextureInfo> & Partial<GPUExtent3DDict> & Partial<Record<"size", Iterable<number, any, any>>> & CopyBufferOptionsCopy options
Returns

void

See

https://www.w3.org/TR/webgpu/#dom-gpucommandencoder-copybuffertotexture

Throws

ERROR.RENDERER_NOT_FOUND if Renderer is not provided and ERROR.TEXTURE_NOT_FOUND if called without options.texture, options.source, and with options.create being falsy.

Destroy()
ts
Destroy(): undefined;

Destroy the multisample texture created in CreateMultisampleTexture.

Returns

undefined

Accessors

PreferredStorageFormat
Get Signature
ts
get PreferredStorageFormat(): GPUTextureFormat;
Returns

GPUTextureFormat

Preferred format for storage textures. The only possible values are "rgba8unorm" and "bgra8unorm".

Renderer
Set Signature
ts
set Renderer(renderer): void;
Parameters
ParameterTypeDescription
rendererRenderStageRenderer instance required in some methods
Returns

void

Released under the MIT License.