wgpu-mipmap
v0.2.0
Published
WebGPU Mipmap provides couple of functionalities to generate mipmaps for textures.
Readme
wgpu-mipmap
The WebGPU mipmap generator implemented in TypeScript. Used generate mipmaps from an Image, ByteArray or GPUTexture.
Usage
Only prerequisite that package expects is to have GPUDevice created. There are multiple function and classes that can be used to generate mipmaps.
For example if you have already created GPUDevice and GPUTexture wgpuGenerateExtureMipmap can be used to generate views and mipmaps.
Afterwards just use your texture as usual.
import { wgpuGenerateTextureMipmap } from './wgpu-mipmap.ts';
// ...
wgpuGenerateTextureMipmap(yourGPUDevice, yourGPUTexture);For more advanced scenarios import WGPUMipmapGenerator itself. For example if you want to generate mipmaps but also get them as HTMLImageElement call generateMipmapsAndCreateImages on WGPUMipmapGenerator.
import { WGPUMipmapGenerator } from './wgpu-mipmap.ts';
const mipmapGenerator = new WGPUMipmapGenerator(yourGPUDevice);
const result = await mipmapGenerator.generateMipmapsAndCreateImages(htmlImageElement);
const htmlImageElements = result.imageElements;
const gpuTexture = result.gpuTexture;Known issues
The mipmap generator uses Compute shaders with texture_storage_2d type to write texture mipmaps. TextureStorage does not support all formats, even some common ones like bgra8unorm, therefore device must be initialized with bgra8unorm-storage feature as required in order to use it.
const device = await adapter.requestDevice({
requiredFeatures: ["bgra8unorm-storage"],
});VERSION
0.1.0
- Initial release.
wgpuGenerateTextureMipmapfunction that takesGPUDeviceandGPUTextureto create mipmaps.WGPUMipmapGeneratorinstance can be used for more advanced scenarios. SupportsgenerateMipmapsandgenerateMipmapsAndCreateImages.
0.2.0
- Support for
bgra8unormtexture type. - Passed as last parameter.
