color.map.fromGPUTextureView¶
Summary¶
color.map.fromGPUTextureView uses an existing one-dimensional GPU texture as a colormap. Use it when the lookup table already lives on the GPU.
Syntax¶
fromGPUTextureView(device: GPUDevice, view: GPUTextureView, sampler: GPUSampler, width: number, filter?: ColormapFilter): Colormap
const map = WasmGPU.color.map.fromGPUTextureView(device, view, sampler, 4);
Parameters¶
| Name | Type | Required | Description |
|---|---|---|---|
device |
GPUDevice |
Yes | Device that owns both resources and will use the map. |
view |
GPUTextureView |
Yes | Sampleable "1d" view with a float sample type compatible with a filtering sampler. |
sampler |
GPUSampler |
Yes | Compatible sampler. For endpoint behavior matching built-ins, use "clamp-to-edge". |
width |
number |
Yes | Positive integer texel count matching the view. |
filter |
ColormapFilter |
No | "linear" by default. Match this metadata to the sampler that actually controls GPU filtering. |
Returns¶
Colormap - GPU-only map that borrows the view and sampler. It is also available as Colormap.fromGPUTextureView. The caller keeps the texture alive through GPU use and destroys it when finished.
Example¶
const wgpu = await WasmGPU.create(document.querySelector("canvas"));
const { device, queue } = wgpu.gpu;
const texture = device.createTexture({
dimension: "1d", size: [2], format: "rgba8unorm-srgb",
usage: GPUTextureUsage.COPY_DST | GPUTextureUsage.TEXTURE_BINDING
});
queue.writeTexture({ texture }, new Uint8Array([0, 0, 0, 255, 255, 255, 255, 255]), {}, [2]);
const view = texture.createView({ dimension: "1d" });
const sampler = device.createSampler({ minFilter: "linear", magFilter: "linear" });
const map = wgpu.color.map.fromGPUTextureView(device, view, sampler, 2);
console.log(map.getGPUResources(device, queue).view === view); // true
texture.destroy();
Notes¶
canSampleCPU is false. CPU sampling, table reads and reversal throw. A legend that generates a CSS gradient requires a CPU-sampleable map.