wgpu-mipmap
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

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.
  • wgpuGenerateTextureMipmap function that takes GPUDevice and GPUTexture to create mipmaps.
  • WGPUMipmapGenerator instance can be used for more advanced scenarios. Supports generateMipmaps and generateMipmapsAndCreateImages.

0.2.0

  • Support for bgra8unorm texture type.
  • Passed as last parameter.

Readme

Keywords

none

Package Sidebar

Install

npm i wgpu-mipmap

Weekly Downloads

47

Version

0.2.0

License

MIT

Unpacked Size

88.5 kB

Total Files

18

Last publish

Collaborators

  • lerkapic