Texture
Introduction
vtkTexture is an image algorithm that handles loading and binding of texture maps. It obtains its data from an input image data dataset type. Thus you can create visualization pipelines to read, process, and construct textures. Note that textures will only work if texture coordinates are also defined, and if the rendering system supports texture.
This class is used in both WebGL and WebGPU rendering backends, but the implementation details may vary. In WebGL, it uses HTMLImageElement and HTMLCanvasElement for textures, while in WebGPU, it uses HTMLImageElement, HTMLCanvasElement, and ImageBitmap.
Methods
extend
Method use to decorate a given object (publicAPI+model) with vtkTexture characteristics.
| Argument | Type | Required | Description |
|---|---|---|---|
publicAPI | Yes | object on which methods will be bounds (public) | |
model | Yes | object on which data structure will be bounds (protected) | |
initialValues | ITextureInitialValues | No | (default: {}) |
generateMipmaps
Generates mipmaps for a given GPU texture using a compute shader.
This function iteratively generates each mip level for the provided texture, using a bilinear downsampling compute shader implemented in WGSL. It creates the necessary pipeline, bind groups, and dispatches compute passes for each mip level.
| Argument | Type | Required | Description |
|---|---|---|---|
device | GPUDevice | Yes | - The WebGPU device used to create resources and submit commands. |
texture | GPUTexture | Yes | - The GPU texture for which mipmaps will be generated. |
mipLevelCount | number | Yes | - The total number of mip levels to generate (including the base level). |
getCanvas
Returns the canvas used by the texture.
getEdgeClamp
Returns true if the texture is set to clamp at the edges.
getImage
Returns the image used by the texture.
getImageBitmap
Returns an ImageBitmap object.
getImageLoaded
Returns true if the image is loaded.
getInputAsJsImageData
Returns the input image data object.
getInterpolate
Returns true if the texture is set to interpolate between texels.
getMipLevel
Returns the current mip level of the texture.
getRepeat
Returns true if the texture is set to repeat at the edges.
getResizable
Returns true if the texture can be resized at run time. This is useful for dynamic textures that may change size based on user interaction or other factors.
newInstance
Method use to create a new instance of vtkTexture.
| Argument | Type | Required | Description |
|---|---|---|---|
initialValues | ITextureInitialValues | No | for pre-setting some of its content |
setCanvas
Returns the canvas used by the texture.
setEdgeClamp
Sets the texture to clamp at the edges.
| Argument | Type | Required | Description |
|---|---|---|---|
edgeClamp | Yes |
setImage
Sets the image used by the texture.
| Argument | Type | Required | Description |
|---|---|---|---|
image | Yes |
setImageBitmap
Sets the image as an ImageBitmap object. Supported in WebGPU only.
| Argument | Type | Required | Description |
|---|---|---|---|
imageBitmap | Yes |
setInterpolate
Sets the texture to interpolate between texels.
| Argument | Type | Required | Description |
|---|---|---|---|
interpolate | Yes |
setJsImageData
Sets the input image data as a JavaScript ImageData object.
| Argument | Type | Required | Description |
|---|---|---|---|
imageData | Yes |
setMipLevel
Sets the current mip level of the texture.
| Argument | Type | Required | Description |
|---|---|---|---|
level | Yes |
setRepeat
Sets the texture to repeat at the edges.
| Argument | Type | Required | Description |
|---|---|---|---|
repeat | Yes |