( owner: string, device: Device, image: any, sampler: SamplerProps )
| 27 | * @returns |
| 28 | */ |
| 29 | export function createTexture( |
| 30 | owner: string, |
| 31 | device: Device, |
| 32 | image: any, |
| 33 | sampler: SamplerProps |
| 34 | ): Texture | null { |
| 35 | if (image instanceof Texture) { |
| 36 | return image; |
| 37 | } else if (image.constructor && image.constructor.name !== 'Object') { |
| 38 | // Browser object |
| 39 | image = {data: image}; |
| 40 | } |
| 41 | |
| 42 | let samplerParameters: SamplerProps | null = null; |
| 43 | if (image.compressed) { |
| 44 | samplerParameters = { |
| 45 | minFilter: 'linear', |
| 46 | mipmapFilter: image.data.length > 1 ? 'nearest' : 'linear' |
| 47 | }; |
| 48 | } |
| 49 | |
| 50 | const {width, height} = image.data; |
| 51 | const texture = device.createTexture({ |
| 52 | ...image, |
| 53 | sampler: { |
| 54 | ...DEFAULT_TEXTURE_PARAMETERS, |
| 55 | ...samplerParameters, |
| 56 | ...sampler |
| 57 | }, |
| 58 | mipLevels: device.getMipLevelCount(width, height) |
| 59 | }); |
| 60 | if (device.type === 'webgl') { |
| 61 | texture.generateMipmapsWebGL(); |
| 62 | } else if (device.type === 'webgpu') { |
| 63 | device.generateMipmapsWebGPU(texture); |
| 64 | } |
| 65 | |
| 66 | // Track this texture |
| 67 | internalTextures[texture.id] = owner; |
| 68 | return texture; |
| 69 | } |
| 70 | |
| 71 | export function destroyTexture(owner: string, texture: Texture) { |
| 72 | if (!texture || !(texture instanceof Texture)) { |
no test coverage detected
searching dependent graphs…