MCPcopy
hub / github.com/visgl/deck.gl / createTexture

Function createTexture

modules/core/src/utils/texture.ts:29–69  ·  view source on GitHub ↗
(
  owner: string,
  device: Device,
  image: any,
  sampler: SamplerProps
)

Source from the content-addressed store, hash-verified

27 * @returns
28 */
29export 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
71export function destroyTexture(owner: string, texture: Texture) {
72 if (!texture || !(texture instanceof Texture)) {

Callers 1

prop-types.tsFile · 0.90

Calls 1

createTextureMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…