UWAL / Texture
Type Aliases
Addresses
type Addresses = Readonly<Record<"CLAMP" | "REPEAT" | "MIRROR", GPUAddressMode>>;Type Parameters
| Type Parameter |
|---|
Filters
type Filters = Readonly<Record<"NEAREST" | "LINEAR", GPUFilterMode>>;Type Parameters
| Type Parameter |
|---|
OptionalGPUExtent3DStrict
type OptionalGPUExtent3DStrict = Partial<GPUExtent3DDict> & Partial<Record<"size", Iterable<GPUIntegerCoordinate>>>;Type Parameters
| Type Parameter |
|---|
TextureDescriptor
type TextureDescriptor = Partial<GPUTextureDescriptor> & Partial<Record<"mipmaps", boolean>>;Type Parameters
| Type Parameter |
|---|
Interfaces
SamplerDescriptor
Properties
addressModeUV?
optional addressModeUV?: GPUAddressMode;addressMode?
optional addressMode?: GPUAddressMode;minMagFilter?
optional minMagFilter?: GPUFilterMode;filter?
optional filter?: GPUFilterMode;CopyImageOptions
Properties
create?
optional create?: boolean | TextureDescriptor;colorSpace?
optional colorSpace?: PredefinedColorSpace;mipLevel?
optional mipLevel?: number;destinationOrigin?
optional destinationOrigin?: GPUOrigin3D;premultipliedAlpha?
optional premultipliedAlpha?: boolean;sourceOrigin?
optional sourceOrigin?: GPUOrigin2D;aspect?
optional aspect?: GPUTextureAspect;texture?
optional texture?: GPUTexture;mipmaps?
optional mipmaps?: boolean;flipY?
optional flipY?: boolean;CopyBufferOptions
Properties
create?
optional create?: boolean | TextureDescriptor;source?
optional source?: GPUCopyExternalImageSource;CopyTextureOptions
Properties
srcMipLevel?
optional srcMipLevel?: number;dstMipLevel?
optional dstMipLevel?: number;srcAspect?
optional srcAspect?: GPUTextureAspect;dstAspect?
optional dstAspect?: GPUTextureAspect;srcOrigin?
optional srcOrigin?: GPUOrigin3D;dstOrigin?
optional dstOrigin?: GPUOrigin3D;srcTexture?
optional srcTexture?: GPUTexture;dstTexture?
optional dstTexture?: GPUTexture;Classes
Texture
Utility class to manage textures and samplers.
Methods
CreateSampler()
CreateSampler(descriptor?): GPUSampler;Create a new sampler from the descriptor object.
Parameters
| Parameter | Type | Description |
|---|---|---|
descriptor? | GPUSamplerDescriptor & SamplerDescriptor | SamplerDescriptor.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()
CreateTexture(descriptor): GPUTexture;Create a new texture from the descriptor object.
Parameters
| Parameter | Type | Description |
|---|---|---|
descriptor | Pick<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()
WriteTexture(data, options): void;Write data into a GPUTexture.
Parameters
| Parameter | Type | Description |
|---|---|---|
data | GPUAllowSharedBufferSource | Data to write |
options | GPUTexelCopyTextureInfo & 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()
CreateStorageTexture(descriptor?): GPUTexture;Create a new storage texture.
Parameters
| Parameter | Type | Description |
|---|---|---|
descriptor | Pick<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()
CreateTextureFromSource(source, descriptor?): GPUTexture;Create a new texture using an existing GPUTexture or any valid external image sources.
Parameters
| Parameter | Type | Description |
|---|---|---|
source | GPUTexture | GPUCopyExternalImageSource | GPUTexture or an image source reference |
descriptor? | boolean | TextureDescriptor | Defaults to { mipmaps: true } |
Returns
GPUTexture
ImportExternalTexture()
ImportExternalTexture(
source,
label?,
colorSpace?): GPUExternalTexture;Create a new GPUExternalTexture from a video source.
Parameters
| Parameter | Type | Description |
|---|---|---|
source | HTMLVideoElement | VideoFrame | Video source reference |
label? | string | Descriptor label |
colorSpace? | PredefinedColorSpace | Predefined color space |
Returns
GPUExternalTexture
See
- Video Color Grading example for reference.
- https://www.w3.org/TR/webgpu/#dom-gpudevice-importexternaltexture
CreateImageBitmap()
CreateImageBitmap(
source,
options?,
requestOptions?): Promise<ImageBitmap>;Create a bitmap image from a valid source path.
Parameters
| Parameter | Type | Description |
|---|---|---|
source | string | Image source path |
options? | ImageBitmapOptions | Bitmap options |
requestOptions? | RequestInit | fetch request options |
Returns
Promise<ImageBitmap>
See
https://developer.mozilla.org/en-US/docs/Web/API/Window/createImageBitmap
CreateMultisampleTexture()
CreateMultisampleTexture(
force?,
sampleCount?,
label?): GPUTexture;Create a multisampled texture for the Renderer.MultisampleTexture.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
force? | boolean | false | Force a new texture to be created |
sampleCount? | number | 4 | Must be either 1 or 4 |
label? | string | undefined | Descriptor label |
Returns
GPUTexture
Throws
ERROR.RENDERER_NOT_FOUND if Renderer is not provided.
CopyImageToTexture()
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
| Parameter | Type | Description |
|---|---|---|
source | GPUCopyExternalImageSource | Image source reference |
options? | Partial<GPUExtent3DDict> & Partial<Record<"size", Iterable<number, any, any>>> & CopyImageOptions | Defaults 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()
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
| Parameter | Type | Description |
|---|---|---|
sources | string[] | Array of 6 valid source paths |
bitmapOptions? | ImageBitmapOptions | Bitmap options for CreateImageBitmap method |
textureDescriptor? | TextureDescriptor | Texture descriptor for CreateTextureFromSource method |
copyOptions? | CopyImageOptions | Copy options for CopyImageToTexture method |
requestOptions? | RequestInit | fetch request options for CreateImageBitmap method |
Returns
Promise<GPUTexture>
Throws
ERROR.RENDERER_NOT_FOUND if Renderer is not provided.
See
- Environment maps and SkyBox lessons for reference.
- https://www.w3.org/TR/webgpu/#dom-gputextureviewdimension-cube
CopyTextureToTexture()
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
| Parameter | Type | Description |
|---|---|---|
options | Partial<GPUExtent3DDict> & Partial<Record<"size", Iterable<number, any, any>>> & CopyBufferOptions & CopyTextureOptions | Copy 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()
CopyTextureToBuffer(options): void;Copy options.texture into options.buffer. If options.texture is omitted, a new one is created using options.source reference.
Parameters
| Parameter | Type | Description |
|---|---|---|
options | GPUTexelCopyBufferInfo & Partial<GPUTexelCopyTextureInfo> & Partial<GPUExtent3DDict> & Partial<Record<"size", Iterable<number, any, any>>> & CopyBufferOptions | Copy 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()
CopyBufferToTexture(options): void;Copy options.buffer into options.texture. If options.texture is omitted, a new one is created using options.source reference.
Parameters
| Parameter | Type | Description |
|---|---|---|
options | GPUTexelCopyBufferInfo & Partial<GPUTexelCopyTextureInfo> & Partial<GPUExtent3DDict> & Partial<Record<"size", Iterable<number, any, any>>> & CopyBufferOptions | Copy 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()
Destroy(): undefined;Destroy the multisample texture created in CreateMultisampleTexture.
Returns
undefined
Accessors
PreferredStorageFormat
Get Signature
get PreferredStorageFormat(): GPUTextureFormat;Returns
GPUTextureFormat
Preferred format for storage textures. The only possible values are "rgba8unorm" and "bgra8unorm".
Renderer
Set Signature
set Renderer(renderer): void;Parameters
| Parameter | Type | Description |
|---|---|---|
renderer | RenderStage | Renderer instance required in some methods |
Returns
void