import { gl , ITexture2D , ITexture2DInitializationOptions , } from '@antv/g-webgpu-core' ; import * as WebGPUConstants from '@webgpu/types/dist/constants' ; import { WebGPUEngine } from '.' ; import { filterMap , formatMap , wrapModeMap } from './constants' ; see https export default class WebGPUTexture2D implements ITexture2D { private texture : GPUTexture ; private sampler : GPUSampler ; private width : number ; private height : number ; constructor ( private engine , private options ) { this . createTexture ( ) ; } public get ( ) { return { texture : this . texture , sampler : this . sampler , } ; } public update ( ) { } public resize ( { width , height } ) { if ( width !== this . width || height !== this . height ) { this . destroy ( ) ; this . createTexture ( ) ; } this . width = width ; this . height = height ; } public destroy ( ) { if ( this . texture ) { this . texture . destroy ( ) ; } } private createTexture ( ) { const { data , type = gl . UNSIGNED_BYTE , width , height , flipY = false , format = gl . RGBA , mipmap = false , wrapS = gl . CLAMP_TO_EDGE , wrapT = gl . CLAMP_TO_EDGE , aniso = 0 , alignment = 1 , premultiplyAlpha = false , mag = gl . NEAREST , min = gl . NEAREST , colorSpace = gl . BROWSER_DEFAULT_WEBGL , usage , } = this . options ; this . width = width ; this . height = height ; this . texture = this . engine . device . createTexture ( { size : [ width , height , 1 ] , mipLevelCount : 1 , sampleCount : 1 , dimension : WebGPUConstants . TextureDimension . E2d , format : formatMap [ format ] , usage : usage || WebGPUConstants . TextureUsage . Sampled | WebGPUConstants . TextureUsage . CopyDst , } ) ; if ( ! usage || usage & WebGPUConstants . TextureUsage . Sampled ) { this . sampler = this . engine . device . createSampler ( { addressModeU : wrapModeMap [ wrapS ] , addressModeV : wrapModeMap [ wrapT ] , addressModeW : wrapModeMap [ wrapS ] , magFilter : filterMap [ mag ] , minFilter : filterMap [ min ] , maxAnisotropy : aniso , } ) ; } } }